Update to dcraw 9.25, Revision: 1.475

This commit is contained in:
Ingo
2015-04-28 15:36:50 +02:00
parent ae6dccacfa
commit 34a419a6ca
4 changed files with 1074 additions and 573 deletions

View File

@@ -1,5 +1,5 @@
--- dcraw.c 2015-04-17 13:02:57 +0000
+++ dcraw.cc 2015-04-17 13:09:41 +0000
--- dcraw.c 2015-04-28 15:32:57.638976274 +0200
+++ dcraw.cc 2015-04-28 15:32:57.665976273 +0200
@@ -1,3 +1,15 @@
+/*RT*/#include <glib.h>
+/*RT*/#include <glib/gstdio.h>
@@ -15,7 +15,7 @@
+
/*
dcraw.c -- Dave Coffin's raw photo decoder
Copyright 1997-2014 by Dave Coffin, dcoffin a cybercom o net
Copyright 1997-2015 by Dave Coffin, dcoffin a cybercom o net
@@ -29,17 +41,17 @@
#define _GNU_SOURCE
#endif
@@ -62,11 +62,10 @@
-#if !defined(ushort)
-#define ushort unsigned short
-#endif
-
+#define ushort UshORt
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+
+#include "dcraw.h"
/*
- All global variables are defined here, and all functions that
@@ -196,7 +195,7 @@
unsigned c;
if (nbits > 25) return 0;
@@ -1265,14 +1228,14 @@
@@ -1284,14 +1247,14 @@
int i, nz;
char tail[424];
@@ -213,25 +212,7 @@
void CLASS ppm_thumb()
{
@@ -1516,14 +1479,15 @@
}
for (qr = 0; qr < 2; qr++) {
for (qc = 0; qc < 2; qc++) {
- int cx[18], cf[18];
+ int cx[19], cf[19];
for (i = 0; i < 16; i++) {
cx[1+i] = lc[qr][qc][i];
cf[1+i] = ref[i];
}
cx[0] = cf[0] = 0;
cx[17] = cf[17] = ((unsigned int)ref[15] * 65535) / lc[qr][qc][15];
- cubic_spline(cx, cf, 18);
+ cx[18] = cf[18] = 65535;
+ cubic_spline(cx, cf, 19);
for (row = (qr ? ph1.split_row : 0);
row < (qr ? raw_height : ph1.split_row); row++)
@@ -1634,10 +1598,10 @@
@@ -1653,10 +1616,10 @@
}
}
@@ -245,7 +226,7 @@
unsigned c;
if (nbits == -1)
@@ -1712,6 +1676,336 @@
@@ -1731,6 +1694,336 @@
maximum = 0xfffc - ph1.black;
}
@@ -582,7 +563,7 @@
void CLASS hasselblad_load_raw()
{
struct jhead jh;
@@ -1903,10 +2197,10 @@
@@ -1954,10 +2247,10 @@
maximum = curve[0x3ff];
}
@@ -596,7 +577,7 @@
int byte;
if (!nbits) return vbits=0;
@@ -2195,11 +2489,11 @@
@@ -2246,11 +2539,11 @@
METHODDEF(boolean)
fill_input_buffer (j_decompress_ptr cinfo)
{
@@ -610,7 +591,7 @@
cinfo->src->next_input_byte = jpeg_buffer;
cinfo->src->bytes_in_buffer = nbytes;
return TRUE;
@@ -2524,10 +2818,9 @@
@@ -2600,10 +2893,9 @@
maximum = (1 << (thumb_misc & 31)) - 1;
}
@@ -623,7 +604,7 @@
if (start) {
for (p=0; p < 4; p++)
pad[p] = key = key * 48828125 + 1;
@@ -2612,11 +2905,13 @@
@@ -2688,11 +2980,13 @@
bit += 7;
}
for (i=0; i < 16; i++, col+=2)
@@ -638,7 +619,7 @@
}
void CLASS samsung_load_raw()
@@ -2863,7 +3158,7 @@
@@ -2988,7 +3282,7 @@
void CLASS foveon_decoder (unsigned size, unsigned code)
{
@@ -647,7 +628,7 @@
struct decode *cur;
int i, len;
@@ -2960,7 +3255,7 @@
@@ -3085,7 +3379,7 @@
pred[c] += diff[dindex->leaf];
if (pred[c] >> 16 && ~pred[c] >> 16) derror();
}
@@ -656,7 +637,7 @@
}
}
}
@@ -3571,6 +3866,8 @@
@@ -3696,6 +3990,8 @@
if (load_raw == &CLASS phase_one_load_raw ||
load_raw == &CLASS phase_one_load_raw_c)
phase_one_correct();
@@ -665,7 +646,7 @@
if (fuji_width) {
for (row=0; row < raw_height-top_margin*2; row++) {
for (col=0; col < fuji_width << !fuji_layout; col++) {
@@ -3586,10 +3883,13 @@
@@ -3711,10 +4007,13 @@
}
}
} else {
@@ -681,7 +662,7 @@
if (mask[0][3] > 0) goto mask_set;
if (load_raw == &CLASS canon_load_raw ||
load_raw == &CLASS lossless_jpeg_load_raw) {
@@ -4191,239 +4491,8 @@
@@ -4316,239 +4615,8 @@
}
}
@@ -730,8 +711,7 @@
-
-/*
- This algorithm is officially called:
+/* RT: delete interpolation functions */
-
- "Interpolation using a Threshold-based variable number of gradients"
-
- described in http://scien.stanford.edu/pages/labsite/1999/psych221/projects/99/tingchen/algodep/vargra.html
@@ -874,7 +854,8 @@
- int dir[5] = { 1, width, -1, -width, 1 };
- int row, col, diff[2], guess[2], c, d, i;
- ushort (*pix)[4];
-
+/* RT: delete interpolation functions */
- border_interpolate(3);
- if (verbose) fprintf (stderr,_("PPG interpolation...\n"));
-
@@ -922,7 +903,7 @@
void CLASS cielab (ushort rgb[3], short lab[3])
{
@@ -4684,112 +4753,7 @@
@@ -4814,112 +4882,7 @@
}
#undef fcol
@@ -948,10 +929,10 @@
- rgb = (ushort(*)[TS][TS][3]) buffer;
- lab = (short (*)[TS][TS][3])(buffer + 12*TS*TS);
- homo = (char (*)[TS][TS]) (buffer + 24*TS*TS);
-
- for (top=2; top < height-5; top += TS-6)
- for (left=2; left < width-5; left += TS-6) {
-
-/* Interpolate green horizontally and vertically: */
- for (row=top; row < top+TS && row < height-2; row++) {
- col = left + (FC(row,left) & 1);
@@ -1035,7 +1016,7 @@
#undef TS
void CLASS median_filter()
@@ -4959,7 +4923,7 @@
@@ -5089,7 +5052,7 @@
}
}
@@ -1044,7 +1025,7 @@
void CLASS parse_makernote (int base, int uptag)
{
@@ -5116,12 +5080,16 @@
@@ -5246,12 +5209,16 @@
cam_mul[2] = get4() << 2;
}
}
@@ -1062,25 +1043,7 @@
if (tag == 0x1d)
while ((c = fgetc(ifp)) && c != EOF)
serial = serial*10 + (isdigit(c) ? c - '0' : c % 10);
@@ -5367,7 +5335,7 @@
{ "","DCB2","Volare","Cantare","CMost","Valeo 6","Valeo 11","Valeo 22",
"Valeo 11p","Valeo 17","","Aptus 17","Aptus 22","Aptus 75","Aptus 65",
"Aptus 54S","Aptus 65S","Aptus 75S","AFi 5","AFi 6","AFi 7",
- "Aptus-II 7","","","Aptus-II 6","","","Aptus-II 10","Aptus-II 5",
+ "AFi-II 7","","","Aptus-II 6","","","Aptus-II 10","Aptus-II 5",
"","","","","Aptus-II 10R","Aptus-II 8","","Aptus-II 12","","AFi-II 12" };
float romm_cam[3][3];
@@ -5456,6 +5424,8 @@
wbi = -2;
}
if (tag == 2118) wbtemp = getint(type);
+ if (tag == 2120 + wbi) /* RT: wb tag for DCS760 */
+ FORC3 cam_mul[c] = 2048.0 / getreal(type); /* RT: wb tag for DCS760 */
if (tag == 2130 + wbi)
FORC3 mul[c] = getreal(type);
if (tag == 2140 + wbi && wbi >= 0)
@@ -5475,8 +5445,8 @@
@@ -5613,8 +5580,8 @@
}
}
@@ -1091,7 +1054,7 @@
int CLASS parse_tiff_ifd (int base)
{
@@ -5489,7 +5459,7 @@
@@ -5627,7 +5594,7 @@
unsigned sony_curve[] = { 0,0,0,0,0,4095 };
unsigned *buf, sony_offset=0, sony_length=0, sony_key=0;
struct jhead jh;
@@ -1100,7 +1063,7 @@
if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0])
return 1;
@@ -5564,7 +5534,8 @@
@@ -5702,7 +5669,8 @@
fgets (make, 64, ifp);
break;
case 272: /* Model */
@@ -1110,7 +1073,7 @@
break;
case 280: /* Panasonic RW2 offset */
if (type != 4) break;
@@ -5620,6 +5591,9 @@
@@ -5762,6 +5730,9 @@
case 315: /* Artist */
fread (artist, 64, 1, ifp);
break;
@@ -1120,7 +1083,7 @@
case 322: /* TileWidth */
tiff_ifd[ifd].tile_width = getint(type);
break;
@@ -5635,6 +5609,9 @@
@@ -5777,6 +5748,9 @@
is_raw = 5;
}
break;
@@ -1130,7 +1093,7 @@
case 330: /* SubIFDs */
if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].width == 3872) {
load_raw = &CLASS sony_arw_load_raw;
@@ -5648,6 +5625,9 @@
@@ -5790,6 +5764,9 @@
fseek (ifp, i+4, SEEK_SET);
}
break;
@@ -1140,7 +1103,7 @@
case 400:
strcpy (make, "Sarnoff");
maximum = 0xfff;
@@ -5828,6 +5808,9 @@
@@ -5971,6 +5948,9 @@
if (!make[0]) strcpy (make, "DNG");
is_raw = 1;
break;
@@ -1150,10 +1113,12 @@
case 50710: /* CFAPlaneColor */
if (filters == 9) break;
if (len > 4) len = 4;
@@ -5859,10 +5842,21 @@
@@ -6002,12 +5982,21 @@
case 61450:
cblack[4] = cblack[5] = MIN(sqrt(len),64);
case 50714: /* BlackLevel */
- if (!(cblack[4] * cblack[5]))
- cblack[4] = cblack[5] = 1;
- FORC (cblack[4] * cblack[5])
- cblack[6+c] = getreal(type);
- black = 0;
@@ -1176,7 +1141,7 @@
case 50715: /* BlackLevelDeltaH */
case 50716: /* BlackLevelDeltaV */
for (num=i=0; i < len; i++)
@@ -5940,12 +5934,15 @@
@@ -6085,12 +6074,15 @@
fread (buf, sony_length, 1, ifp);
sony_decrypt (buf, sony_length/4, 1, sony_key);
sfp = ifp;
@@ -1198,7 +1163,7 @@
ifp = sfp;
free (buf);
}
@@ -5969,6 +5966,7 @@
@@ -6114,6 +6106,7 @@
int CLASS parse_tiff (int base)
{
int doff;
@@ -1206,7 +1171,7 @@
fseek (ifp, base, SEEK_SET);
order = get2();
@@ -6046,7 +6044,7 @@
@@ -6191,7 +6184,7 @@
case 8: load_raw = &CLASS eight_bit_load_raw; break;
case 12: if (tiff_ifd[raw].phint == 2)
load_flags = 6;
@@ -1215,7 +1180,7 @@
case 14: load_flags = 0;
case 16: load_raw = &CLASS unpacked_load_raw;
if (!strncmp(make,"OLYMPUS",7) &&
@@ -6079,6 +6077,7 @@
@@ -6230,6 +6223,7 @@
case 32803: load_raw = &CLASS kodak_65000_load_raw;
}
case 32867: case 34892: break;
@@ -1223,7 +1188,7 @@
default: is_raw = 0;
}
if (!dng_version)
@@ -6164,7 +6163,7 @@
@@ -6315,7 +6309,7 @@
{
const char *file, *ext;
char *jname, *jfile, *jext;
@@ -1232,7 +1197,7 @@
ext = strrchr (ifname, '.');
file = strrchr (ifname, '/');
@@ -6186,13 +6185,14 @@
@@ -6337,13 +6331,14 @@
} else
while (isdigit(*--jext)) {
if (*jext != '9') {
@@ -1249,7 +1214,7 @@
if (verbose)
fprintf (stderr,_("Reading metadata from %s ...\n"), jname);
parse_tiff (12);
@@ -6537,7 +6537,11 @@
@@ -6688,7 +6683,11 @@
order = get2();
hlen = get4();
if (get4() == 0x48454150) /* "HEAP" */
@@ -1261,7 +1226,7 @@
if (parse_tiff (save+6)) apply_tiff();
fseek (ifp, save+len, SEEK_SET);
}
@@ -6789,7 +6793,8 @@
@@ -6960,7 +6959,8 @@
{
static const struct {
const char *prefix;
@@ -1271,7 +1236,7 @@
} table[] = {
{ "AgfaPhoto DC-833m", 0, 0, /* DJC */
{ 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } },
@@ -7690,6 +7695,27 @@
@@ -7919,6 +7919,27 @@
}
break;
}
@@ -1290,7 +1255,7 @@
+ }
+ if (trans[0]) {
+ for (j=0; j < 12; j++) {
+ cam_xyz[0][j] = trans[j] / 10000.0;
+ ((double *)cam_xyz)[j] = trans[j] / 10000.0;
+ }
+ cam_xyz_coeff (rgb_cam,cam_xyz);
+ }
@@ -1299,7 +1264,7 @@
}
void CLASS simple_coeff (int index)
@@ -7967,7 +7993,7 @@
@@ -8229,7 +8250,7 @@
tiff_flip = flip = filters = UINT_MAX; /* unknown */
raw_height = raw_width = fuji_width = fuji_layout = cr2_slice[0] = 0;
maximum = height = width = top_margin = left_margin = 0;
@@ -1308,7 +1273,7 @@
iso_speed = shutter = aperture = focal_len = unique_id = 0;
tiff_nifds = 0;
memset (tiff_ifd, 0, sizeof tiff_ifd);
@@ -7999,13 +8025,20 @@
@@ -8261,13 +8282,20 @@
fread (head, 1, 32, ifp);
fseek (ifp, 0, SEEK_END);
flen = fsize = ftell(ifp);
@@ -1331,7 +1296,7 @@
parse_ciff (hlen, flen-hlen, 0);
load_raw = &CLASS canon_load_raw;
} else if (parse_tiff(0)) apply_tiff();
@@ -8051,6 +8084,7 @@
@@ -8313,6 +8341,7 @@
fseek (ifp, 100+28*(shot_select > 0), SEEK_SET);
parse_tiff (data_offset = get4());
parse_tiff (thumb_offset+12);
@@ -1339,35 +1304,29 @@
apply_tiff();
} else if (!memcmp (head,"RIFF",4)) {
fseek (ifp, 0, SEEK_SET);
@@ -8160,15 +8194,18 @@
@@ -8426,9 +8455,10 @@
if (make[0] == 0) parse_smal (0, flen);
if (make[0] == 0) {
parse_jpeg(0);
- if (!strncmp(model,"ov",2) && !fseek (ifp, -6404096, SEEK_END) &&
- if (!(strncmp(model,"ov",2) && strncmp(model,"RP_OV",5)) &&
- !fseek (ifp, -6404096, SEEK_END) &&
- fread (head, 1, 32, ifp) && !strcmp(head,"BRCMn")) {
- strcpy (make, "OmniVision");
- data_offset = ftell(ifp) + 0x8000-32;
- width = raw_width;
- raw_width = 2611;
- load_raw = &CLASS nokia_load_raw;
- filters = 0x16161616;
- } else is_raw = 0;
+ //RT fix for the use of fseek below
+ if (!strncmp(model,"ov",2)) {
+ //RT fix for the use of fseek below
+ if (!(strncmp(model,"ov",2) && strncmp(model,"RP_OV",5))) {
+ fseek (ifp, -6404096, SEEK_END);
+ if (fread (head, 1, 32, ifp) && !strcmp(head,"BRCMn")) {
+ strcpy (make, "OmniVision");
+ data_offset = ftell(ifp) + 0x8000-32;
+ width = raw_width;
+ raw_width = 2611;
+ load_raw = &CLASS nokia_load_raw;
+ filters = 0x16161616;
+ } else is_raw = 0;
+ }
strcpy (make, "OmniVision");
data_offset = ftell(ifp) + 0x8000-32;
width = raw_width;
@@ -8437,6 +8467,7 @@
filters = 0x16161616;
} else is_raw = 0;
}
+ }
for (i=0; i < sizeof corp / sizeof *corp; i++)
@@ -8201,7 +8238,7 @@
if (strcasestr (make, corp[i])) /* Simplify company names */
@@ -8468,7 +8499,7 @@
if (height == 3136 && width == 4864) /* Pentax K20D and Samsung GX20 */
{ height = 3124; width = 4688; filters = 0x16161616; }
if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x")))
@@ -1376,7 +1335,7 @@
if (width >= 4960 && !strncmp(model,"K-5",3))
{ left_margin = 10; width = 4950; filters = 0x16161616; }
if (width == 4736 && !strcmp(model,"K-7"))
@@ -8220,6 +8257,7 @@
@@ -8487,6 +8518,7 @@
switch (tiff_compress) {
case 1: load_raw = &CLASS packed_dng_load_raw; break;
case 7: load_raw = &CLASS lossless_dng_load_raw; break;
@@ -1384,7 +1343,7 @@
case 34892: load_raw = &CLASS lossy_dng_load_raw; break;
default: load_raw = 0;
}
@@ -8268,6 +8306,7 @@
@@ -8541,6 +8573,7 @@
if (height > width) pixel_aspect = 2;
filters = 0;
simple_coeff(0);
@@ -1392,16 +1351,7 @@
} else if (!strcmp(make,"Canon") && tiff_bps == 15) {
switch (width) {
case 3344: width -= 66;
@@ -8347,7 +8386,7 @@
width -= 44;
} else if (!strcmp(model,"D3200") ||
!strcmp(model,"D600") ||
- !strncmp(model,"D800",4)) {
+ !strcmp(model,"D800") || !strcmp(model,"D800E") ) {
width -= 46;
} else if (!strcmp(model,"D4") ||
!strcmp(model,"Df")) {
@@ -8567,24 +8606,53 @@
@@ -8846,24 +8879,53 @@
if (load_raw == &CLASS lossless_jpeg_load_raw)
load_raw = &CLASS hasselblad_load_raw;
if (raw_width == 7262) {
@@ -1411,10 +1361,13 @@
top_margin = 4;
left_margin = 7;
filters = 0x61616161;
} else if (raw_width == 7410) {
- } else if (raw_width == 7410 || raw_width == 8282) {
- height -= 84;
- width -= 82;
+ } else if (raw_width == 7410) {
+ if (!strcmp(model, "H4D")) strcpy(model, "H4D-40"); // RT
height = 5502;
width = 7328;
+ height = 5502;
+ width = 7328;
top_margin = 4;
left_margin = 41;
filters = 0x61616161;
@@ -1457,7 +1410,7 @@
} else if (raw_width == 4090) {
strcpy (model, "V96C");
height -= (top_margin = 6);
@@ -8637,6 +8705,7 @@
@@ -8921,6 +8983,7 @@
filters = 0x16161616;
}
} else if (!strcmp(make,"Leica") || !strcmp(make,"Panasonic")) {
@@ -1465,7 +1418,7 @@
if ((flen - data_offset) / (raw_width*8/7) == raw_height)
load_raw = &CLASS panasonic_load_raw;
if (!load_raw) {
@@ -8654,6 +8723,7 @@
@@ -8938,6 +9001,7 @@
}
filters = 0x01010101 * (uchar) "\x94\x61\x49\x16"
[((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3];
@@ -1473,7 +1426,7 @@
} else if (!strcmp(model,"C770UZ")) {
height = 1718;
width = 2304;
@@ -8883,6 +8953,14 @@
@@ -9155,6 +9219,14 @@
memcpy (rgb_cam, cmatrix, sizeof cmatrix);
raw_color = 0;
}
@@ -1488,16 +1441,7 @@
if (raw_color) adobe_coeff (make, model);
if (load_raw == &CLASS kodak_radc_load_raw)
if (raw_color) adobe_coeff ("Apple","Quicktake");
@@ -8899,7 +8977,7 @@
if (!tiff_bps) tiff_bps = 12;
if (!maximum) maximum = (1 << tiff_bps) - 1;
if (!load_raw || height < 22 || width < 22 ||
- tiff_bps > 16 || tiff_samples > 4 || colors > 4)
+ tiff_samples > 4 || colors > 4)
is_raw = 0;
#ifdef NO_JASPER
if (load_raw == &CLASS redcine_load_raw) {
@@ -8978,195 +9056,250 @@
@@ -9250,194 +9322,249 @@
}
#endif
@@ -1582,11 +1526,77 @@
- for (j=0; j < colors; j++)
- for (out_cam[i][j] = k=0; k < 3; k++)
- out_cam[i][j] += out_rgb[output_color-1][i][k] * rgb_cam[k][j];
- }
+/* RT: DNG Float */
+
+#include <zlib.h>
+#include <stdint.h>
+
+static void decodeFPDeltaRow(Bytef * src, Bytef * dst, size_t tileWidth, size_t realTileWidth, int bytesps, int factor) {
+ // DecodeDeltaBytes
+ for (size_t col = factor; col < realTileWidth*bytesps; ++col) {
+ src[col] += src[col - factor];
+ }
+ // Reorder bytes into the image
+ // 16 and 32-bit versions depend on local architecture, 24-bit does not
+ if (bytesps == 3) {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ dst[col*3] = src[col];
+ dst[col*3 + 1] = src[col + realTileWidth];
+ dst[col*3 + 2] = src[col + realTileWidth*2];
+ }
+ } else {
+ union X { uint32_t x; uint8_t c; };
+ if (((union X){1}).c) {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ for (size_t byte = 0; byte < bytesps; ++byte)
+ dst[col*bytesps + byte] = src[col + realTileWidth*(bytesps-byte-1)]; // Little endian
+ }
+ } else {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ for (size_t byte = 0; byte < bytesps; ++byte)
+ dst[col*bytesps + byte] = src[col + realTileWidth*byte];
+ }
+ }
+ }
+
+}
+
+// From DNG SDK dng_utils.h
+static inline uint32_t DNG_HalfToFloat(uint16_t halfValue) {
+ int32_t sign = (halfValue >> 15) & 0x00000001;
+ int32_t exponent = (halfValue >> 10) & 0x0000001f;
+ int32_t mantissa = halfValue & 0x000003ff;
+ if (exponent == 0) {
+ if (mantissa == 0) {
+ // Plus or minus zero
+ return (uint32_t) (sign << 31);
+ } else {
+ // Denormalized number -- renormalize it
+ while (!(mantissa & 0x00000400)) {
+ mantissa <<= 1;
+ exponent -= 1;
+ }
+ exponent += 1;
+ mantissa &= ~0x00000400;
+ }
+ } else if (exponent == 31) {
+ if (mantissa == 0) {
+ // Positive or negative infinity, convert to maximum (16 bit) values.
+ return (uint32_t) ((sign << 31) | ((0x1eL + 127 - 15) << 23) | (0x3ffL << 13));
+ } else {
+ // Nan -- Just set to zero.
+ return 0;
+ }
}
- if (verbose)
- fprintf (stderr, raw_color ? _("Building histograms...\n") :
- _("Converting to %s colorspace...\n"), name[output_color-1]);
+/* RT: DNG Float */
+ // Normalized number
+ exponent += (127 - 15);
+ mantissa <<= 13;
+ // Assemble sign, exponent and mantissa.
+ return (uint32_t) ((sign << 31) | (exponent << 23) | mantissa);
+}
- memset (histogram, 0, sizeof histogram);
- for (img=image[0], row=0; row < height; row++)
@@ -1615,117 +1625,6 @@
- float r, c, fr, fc;
- unsigned ur, uc;
- ushort wide, high, (*img)[4], (*pix)[4];
+#include <zlib.h>
+#include <stdint.h>
- if (!fuji_width) return;
- if (verbose)
- fprintf (stderr,_("Rotating image 45 degrees...\n"));
- fuji_width = (fuji_width - 1 + shrink) >> shrink;
- step = sqrt(0.5);
- wide = fuji_width / step;
- high = (height - fuji_width) / step;
- img = (ushort (*)[4]) calloc (high, wide*sizeof *img);
- merror (img, "fuji_rotate()");
-
- for (row=0; row < high; row++)
- for (col=0; col < wide; col++) {
- ur = r = fuji_width + (row-col)*step;
- uc = c = (row+col)*step;
- if (ur > height-2 || uc > width-2) continue;
- fr = r - ur;
- fc = c - uc;
- pix = image + ur*width + uc;
- for (i=0; i < colors; i++)
- img[row*wide+col][i] =
- (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) +
- (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr;
+static void decodeFPDeltaRow(Bytef * src, Bytef * dst, size_t tileWidth, size_t realTileWidth, int bytesps, int factor) {
+ // DecodeDeltaBytes
+ for (size_t col = factor; col < realTileWidth*bytesps; ++col) {
+ src[col] += src[col - factor];
+ }
+ // Reorder bytes into the image
+ // 16 and 32-bit versions depend on local architecture, 24-bit does not
+ if (bytesps == 3) {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ dst[col*3] = src[col];
+ dst[col*3 + 1] = src[col + realTileWidth];
+ dst[col*3 + 2] = src[col + realTileWidth*2];
}
- free (image);
- width = wide;
- height = high;
- image = img;
- fuji_width = 0;
+ } else {
+ union X { uint32_t x; uint8_t c; };
+ if (((union X){1}).c) {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ for (size_t byte = 0; byte < bytesps; ++byte)
+ dst[col*bytesps + byte] = src[col + realTileWidth*(bytesps-byte-1)]; // Little endian
+ }
+ } else {
+ for (size_t col = 0; col < tileWidth; ++col) {
+ for (size_t byte = 0; byte < bytesps; ++byte)
+ dst[col*bytesps + byte] = src[col + realTileWidth*byte];
+ }
+ }
+ }
+
}
-void CLASS stretch()
-{
- ushort newdim, (*img)[4], *pix0, *pix1;
- int row, col, c;
- double rc, frac;
+// From DNG SDK dng_utils.h
+static inline uint32_t DNG_HalfToFloat(uint16_t halfValue) {
+ int32_t sign = (halfValue >> 15) & 0x00000001;
+ int32_t exponent = (halfValue >> 10) & 0x0000001f;
+ int32_t mantissa = halfValue & 0x000003ff;
+ if (exponent == 0) {
+ if (mantissa == 0) {
+ // Plus or minus zero
+ return (uint32_t) (sign << 31);
+ } else {
+ // Denormalized number -- renormalize it
+ while (!(mantissa & 0x00000400)) {
+ mantissa <<= 1;
+ exponent -= 1;
+ }
+ exponent += 1;
+ mantissa &= ~0x00000400;
+ }
+ } else if (exponent == 31) {
+ if (mantissa == 0) {
+ // Positive or negative infinity, convert to maximum (16 bit) values.
+ return (uint32_t) ((sign << 31) | ((0x1eL + 127 - 15) << 23) | (0x3ffL << 13));
+ } else {
+ // Nan -- Just set to zero.
+ return 0;
+ }
+ }
+ // Normalized number
+ exponent += (127 - 15);
+ mantissa <<= 13;
+ // Assemble sign, exponent and mantissa.
+ return (uint32_t) ((sign << 31) | (exponent << 23) | mantissa);
+}
- if (pixel_aspect == 1) return;
- if (verbose) fprintf (stderr,_("Stretching the image...\n"));
- if (pixel_aspect < 1) {
- newdim = height / pixel_aspect + 0.5;
- img = (ushort (*)[4]) calloc (width, newdim*sizeof *img);
- merror (img, "stretch()");
- for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) {
- frac = rc - (c = rc);
- pix0 = pix1 = image[c*width];
- if (c+1 < height) pix1 += width*4;
- for (col=0; col < width; col++, pix0+=4, pix1+=4)
- FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5;
+static inline uint32_t DNG_FP24ToFloat(const uint8_t * input) {
+ int32_t sign = (input [0] >> 7) & 0x01;
+ int32_t exponent = (input [0] ) & 0x7F;
@@ -1750,18 +1649,7 @@
+ } else {
+ // Nan -- Just set to zero.
+ return 0;
}
- height = newdim;
- } else {
- newdim = width * pixel_aspect + 0.5;
- img = (ushort (*)[4]) calloc (height, newdim*sizeof *img);
- merror (img, "stretch()");
- for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) {
- frac = rc - (c = rc);
- pix0 = pix1 = image[c];
- if (c+1 < width) pix1 += 4;
- for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4)
- FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5;
+ }
+ }
+ // Normalized number
+ exponent += (128 - 64);
@@ -1769,7 +1657,35 @@
+ // Assemble sign, exponent and mantissa.
+ return (uint32_t) ((sign << 31) | (exponent << 23) | mantissa);
+}
+
- if (!fuji_width) return;
- if (verbose)
- fprintf (stderr,_("Rotating image 45 degrees...\n"));
- fuji_width = (fuji_width - 1 + shrink) >> shrink;
- step = sqrt(0.5);
- wide = fuji_width / step;
- high = (height - fuji_width) / step;
- img = (ushort (*)[4]) calloc (high, wide*sizeof *img);
- merror (img, "fuji_rotate()");
-
- for (row=0; row < high; row++)
- for (col=0; col < wide; col++) {
- ur = r = fuji_width + (row-col)*step;
- uc = c = (row+col)*step;
- if (ur > height-2 || uc > width-2) continue;
- fr = r - ur;
- fc = c - uc;
- pix = image + ur*width + uc;
- for (i=0; i < colors; i++)
- img[row*wide+col][i] =
- (pix[ 0][i]*(1-fc) + pix[ 1][i]*fc) * (1-fr) +
- (pix[width][i]*(1-fc) + pix[width+1][i]*fc) * fr;
- }
- free (image);
- width = wide;
- height = high;
- image = img;
- fuji_width = 0;
+static void expandFloats(Bytef * dst, int tileWidth, int bytesps) {
+ if (bytesps == 2) {
+ uint16_t * dst16 = (uint16_t *) dst;
@@ -1782,14 +1698,11 @@
+ uint32_t * dst32 = (uint32_t *) dst;
+ for (int index = tileWidth - 1; index >= 0; --index, dst8 -= 3) {
+ dst32[index] = DNG_FP24ToFloat(dst8);
}
- width = newdim;
}
- free (image);
- image = img;
+ }
+ }
}
-int CLASS flip_index (int row, int col)
-void CLASS stretch()
+static void copyFloatDataToInt(float * src, ushort * dst, size_t size, float max) {
+ bool negative = false, nan = false;
+
@@ -1870,13 +1783,24 @@
+#pragma omp parallel
+#endif
{
- if (flip & 4) SWAP(row,col);
- if (flip & 2) row = iheight - 1 - row;
- if (flip & 1) col = iwidth - 1 - col;
- return row * iwidth + col;
- ushort newdim, (*img)[4], *pix0, *pix1;
- int row, col, c;
- double rc, frac;
+ Bytef * cBuffer = new Bytef[maxCompressed];
+ Bytef * uBuffer = new Bytef[dstLen];
+
- if (pixel_aspect == 1) return;
- if (verbose) fprintf (stderr,_("Stretching the image...\n"));
- if (pixel_aspect < 1) {
- newdim = height / pixel_aspect + 0.5;
- img = (ushort (*)[4]) calloc (width, newdim*sizeof *img);
- merror (img, "stretch()");
- for (rc=row=0; row < newdim; row++, rc+=pixel_aspect) {
- frac = rc - (c = rc);
- pix0 = pix1 = image[c*width];
- if (c+1 < height) pix1 += width*4;
- for (col=0; col < width; col++, pix0+=4, pix1+=4)
- FORCC img[row*width+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5;
+#ifdef _OPENMP
+#pragma omp for collapse(2) nowait
+#endif
@@ -1906,35 +1830,49 @@
+ // TODO
+ }
+ }
+ }
+
}
- height = newdim;
- } else {
- newdim = width * pixel_aspect + 0.5;
- img = (ushort (*)[4]) calloc (height, newdim*sizeof *img);
- merror (img, "stretch()");
- for (rc=col=0; col < newdim; col++, rc+=1/pixel_aspect) {
- frac = rc - (c = rc);
- pix0 = pix1 = image[c];
- if (c+1 < width) pix1 += 4;
- for (row=0; row < height; row++, pix0+=width*4, pix1+=width*4)
- FORCC img[row*newdim+col][c] = pix0[c]*(1-frac) + pix1[c]*frac + 0.5;
- }
- width = newdim;
- }
- free (image);
- image = img;
-}
-
-int CLASS flip_index (int row, int col)
-{
- if (flip & 4) SWAP(row,col);
- if (flip & 2) row = iheight - 1 - row;
- if (flip & 1) col = iwidth - 1 - col;
- return row * iwidth + col;
+
+ delete [] cBuffer;
+ delete [] uBuffer;
+}
}
+ }
+
+
+ if (ifd->sample_format == 3) { // Floating point data
+ copyFloatDataToInt(float_raw_image, raw_image, raw_width*raw_height, maximum);
+ }
}
+/* RT: removed unused functions */
+}
+
+/* RT: removed unused functions */
struct tiff_tag {
ushort tag, type;
int count;
@@ -9188,585 +9321,12 @@
unsigned gps[26];
@@ -9461,590 +9588,11 @@
char desc[512], make[64], model[64], soft[32], date[20], artist[64];
};
+/* RT: Delete from here */
+/*RT*/#undef SQR
+/*RT*/#undef MAX
+/*RT*/#undef MIN
+/*RT*/#undef ABS
+/*RT*/#undef LIM
+/*RT*/#undef ULIM
+/*RT*/#undef CLIP
-void CLASS tiff_set (ushort *ntag,
- ushort tag, ushort type, int count, int val)
@@ -2369,9 +2307,15 @@
- printf (_("Output size: %4d x %d\n"), iwidth, iheight);
- printf (_("Raw colors: %d"), colors);
- if (filters) {
- int fhigh = 2, fwide = 2;
- if ((filters ^ (filters >> 8)) & 0xff) fhigh = 4;
- if ((filters ^ (filters >> 16)) & 0xffff) fhigh = 8;
- if (filters == 1) fhigh = fwide = 16;
- if (filters == 9) fhigh = fwide = 6;
- printf (_("\nFilter pattern: "));
- for (i=0; i < 16; i++)
- putchar (cdesc[fcol(i >> 1,i & 1)]);
- for (i=0; i < fhigh; i++)
- for (c = i && putchar('/') && 0; c < fwide; c++)
- putchar (cdesc[fcol(i,c)]);
- }
- printf (_("\nDaylight multipliers:"));
- FORCC printf (" %f", pre_mul[c]);
@@ -2517,3 +2461,11 @@
- }
- return status;
-}
+/* RT: Delete from here */
+/*RT*/#undef SQR
+/*RT*/#undef MAX
+/*RT*/#undef MIN
+/*RT*/#undef ABS
+/*RT*/#undef LIM
+/*RT*/#undef ULIM
+/*RT*/#undef CLIP