/src/libraw/internal/defines.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Copyright 2008-2024 LibRaw LLC (info@libraw.org) |
3 | | |
4 | | LibRaw is free software; you can redistribute it and/or modify |
5 | | it under the terms of the one of two licenses as you choose: |
6 | | |
7 | | 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 |
8 | | (See file LICENSE.LGPL provided in LibRaw distribution archive for details). |
9 | | |
10 | | 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 |
11 | | (See file LICENSE.CDDL provided in LibRaw distribution archive for details). |
12 | | |
13 | | This file is generated from Dave Coffin's dcraw.c |
14 | | dcraw.c -- Dave Coffin's raw photo decoder |
15 | | Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net |
16 | | |
17 | | Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) |
18 | | for more information |
19 | | */ |
20 | | |
21 | | #ifndef LIBRAW_INT_DEFINES_H |
22 | | #define LIBRAW_INT_DEFINES_H |
23 | | #ifndef USE_JPEG |
24 | | #define NO_JPEG |
25 | | #endif |
26 | | |
27 | 0 | #define DCRAW_VERSION "9.26" |
28 | | |
29 | | #ifndef _GNU_SOURCE |
30 | | #define _GNU_SOURCE |
31 | | #endif |
32 | | #define _USE_MATH_DEFINES |
33 | | #include <ctype.h> |
34 | | #include <errno.h> |
35 | | #include <fcntl.h> |
36 | | #include <float.h> |
37 | | #include <limits.h> |
38 | | #include <math.h> |
39 | | #include <setjmp.h> |
40 | | #include <stdio.h> |
41 | | #include <stdlib.h> |
42 | | #include <string.h> |
43 | | #include <time.h> |
44 | | #include <sys/types.h> |
45 | | #ifdef __CYGWIN__ |
46 | | #include <io.h> |
47 | | #endif |
48 | | #if defined LIBRAW_WIN32_CALLS |
49 | | #include <sys/utime.h> |
50 | | #ifndef LIBRAW_NO_WINSOCK2 |
51 | | #include <winsock2.h> |
52 | | #pragma comment(lib, "ws2_32.lib") |
53 | | #endif |
54 | | #define snprintf _snprintf |
55 | | #define strcasecmp stricmp |
56 | | #define strncasecmp strnicmp |
57 | | #else |
58 | | #include <unistd.h> |
59 | | #include <utime.h> |
60 | | #include <netinet/in.h> |
61 | | typedef long long INT64; |
62 | | typedef unsigned long long UINT64; |
63 | | #endif |
64 | | |
65 | | #ifdef NODEPS |
66 | | #define NO_JPEG |
67 | | #define NO_LCMS |
68 | | #endif |
69 | | #ifndef NO_JPEG |
70 | | #include <jpeglib.h> /* Decode compressed Kodak DC120 photos */ |
71 | | #endif /* and Adobe Lossy DNGs */ |
72 | | #ifndef NO_LCMS |
73 | | #ifdef USE_LCMS |
74 | | #include <lcms.h> /* Support color profiles */ |
75 | | #else |
76 | | #include <lcms2.h> /* Support color profiles */ |
77 | | #endif |
78 | | #endif |
79 | | #ifdef LOCALEDIR |
80 | | #include <libintl.h> |
81 | | #define _(String) gettext(String) |
82 | | #else |
83 | | #define _(String) (String) |
84 | | #endif |
85 | | |
86 | | #ifdef LJPEG_DECODE |
87 | | #error Please compile dcraw.c by itself. |
88 | | #error Do not link it with ljpeg_decode. |
89 | | #endif |
90 | | |
91 | | #ifndef LONG_BIT |
92 | | #define LONG_BIT (8 * sizeof(long)) |
93 | | #endif |
94 | 4.53G | #define FORC(cnt) for (c = 0; c < cnt; c++) |
95 | 812M | #define FORC3 FORC(3) |
96 | 316M | #define FORC4 FORC(4) |
97 | 4.36G | #define FORCC for (c = 0; c < colors && c < 4; c++) |
98 | | |
99 | 5.34G | #define SQR(x) ((x) * (x)) |
100 | 2.50G | #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) |
101 | 777M | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
102 | 11.9G | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
103 | 5.99G | #define LIM(x, min, max) MAX(min, MIN(x, max)) |
104 | 204M | #define ULIM(x, y, z) ((y) < (z) ? LIM(x, y, z) : LIM(x, z, y)) |
105 | 6.37G | #define CLIP(x) LIM((int)(x), 0, 65535) |
106 | 0 | #define CLIP15(x) LIM((int)(x), 0, 32767) |
107 | | #define SWAP(a, b) \ |
108 | 3.53M | { \ |
109 | 3.53M | a = a + b; \ |
110 | 3.53M | b = a - b; \ |
111 | 3.53M | a = a - b; \ |
112 | 3.53M | } |
113 | | |
114 | | #define my_swap(type, i, j) \ |
115 | | { \ |
116 | | type t = i; \ |
117 | | i = j; \ |
118 | | j = t; \ |
119 | | } |
120 | | |
121 | | #ifdef __GNUC__ |
122 | | inline |
123 | | #elif defined(_MSC_VER) |
124 | | __forceinline |
125 | | #else |
126 | | static |
127 | | #endif |
128 | 544k | float fMAX(float a, float b) { return MAX(a, b); } |
129 | | |
130 | | /* |
131 | | In order to inline this calculation, I make the risky |
132 | | assumption that all filter patterns can be described |
133 | | by a repeating pattern of eight rows and two columns |
134 | | |
135 | | Do not use the FC or BAYER macros with the Leaf CatchLight, |
136 | | because its pattern is 16x16, not 2x8. |
137 | | |
138 | | Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 |
139 | | |
140 | | PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 |
141 | | 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: |
142 | | |
143 | | 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 |
144 | | 0 G M G M G M 0 C Y C Y C Y 0 Y C Y C Y C 0 G M G M G M |
145 | | 1 C Y C Y C Y 1 M G M G M G 1 M G M G M G 1 Y C Y C Y C |
146 | | 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y |
147 | | 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M |
148 | | 4 C Y C Y C Y 4 Y C Y C Y C |
149 | | PowerShot A5 5 G M G M G M 5 G M G M G M |
150 | | 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y |
151 | | 7 M G M G M G 7 M G M G M G |
152 | | 0 1 2 3 4 5 |
153 | | 0 C Y C Y C Y |
154 | | 1 G M G M G M |
155 | | 2 C Y C Y C Y |
156 | | 3 M G M G M G |
157 | | |
158 | | All RGB cameras use one of these Bayer grids: |
159 | | |
160 | | 0x16161616: 0x61616161: 0x49494949: 0x94949494: |
161 | | |
162 | | 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 |
163 | | 0 B G B G B G 0 G R G R G R 0 G B G B G B 0 R G R G R G |
164 | | 1 G R G R G R 1 B G B G B G 1 R G R G R G 1 G B G B G B |
165 | | 2 B G B G B G 2 G R G R G R 2 G B G B G B 2 R G R G R G |
166 | | 3 G R G R G R 3 B G B G B G 3 R G R G R G 3 G B G B G B |
167 | | */ |
168 | | |
169 | | // _RGBG means R, G1, B, G2 sequence |
170 | 677k | #define GRBG_2_RGBG(q) (q ^ (q >> 1) ^ 1) |
171 | 1.31M | #define RGGB_2_RGBG(q) (q ^ (q >> 1)) |
172 | 9.89k | #define BG2RG1_2_RGBG(q) (q ^ 2) |
173 | 0 | #define G2BRG1_2_RGBG(q) (q ^ (q >> 1) ^ 3) |
174 | 135k | #define GRGB_2_RGBG(q) (q ^ 1) |
175 | 0 | #define RBGG_2_RGBG(q) ((q >> 1) | ((q & 1) << 1)) |
176 | | |
177 | 28.6M | #define RAWINDEX(row, col) ((row)*raw_width + (col)) |
178 | 293M | #define RAW(row, col) raw_image[(row)*raw_width + (col)] |
179 | | #define BAYER(row, col) \ |
180 | 43.8M | image[((row) >> shrink) * iwidth + ((col) >> shrink)][FC(row, col)] |
181 | | |
182 | | #define BAYER2(row, col) \ |
183 | 243M | image[((row) >> shrink) * iwidth + ((col) >> shrink)][fcol(row, col)] |
184 | | #define BAYERC(row, col, c) \ |
185 | | imgdata.image[((row) >> IO.shrink) * S.iwidth + ((col) >> IO.shrink)][c] |
186 | | |
187 | | #endif |