From 23e2f0cca5f16bb6cfcc4e852ce1a9a7fe98c94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Batty=C3=A1nyi?= <86350313+LoKolbasz@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:17:16 +0200 Subject: [PATCH 01/12] Fixed issue #6312 Fixed issue, where raw cropped Fuji X-Pro3 could not be loaded correctly. This would result in a Segmentation Fault. With these changes the program should read the correct dimensions from the file's metadata, and load the image accordingly. --- rtengine/dcraw.cc | 44 +++++++++++++++++++++++++++++++++++++++----- rtengine/dcraw.h | 16 ++++++++++++++++ rtengine/rawimage.cc | 13 +++++++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 82c72a53b..0ac579149 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7113,8 +7113,8 @@ void CLASS apply_tiff() (unsigned)tiff_ifd[i].bps < 33 && (unsigned)tiff_ifd[i].samples < 13 && // RT ns && ((ns > os && (ties = 1)) || (ns == os && shot_select == ties++))) { - raw_width = tiff_ifd[i].width; - raw_height = tiff_ifd[i].height; + raw_width = read_crop.complete ? read_crop.width : tiff_ifd[i].width; + raw_height = read_crop.complete ? read_crop.height : tiff_ifd[i].height; tiff_bps = tiff_ifd[i].bps; tiff_compress = tiff_ifd[i].comp; data_offset = tiff_ifd[i].offset; @@ -7647,37 +7647,62 @@ void CLASS parse_fuji (int offset) fseek (ifp, offset, SEEK_SET); entries = get4(); + int read_crop_c = 0; + bool read_crop_dimensions = false; if (entries > 255) return; while (entries--) { tag = get2(); len = get2(); save = ftell(ifp); + // tag 0x100 = 256 RawImageFullSize if (tag == 0x100) { raw_height = get2(); raw_width = get2(); } else if (tag == 0x121) { height = get2(); if ((width = get2()) == 4284) width += 3; + // tag 0x130 = 304 FujiLayout } else if (tag == 0x130) { fuji_layout = fgetc(ifp) >> 7; fuji_width = !(fgetc(ifp) & 8); + // tag 0x131 = 305 XTransLayout } else if (tag == 0x131) { filters = 9; FORC(36) xtrans_abs[0][35-c] = fgetc(ifp) & 3; } else if (tag == 0x2ff0) { FORC4 cam_mul[c ^ 1] = get2(); - } else if (tag == 0xc000 && len > 20000) { + } else if (tag == 0xc000 && len > 20000 && !read_crop_dimensions) { c = order; order = 0x4949; while ((tag = get4()) > raw_width); width = tag; height = get4(); order = c; + // RawImageCroppedSize 0x111 = 273 (including borders) + } else if (tag == 0x111) { + height = raw_height = read_crop.height = get2(); + width = raw_width = read_crop.width = get2(); + read_crop_dimensions = true; + read_crop_c += 2; + // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) + } else if (tag == 0x110){ + read_crop.top_margin = get2(); + read_crop.left_margin = get2(); + read_crop_c += 2; } + // 0x112 = 274 unknown tag + // 0x113 = 275 unknown tag + // 0x115 = 277 RawImageAspectRatio + // 0x141 = 321 unknown tag + // 0x9650 = 38480 RawExposureBias + // 0x9651 = 38481 unknown tag + // 0x17f8 = 6136 unknown tag + fseek (ifp, save+len, SEEK_SET); } height <<= fuji_layout; width >>= fuji_layout; + read_crop.complete = read_crop_c == 4; } int CLASS parse_jpeg (int offset) @@ -10133,8 +10158,17 @@ canon_a5: width = raw_width = 6016; height = raw_height = 4014; } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { - width = raw_width = 6384; - height = raw_height = 4182; + constexpr std::uint_fast16_t x_width = 6384, x_height = 4182; + is_cropped = read_crop.complete && (x_width - raw_width > is_cropped_margin || x_height - raw_height > is_cropped_margin); + if (!is_cropped) { + width = raw_width = x_width; + height = raw_height = x_height; + } + // due to this (mainly raw_width and raw_height) not beimg read from the file, a segmentation fault occurs, when trying to read the raw image + // the following data should be read from the exif data, and passed to the corresponding variables: + // RAF - RawImageCroppedSize ------- Test image: 4992x3328 + // raw_width = 4992; + // raw_height = 3328; } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; height = raw_height = 3856; diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index aadc0b969..33e3eb7b1 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -76,6 +76,22 @@ public: } protected: + // stores the cropdata read from the file + struct CropData { + std::uint_fast16_t width, + height, + top_margin, + left_margin; + bool complete = false; + } read_crop; + /* + If the difference between the read dimension (width /height) + and the constant dimension (eg.: from cameraconstants) + is greater than this amount, + then the file should be considered raw cropped (for fuji cropped raw) + */ + static constexpr std::uint_fast16_t is_cropped_margin = 500; + bool is_cropped = false; int exif_base, ciff_base, ciff_len; rtengine::IMFILE *ifp; FILE *ofp; diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 8478d56ab..370666018 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -560,6 +560,13 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog raw_crop_cc = true; int lm, tm, w, h; cc->get_rawCrop(raw_width, raw_height, lm, tm, w, h); + is_cropped = read_crop.complete && (raw_width - read_crop.width > is_cropped_margin || raw_height - read_crop.height > is_cropped_margin); + if (is_cropped){ + left_margin = read_crop.left_margin; + top_margin = read_crop.top_margin; + tm = 0; + lm = 0; + } if (isXtrans()) { shiftXtransMatrix(6 - ((top_margin - tm) % 6), 6 - ((left_margin - lm) % 6)); @@ -569,8 +576,10 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog } } - left_margin = lm; - top_margin = tm; + if (!is_cropped) { + left_margin = lm; + top_margin = tm; + } if (w < 0) { iwidth += w; From 5231f3a74253d8c5586a701e61b700158c162f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Batty=C3=A1nyi?= <86350313+LoKolbasz@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:09:03 +0200 Subject: [PATCH 02/12] Removed comments --- rtengine/dcraw.cc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 0ac579149..0640d4bd0 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7690,13 +7690,8 @@ void CLASS parse_fuji (int offset) read_crop.left_margin = get2(); read_crop_c += 2; } - // 0x112 = 274 unknown tag - // 0x113 = 275 unknown tag // 0x115 = 277 RawImageAspectRatio - // 0x141 = 321 unknown tag // 0x9650 = 38480 RawExposureBias - // 0x9651 = 38481 unknown tag - // 0x17f8 = 6136 unknown tag fseek (ifp, save+len, SEEK_SET); } @@ -10164,11 +10159,6 @@ canon_a5: width = raw_width = x_width; height = raw_height = x_height; } - // due to this (mainly raw_width and raw_height) not beimg read from the file, a segmentation fault occurs, when trying to read the raw image - // the following data should be read from the exif data, and passed to the corresponding variables: - // RAF - RawImageCroppedSize ------- Test image: 4992x3328 - // raw_width = 4992; - // raw_height = 3328; } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; height = raw_height = 3856; From 554a6dc1611cbc5d1d46fb494fcf18e85e388248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Batty=C3=A1nyi?= <86350313+LoKolbasz@users.noreply.github.com> Date: Wed, 30 Aug 2023 23:34:36 +0200 Subject: [PATCH 03/12] Added RT signifier comments --- rtengine/dcraw.cc | 58 ++++++++++++++++++++++---------------------- rtengine/dcraw.h | 32 ++++++++++++------------ rtengine/rawimage.cc | 18 +++++++------- 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 0640d4bd0..635c8d377 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7113,8 +7113,8 @@ void CLASS apply_tiff() (unsigned)tiff_ifd[i].bps < 33 && (unsigned)tiff_ifd[i].samples < 13 && // RT ns && ((ns > os && (ties = 1)) || (ns == os && shot_select == ties++))) { - raw_width = read_crop.complete ? read_crop.width : tiff_ifd[i].width; - raw_height = read_crop.complete ? read_crop.height : tiff_ifd[i].height; + raw_width = read_crop.complete ? read_crop.width : tiff_ifd[i].width; // RT + raw_height = read_crop.complete ? read_crop.height : tiff_ifd[i].height; // RT tiff_bps = tiff_ifd[i].bps; tiff_compress = tiff_ifd[i].comp; data_offset = tiff_ifd[i].offset; @@ -7647,57 +7647,57 @@ void CLASS parse_fuji (int offset) fseek (ifp, offset, SEEK_SET); entries = get4(); - int read_crop_c = 0; - bool read_crop_dimensions = false; + int read_crop_c = 0; // RT + bool read_crop_dimensions = false; // RT if (entries > 255) return; while (entries--) { tag = get2(); len = get2(); save = ftell(ifp); - // tag 0x100 = 256 RawImageFullSize + // tag 0x100 = 256 RawImageFullSize RT if (tag == 0x100) { raw_height = get2(); raw_width = get2(); } else if (tag == 0x121) { height = get2(); if ((width = get2()) == 4284) width += 3; - // tag 0x130 = 304 FujiLayout + // tag 0x130 = 304 FujiLayout RT } else if (tag == 0x130) { fuji_layout = fgetc(ifp) >> 7; fuji_width = !(fgetc(ifp) & 8); - // tag 0x131 = 305 XTransLayout + // tag 0x131 = 305 XTransLayout RT } else if (tag == 0x131) { filters = 9; FORC(36) xtrans_abs[0][35-c] = fgetc(ifp) & 3; } else if (tag == 0x2ff0) { FORC4 cam_mul[c ^ 1] = get2(); - } else if (tag == 0xc000 && len > 20000 && !read_crop_dimensions) { + } else if (tag == 0xc000 && len > 20000 && !read_crop_dimensions) { // RT c = order; order = 0x4949; while ((tag = get4()) > raw_width); width = tag; height = get4(); order = c; - // RawImageCroppedSize 0x111 = 273 (including borders) - } else if (tag == 0x111) { - height = raw_height = read_crop.height = get2(); - width = raw_width = read_crop.width = get2(); - read_crop_dimensions = true; - read_crop_c += 2; - // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) - } else if (tag == 0x110){ - read_crop.top_margin = get2(); - read_crop.left_margin = get2(); - read_crop_c += 2; - } - // 0x115 = 277 RawImageAspectRatio - // 0x9650 = 38480 RawExposureBias + // RawImageCroppedSize 0x111 = 273 (including borders) RT + } else if (tag == 0x111) { // RT + height = raw_height = read_crop.height = get2(); // RT + width = raw_width = read_crop.width = get2(); // RT + read_crop_dimensions = true; // RT + read_crop_c += 2; // RT + // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) RT + } else if (tag == 0x110){ // RT + read_crop.top_margin = get2(); // RT + read_crop.left_margin = get2(); // RT + read_crop_c += 2; // RT + } // RT + // 0x115 = 277 RawImageAspectRatio RT + // 0x9650 = 38480 RawExposureBias RT fseek (ifp, save+len, SEEK_SET); } height <<= fuji_layout; width >>= fuji_layout; - read_crop.complete = read_crop_c == 4; + read_crop.complete = read_crop_c == 4; // RT } int CLASS parse_jpeg (int offset) @@ -10153,12 +10153,12 @@ canon_a5: width = raw_width = 6016; height = raw_height = 4014; } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { - constexpr std::uint_fast16_t x_width = 6384, x_height = 4182; - is_cropped = read_crop.complete && (x_width - raw_width > is_cropped_margin || x_height - raw_height > is_cropped_margin); - if (!is_cropped) { - width = raw_width = x_width; - height = raw_height = x_height; - } + constexpr std::uint_fast16_t x_width = 6384, x_height = 4182; // RT + is_cropped = read_crop.complete && (x_width - raw_width > is_cropped_margin || x_height - raw_height > is_cropped_margin); // RT + if (!is_cropped) { // RT + width = raw_width = x_width; // RT + height = raw_height = x_height; // RT + } // RT } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; height = raw_height = 3856; diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index 33e3eb7b1..a963bf2a2 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -76,22 +76,22 @@ public: } protected: - // stores the cropdata read from the file - struct CropData { - std::uint_fast16_t width, - height, - top_margin, - left_margin; - bool complete = false; - } read_crop; - /* - If the difference between the read dimension (width /height) - and the constant dimension (eg.: from cameraconstants) - is greater than this amount, - then the file should be considered raw cropped (for fuji cropped raw) - */ - static constexpr std::uint_fast16_t is_cropped_margin = 500; - bool is_cropped = false; + // stores the cropdata read from the file RT + struct CropData { // RT + std::uint_fast16_t width, // RT + height, // RT + top_margin, // RT + left_margin; // RT + bool complete = false; // RT + } read_crop; // RT + /* RT + If the difference between the read dimension (width /height) RT + and the constant dimension (eg.: from cameraconstants) RT + is greater than this amount, RT + then the file should be considered raw cropped (for fuji cropped raw) RT + */ // RT + static constexpr std::uint_fast16_t is_cropped_margin = 500; // RT + bool is_cropped = false; // RT int exif_base, ciff_base, ciff_len; rtengine::IMFILE *ifp; FILE *ofp; diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 370666018..9567f3fb9 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -560,13 +560,13 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog raw_crop_cc = true; int lm, tm, w, h; cc->get_rawCrop(raw_width, raw_height, lm, tm, w, h); - is_cropped = read_crop.complete && (raw_width - read_crop.width > is_cropped_margin || raw_height - read_crop.height > is_cropped_margin); - if (is_cropped){ - left_margin = read_crop.left_margin; - top_margin = read_crop.top_margin; - tm = 0; - lm = 0; - } + is_cropped = read_crop.complete && (raw_width - read_crop.width > is_cropped_margin || raw_height - read_crop.height > is_cropped_margin); // RT + if (is_cropped){ // RT + left_margin = read_crop.left_margin; // RT + top_margin = read_crop.top_margin; // RT + tm = 0; // RT + lm = 0; // RT + } // RT if (isXtrans()) { shiftXtransMatrix(6 - ((top_margin - tm) % 6), 6 - ((left_margin - lm) % 6)); @@ -576,10 +576,10 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog } } - if (!is_cropped) { + if (!is_cropped) { // RT left_margin = lm; top_margin = tm; - } + } // RT if (w < 0) { iwidth += w; From ea86a14dff33547d86825fbd3394532b0ddf6a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Mon, 11 Sep 2023 20:53:17 +0200 Subject: [PATCH 04/12] removed unecessarily setting of raw_height and raw_width --- rtengine/dcraw.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 635c8d377..8154fd03b 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7113,8 +7113,8 @@ void CLASS apply_tiff() (unsigned)tiff_ifd[i].bps < 33 && (unsigned)tiff_ifd[i].samples < 13 && // RT ns && ((ns > os && (ties = 1)) || (ns == os && shot_select == ties++))) { - raw_width = read_crop.complete ? read_crop.width : tiff_ifd[i].width; // RT - raw_height = read_crop.complete ? read_crop.height : tiff_ifd[i].height; // RT + raw_width = tiff_ifd[i].width; + raw_height = tiff_ifd[i].height; tiff_bps = tiff_ifd[i].bps; tiff_compress = tiff_ifd[i].comp; data_offset = tiff_ifd[i].offset; @@ -7680,8 +7680,8 @@ void CLASS parse_fuji (int offset) order = c; // RawImageCroppedSize 0x111 = 273 (including borders) RT } else if (tag == 0x111) { // RT - height = raw_height = read_crop.height = get2(); // RT - width = raw_width = read_crop.width = get2(); // RT + height = read_crop.height = get2(); // RT + width = read_crop.width = get2(); // RT read_crop_dimensions = true; // RT read_crop_c += 2; // RT // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) RT From 380610731523d6ac733146373597c18d87758ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:58:24 +0200 Subject: [PATCH 05/12] Changed crop detection mechanism according to code review comment Changed the crop detection to use the CropMode Fujifilm tag from the makernotes instead of an arbitrary threshold. --- rtengine/dcraw.cc | 15 ++++++++------- rtengine/dcraw.h | 16 +++++++--------- rtengine/rawimage.cc | 7 +++---- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 8154fd03b..3129f7d15 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -5775,6 +5775,8 @@ nf: order = 0x4949; cam_mul[0] = get2() / 256.0; if (tag == 0x1018 || tag == 0x20400100) cam_mul[2] = get2() / 256.0; + if (tag == 0x104D) + read_crop.crop_mode = (CropMode)get2(); if (tag == 0x2011 && len == 2) { get2_256: order = 0x4d4d; @@ -7697,7 +7699,6 @@ void CLASS parse_fuji (int offset) } height <<= fuji_layout; width >>= fuji_layout; - read_crop.complete = read_crop_c == 4; // RT } int CLASS parse_jpeg (int offset) @@ -10153,12 +10154,12 @@ canon_a5: width = raw_width = 6016; height = raw_height = 4014; } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { - constexpr std::uint_fast16_t x_width = 6384, x_height = 4182; // RT - is_cropped = read_crop.complete && (x_width - raw_width > is_cropped_margin || x_height - raw_height > is_cropped_margin); // RT - if (!is_cropped) { // RT - width = raw_width = x_width; // RT - height = raw_height = x_height; // RT - } // RT + raw_width = 6384; // RT + raw_height = 4182; // RT + if (!read_crop.crop_mode) { // RT + width = 6384; // RT + height = 4182; // RT + } // RT } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; height = raw_height = 3856; diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index a963bf2a2..fad979919 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -76,22 +76,20 @@ public: } protected: + enum CropMode : std::uint_fast16_t { // RT + NA = 0, // RT + FullFrameOnGfx = 1, // RT + SportsFinderMode = 2, // RT + ElectronicShutter1_25xCrop = 4 // RT + }; // RT // stores the cropdata read from the file RT struct CropData { // RT std::uint_fast16_t width, // RT height, // RT top_margin, // RT left_margin; // RT - bool complete = false; // RT + CropMode crop_mode = NA; // RT } read_crop; // RT - /* RT - If the difference between the read dimension (width /height) RT - and the constant dimension (eg.: from cameraconstants) RT - is greater than this amount, RT - then the file should be considered raw cropped (for fuji cropped raw) RT - */ // RT - static constexpr std::uint_fast16_t is_cropped_margin = 500; // RT - bool is_cropped = false; // RT int exif_base, ciff_base, ciff_len; rtengine::IMFILE *ifp; FILE *ofp; diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 9567f3fb9..618ab4f38 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -560,8 +560,7 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog raw_crop_cc = true; int lm, tm, w, h; cc->get_rawCrop(raw_width, raw_height, lm, tm, w, h); - is_cropped = read_crop.complete && (raw_width - read_crop.width > is_cropped_margin || raw_height - read_crop.height > is_cropped_margin); // RT - if (is_cropped){ // RT + if (read_crop.crop_mode){ // RT left_margin = read_crop.left_margin; // RT top_margin = read_crop.top_margin; // RT tm = 0; // RT @@ -576,10 +575,10 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog } } - if (!is_cropped) { // RT + if (!read_crop.crop_mode) { // RT left_margin = lm; top_margin = tm; - } // RT + } // RT if (w < 0) { iwidth += w; From 6ee6a46750f4d017c3748bd19e8c422bd274e8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Mon, 11 Sep 2023 23:11:38 +0200 Subject: [PATCH 06/12] Width and height only updates to cropped version after detecting crop As suggested by review comment --- rtengine/dcraw.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 3129f7d15..7388b2159 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7649,8 +7649,6 @@ void CLASS parse_fuji (int offset) fseek (ifp, offset, SEEK_SET); entries = get4(); - int read_crop_c = 0; // RT - bool read_crop_dimensions = false; // RT if (entries > 255) return; while (entries--) { tag = get2(); @@ -7673,7 +7671,7 @@ void CLASS parse_fuji (int offset) FORC(36) xtrans_abs[0][35-c] = fgetc(ifp) & 3; } else if (tag == 0x2ff0) { FORC4 cam_mul[c ^ 1] = get2(); - } else if (tag == 0xc000 && len > 20000 && !read_crop_dimensions) { // RT + } else if (tag == 0xc000 && len > 20000) { c = order; order = 0x4949; while ((tag = get4()) > raw_width); @@ -7682,21 +7680,27 @@ void CLASS parse_fuji (int offset) order = c; // RawImageCroppedSize 0x111 = 273 (including borders) RT } else if (tag == 0x111) { // RT - height = read_crop.height = get2(); // RT - width = read_crop.width = get2(); // RT - read_crop_dimensions = true; // RT - read_crop_c += 2; // RT + read_crop.height = get2(); // RT + read_crop.width = get2(); // RT // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) RT } else if (tag == 0x110){ // RT read_crop.top_margin = get2(); // RT read_crop.left_margin = get2(); // RT - read_crop_c += 2; // RT } // RT // 0x115 = 277 RawImageAspectRatio RT // 0x9650 = 38480 RawExposureBias RT fseek (ifp, save+len, SEEK_SET); } + + if (read_crop.crop_mode) // RT + { // RT + height = read_crop.height; // RT + width = read_crop.width; // RT + top_margin = read_crop.top_margin; // RT + left_margin = read_crop.left_margin; // RT + } // RT + height <<= fuji_layout; width >>= fuji_layout; } From ab6d5b190c2dbaf11dac5369e0291543ee688ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Mon, 11 Sep 2023 23:18:57 +0200 Subject: [PATCH 07/12] Tags in numerical order inside parse_fuji() As suggested by review comment --- rtengine/dcraw.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 7388b2159..041f7fcde 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7658,6 +7658,15 @@ void CLASS parse_fuji (int offset) if (tag == 0x100) { raw_height = get2(); raw_width = get2(); + // RawImageCroppedSize 0x111 = 273 (including borders) RT + } else if (tag == 0x111) { // RT + read_crop.height = get2(); // RT + read_crop.width = get2(); // RT + // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) RT + } else if (tag == 0x110){ // RT + read_crop.top_margin = get2(); // RT + read_crop.left_margin = get2(); // RT + // 0x115 = 277 RawImageAspectRatio RT } else if (tag == 0x121) { height = get2(); if ((width = get2()) == 4284) width += 3; @@ -7678,16 +7687,7 @@ void CLASS parse_fuji (int offset) width = tag; height = get4(); order = c; - // RawImageCroppedSize 0x111 = 273 (including borders) RT - } else if (tag == 0x111) { // RT - read_crop.height = get2(); // RT - read_crop.width = get2(); // RT - // RawImageTopLeft 0x110 = 272 (top margin first, then left margin) RT - } else if (tag == 0x110){ // RT - read_crop.top_margin = get2(); // RT - read_crop.left_margin = get2(); // RT - } // RT - // 0x115 = 277 RawImageAspectRatio RT + } // 0x9650 = 38480 RawExposureBias RT fseek (ifp, save+len, SEEK_SET); From f09612453aa11eb58a131f1c67e9e1af32bef6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:07:43 +0200 Subject: [PATCH 08/12] Metadata no longer overwrites camconsts Added suggested changes to camconst and removed the camconst.json overwriting part as per the review comment --- rtengine/camconst.json | 5 ++++- rtengine/rawimage.cc | 12 ++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/rtengine/camconst.json b/rtengine/camconst.json index ce98bee01..48400f72a 100644 --- a/rtengine/camconst.json +++ b/rtengine/camconst.json @@ -1571,7 +1571,10 @@ Camera constants: { // Quality A, samples provided by Daniel Catalina (#5839) and pi99y (#5860) "make_model": [ "FUJIFILM X-T3", "FUJIFILM X-PRO3" ], "dcraw_matrix": [ 13426,-6334,-1177,-4244,12136,2371,-580,1303,5980 ], // DNG_v11, standard_v2 d65 - "raw_crop": [ 0, 5, 6252, 4176], + "raw_crop" : [ + { "frame" : [6384, 4182], "crop": [ 0, 5, 6252, 4176] }, + { "frame" : [6384, 3348], "crop": [624, 0, 5004, 3348] } + ], "white": [ 16170, 16275, 16170 ] // typical safe-margins with LENR // negligible aperture scaling effect }, diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 618ab4f38..8478d56ab 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -560,12 +560,6 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog raw_crop_cc = true; int lm, tm, w, h; cc->get_rawCrop(raw_width, raw_height, lm, tm, w, h); - if (read_crop.crop_mode){ // RT - left_margin = read_crop.left_margin; // RT - top_margin = read_crop.top_margin; // RT - tm = 0; // RT - lm = 0; // RT - } // RT if (isXtrans()) { shiftXtransMatrix(6 - ((top_margin - tm) % 6), 6 - ((left_margin - lm) % 6)); @@ -575,10 +569,8 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog } } - if (!read_crop.crop_mode) { // RT - left_margin = lm; - top_margin = tm; - } // RT + left_margin = lm; + top_margin = tm; if (w < 0) { iwidth += w; From 0fe4c187520c153862230169cfd604b5e58cba25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:33:04 +0200 Subject: [PATCH 09/12] Semantic changes --- rtengine/dcraw.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 041f7fcde..0213ff8be 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7693,8 +7693,7 @@ void CLASS parse_fuji (int offset) fseek (ifp, save+len, SEEK_SET); } - if (read_crop.crop_mode) // RT - { // RT + if (read_crop.crop_mode) { // RT height = read_crop.height; // RT width = read_crop.width; // RT top_margin = read_crop.top_margin; // RT @@ -10161,8 +10160,8 @@ canon_a5: raw_width = 6384; // RT raw_height = 4182; // RT if (!read_crop.crop_mode) { // RT - width = 6384; // RT - height = 4182; // RT + width = raw_width; // RT + height = raw_height; // RT } // RT } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; From b4daf36349dcfc7373da337e38dd5f2f01c08c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:39:50 +0200 Subject: [PATCH 10/12] CropMode changed from "plain enum" to "enum class" --- rtengine/dcraw.cc | 20 ++++++++++---------- rtengine/dcraw.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 0213ff8be..26ddd5e0e 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7693,12 +7693,12 @@ void CLASS parse_fuji (int offset) fseek (ifp, save+len, SEEK_SET); } - if (read_crop.crop_mode) { // RT - height = read_crop.height; // RT - width = read_crop.width; // RT - top_margin = read_crop.top_margin; // RT - left_margin = read_crop.left_margin; // RT - } // RT + if ((std::uint_fast16_t)read_crop.crop_mode) { // RT + height = read_crop.height; // RT + width = read_crop.width; // RT + top_margin = read_crop.top_margin; // RT + left_margin = read_crop.left_margin; // RT + } // RT height <<= fuji_layout; width >>= fuji_layout; @@ -10159,10 +10159,10 @@ canon_a5: } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { raw_width = 6384; // RT raw_height = 4182; // RT - if (!read_crop.crop_mode) { // RT - width = raw_width; // RT - height = raw_height; // RT - } // RT + if (!(std::uint_fast16_t)read_crop.crop_mode) { // RT + width = raw_width; // RT + height = raw_height; // RT + } // RT } else if (!strcmp(model, "DBP for GX680")) { // Special case for #4204 width = raw_width = 5504; height = raw_height = 3856; diff --git a/rtengine/dcraw.h b/rtengine/dcraw.h index fad979919..4c199c4b0 100644 --- a/rtengine/dcraw.h +++ b/rtengine/dcraw.h @@ -76,7 +76,7 @@ public: } protected: - enum CropMode : std::uint_fast16_t { // RT + enum class CropMode : std::uint_fast16_t { // RT NA = 0, // RT FullFrameOnGfx = 1, // RT SportsFinderMode = 2, // RT @@ -88,7 +88,7 @@ protected: height, // RT top_margin, // RT left_margin; // RT - CropMode crop_mode = NA; // RT + CropMode crop_mode = CropMode::NA; // RT } read_crop; // RT int exif_base, ciff_base, ciff_len; rtengine::IMFILE *ifp; From 1a0b7f45620350cba94e68aa56fab68fc9a5a840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:01:35 +0200 Subject: [PATCH 11/12] Replaced casting with != --- rtengine/dcraw.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 26ddd5e0e..5e3eafbd0 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -7693,7 +7693,7 @@ void CLASS parse_fuji (int offset) fseek (ifp, save+len, SEEK_SET); } - if ((std::uint_fast16_t)read_crop.crop_mode) { // RT + if (read_crop.crop_mode != CropMode::NA) { // RT height = read_crop.height; // RT width = read_crop.width; // RT top_margin = read_crop.top_margin; // RT @@ -10159,7 +10159,7 @@ canon_a5: } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { raw_width = 6384; // RT raw_height = 4182; // RT - if (!(std::uint_fast16_t)read_crop.crop_mode) { // RT + if (read_crop.crop_mode != CropMode::NA) { // RT width = raw_width; // RT height = raw_height; // RT } // RT From d0b34a3234e91e07ef214fef2a0678c32833bbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batty=C3=A1nyi=20D=C3=A1niel?= <86350313+LoKolbasz@users.noreply.github.com> Date: Tue, 12 Sep 2023 18:19:51 +0200 Subject: [PATCH 12/12] Fixed crop mode checking Me make dumb mistake in prev. commit sry. --- rtengine/dcraw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index 5e3eafbd0..70e18ad86 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -10159,7 +10159,7 @@ canon_a5: } else if (!strcmp(model, "X-Pro3") || !strcmp(model, "X-T3") || !strcmp(model, "X-T30") || !strcmp(model, "X-T4") || !strcmp(model, "X100V") || !strcmp(model, "X-S10")) { raw_width = 6384; // RT raw_height = 4182; // RT - if (read_crop.crop_mode != CropMode::NA) { // RT + if (read_crop.crop_mode == CropMode::NA) { // RT width = raw_width; // RT height = raw_height; // RT } // RT