diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index 3d4342ed9..43de5d688 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -25,6 +25,7 @@ CameraConst::CameraConst() : pdafOffset(0) memset(raw_crop, 0, sizeof(raw_crop)); memset(raw_mask, 0, sizeof(raw_mask)); white_max = 0; + globalGreenEquilibration = -1; } @@ -310,17 +311,17 @@ CameraConst::parseEntry(void *cJSON_, const char *make_model) } } - ji = cJSON_GetObjectItem(js, "pdafPattern"); + ji = cJSON_GetObjectItem(js, "pdaf_pattern"); if (ji) { if (ji->type != cJSON_Array) { - fprintf(stderr, "\"pdafPattern\" must be an array\n"); + fprintf(stderr, "\"pdaf_pattern\" must be an array\n"); goto parse_error; } for (ji = ji->child; ji != nullptr; ji = ji->next) { if (ji->type != cJSON_Number) { - fprintf(stderr, "\"pdafPattern\" array must contain numbers\n"); + fprintf(stderr, "\"pdaf_pattern\" array must contain numbers\n"); goto parse_error; } @@ -328,17 +329,28 @@ CameraConst::parseEntry(void *cJSON_, const char *make_model) } } - ji = cJSON_GetObjectItem(js, "pdafOffset"); + ji = cJSON_GetObjectItem(js, "pdaf_offset"); if (ji) { if (ji->type != cJSON_Number) { - fprintf(stderr, "\"pdafOffset\" must contain a number\n"); + fprintf(stderr, "\"pdaf_offset\" must contain a number\n"); goto parse_error; } cc->pdafOffset = ji->valueint; } + ji = cJSON_GetObjectItem(js, "global_green_equilibration"); + + if (ji) { + if (ji->type != cJSON_False && ji->type != cJSON_True) { + fprintf(stderr, "\"global_green_equilibration\" must be a boolean\n"); + goto parse_error; + } + + cc->globalGreenEquilibration = (ji->type == cJSON_True); + } + return cc; parse_error: @@ -606,6 +618,24 @@ CameraConst::get_WhiteLevel(const int idx, const int iso_speed, const float fnum return lvl.levels[idx]; } +bool +CameraConst::has_globalGreenEquilibration() +{ + return globalGreenEquilibration >= 0; +} + +bool +CameraConst::get_globalGreenEquilibration() +{ + return globalGreenEquilibration > 0; +} + +void +CameraConst::update_globalGreenEquilibration(bool other) +{ + globalGreenEquilibration = (other ? 1 : 0); +} + bool CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) { @@ -739,6 +769,9 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) existingcc->update_Crop(cc); existingcc->update_pdafPattern(cc->get_pdafPattern()); existingcc->update_pdafOffset(cc->get_pdafOffset()); + if (cc->has_globalGreenEquilibration()) { + existingcc->update_globalGreenEquilibration(cc->get_globalGreenEquilibration()); + } if (settings->verbose) { printf("Merging camera constants for \"%s\"\n", make_model.c_str()); diff --git a/rtengine/camconst.h b/rtengine/camconst.h index 60e17201b..eb43da483 100644 --- a/rtengine/camconst.h +++ b/rtengine/camconst.h @@ -26,6 +26,8 @@ private: std::map mApertureScaling; std::vector pdafPattern; int pdafOffset; + int globalGreenEquilibration; + CameraConst(); static bool parseLevels(CameraConst *cc, int bw, void *ji); static bool parseApertureScaling(CameraConst *cc, void *ji); @@ -45,10 +47,13 @@ public: void get_rawMask(int idx, int& top, int& left, int& bottom, int& right); int get_BlackLevel(int idx, int iso_speed); int get_WhiteLevel(int idx, int iso_speed, float fnumber); + bool has_globalGreenEquilibration(); + bool get_globalGreenEquilibration(); void update_Levels(const CameraConst *other); void update_Crop(CameraConst *other); void update_pdafPattern(const std::vector &other); void update_pdafOffset(int other); + void update_globalGreenEquilibration(bool other); }; class CameraConstantsStore diff --git a/rtengine/camconst.json b/rtengine/camconst.json index 597c5e4d4..449484e8a 100644 --- a/rtengine/camconst.json +++ b/rtengine/camconst.json @@ -83,10 +83,10 @@ Examples: // instead, to take care of possible light leaks from the light sensing area to the optically black (masked) // area or sensor imperfections at the outer borders. - // list of indices of the rows with on-sensor PDAF pixels, for cameras that have such features. The indices here form a pattern that is repeated for the whole height of the sensor. The values are relative to the "pdafOffset" value (see below) - "pdafPattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], + // list of indices of the rows with on-sensor PDAF pixels, for cameras that have such features. The indices here form a pattern that is repeated for the whole height of the sensor. The values are relative to the "pdaf_offset" value (see below) + "pdaf_pattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], // index of the first row of the PDAF pattern in the sensor (0 is the topmost row). Allowed to be negative for convenience (this means that the first repetition of the pattern doesn't start from the first row) - "pdafOffset" : 3 + "pdaf_offset" : 3 }, { @@ -1604,6 +1604,7 @@ Camera constants: { // Quality B, missing per ISO samples "make_model": "OLYMPUS E-M1", + "global_green_equilibration" : true, "dcraw_matrix": [ 7687,-1984,-606,-4327,11928,2721,-1381,2339,6452 ], // dng d65 "ranges": { "white": 4080 } // nominal 4095-4094, spread with some settings as long exposure }, @@ -1618,12 +1619,14 @@ Camera constants: { // Quality A, white level correction "make_model": "OLYMPUS E-PM2", + "global_green_equilibration" : true, "dcraw_matrix": [ 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 ], "ranges": { "white": 4040 } // nominal 4056 }, { // Quality B, with long exposure noise reduction White Level gets WL-BL = around 256_12-bit levels less "make_model": [ "OLYMPUS E-PL7", "OLYMPUS E-PL8" ], + "global_green_equilibration" : true, "dcraw_matrix": [ 9197,-3190,-659,-2606,10830,2039,-458,1250,5458 ], // DNG_v9.8 D65 "ranges": { "white": 4080 } // nominal 4093 }, @@ -1640,6 +1643,11 @@ Camera constants: "ranges": { "white": 4050 } // safe for worst case detected, nominal is 4093 }, + { // Quality C, only green equilibration + "make_model" : ["OLYMPUS E-3", "OLYMPUS E-520"], + "global_green_equilibration" : true + }, + { // Quality C, proper ISO 100-125-160 samples missing, pixelshift files have no black offset etc. #4574 "make_model": [ "Panasonic DC-G9" ], "dcraw_matrix": [ 7685, -2375, -634, -3687, 11700, 2249, -748, 1546, 5111 ], // Adobe DNG Converter 10.3 ColorMatrix2 @@ -2269,8 +2277,8 @@ Camera constants: "ranges": { "black": 512, "white": 16300 }, // detected by hand, using the picture from https://www.dpreview.com/forums/thread/3923513 // P 11 P 23 P 17 P 17 P 17 P 23 P 11 P 17 P 17 P 17 P 23 P 11 P 23 P 11 P 17 P 23 P 11 P 17 P 17 P 23 P 17 P 11 P 17 P 17 P 17 P 23 P 17 P 11 P 17 P 17 P 23 P 11 P 17 P 11 P 23 - "pdafPattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], - "pdafOffset" : 3 + "pdaf_pattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], + "pdaf_offset" : 3 }, { // Quality A @@ -2279,8 +2287,8 @@ Camera constants: "raw_crop": [ 0, 0, 6024, 4024 ], "ranges": { "black": 512, "white": 16300 }, // contributed by Horshak from https://www.dpreview.com/forums/post/60873077 - "pdafPattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], - "pdafOffset" : 3 + "pdaf_pattern" : [ 0,12,36,54,72,90,114,126,144,162,180,204,216,240,252,270,294,306,324,342,366,384,396,414,432,450,474,492,504,522,540,564,576,594,606,630 ], + "pdaf_offset" : 3 }, { // Quality C, only pdaf data @@ -2291,8 +2299,8 @@ Camera constants: // // rotated to match the start of the frame // P 11 P 11 P 11 P 17 P 11 P 5 P 11 P 11 P 17 P 5 P 11 P 17 P 5 P 17 P 5 P 11 P 11 P 11 P 17 P 5 P 11 P 11 P 11 P 5 P 17 P 5 P 17 P 11 P 5 P 17 P 11 P 11 P 17 P 11 P 5 - "pdafPattern" : [ 0,12,24,36,54,66,72,84,96,114,120,132,150,156,174,180,192,204,216,234,240,252,264,276,282,300,306,324,336,342,360,372,384,402,414,420], - "pdafOffset" : 9 + "pdaf_pattern" : [ 0,12,24,36,54,66,72,84,96,114,120,132,150,156,174,180,192,204,216,234,240,252,264,276,282,300,306,324,336,342,360,372,384,402,414,420], + "pdaf_offset" : 9 }, { // Quality A, correction for frame width @@ -2314,8 +2322,8 @@ Camera constants: "raw_crop": [ 0, 0, -36, 0 ], // full raw frame 8000x5320 - 36 rightmost columns are garbage "ranges": { "black": 512, "white": 16300 }, // PDAF info provided by Horshack with the rawshack tool (http://testcams.com/rawshack/) - "pdafPattern" : [ 0,24,36,60,84,120,132,156,192,204,240,252,276,300,324,360,372,396,420 ], - "pdafOffset" : 31 + "pdaf_pattern" : [ 0,24,36,60,84,120,132,156,192,204,240,252,276,300,324,360,372,396,420 ], + "pdaf_offset" : 31 }, { // Quality C, color matrix copied from ILCE-9, LongExposures 2-3sec only @@ -2345,8 +2353,8 @@ Camera constants: "dcraw_matrix": [ 6640,-1847,-503,-5238,13010,2474,-993,1673,6527 ], // DNG_v10.1 D65 "raw_crop": [ 0, 0, -36, 0 ], // full raw frame 8000x5320 - 36 rightmost columns are garbage "ranges": { "black": 512, "white": 16300 }, - "pdafPattern" : [0, 24, 36, 60, 84, 120, 132, 156, 192, 204, 240, 252, 276, 300, 324, 360, 372, 396, 420, 444, 480, 492, 504, 540, 564, 576, 612, 636, 660, 696, 720, 732, 756, 780, 804, 840], - "pdafOffset" : 31 + "pdaf_pattern" : [0, 24, 36, 60, 84, 120, 132, 156, 192, 204, 240, 252, 276, 300, 324, 360, 372, 396, 420, 444, 480, 492, 504, 540, 564, 576, 612, 636, 660, 696, 720, 732, 756, 780, 804, 840], + "pdaf_offset" : 31 }, { // Quality B, color matrix copied from a7rm2 @@ -2357,8 +2365,8 @@ Camera constants: // the A9 is the same as the A7III, rotated of 1 position // source: https://www.dpreview.com/forums/post/60857788 // P 11 P 11 P 11 P 17 P 11 P 5 P 11 P 11 P 17 P 5 P 11 P 17 P 5 P 17 P 5 P 11 P 11 P 11 P 17 P 5 P 11 P 11 P 11 P 5 P 17 P 5 P 17 P 11 P 5 P 17 P 11 P 11 P 17 P 11 P 5 - "pdafPattern" : [ 0,12,24,36,54,66,72,84,96,114,120,132,150,156,174,180,192,204,216,234,240,252,264,276,282,300,306,324,336,342,360,372,384,402,414,420 ], - "pdafOffset" : -7 + "pdaf_pattern" : [ 0,12,24,36,54,66,72,84,96,114,120,132,150,156,174,180,192,204,216,234,240,252,264,276,282,300,306,324,336,342,360,372,384,402,414,420 ], + "pdaf_offset" : -7 }, { // Quality B, correction for frame width diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 070bed63f..73a63a1a1 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -35,6 +35,7 @@ #include "improcfun.h" #include "rtlensfun.h" #include "pdaflinesfilter.h" +#include "camconst.h" #ifdef _OPENMP #include #endif @@ -1945,8 +1946,19 @@ void RawImageSource::preprocess (const RAWParams &raw, const LensProfParams &le } } - // check if it is an olympus E camera or green equilibration is enabled. If yes, compute G channel pre-compensation factors - if ( ri->getSensorType() == ST_BAYER && (raw.bayersensor.greenthresh || (((idata->getMake().size() >= 7 && idata->getMake().substr(0, 7) == "OLYMPUS" && idata->getModel()[0] == 'E') || (idata->getMake().size() >= 9 && idata->getMake().substr(0, 9) == "Panasonic")) && raw.bayersensor.method != RAWParams::BayerSensor::getMethodString( RAWParams::BayerSensor::Method::VNG4))) ) { + // check if green equilibration is needed. If yes, compute G channel pre-compensation factors + const auto globalGreenEq = + [&]() -> bool + { + CameraConstantsStore *ccs = CameraConstantsStore::getInstance(); + CameraConst *cc = ccs->get(ri->get_maker().c_str(), ri->get_model().c_str()); + return cc && cc->get_globalGreenEquilibration(); + }; + + if ( ri->getSensorType() == ST_BAYER && (raw.bayersensor.greenthresh || (globalGreenEq() && raw.bayersensor.method != RAWParams::BayerSensor::getMethodString( RAWParams::BayerSensor::Method::VNG4))) ) { + if (settings->verbose) { + printf("Performing global green equilibration...\n"); + } // global correction if(numFrames == 4) { for(int i = 0; i < 4; ++i) {