libgphoto2 photo camera library (libgphoto2) Internals  2.5.26
bayer.c File Reference

Bayer array conversion routines. More...

#include "config.h"
#include "bayer.h"
#include <gphoto2/gphoto2-port-log.h>
#include <gphoto2/gphoto2-result.h>

Go to the source code of this file.

Macros

#define RED   0
 
#define GREEN   1
 
#define BLUE   2
 
#define AD(x, y, w)   ((y)*(w)*3+3*(x))
 

Functions

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 More...
 
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_interpolate (unsigned char *image, int w, int h, BayerTile tile)
 Interpolate a expanded bayer array into an RGB image. 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...
 

Variables

static const int tile_colours [8][4]
 

Detailed Description

Bayer array conversion routines.

Author
Copyright 2001 Lutz Mueller lutz@.nosp@m.user.nosp@m.s.sf..nosp@m.net
Copyright 2007 Theodore Kilgore kilgo.nosp@m.ta@a.nosp@m.uburn.nosp@m..edu
gp_bayer_accrue() from Theodore Kilgore kilgo.nosp@m.ta@a.nosp@m.uburn.nosp@m..edu contains suggestions by B. R. Harris (e-mail address disappeared) and Werner Eugster eugst.nosp@m.er@g.nosp@m.iub.u.nosp@m.nibe.nosp@m..ch
License
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

Definition in file bayer.c.

Macro Definition Documentation

◆ AD

#define AD (   x,
  y,
 
)    ((y)*(w)*3+3*(x))

Definition at line 130 of file bayer.c.

◆ BLUE

#define BLUE   2

Definition at line 49 of file bayer.c.

◆ GREEN

#define GREEN   1

Definition at line 48 of file bayer.c.

◆ RED

#define RED   0

Definition at line 47 of file bayer.c.

Function Documentation

◆ gp_bayer_accrue()

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 
)
static

interpolate one pixel from a bayer 2x2 raster

For red and blue data, compare the four surrounding values. If three values are all one side of the mean value, the fourth value is ignored. This will sharpen boundaries. Treatment of green data looks for vertical and horizontal edges. Any such which are discovered get special treatment. Otherwise, the same comparison test is applied which is applied for red and blue. Standard algorithm is applied without change at edges of the image.

Definition at line 263 of file bayer.c.

References AD, and GREEN.

Referenced by gp_bayer_interpolate().

◆ gp_bayer_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 laid 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

Definition at line 371 of file bayer.c.

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

◆ gp_bayer_expand()

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 laid 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

Definition at line 75 of file bayer.c.

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, BLUE, gp_log(), GP_LOG_DEBUG, GP_OK, GREEN, RED, and tile_colours.

Referenced by gp_ahd_decode(), and gp_bayer_decode().

◆ gp_bayer_interpolate()

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 laid 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

Definition at line 147 of file bayer.c.

References AD, 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, BLUE, gp_bayer_accrue(), GP_ERROR, GP_OK, GREEN, and RED.

Referenced by gp_bayer_decode().

Variable Documentation

◆ tile_colours

const int tile_colours[8][4]
static
Initial value:
= {
{0, 1, 1, 2},
{1, 0, 2, 1},
{2, 1, 1, 0},
{1, 2, 0, 1},
{0, 1, 1, 2},
{1, 0, 2, 1},
{2, 1, 1, 0},
{1, 2, 0, 1}}

Definition at line 37 of file bayer.c.

Referenced by gp_bayer_expand().