From 5ce132c177a1bd99d53ba183fd37901851634ca2 Mon Sep 17 00:00:00 2001 From: torger Date: Sat, 24 May 2014 13:43:56 +0200 Subject: [PATCH] Hasselblad identification and color matrix fixes for 31, 50 and 60 megapixel backs --- rtengine/camconst.json | 14 +++++-- rtengine/dcraw.cc | 15 +++++++- rtengine/dcraw.patch | 87 +++++++++++++++++++++++++++--------------- 3 files changed, 82 insertions(+), 34 deletions(-) diff --git a/rtengine/camconst.json b/rtengine/camconst.json index 591c2eae9..fb4d3a501 100755 --- a/rtengine/camconst.json +++ b/rtengine/camconst.json @@ -884,9 +884,17 @@ Quality X: unknown, ie we knowing to little about the camera properties to know "ranges": { "black": 0, "white": 63300 } }, - { // Quality B, only raw crop fix here, dcraw hard-coded seems to handle the rest just fine - "make_model": [ "Hasselblad CFV-50" ], - "raw_crop": [ 44, 4, 8196, 6152 ] + { // Quality A + "make_model": [ "Hasselblad H3D-31", "Hasselblad H3DII-31", "Hasselblad H4D-31" ], + "dcraw_matrix": [ 5458, -1448, 145, -4479, 12338, 2401, -1659, 3086, 6710 ] + }, + { // Quality A + "make_model": [ "Hasselblad CFV-50", "Hasselblad H3DII-50", "Hasselblad H3DII-50MS", "Hasselblad H4D-50", "Hasselblad H4D-50MS", "Hasselblad H4D-200MS", "Hasselblad H5D-50", "Hasselblad H5D-50 Multi-Shot" ], + "dcraw_matrix": [ 5656, -659, -346, -3923, 12306, 1791, -1602, 3509, 5442 ] + }, + { // Quality A + "make_model": [ "Hasselblad H4D-60", "Hasselblad H5D-60" ], + "dcraw_matrix": [ 9662, -684, -279, -4903, 12293, 2950, -344, 1669, 6024 ] }, // dummy test entry to test the parser and show the format with all entries active diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 3cdcc4d97..792aa14c4 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -5228,7 +5228,8 @@ int CLASS parse_tiff_ifd (int base) fgets (make, 64, ifp); break; case 272: /* Model */ - fgets (model, 64, ifp); + if (strstr(model, "Hasselblad ") != model) // RT: if Hasselblad, only parse the first model name (otherwise it can change from say Hasselblad CFV-50 to Hasselblad CW (ie the camera body model, not the back model which we are interested in) + fgets (model, 64, ifp); break; case 280: /* Panasonic RW2 offset */ if (type != 4) break; @@ -8250,6 +8251,18 @@ konica_400z: top_margin = 4; left_margin = 41; filters = 0x61616161; + } else if (raw_width == 6542) { // RT, H3D-31, H3DII-31 + if (!strcmp(model, "H3D")) strcpy(model, "H3D-31"); // note: can't differ between H3D-31 and H3DII-31. + height = 4904; + width = 6524; + top_margin = 4; + left_margin = 8; + } else if (raw_width == 8282) { // RT, H3DII-50, H3DII-50MS, CFV-50 + if (!strcmp(model, "H3D")) strcpy(model, "H3DII-50"); // note: can't differ between H3DII-50 and H3DII-50MS + height = 6152; + width = 8196; + top_margin = 4; + left_margin = 44; } else if (raw_width == 9044) { height = 6716; width = 8964; diff --git a/rtengine/dcraw.patch b/rtengine/dcraw.patch index 224292888..49b3a2fe5 100755 --- a/rtengine/dcraw.patch +++ b/rtengine/dcraw.patch @@ -1,5 +1,5 @@ --- dcraw.c 2014-02-19 17:25:45.051457734 +0100 -+++ dcraw.cc 2014-05-24 11:45:53.712407849 +0200 ++++ dcraw.cc 2014-05-24 13:32:56.039537212 +0200 @@ -1,3 +1,15 @@ +/*RT*/#include +/*RT*/#include @@ -857,9 +857,9 @@ - ushort (*rgb)[TS][TS][3], (*rix)[3], (*pix)[4]; - short (*lab)[TS][TS][3], (*lix)[3]; - char (*homo)[TS][TS], *buffer; - -- if (verbose) fprintf (stderr,_("AHD interpolation...\n")); - +- if (verbose) fprintf (stderr,_("AHD interpolation...\n")); + - cielab (0,0); - border_interpolate(5); - buffer = (char *) malloc (26*TS*TS); @@ -1011,7 +1011,17 @@ if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) return 1; -@@ -5435,6 +5284,9 @@ +@@ -5379,7 +5228,8 @@ + fgets (make, 64, ifp); + break; + case 272: /* Model */ +- fgets (model, 64, ifp); ++ if (strstr(model, "Hasselblad ") != model) // RT: if Hasselblad, only parse the first model name (otherwise it can change from say Hasselblad CFV-50 to Hasselblad CW (ie the camera body model, not the back model which we are interested in) ++ fgets (model, 64, ifp); + break; + case 280: /* Panasonic RW2 offset */ + if (type != 4) break; +@@ -5435,6 +5285,9 @@ case 315: /* Artist */ fread (artist, 64, 1, ifp); break; @@ -1021,7 +1031,7 @@ case 322: /* TileWidth */ tiff_ifd[ifd].tile_width = getint(type); break; -@@ -5448,6 +5300,9 @@ +@@ -5448,6 +5301,9 @@ is_raw = 5; } break; @@ -1031,7 +1041,7 @@ case 330: /* SubIFDs */ if (!strcmp(model,"DSLR-A100") && tiff_ifd[ifd].width == 3872) { load_raw = &CLASS sony_arw_load_raw; -@@ -5461,6 +5316,9 @@ +@@ -5461,6 +5317,9 @@ fseek (ifp, i+4, SEEK_SET); } break; @@ -1041,7 +1051,7 @@ case 400: strcpy (make, "Sarnoff"); maximum = 0xfff; -@@ -5660,10 +5518,21 @@ +@@ -5660,10 +5519,21 @@ case 61450: cblack[4] = cblack[5] = MIN(sqrt(len),64); case 50714: /* BlackLevel */ @@ -1067,7 +1077,7 @@ case 50715: /* BlackLevelDeltaH */ case 50716: /* BlackLevelDeltaV */ for (num=i=0; i < len; i++) -@@ -5741,12 +5610,15 @@ +@@ -5741,12 +5611,15 @@ fread (buf, sony_length, 1, ifp); sony_decrypt (buf, sony_length/4, 1, sony_key); sfp = ifp; @@ -1089,7 +1099,7 @@ ifp = sfp; free (buf); } -@@ -5770,6 +5642,7 @@ +@@ -5770,6 +5643,7 @@ int CLASS parse_tiff (int base) { int doff; @@ -1097,7 +1107,7 @@ fseek (ifp, base, SEEK_SET); order = get2(); -@@ -5847,7 +5720,7 @@ +@@ -5847,7 +5721,7 @@ case 8: load_raw = &CLASS eight_bit_load_raw; break; case 12: if (tiff_ifd[raw].phint == 2) load_flags = 6; @@ -1106,7 +1116,7 @@ case 14: load_flags = 0; case 16: load_raw = &CLASS unpacked_load_raw; if (!strncmp(make,"OLYMPUS",7) && -@@ -5878,6 +5751,7 @@ +@@ -5878,6 +5752,7 @@ case 32803: load_raw = &CLASS kodak_65000_load_raw; } case 32867: case 34892: break; @@ -1114,7 +1124,7 @@ default: is_raw = 0; } if (!dng_version) -@@ -5963,7 +5837,7 @@ +@@ -5963,7 +5838,7 @@ { const char *file, *ext; char *jname, *jfile, *jext; @@ -1123,7 +1133,7 @@ ext = strrchr (ifname, '.'); file = strrchr (ifname, '/'); -@@ -5985,13 +5859,14 @@ +@@ -5985,13 +5860,14 @@ } else while (isdigit(*--jext)) { if (*jext != '9') { @@ -1140,7 +1150,7 @@ if (verbose) fprintf (stderr,_("Reading metadata from %s ...\n"), jname); parse_tiff (12); -@@ -6256,6 +6131,8 @@ +@@ -6256,6 +6132,8 @@ case 0x21d: ph1.black = data; break; case 0x222: ph1.split_col = data; break; case 0x223: ph1.black_off = data+base; break; @@ -1149,7 +1159,7 @@ case 0x301: model[63] = 0; fread (model, 1, 63, ifp); -@@ -6334,7 +6211,11 @@ +@@ -6334,7 +6212,11 @@ order = get2(); hlen = get4(); if (get4() == 0x48454150) /* "HEAP" */ @@ -1161,7 +1171,7 @@ if (parse_tiff (save+6)) apply_tiff(); fseek (ifp, save+len, SEEK_SET); } -@@ -6586,7 +6467,8 @@ +@@ -6586,7 +6468,8 @@ { static const struct { const char *prefix; @@ -1171,7 +1181,7 @@ } table[] = { { "AgfaPhoto DC-833m", 0, 0, /* DJC */ { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, -@@ -7457,6 +7339,27 @@ +@@ -7457,6 +7340,27 @@ } break; } @@ -1199,7 +1209,7 @@ } void CLASS simple_coeff (int index) -@@ -7764,13 +7667,20 @@ +@@ -7764,13 +7668,20 @@ fread (head, 1, 32, ifp); fseek (ifp, 0, SEEK_END); flen = fsize = ftell(ifp); @@ -1222,7 +1232,7 @@ parse_ciff (hlen, flen-hlen, 0); load_raw = &CLASS canon_load_raw; } else if (parse_tiff(0)) apply_tiff(); -@@ -7816,6 +7726,7 @@ +@@ -7816,6 +7727,7 @@ fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); parse_tiff (data_offset = get4()); parse_tiff (thumb_offset+12); @@ -1230,7 +1240,7 @@ apply_tiff(); } else if (!memcmp (head,"RIFF",4)) { fseek (ifp, 0, SEEK_SET); -@@ -7925,15 +7836,18 @@ +@@ -7925,15 +7837,18 @@ if (make[0] == 0) parse_smal (0, flen); if (make[0] == 0) { parse_jpeg(0); @@ -1258,7 +1268,7 @@ } for (i=0; i < sizeof corp / sizeof *corp; i++) -@@ -7966,7 +7880,7 @@ +@@ -7966,7 +7881,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"))) @@ -1267,7 +1277,7 @@ if (width >= 4960 && !strncmp(model,"K-5",3)) { left_margin = 10; width = 4950; filters = 0x16161616; } if (width == 4736 && !strcmp(model,"K-7")) -@@ -7985,6 +7899,7 @@ +@@ -7985,6 +7900,7 @@ switch (tiff_compress) { case 1: load_raw = &CLASS packed_dng_load_raw; break; case 7: load_raw = &CLASS lossless_dng_load_raw; break; @@ -1275,7 +1285,7 @@ case 34892: load_raw = &CLASS lossy_dng_load_raw; break; default: load_raw = 0; } -@@ -8112,7 +8027,7 @@ +@@ -8112,7 +8028,7 @@ width -= 44; } else if (!strcmp(model,"D3200") || !strcmp(model,"D600") || @@ -1284,7 +1294,24 @@ width -= 46; } else if (!strcmp(model,"D4") || !strcmp(model,"Df")) { -@@ -8340,8 +8255,9 @@ +@@ -8335,13 +8251,26 @@ + top_margin = 4; + left_margin = 41; + filters = 0x61616161; ++ } else if (raw_width == 6542) { // RT, H3D-31, H3DII-31 ++ if (!strcmp(model, "H3D")) strcpy(model, "H3D-31"); // note: can't differ between H3D-31 and H3DII-31. ++ height = 4904; ++ width = 6524; ++ top_margin = 4; ++ left_margin = 8; ++ } else if (raw_width == 8282) { // RT, H3DII-50, H3DII-50MS, CFV-50 ++ if (!strcmp(model, "H3D")) strcpy(model, "H3DII-50"); // note: can't differ between H3DII-50 and H3DII-50MS ++ height = 6152; ++ width = 8196; ++ top_margin = 4; ++ left_margin = 44; + } else if (raw_width == 9044) { + height = 6716; width = 8964; top_margin = 8; left_margin = 40; @@ -1296,7 +1323,7 @@ } else if (raw_width == 4090) { strcpy (model, "V96C"); height -= (top_margin = 6); -@@ -8394,6 +8310,7 @@ +@@ -8394,6 +8323,7 @@ filters = 0x16161616; } } else if (!strcmp(make,"Leica") || !strcmp(make,"Panasonic")) { @@ -1304,7 +1331,7 @@ if ((flen - data_offset) / (raw_width*8/7) == raw_height) load_raw = &CLASS panasonic_load_raw; if (!load_raw) { -@@ -8411,6 +8328,7 @@ +@@ -8411,6 +8341,7 @@ } filters = 0x01010101 * (uchar) "\x94\x61\x49\x16" [((filters-1) ^ (left_margin & 1) ^ (top_margin << 1)) & 3]; @@ -1312,7 +1339,7 @@ } else if (!strcmp(model,"C770UZ")) { height = 1718; width = 2304; -@@ -8630,6 +8548,10 @@ +@@ -8630,6 +8561,10 @@ memcpy (rgb_cam, cmatrix, sizeof cmatrix); raw_color = 0; } @@ -1323,7 +1350,7 @@ if (raw_color) adobe_coeff (make, model); if (load_raw == &CLASS kodak_radc_load_raw) if (raw_color) adobe_coeff ("Apple","Quicktake"); -@@ -8646,7 +8568,7 @@ +@@ -8646,7 +8581,7 @@ if (!tiff_bps) tiff_bps = 12; if (!maximum) maximum = (1 << tiff_bps) - 1; if (!load_raw || height < 22 || width < 22 || @@ -1332,7 +1359,7 @@ is_raw = 0; #ifdef NO_JASPER if (load_raw == &CLASS redcine_load_raw) { -@@ -8725,195 +8647,269 @@ +@@ -8725,195 +8660,269 @@ } #endif @@ -1777,7 +1804,7 @@ struct tiff_tag { ushort tag, type; int count; -@@ -8935,585 +8931,12 @@ +@@ -8935,585 +8944,12 @@ unsigned gps[26]; char desc[512], make[64], model[64], soft[32], date[20], artist[64]; };