53 int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int colour);
80 unsigned char *ptr = input;
90 for (y = 0; y < h; ++y)
91 for (x = 0; x < w; ++x, ++ptr) {
92 bayer = (x&1?0:1) + (y&1?0:2);
101 output[i+colour] = *ptr;
111 for (y = 0; y < h; ++y, ptr+=w)
112 for (x = 0; x < w; ++x) {
113 bayer = (x&1?0:1) + (y&1?0:2);
122 output[i+colour] = (x&1)? ptr[x>>1]:ptr[(w>>1)+(x>>1)];
130 #define AD(x, y, w) ((y)*(w)*3+3*(x))
153 if (w < 2 || h < 2)
return GP_ERROR;
159 p0 = 0; p1 = 1; p2 = 2;
163 p0 = 1; p1 = 0; p2 = 3;
167 p0 = 3; p1 = 2; p2 = 1;
171 p0 = 2; p1 = 3; p2 = 0;
175 for (y = 0; y < h; y++)
176 for (x = 0; x < w; x++) {
177 bayer = (x&1?0:1) + (y&1?0:2);
183 gp_bayer_accrue(image, w, h, x-1, y, x+1, y, x, y-1, x, y+1,
GREEN) ;
186 gp_bayer_accrue(image, w, h, x+1, y+1, x-1, y-1, x-1, y+1, x+1, y-1,
BLUE) ;
188 }
else if (bayer == p1) {
193 value += image[
AD(x+1,y,w)+
RED];
197 value += image[
AD(x-1,y,w)+
RED];
200 image[
AD(x,y,w)+
RED] = value / div;
204 value += image[
AD(x,y+1,w)+
BLUE];
208 value += image[
AD(x,y-1,w)+
BLUE];
211 image[
AD(x,y,w)+
BLUE] = value / div;
213 }
else if ( bayer == p2 ) {
219 value += image[
AD(x+1,y,w)+
BLUE];
223 value += image[
AD(x-1,y,w)+
BLUE];
226 image[
AD(x,y,w)+
BLUE] = value / div;
230 value += image[
AD(x,y+1,w)+
RED];
234 value += image[
AD(x,y-1,w)+
RED];
237 image[
AD(x,y,w)+
RED] = value / div;
243 gp_bayer_accrue (image, w, h, x-1, y, x+1, y, x, y-1, x, y+1,
GREEN) ;
245 image[
AD(x,y,w)+
RED] =
246 gp_bayer_accrue (image, w, h, x+1, y+1, x-1, y-1, x-1, y+1, x+1, y-1,
RED) ;
264 int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int colour)
273 x[0] = x0 ; x[1] = x1 ; x[2] = x2 ; x[3] = x3 ;
274 y[0] = y0 ; y[1] = y1 ; y[2] = y2 ; y[3] = y3 ;
277 counter = sum_of_values = 0 ;
286 for (i = 0 ; i < 4 ; i++)
287 {
if ((x[i] >= 0) && (x[i] < w) && (y[i] >= 0) && (y[i] < h))
289 value [i] = image[
AD(x[i],y[i],w) + colour] ;
305 hdiff = value [1] - value [0] ;
307 vdiff = value [3] - value [2] ;
312 return (value [3] + value [2])/2 ;
317 return (value [1] + value [0])/2 ;
326 counter = sum_of_values = 0 ;
327 for (i = 0 ; i < 4 ; i++)
328 {
if ((x[i] >= 0) && (x[i] < w) && (y[i] >= 0) && (y[i] < h))
329 { value [i] = image[
AD(x[i],y[i],w) + colour] ;
330 sum_of_values += value [i] ;
334 average = sum_of_values / counter ;
335 if (counter < 4)
return average ;
338 for (i = 0 ; i < 4 ; i++)
339 { above[i] = value[i] > average ;
340 if (above[i]) counter++ ;
343 if ((counter == 2) || (counter == 0))
return average ;
345 for (i = 0 ; i < 4 ; i++)
346 {
if ((counter == 3) == above[i])
347 { sum_of_values += value[i] ; }
349 return sum_of_values / 3 ;
int gp_bayer_interpolate(unsigned char *image, int w, int h, BayerTile tile)
Interpolate a expanded bayer array into an RGB image.
static const int tile_colours[8][4]
static int gp_bayer_accrue(unsigned char *image, int w, int h, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int colour)
interpolate one pixel from a bayer 2x2 raster
int gp_bayer_expand(unsigned char *input, int w, int h, unsigned char *output, BayerTile tile)
Expand a bayer raster style image to a RGB raster.
int gp_bayer_decode(unsigned char *input, int w, int h, unsigned char *output, BayerTile tile)
Convert a bayer raster style image to a RGB raster.
BayerTile
how the bayer CCD array is laid out
@ BAYER_TILE_GBRG_INTERLACED
scanline order: G1,B1,G2,B2,...,R1,G1,R2,G2,...
@ BAYER_TILE_GBRG
raster is RG,GB
@ BAYER_TILE_RGGB_INTERLACED
scanline order: R1,G1,R2,G2,...,G1,B1,G2,B2,...
@ BAYER_TILE_BGGR_INTERLACED
scanline order: B1,G1,R2,G2,...,G1,R1,G2,R2,...
@ BAYER_TILE_BGGR
raster is BG,GR
@ BAYER_TILE_RGGB
raster is RG,GN
@ BAYER_TILE_GRBG
raster is GR,BG
@ BAYER_TILE_GRBG_INTERLACED
scanline order: G1,R1,R2,G2,...,B1,G1,B2,G2,...
void gp_log(GPLogLevel level, const char *domain, const char *format,...)
Log a debug or error message.
@ GP_LOG_DEBUG
Log message is an debug information.
#define GP_OK
Everything is OK.
#define GP_ERROR
Generic Error.