/src/freeimage-svn/FreeImage/trunk/Source/LibRawLite/internal/defines.h
Line  | Count  | Source  | 
1  |  | /*  | 
2  |  |   Copyright 2008-2021 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  |  | #ifndef USE_JASPER  | 
27  |  | #define NO_JASPER  | 
28  |  | #endif  | 
29  | 0  | #define DCRAW_VERSION "9.26"  | 
30  |  |  | 
31  |  | #ifndef _GNU_SOURCE  | 
32  |  | #define _GNU_SOURCE  | 
33  |  | #endif  | 
34  |  | #define _USE_MATH_DEFINES  | 
35  |  | #include <ctype.h>  | 
36  |  | #include <errno.h>  | 
37  |  | #include <fcntl.h>  | 
38  |  | #include <float.h>  | 
39  |  | #include <limits.h>  | 
40  |  | #include <math.h>  | 
41  |  | #include <setjmp.h>  | 
42  |  | #include <stdio.h>  | 
43  |  | #include <stdlib.h>  | 
44  |  | #include <string.h>  | 
45  |  | #include <time.h>  | 
46  |  | #include <sys/types.h>  | 
47  |  | #ifdef __CYGWIN__  | 
48  |  | #include <io.h>  | 
49  |  | #endif  | 
50  |  | #if defined LIBRAW_WIN32_CALLS  | 
51  |  | #include <sys/utime.h>  | 
52  |  | #ifndef LIBRAW_NO_WINSOCK2  | 
53  |  | #include <winsock2.h>  | 
54  |  | #pragma comment(lib, "ws2_32.lib")  | 
55  |  | #endif  | 
56  |  | #define snprintf _snprintf  | 
57  |  | #define strcasecmp stricmp  | 
58  |  | #define strncasecmp strnicmp  | 
59  |  | #else  | 
60  |  | #include <unistd.h>  | 
61  |  | #include <utime.h>  | 
62  |  | #include <netinet/in.h>  | 
63  |  | #include <stdint.h>  | 
64  |  | typedef int64_t INT64;  | 
65  |  | typedef uint64_t UINT64;  | 
66  |  | #endif  | 
67  |  |  | 
68  |  | #ifdef NODEPS  | 
69  |  | #define NO_JASPER  | 
70  |  | #define NO_JPEG  | 
71  |  | #define NO_LCMS  | 
72  |  | #endif  | 
73  |  | #ifndef NO_JASPER  | 
74  |  | #include <jasper/jasper.h> /* Decode Red camera movies */  | 
75  |  | #endif  | 
76  |  | #ifndef NO_JPEG  | 
77  |  | #include <jpeglib.h> /* Decode compressed Kodak DC120 photos */  | 
78  |  | #endif               /* and Adobe Lossy DNGs */  | 
79  |  | #ifndef NO_LCMS  | 
80  |  | #ifdef USE_LCMS  | 
81  |  | #include <lcms.h> /* Support color profiles */  | 
82  |  | #else  | 
83  |  | #include <lcms2.h> /* Support color profiles */  | 
84  |  | #endif  | 
85  |  | #endif  | 
86  |  | #ifdef LOCALEDIR  | 
87  |  | #include <libintl.h>  | 
88  |  | #define _(String) gettext(String)  | 
89  |  | #else  | 
90  |  | #define _(String) (String)  | 
91  |  | #endif  | 
92  |  |  | 
93  |  | #ifdef LJPEG_DECODE  | 
94  |  | #error Please compile dcraw.c by itself.  | 
95  |  | #error Do not link it with ljpeg_decode.  | 
96  |  | #endif  | 
97  |  |  | 
98  |  | #ifndef LONG_BIT  | 
99  |  | #define LONG_BIT (8 * sizeof(long))  | 
100  |  | #endif  | 
101  | 18.6M  | #define FORC(cnt) for (c = 0; c < cnt; c++)  | 
102  | 168k  | #define FORC3 FORC(3)  | 
103  | 3.50M  | #define FORC4 FORC(4)  | 
104  | 1.38M  | #define FORCC for (c = 0; c < colors && c < 4; c++)  | 
105  |  |  | 
106  | 41.1k  | #define SQR(x) ((x) * (x))  | 
107  | 8.20k  | #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31))  | 
108  | 60.5k  | #define MIN(a, b) ((a) < (b) ? (a) : (b))  | 
109  | 608k  | #define MAX(a, b) ((a) > (b) ? (a) : (b))  | 
110  | 156k  | #define LIM(x, min, max) MAX(min, MIN(x, max))  | 
111  | 0  | #define ULIM(x, y, z) ((y) < (z) ? LIM(x, y, z) : LIM(x, z, y))  | 
112  | 0  | #define CLIP(x) LIM((int)(x), 0, 65535)  | 
113  | 0  | #define CLIP15(x) LIM((int)(x), 0, 32767)  | 
114  |  | #define SWAP(a, b)                                                             \  | 
115  | 102  |   {                                                                            \ | 
116  | 102  |     a = a + b;                                                                 \  | 
117  | 102  |     b = a - b;                                                                 \  | 
118  | 102  |     a = a - b;                                                                 \  | 
119  | 102  |   }  | 
120  |  |  | 
121  |  | #define my_swap(type, i, j)                                                    \  | 
122  |  |   {                                                                            \ | 
123  |  |     type t = i;                                                                \  | 
124  |  |     i = j;                                                                     \  | 
125  |  |     j = t;                                                                     \  | 
126  |  |   }  | 
127  |  |  | 
128  |  | #ifdef __GNUC__  | 
129  |  | inline  | 
130  |  | #elif defined(_MSC_VER)  | 
131  |  | __forceinline  | 
132  |  | #else  | 
133  |  | static  | 
134  |  | #endif  | 
135  | 305k  | float fMAX(float a, float b) { return MAX(a, b); } | 
136  |  |  | 
137  |  | /*  | 
138  |  |    In order to inline this calculation, I make the risky  | 
139  |  |    assumption that all filter patterns can be described  | 
140  |  |    by a repeating pattern of eight rows and two columns  | 
141  |  |  | 
142  |  |    Do not use the FC or BAYER macros with the Leaf CatchLight,  | 
143  |  |    because its pattern is 16x16, not 2x8.  | 
144  |  |  | 
145  |  |    Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2  | 
146  |  |  | 
147  |  |         PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1  | 
148  |  |         0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4:  | 
149  |  |  | 
150  |  |           0 1 2 3 4 5   0 1 2 3 4 5   0 1 2 3 4 5   0 1 2 3 4 5  | 
151  |  |         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  | 
152  |  |         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  | 
153  |  |         2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y  | 
154  |  |         3 C Y C Y C Y 3 G M G M G M 3 G M G M G M  | 
155  |  |                         4 C Y C Y C Y 4 Y C Y C Y C  | 
156  |  |         PowerShot A5  5 G M G M G M 5 G M G M G M  | 
157  |  |         0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y  | 
158  |  |                         7 M G M G M G 7 M G M G M G  | 
159  |  |           0 1 2 3 4 5  | 
160  |  |         0 C Y C Y C Y  | 
161  |  |         1 G M G M G M  | 
162  |  |         2 C Y C Y C Y  | 
163  |  |         3 M G M G M G  | 
164  |  |  | 
165  |  |    All RGB cameras use one of these Bayer grids:  | 
166  |  |  | 
167  |  |         0x16161616: 0x61616161: 0x49494949: 0x94949494:  | 
168  |  |  | 
169  |  |           0 1 2 3 4 5   0 1 2 3 4 5   0 1 2 3 4 5   0 1 2 3 4 5  | 
170  |  |         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  | 
171  |  |         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  | 
172  |  |         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  | 
173  |  |         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  | 
174  |  |  */  | 
175  |  |  | 
176  |  | // _RGBG means R, G1, B, G2 sequence  | 
177  | 507k  | #define GRBG_2_RGBG(q)    (q ^ (q >> 1) ^ 1)  | 
178  | 1.06M  | #define RGGB_2_RGBG(q)    (q ^ (q >> 1))  | 
179  | 1.45k  | #define BG2RG1_2_RGBG(q)  (q ^ 2)  | 
180  | 236  | #define G2BRG1_2_RGBG(q)  (q ^ (q >> 1) ^ 3)  | 
181  | 410k  | #define GRGB_2_RGBG(q)    (q ^ 1)  | 
182  | 12  | #define RBGG_2_RGBG(q)    ((q >> 1) | ((q & 1) << 1))  | 
183  |  |  | 
184  | 0  | #define RAWINDEX(row, col) ((row)*raw_width + (col))  | 
185  | 0  | #define RAW(row, col) raw_image[(row)*raw_width + (col)]  | 
186  |  | #define BAYER(row, col)                                                        \  | 
187  | 0  |   image[((row) >> shrink) * iwidth + ((col) >> shrink)][FC(row, col)]  | 
188  |  |  | 
189  |  | #define BAYER2(row, col)                                                       \  | 
190  | 0  |   image[((row) >> shrink) * iwidth + ((col) >> shrink)][fcol(row, col)]  | 
191  |  | #define BAYERC(row, col, c)                                                    \  | 
192  |  |   imgdata.image[((row) >> IO.shrink) * S.iwidth + ((col) >> IO.shrink)][c]  | 
193  |  |  | 
194  |  | #endif  |