12b0e5d60 Snapshot 202403 a4c9b1981 loop parameters in remove_trailing_spaces e231b01a4 CR3-Qstep table: avoid wrong 64-bit code generation 21368133a 0.21.2 release a6f212a4a tag type => tag size mapping fixed 41506ef73 cubic_spline: better handling of non-integer data 17294b5fd extra metadata check in arq_load_raw 47d9dd8e2 Better incorrect data handling in cubic_spline 3baa51068 skip invalid pattern in xtrans_interpolate eaf63bf5f Check HL recovery coeffs before processing a14574080 limit wavelet denoise minimum size 4e597e4e9 Merge pull request #594 from pinotree/path_max 086dcb9a6 raw-identify: use fallback if PATH_MAX not available 0e105f9f8 additional check against corrupted ljpeg layout 0c8b68e9f Disable color conversion for Canon 16-bit thumbnails cd1abd695 docs/changelog: explained the case when no thumbnail is found in specific file 6fffd414b rename swapXX to libraw_swapXX to avoid name conflict af78ae48a Check against corrupted LJPEG header in Canon sRAW decoder ba780e600 Limit embedded color profile allocation/read size 122bf7c5b Wrong alloc result check for 16-bit bitmap thumbnail e6dd2709e check pana_data/buffer offset before use ae2dc5884 Check P1 quadrant linearization coeff[15] against zero f2998bacc avoid integer overflow in buffer space check 443b7fb51 prevent buffer overrun in buffer_datastream::scanf_one 35a6d3615 ensure correct T.tlength for 16b bitmap thumbnails(2) b69ea8be5 ensure correct T.tlength for 16b bitmap thumbnails 2b6eca897 Do not run sraw decoder on (crafted) bayer files 68808b57f better striped thumbnails handling 9ab70f6dc do not set shrink flag for 3/4 component images 32425dd96 allow more decoders for fuji-rotated RAWs REVERT: 1ef70158d 0.21.2 release REVERT: 62f042366 tag type => tag size mapping fixed REVERT: ee087e3fe cubic_spline: better handling of non-integer data REVERT: af755b991 extra metadata check in arq_load_raw REVERT: 0fadd8819 Better incorrect data handling in cubic_spline REVERT: d7fb66053 skip invalid pattern in xtrans_interpolate REVERT: d059ed280 Check HL recovery coeffs before processing REVERT: 104730519 limit wavelet denoise minimum size REVERT: cae09838e raw-identify: use fallback if PATH_MAX not available REVERT: d6c677608 additional check against corrupted ljpeg layout REVERT: 1001a6ac1 Disable color conversion for Canon 16-bit thumbnails REVERT: a5130b01b docs/changelog: explained the case when no thumbnail is found in specific file REVERT: 600c0c63d rename swapXX to libraw_swapXX to avoid name conflict REVERT: 299c8a11b Check against corrupted LJPEG header in Canon sRAW decoder REVERT: ec8671ad9 Limit embedded color profile allocation/read size REVERT: 5229d5942 Wrong alloc result check for 16-bit bitmap thumbnail REVERT: b278b775f check pana_data/buffer offset before use REVERT: 7f4b8d3af Check P1 quadrant linearization coeff[15] against zero REVERT: e942a7db6 avoid integer overflow in buffer space check REVERT: f6a57cfb8 prevent buffer overrun in buffer_datastream::scanf_one REVERT: 3e62ed304 ensure correct T.tlength for 16b bitmap thumbnails(2) REVERT: 8e52d81cd ensure correct T.tlength for 16b bitmap thumbnails REVERT: 8e1af15e2 Do not run sraw decoder on (crafted) bayer files REVERT: 0ace959c2 better striped thumbnails handling REVERT: 477e0719f do not set shrink flag for 3/4 component images REVERT: c8efae6c5 allow more decoders for fuji-rotated RAWs git-subtree-dir: rtengine/libraw git-subtree-split: 12b0e5d60c57bb795382fda8494fc45f683550b8
188 lines
5.9 KiB
C
188 lines
5.9 KiB
C
/*
|
|
Copyright 2008-2024 LibRaw LLC (info@libraw.org)
|
|
|
|
LibRaw is free software; you can redistribute it and/or modify
|
|
it under the terms of the one of two licenses as you choose:
|
|
|
|
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
|
|
(See file LICENSE.LGPL provided in LibRaw distribution archive for details).
|
|
|
|
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
|
|
(See file LICENSE.CDDL provided in LibRaw distribution archive for details).
|
|
|
|
This file is generated from Dave Coffin's dcraw.c
|
|
dcraw.c -- Dave Coffin's raw photo decoder
|
|
Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net
|
|
|
|
Look into dcraw homepage (probably http://cybercom.net/~dcoffin/dcraw/)
|
|
for more information
|
|
*/
|
|
|
|
#ifndef LIBRAW_INT_DEFINES_H
|
|
#define LIBRAW_INT_DEFINES_H
|
|
#ifndef USE_JPEG
|
|
#define NO_JPEG
|
|
#endif
|
|
|
|
#define DCRAW_VERSION "9.26"
|
|
|
|
#ifndef _GNU_SOURCE
|
|
#define _GNU_SOURCE
|
|
#endif
|
|
#define _USE_MATH_DEFINES
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <float.h>
|
|
#include <limits.h>
|
|
#include <math.h>
|
|
#include <setjmp.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <sys/types.h>
|
|
#ifdef __CYGWIN__
|
|
#include <io.h>
|
|
#endif
|
|
#if defined LIBRAW_WIN32_CALLS
|
|
#include <sys/utime.h>
|
|
#ifndef LIBRAW_NO_WINSOCK2
|
|
#include <winsock2.h>
|
|
#pragma comment(lib, "ws2_32.lib")
|
|
#endif
|
|
#define snprintf _snprintf
|
|
#define strcasecmp stricmp
|
|
#define strncasecmp strnicmp
|
|
#else
|
|
#include <unistd.h>
|
|
#include <utime.h>
|
|
#include <netinet/in.h>
|
|
typedef long long INT64;
|
|
typedef unsigned long long UINT64;
|
|
#endif
|
|
|
|
#ifdef NODEPS
|
|
#define NO_JPEG
|
|
#define NO_LCMS
|
|
#endif
|
|
#ifndef NO_JPEG
|
|
#include <jpeglib.h> /* Decode compressed Kodak DC120 photos */
|
|
#endif /* and Adobe Lossy DNGs */
|
|
#ifndef NO_LCMS
|
|
#ifdef USE_LCMS
|
|
#include <lcms.h> /* Support color profiles */
|
|
#else
|
|
#include <lcms2.h> /* Support color profiles */
|
|
#endif
|
|
#endif
|
|
#ifdef LOCALEDIR
|
|
#include <libintl.h>
|
|
#define _(String) gettext(String)
|
|
#else
|
|
#define _(String) (String)
|
|
#endif
|
|
|
|
#ifdef LJPEG_DECODE
|
|
#error Please compile dcraw.c by itself.
|
|
#error Do not link it with ljpeg_decode.
|
|
#endif
|
|
|
|
#ifndef LONG_BIT
|
|
#define LONG_BIT (8 * sizeof(long))
|
|
#endif
|
|
#define FORC(cnt) for (c = 0; c < cnt; c++)
|
|
#define FORC3 FORC(3)
|
|
#define FORC4 FORC(4)
|
|
#define FORCC for (c = 0; c < colors && c < 4; c++)
|
|
|
|
#define SQR(x) ((x) * (x))
|
|
#define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31))
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
#define LIM(x, min, max) MAX(min, MIN(x, max))
|
|
#define ULIM(x, y, z) ((y) < (z) ? LIM(x, y, z) : LIM(x, z, y))
|
|
#define CLIP(x) LIM((int)(x), 0, 65535)
|
|
#define CLIP15(x) LIM((int)(x), 0, 32767)
|
|
#define SWAP(a, b) \
|
|
{ \
|
|
a = a + b; \
|
|
b = a - b; \
|
|
a = a - b; \
|
|
}
|
|
|
|
#define my_swap(type, i, j) \
|
|
{ \
|
|
type t = i; \
|
|
i = j; \
|
|
j = t; \
|
|
}
|
|
|
|
#ifdef __GNUC__
|
|
inline
|
|
#elif defined(_MSC_VER)
|
|
__forceinline
|
|
#else
|
|
static
|
|
#endif
|
|
float fMAX(float a, float b) { return MAX(a, b); }
|
|
|
|
/*
|
|
In order to inline this calculation, I make the risky
|
|
assumption that all filter patterns can be described
|
|
by a repeating pattern of eight rows and two columns
|
|
|
|
Do not use the FC or BAYER macros with the Leaf CatchLight,
|
|
because its pattern is 16x16, not 2x8.
|
|
|
|
Return values are either 0/1/2/3 = G/M/C/Y or 0/1/2/3 = R/G1/B/G2
|
|
|
|
PowerShot 600 PowerShot A50 PowerShot Pro70 Pro90 & G1
|
|
0xe1e4e1e4: 0x1b4e4b1e: 0x1e4b4e1b: 0xb4b4b4b4:
|
|
|
|
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
|
|
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
|
|
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
|
|
2 M G M G M G 2 Y C Y C Y C 2 C Y C Y C Y
|
|
3 C Y C Y C Y 3 G M G M G M 3 G M G M G M
|
|
4 C Y C Y C Y 4 Y C Y C Y C
|
|
PowerShot A5 5 G M G M G M 5 G M G M G M
|
|
0x1e4e1e4e: 6 Y C Y C Y C 6 C Y C Y C Y
|
|
7 M G M G M G 7 M G M G M G
|
|
0 1 2 3 4 5
|
|
0 C Y C Y C Y
|
|
1 G M G M G M
|
|
2 C Y C Y C Y
|
|
3 M G M G M G
|
|
|
|
All RGB cameras use one of these Bayer grids:
|
|
|
|
0x16161616: 0x61616161: 0x49494949: 0x94949494:
|
|
|
|
0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5
|
|
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
|
|
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
|
|
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
|
|
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
|
|
*/
|
|
|
|
// _RGBG means R, G1, B, G2 sequence
|
|
#define GRBG_2_RGBG(q) (q ^ (q >> 1) ^ 1)
|
|
#define RGGB_2_RGBG(q) (q ^ (q >> 1))
|
|
#define BG2RG1_2_RGBG(q) (q ^ 2)
|
|
#define G2BRG1_2_RGBG(q) (q ^ (q >> 1) ^ 3)
|
|
#define GRGB_2_RGBG(q) (q ^ 1)
|
|
#define RBGG_2_RGBG(q) ((q >> 1) | ((q & 1) << 1))
|
|
|
|
#define RAWINDEX(row, col) ((row)*raw_width + (col))
|
|
#define RAW(row, col) raw_image[(row)*raw_width + (col)]
|
|
#define BAYER(row, col) \
|
|
image[((row) >> shrink) * iwidth + ((col) >> shrink)][FC(row, col)]
|
|
|
|
#define BAYER2(row, col) \
|
|
image[((row) >> shrink) * iwidth + ((col) >> shrink)][fcol(row, col)]
|
|
#define BAYERC(row, col, c) \
|
|
imgdata.image[((row) >> IO.shrink) * S.iwidth + ((col) >> IO.shrink)][c]
|
|
|
|
#endif
|