54 static int ParseParams(
programparams *Param,
int argc,
char *argv[]);
60 puts(
"Image mosaicing utility, P. Getreuer 2010-2011\n");
61 puts(
"Usage: mosaic [options] <input file> <output file>\n\n"
64 puts(
" -p <pattern> CFA pattern, choices for <pattern> are");
65 puts(
" RGGB upperleftmost red pixel is at (0,0)");
66 puts(
" GRBG upperleftmost red pixel is at (1,0)");
67 puts(
" GBRG upperleftmost red pixel is at (0,1)");
68 puts(
" BGGR upperleftmost red pixel is at (1,1)\n");
69 puts(
" -f Flatten result to a grayscale image");
70 puts(
" -r Add one extra row to the top");
71 puts(
" -c Add one extra column to the left");
72 puts(
" -e <padding> Add <padding> pixels to each border of the image");
73 puts(
" -v Verbose output\n");
75 puts(
" -q <number> Quality for saving JPEG images (0 to 100)\n");
78 " mosaic -v -p RGGB frog.bmp frog-m.bmp");
88 static int WSymExtension(
int N,
int n)
102 int main(
int argc,
char *argv[])
105 image u = {NULL, 0, 0}, f = {NULL, 0, 0};
107 int i, x, y, xOffset, yOffset, Green, Status = 1;
112 if(!ParseParams(&Param, argc, argv))
115 Green = 1 - ((Param.
RedX + Param.
RedY) & 1);
119 IMAGEIO_U8 | IMAGEIO_RGBA)))
125 if(!(f.Data = (uint32_t *)
Malloc(
sizeof(uint32_t)*f.Width*f.Height)))
132 printf(
"Resampling with pattern\n\n");
135 for(y = 0; y < f.Height; y++)
136 for(x = 0; x < f.Width; x++)
138 Pixel = u.
Data[WSymExtension(u.
Width, x - xOffset)
141 if(Param.
Verbose && x <= xOffset + 2 && y <= yOffset + 2)
143 if((x < MaxShow || x >= xOffset)
144 && (y < MaxShow || y >= yOffset))
146 if(y == yOffset && x == xOffset)
153 printf(
"%c", FillNext);
157 if(((x + y) & 1) == Green)
159 else if((y & 1) == Param.
RedY)
166 if(y == 0 || (yOffset > MaxShow && y == yOffset))
171 if(y == MaxShow - 1 && yOffset > MaxShow)
173 if(xOffset <= MaxShow)
186 if(x == MaxShow - 1 && xOffset > MaxShow)
196 if(((x + y) & 1) == Green)
197 ((uint8_t *)&Pixel)[0] = ((uint8_t *)&Pixel)[2] = 0;
198 else if((y & 1) == Param.
RedY)
199 ((uint8_t *)&Pixel)[1] = ((uint8_t *)&Pixel)[2] = 0;
201 ((uint8_t *)&Pixel)[0] = ((uint8_t *)&Pixel)[1] = 0;
205 if(((x + y) & 1) == Green)
206 ((uint8_t *)&Pixel)[0] =
207 ((uint8_t *)&Pixel)[2] = ((uint8_t *)&Pixel)[1];
208 else if((y & 1) == Param.
RedY)
209 ((uint8_t *)&Pixel)[1] =
210 ((uint8_t *)&Pixel)[2] = ((uint8_t *)&Pixel)[0];
212 ((uint8_t *)&Pixel)[0] =
213 ((uint8_t *)&Pixel)[1] = ((uint8_t *)&Pixel)[2];
216 ((uint8_t *)&Pixel)[3] = 255;
218 f.Data[x + f.Width*y] = Pixel;
225 if(xOffset > MaxShow)
243 printf(
"Output written to \"%s\".\n", Param.
OutputFile);
253 static int ParseParams(
programparams *Param,
int argc,
char *argv[])
255 static char *DefaultOutputFile = (
char *)
"out.bmp";
279 for(i = 1; i < argc;)
281 if(argv[i] && argv[i][0] ==
'-')
283 if((OptionChar = argv[i][1]) == 0)
290 OptionString = &argv[i][2];
292 OptionString = argv[i];
302 if(!strcmp(OptionString,
"RGGB")
303 || !strcmp(OptionString,
"rggb"))
308 else if(!strcmp(OptionString,
"GRBG")
309 || !strcmp(OptionString,
"grbg"))
314 else if(!strcmp(OptionString,
"GBRG")
315 || !strcmp(OptionString,
"gbrg"))
320 else if(!strcmp(OptionString,
"BGGR")
321 || !strcmp(OptionString,
"bggr"))
327 ErrorMessage(
"CFA pattern must be RGGB, GRBG, GBRG, or BGGR\n");
334 Param->
Padding = atoi(OptionString);
361 ErrorMessage(
"JPEG quality must be between 0 and 100.\n");
370 if(isprint(OptionChar))