libgphoto2 photo camera library (libgphoto2) API  2.5.10.1
bayer.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  BayerTile {
  BAYER_TILE_RGGB = 0, BAYER_TILE_GRBG = 1, BAYER_TILE_BGGR = 2, BAYER_TILE_GBRG = 3,
  BAYER_TILE_RGGB_INTERLACED = 4, BAYER_TILE_GRBG_INTERLACED = 5, BAYER_TILE_BGGR_INTERLACED = 6, BAYER_TILE_GBRG_INTERLACED = 7
}
 how the bayer CCD array is layed out More...
 

Functions

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. More...
 
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. More...
 
int gp_bayer_interpolate (unsigned char *image, int w, int h, BayerTile tile)
 Interpolate a expanded bayer array into an RGB image. More...
 
int gp_ahd_decode (unsigned char *input, int w, int h, unsigned char *output, BayerTile tile)
 Convert a bayer raster style image to a RGB raster. More...
 
int gp_ahd_interpolate (unsigned char *image, int w, int h, BayerTile tile)
 Interpolate a expanded bayer array into an RGB image. More...
 

Detailed Description

Author
Copyright 2001 Lutz Mueller lutz@.nosp@m.user.nosp@m.s.sf..nosp@m.net
Note
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Enumeration Type Documentation

enum BayerTile

how the bayer CCD array is layed out

This enumeration defines how the CCD bayer array is laid out.

Enumerator
BAYER_TILE_RGGB 

raster is RG,GN

BAYER_TILE_GRBG 

raster is GR,BG

BAYER_TILE_BGGR 

raster is BG,GR

BAYER_TILE_GBRG 

raster is RG,GB

BAYER_TILE_RGGB_INTERLACED 

scanline order: R1,G1,R2,G2,...,G1,B1,G2,B2,...

BAYER_TILE_GRBG_INTERLACED 

scanline order: G1,R1,R2,G2,...,B1,G1,B2,G2,...

BAYER_TILE_BGGR_INTERLACED 

scanline order: B1,G1,R2,G2,...,G1,R1,G2,R2,...

BAYER_TILE_GBRG_INTERLACED 

scanline order: G1,B1,G2,B2,...,R1,G1,R2,G2,...

Function Documentation

int gp_ahd_decode ( unsigned char *  input,
int  w,
int  h,
unsigned char *  output,
BayerTile  tile 
)

Convert a bayer raster style image to a RGB raster.

Parameters
inputthe bayer CCD array as linear input
wwidth of the above array
hheight of the above array
outputRGB output array (linear, 3 bytes of R,G,B for every pixel)
tilehow the 2x2 bayer array is layed out

A regular CCD uses a raster of 2 green, 1 blue and 1 red components to cover a 2x2 pixel area. The camera or the driver then interpolates a 2x2 RGB pixel set out of this data.

This function expands and interpolates the bayer array to 3 times larger bitmap with RGB values interpolated. It does the same job as gp_bayer_decode() but it calls gp_ahd_interpolate() instead of calling gp_bayer_interpolate(). Use this instead of gp_bayer_decode() if you want to use or to test AHD interpolation in a camera library.

Returns
a gphoto error code

References gp_ahd_interpolate(), gp_bayer_expand(), and GP_OK.

int gp_ahd_interpolate ( unsigned char *  image,
int  w,
int  h,
BayerTile  tile 
)

Interpolate a expanded bayer array into an RGB image.

Parameters
imagethe linear RGB array as both input and output
wwidth of the above array
hheight of the above array
tilehow the 2x2 bayer array is layed out

This function interpolates a bayer array which has been pre-expanded by gp_bayer_expand() to an RGB image. It applies the method of adaptive homogeneity-directed demosaicing.

Returns
a gphoto error code
In outline, the interpolation algorithm used here does the following:
In principle, the first thing which is done is to split off from the image two copies. In one of these, interpolation will be done in the vertical direction only, and in the other copy only in the horizontal direction. "Cross-color" data is used throughout, on the principle that it can be used as a corrector for brightness even if it is derived from the "wrong" color. Finally, at each pixel there is a choice criterion to decide whether to use the result of the vertical interpolation, the horizontal interpolation, or an average of the two.
Memory use and speed are optimized by using two sliding windows, one for the vertical interpolation and the other for the horizontal interpolation instead of using two copies of the entire input image. The nterpolation and the choice algorithm are then implemented entirely within these windows, too. When this has been done, a completed row is written back to the image. Then the windows are moved, and the process repeats.

References BAYER_TILE_BGGR, BAYER_TILE_BGGR_INTERLACED, BAYER_TILE_GBRG, BAYER_TILE_GBRG_INTERLACED, BAYER_TILE_GRBG, BAYER_TILE_GRBG_INTERLACED, BAYER_TILE_RGGB, BAYER_TILE_RGGB_INTERLACED, GP_ERROR_NO_MEMORY, and GP_OK.

Referenced by gp_ahd_decode().

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.

Parameters
inputthe bayer CCD array as linear input
wwidth of the above array
hheight of the above array
outputRGB output array (linear, 3 bytes of R,G,B for every pixel)
tilehow the 2x2 bayer array is layed out

A regular CCD uses a raster of 2 green, 1 blue and 1 red components to cover a 2x2 pixel area. The camera or the driver then interpolates a 2x2 RGB pixel set out of this data.

This function expands and interpolates the bayer array to 3 times larger bitmap with RGB values interpolated.

Returns
a gphoto error code

References gp_bayer_expand(), gp_bayer_interpolate(), and GP_OK.

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.

Parameters
inputthe bayer CCD array as linear input
wwidth of the above array
hheight of the above array
outputRGB output array (linear, 3 bytes of R,G,B for every pixel)
tilehow the 2x2 bayer array is layed out

A regular CCD uses a raster of 2 green, 1 blue and 1 red components to cover a 2x2 pixel area. The camera or the driver then interpolates a 2x2 RGB pixel set out of this data.

This function expands the bayer array to 3 times larger bitmap with RGB values copied as-is. Pixels were no sensor was there are 0. The data is supposed to be processed further by for instance gp_bayer_interpolate().

Returns
a gphoto error code

References BAYER_TILE_BGGR, BAYER_TILE_BGGR_INTERLACED, BAYER_TILE_GBRG, BAYER_TILE_GBRG_INTERLACED, BAYER_TILE_GRBG, BAYER_TILE_GRBG_INTERLACED, BAYER_TILE_RGGB, BAYER_TILE_RGGB_INTERLACED, and GP_OK.

Referenced by gp_ahd_decode(), and gp_bayer_decode().

int gp_bayer_interpolate ( unsigned char *  image,
int  w,
int  h,
BayerTile  tile 
)

Interpolate a expanded bayer array into an RGB image.

Parameters
imagethe linear RGB array as both input and output
wwidth of the above array
hheight of the above array
tilehow the 2x2 bayer array is layed out

This function interpolates a bayer array which has been pre-expanded by gp_bayer_expand() to an RGB image. It uses various interpolation methods, also see gp_bayer_accrue().

Returns
a gphoto error code

References BAYER_TILE_BGGR, BAYER_TILE_BGGR_INTERLACED, BAYER_TILE_GBRG, BAYER_TILE_GBRG_INTERLACED, BAYER_TILE_GRBG, BAYER_TILE_GRBG_INTERLACED, BAYER_TILE_RGGB, BAYER_TILE_RGGB_INTERLACED, and GP_OK.

Referenced by gp_bayer_decode().