Kstars

bayer.h
1/*
2 1394-Based Digital Camera Control Library
3
4 Bayer pattern decoding functions
5
6 Written by Damien Douxchamps and Frederic Devernay
7 The original VNG and AHD Bayer decoding are from Dave Coffin's DCRAW.
8
9 SPDX-License-Identifier: LGPL-2.1-or-later
10*/
11
12#pragma once
13
14#include <stdint.h>
15
16/**
17 * Error codes returned by most libdc1394 functions.
18 *
19 * General rule: 0 is success, negative denotes a problem.
20 */
21typedef enum
22{
23 DC1394_SUCCESS = 0,
24 DC1394_FAILURE = -1,
25 DC1394_NOT_A_CAMERA = -2,
26 DC1394_FUNCTION_NOT_SUPPORTED = -3,
27 DC1394_CAMERA_NOT_INITIALIZED = -4,
28 DC1394_MEMORY_ALLOCATION_FAILURE = -5,
29 DC1394_TAGGED_REGISTER_NOT_FOUND = -6,
30 DC1394_NO_ISO_CHANNEL = -7,
31 DC1394_NO_BANDWIDTH = -8,
32 DC1394_IOCTL_FAILURE = -9,
33 DC1394_CAPTURE_IS_NOT_SET = -10,
34 DC1394_CAPTURE_IS_RUNNING = -11,
35 DC1394_RAW1394_FAILURE = -12,
36 DC1394_FORMAT7_ERROR_FLAG_1 = -13,
37 DC1394_FORMAT7_ERROR_FLAG_2 = -14,
38 DC1394_INVALID_ARGUMENT_VALUE = -15,
39 DC1394_REQ_VALUE_OUTSIDE_RANGE = -16,
40 DC1394_INVALID_FEATURE = -17,
41 DC1394_INVALID_VIDEO_FORMAT = -18,
42 DC1394_INVALID_VIDEO_MODE = -19,
43 DC1394_INVALID_FRAMERATE = -20,
44 DC1394_INVALID_TRIGGER_MODE = -21,
45 DC1394_INVALID_TRIGGER_SOURCE = -22,
46 DC1394_INVALID_ISO_SPEED = -23,
47 DC1394_INVALID_IIDC_VERSION = -24,
48 DC1394_INVALID_COLOR_CODING = -25,
49 DC1394_INVALID_COLOR_FILTER = -26,
50 DC1394_INVALID_CAPTURE_POLICY = -27,
51 DC1394_INVALID_ERROR_CODE = -28,
52 DC1394_INVALID_BAYER_METHOD = -29,
53 DC1394_INVALID_VIDEO1394_DEVICE = -30,
54 DC1394_INVALID_OPERATION_MODE = -31,
55 DC1394_INVALID_TRIGGER_POLARITY = -32,
56 DC1394_INVALID_FEATURE_MODE = -33,
57 DC1394_INVALID_LOG_TYPE = -34,
58 DC1394_INVALID_BYTE_ORDER = -35,
59 DC1394_INVALID_STEREO_METHOD = -36,
60 DC1394_BASLER_NO_MORE_SFF_CHUNKS = -37,
61 DC1394_BASLER_CORRUPTED_SFF_CHUNK = -38,
62 DC1394_BASLER_UNKNOWN_SFF_CHUNK = -39
63} dc1394error_t;
64#define DC1394_ERROR_MIN DC1394_BASLER_UNKNOWN_SFF_CHUNK
65#define DC1394_ERROR_MAX DC1394_SUCCESS
66#define DC1394_ERROR_NUM (DC1394_ERROR_MAX - DC1394_ERROR_MIN + 1)
67
68/**
69 * Enumeration of video modes. Note that the notion of IIDC "format" is not present here, except in the format_7 name.
70 */
71typedef enum
72{
73 DC1394_VIDEO_MODE_160x120_YUV444 = 64,
74 DC1394_VIDEO_MODE_320x240_YUV422,
75 DC1394_VIDEO_MODE_640x480_YUV411,
76 DC1394_VIDEO_MODE_640x480_YUV422,
77 DC1394_VIDEO_MODE_640x480_RGB8,
78 DC1394_VIDEO_MODE_640x480_MONO8,
79 DC1394_VIDEO_MODE_640x480_MONO16,
80 DC1394_VIDEO_MODE_800x600_YUV422,
81 DC1394_VIDEO_MODE_800x600_RGB8,
82 DC1394_VIDEO_MODE_800x600_MONO8,
83 DC1394_VIDEO_MODE_1024x768_YUV422,
84 DC1394_VIDEO_MODE_1024x768_RGB8,
85 DC1394_VIDEO_MODE_1024x768_MONO8,
86 DC1394_VIDEO_MODE_800x600_MONO16,
87 DC1394_VIDEO_MODE_1024x768_MONO16,
88 DC1394_VIDEO_MODE_1280x960_YUV422,
89 DC1394_VIDEO_MODE_1280x960_RGB8,
90 DC1394_VIDEO_MODE_1280x960_MONO8,
91 DC1394_VIDEO_MODE_1600x1200_YUV422,
92 DC1394_VIDEO_MODE_1600x1200_RGB8,
93 DC1394_VIDEO_MODE_1600x1200_MONO8,
94 DC1394_VIDEO_MODE_1280x960_MONO16,
95 DC1394_VIDEO_MODE_1600x1200_MONO16,
96 DC1394_VIDEO_MODE_EXIF,
97 DC1394_VIDEO_MODE_FORMAT7_0,
98 DC1394_VIDEO_MODE_FORMAT7_1,
99 DC1394_VIDEO_MODE_FORMAT7_2,
100 DC1394_VIDEO_MODE_FORMAT7_3,
101 DC1394_VIDEO_MODE_FORMAT7_4,
102 DC1394_VIDEO_MODE_FORMAT7_5,
103 DC1394_VIDEO_MODE_FORMAT7_6,
104 DC1394_VIDEO_MODE_FORMAT7_7
105} dc1394video_mode_t;
106#define DC1394_VIDEO_MODE_MIN DC1394_VIDEO_MODE_160x120_YUV444
107#define DC1394_VIDEO_MODE_MAX DC1394_VIDEO_MODE_FORMAT7_7
108#define DC1394_VIDEO_MODE_NUM (DC1394_VIDEO_MODE_MAX - DC1394_VIDEO_MODE_MIN + 1)
109
110/* Special min/max are defined for Format_7 */
111#define DC1394_VIDEO_MODE_FORMAT7_MIN DC1394_VIDEO_MODE_FORMAT7_0
112#define DC1394_VIDEO_MODE_FORMAT7_MAX DC1394_VIDEO_MODE_FORMAT7_7
113#define DC1394_VIDEO_MODE_FORMAT7_NUM (DC1394_VIDEO_MODE_FORMAT7_MAX - DC1394_VIDEO_MODE_FORMAT7_MIN + 1)
114
115/**
116 * Enumeration of colour codings. For details on the data format please read the IIDC specifications.
117 */
118typedef enum
119{
120 DC1394_COLOR_CODING_MONO8 = 352,
121 DC1394_COLOR_CODING_YUV411,
122 DC1394_COLOR_CODING_YUV422,
123 DC1394_COLOR_CODING_YUV444,
124 DC1394_COLOR_CODING_RGB8,
125 DC1394_COLOR_CODING_MONO16,
126 DC1394_COLOR_CODING_RGB16,
127 DC1394_COLOR_CODING_MONO16S,
128 DC1394_COLOR_CODING_RGB16S,
129 DC1394_COLOR_CODING_RAW8,
130 DC1394_COLOR_CODING_RAW16
131} dc1394color_coding_t;
132#define DC1394_COLOR_CODING_MIN DC1394_COLOR_CODING_MONO8
133#define DC1394_COLOR_CODING_MAX DC1394_COLOR_CODING_RAW16
134#define DC1394_COLOR_CODING_NUM (DC1394_COLOR_CODING_MAX - DC1394_COLOR_CODING_MIN + 1)
135
136/**
137 * RAW sensor filters. These elementary tiles tesselate the image plane in RAW modes. RGGB should be interpreted in 2D as
138 *
139 * RG
140 * GB
141 *
142 * and similarly for other filters.
143 */
144typedef enum
145{
146 DC1394_COLOR_FILTER_RGGB = 512,
147 DC1394_COLOR_FILTER_GBRG,
148 DC1394_COLOR_FILTER_GRBG,
149 DC1394_COLOR_FILTER_BGGR
150} dc1394color_filter_t;
151#define DC1394_COLOR_FILTER_MIN DC1394_COLOR_FILTER_RGGB
152#define DC1394_COLOR_FILTER_MAX DC1394_COLOR_FILTER_BGGR
153#define DC1394_COLOR_FILTER_NUM (DC1394_COLOR_FILTER_MAX - DC1394_COLOR_FILTER_MIN + 1)
154
155/**
156 * Byte order for YUV formats (may be expanded to RGB in the future)
157 *
158 * IIDC cameras always return data in UYVY order, but conversion functions can change this if requested.
159 */
160typedef enum { DC1394_BYTE_ORDER_UYVY = 800, DC1394_BYTE_ORDER_YUYV } dc1394byte_order_t;
161#define DC1394_BYTE_ORDER_MIN DC1394_BYTE_ORDER_UYVY
162#define DC1394_BYTE_ORDER_MAX DC1394_BYTE_ORDER_YUYV
163#define DC1394_BYTE_ORDER_NUM (DC1394_BYTE_ORDER_MAX - DC1394_BYTE_ORDER_MIN + 1)
164
165/**
166 * A struct containing a list of color codings
167 */
168typedef struct
169{
170 uint32_t num;
171 dc1394color_coding_t codings[DC1394_COLOR_CODING_NUM];
173
174/**
175 * A struct containing a list of video modes
176 */
177typedef struct
178{
179 uint32_t num;
180 dc1394video_mode_t modes[DC1394_VIDEO_MODE_NUM];
182
183/**
184 * Yet another boolean data type
185 */
186typedef enum { DC1394_FALSE = 0, DC1394_TRUE } dc1394bool_t;
187
188/**
189 * Yet another boolean data type, a bit more oriented towards electrical-engineers
190 */
191typedef enum { DC1394_OFF = 0, DC1394_ON } dc1394switch_t;
192
193/**
194 * A list of de-mosaicing techniques for Bayer-patterns.
195 *
196 * The speed of the techniques can vary greatly, as well as their quality.
197 */
198typedef enum
199{
200 DC1394_BAYER_METHOD_NEAREST = 0,
201 DC1394_BAYER_METHOD_SIMPLE,
202 DC1394_BAYER_METHOD_BILINEAR,
203 DC1394_BAYER_METHOD_HQLINEAR,
204 DC1394_BAYER_METHOD_DOWNSAMPLE,
205 DC1394_BAYER_METHOD_EDGESENSE,
206 DC1394_BAYER_METHOD_VNG,
207 DC1394_BAYER_METHOD_AHD
208} dc1394bayer_method_t;
209#define DC1394_BAYER_METHOD_MIN DC1394_BAYER_METHOD_NEAREST
210#define DC1394_BAYER_METHOD_MAX DC1394_BAYER_METHOD_AHD
211#define DC1394_BAYER_METHOD_NUM (DC1394_BAYER_METHOD_MAX - DC1394_BAYER_METHOD_MIN + 1)
212
213typedef struct
214{
215 dc1394bayer_method_t method; /* Debayer method */
216 dc1394color_filter_t filter; /* Debayer pattern */
217 int offsetX, offsetY; /* Debayer offset */
218} BayerParams;
219
220/************************************************************************************************
221 * *
222 * Color conversion functions for cameras that can output raw Bayer pattern images (color *
223 * codings DC1394_COLOR_CODING_RAW8 and DC1394_COLOR_CODING_RAW16). *
224 * *
225 * Credits and sources: *
226 * - Nearest Neighbor : OpenCV library *
227 * - Bilinear : OpenCV library *
228 * - HQLinear : High-Quality Linear Interpolation For Demosaicing Of Bayer-Patterned *
229 * Color Images, by Henrique S. Malvar, Li-wei He, and Ross Cutler, *
230 * in Proceedings of the ICASSP'04 Conference. *
231 * - Edge Sense II : Laroche, Claude A. "Apparatus and method for adaptively interpolating *
232 * a full color image utilizing chrominance gradients" *
233 * U.S. Patent 5,373,322. Based on the code found on the website *
234 * http://www-ise.stanford.edu/~tingchen/ Converted to C and adapted to *
235 * all four elementary patterns. *
236 * - Downsample : "Known to the Ancients" *
237 * - Simple : Implemented from the information found in the manual of Allied Vision *
238 * Technologies (AVT) cameras. *
239 * - VNG : Variable Number of Gradients, a method described in *
240 * http://www-ise.stanford.edu/~tingchen/algodep/vargra.html *
241 * Sources import from DCRAW by Frederic Devernay. DCRAW is a RAW *
242 * converter program by Dave Coffin. URL: *
243 * https://dechifro.org/dcraw/ *
244 * - AHD : Adaptive Homogeneity-Directed Demosaicing Algorithm, by K. Hirakawa *
245 * and T.W. Parks, IEEE Transactions on Image Processing, Vol. 14, Nr. 3, *
246 * March 2005, pp. 360 - 369. *
247 * *
248 ************************************************************************************************/
249
250#ifdef __cplusplus
251extern "C" {
252#endif
253
254/**
255 * Perform de-mosaicing on an 8-bit image buffer
256 */
257dc1394error_t dc1394_bayer_decoding_8bit(const uint8_t *bayer, uint8_t *rgb, uint32_t width, uint32_t height,
258 dc1394color_filter_t tile, dc1394bayer_method_t method);
259
260/**
261 * Perform de-mosaicing on an 16-bit image buffer
262 */
263dc1394error_t dc1394_bayer_decoding_16bit(const uint16_t *bayer, uint16_t *rgb, uint32_t width, uint32_t height,
264 dc1394color_filter_t tile, dc1394bayer_method_t method, uint32_t bits);
265
266/* Bayer to RGBX */
267dc1394error_t dc1394_bayer16_RGBX_NearestNeighbor(const uint16_t *bayer, uint16_t *rgbx, int sx, int sy, int tile);
268#ifdef __cplusplus
269}
270#endif
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
A struct containing a list of color codings.
Definition bayer.h:169
A struct containing a list of video modes.
Definition bayer.h:178
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:51:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.