File indexing completed on 2025-01-05 03:56:45
0001 /* 0002 Copyright 2008-2021 LibRaw LLC (info@libraw.org) 0003 0004 LibRaw is free software; you can redistribute it and/or modify 0005 it under the terms of the one of two licenses as you choose: 0006 0007 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 0008 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 0009 0010 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 0011 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 0012 0013 This file is generated from Dave Coffin's dcraw.c 0014 dcraw.c -- Dave Coffin's raw photo decoder 0015 Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net 0016 0017 Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/) 0018 for more information 0019 */ 0020 0021 #ifndef LIBRAW_INT_DEFINES_H 0022 #define LIBRAW_INT_DEFINES_H 0023 #ifndef USE_JPEG 0024 #define NO_JPEG 0025 #endif 0026 #ifndef USE_JASPER 0027 #define NO_JASPER 0028 #endif 0029 #define DCRAW_VERSION "9.26" 0030 0031 #ifndef _GNU_SOURCE 0032 #define _GNU_SOURCE 0033 #endif 0034 #define _USE_MATH_DEFINES 0035 #include <ctype.h> 0036 #include <errno.h> 0037 #include <fcntl.h> 0038 #include <float.h> 0039 #include <limits.h> 0040 #include <math.h> 0041 #include <setjmp.h> 0042 #include <stdio.h> 0043 #include <stdlib.h> 0044 #include <string.h> 0045 #include <time.h> 0046 #include <sys/types.h> 0047 #ifdef __CYGWIN__ 0048 #include <io.h> 0049 #endif 0050 #if defined LIBRAW_WIN32_CALLS 0051 #include <sys/utime.h> 0052 #ifndef LIBRAW_NO_WINSOCK2 0053 #include <winsock2.h> 0054 #pragma comment(lib, "ws2_32.lib") 0055 #endif 0056 #define snprintf _snprintf 0057 #define strcasecmp stricmp 0058 #define strncasecmp strnicmp 0059 #else 0060 #include <unistd.h> 0061 #include <utime.h> 0062 #include <netinet/in.h> 0063 typedef long long INT64; 0064 typedef unsigned long long UINT64; 0065 #endif 0066 0067 #ifdef NODEPS 0068 #define NO_JASPER 0069 #define NO_JPEG 0070 #define NO_LCMS 0071 #endif 0072 #ifndef NO_JASPER 0073 #include <jasper/jasper.h> /* Decode Red camera movies */ 0074 #endif 0075 #ifndef NO_JPEG 0076 #include <jpeglib.h> /* Decode compressed Kodak DC120 photos */ 0077 #endif /* and Adobe Lossy DNGs */ 0078 #ifndef NO_LCMS 0079 #ifdef USE_LCMS 0080 #include <lcms.h> /* Support color profiles */ 0081 #else 0082 #include <lcms2.h> /* Support color profiles */ 0083 #endif 0084 #endif 0085 #ifdef LOCALEDIR 0086 #include <libintl.h> 0087 #define _(String) gettext(String) 0088 #else 0089 #define _(String) (String) 0090 #endif 0091 0092 #ifdef LJPEG_DECODE 0093 #error Please compile dcraw.c by itself. 0094 #error Do not link it with ljpeg_decode. 0095 #endif 0096 0097 #ifndef LONG_BIT 0098 #define LONG_BIT (8 * sizeof(long)) 0099 #endif 0100 #define FORC(cnt) for (c = 0; c < cnt; c++) 0101 #define FORC3 FORC(3) 0102 #define FORC4 FORC(4) 0103 #define FORCC for (c = 0; c < colors && c < 4; c++) 0104 0105 #define SQR(x) ((x) * (x)) 0106 #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) 0107 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 0108 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 0109 #define LIM(x, min, max) MAX(min, MIN(x, max)) 0110 #define ULIM(x, y, z) ((y) < (z) ? LIM(x, y, z) : LIM(x, z, y)) 0111 #define CLIP(x) LIM((int)(x), 0, 65535) 0112 #define CLIP15(x) LIM((int)(x), 0, 32767) 0113 #define SWAP(a, b) \ 0114 { \ 0115 a = a + b; \ 0116 b = a - b; \ 0117 a = a - b; \ 0118 } 0119 0120 #define my_swap(type, i, j) \ 0121 { \ 0122 type t = i; \ 0123 i = j; \ 0124 j = t; \ 0125 } 0126 0127 #ifdef __GNUC__ 0128 inline 0129 #elif defined(_MSC_VER) 0130 __forceinline 0131 #else 0132 static 0133 #endif 0134 float fMAX(float a, float b) { return MAX(a, b); } 0135 0136 /* 0137 In order to inline this calculation, I make the risky 0138 assumption that all filter patterns can be described 0139 by a repeating pattern of eight rows and two columns 0140 0141 Do not use the FC or BAYER macros with the Leaf CatchLight, 0142 because its pattern is 16x16, not 2x8. 0143 0144 Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2 0145 0146 PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1 0147 0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4: 0148 0149 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0150 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 0151 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 0152 2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y 0153 3 C Y C Y C Y 3 G M G M G M 3 G M G M G M 0154 4 C Y C Y C Y 4 Y C Y C Y C 0155 PowerShot A5 5 G M G M G M 5 G M G M G M 0156 0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y 0157 7 M G M G M G 7 M G M G M G 0158 0 1 2 3 4 5 0159 0 C Y C Y C Y 0160 1 G M G M G M 0161 2 C Y C Y C Y 0162 3 M G M G M G 0163 0164 All RGB cameras use one of these Bayer grids: 0165 0166 0x16161616: 0x61616161: 0x49494949: 0x94949494: 0167 0168 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0169 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 0170 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 0171 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 0172 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 0173 */ 0174 0175 // _RGBG means R, G1, B, G2 sequence 0176 #define GRBG_2_RGBG(q) (q ^ (q >> 1) ^ 1) 0177 #define RGGB_2_RGBG(q) (q ^ (q >> 1)) 0178 #define BG2RG1_2_RGBG(q) (q ^ 2) 0179 #define G2BRG1_2_RGBG(q) (q ^ (q >> 1) ^ 3) 0180 #define GRGB_2_RGBG(q) (q ^ 1) 0181 #define RBGG_2_RGBG(q) ((q >> 1) | ((q & 1) << 1)) 0182 0183 #define RAWINDEX(row, col) ((row)*raw_width + (col)) 0184 #define RAW(row, col) raw_image[(row)*raw_width + (col)] 0185 #define BAYER(row, col) \ 0186 image[((row) >> shrink) * iwidth + ((col) >> shrink)][FC(row, col)] 0187 0188 #define BAYER2(row, col) \ 0189 image[((row) >> shrink) * iwidth + ((col) >> shrink)][fcol(row, col)] 0190 #define BAYERC(row, col, c) \ 0191 imgdata.image[((row) >> IO.shrink) * S.iwidth + ((col) >> IO.shrink)][c] 0192 0193 #endif