From 9ef10d741aaded31a7e5d8f534dbb74bc1d84063 Mon Sep 17 00:00:00 2001 From: torger Date: Wed, 23 Oct 2013 18:19:46 +0200 Subject: [PATCH] Camconst stuff: now case insensitive matching; print levels and where they come from if verbose; Phase One camconst.json minor fixes and comments --- rtengine/camconst.cc | 15 +++++++++++++-- rtengine/camconst.json | 9 ++++++--- rtengine/rawimage.cc | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index a2683041c..533522913 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -2,6 +2,7 @@ * This file is part of RawTherapee. */ #include "camconst.h" +#include "settings.h" #include "safegtk.h" #include "rt_math.h" #include @@ -16,6 +17,8 @@ namespace rtengine { +extern const Settings* settings; + CameraConst::CameraConst() { memset(dcraw_matrix, 0, sizeof(dcraw_matrix)); @@ -438,12 +441,16 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) goto parse_error; } Glib::ustring make_model(ji->valuestring); + make_model = make_model.uppercase(); std::map::iterator existingccIter = mCameraConstants.find(make_model); - if (existingccIter == mCameraConstants.end()) + if (existingccIter == mCameraConstants.end()) { // add the new CamConst to the map mCameraConstants.insert(std::pair(make_model, cc)); - else { + if (settings->verbose) { + printf("Add camera constants for \"%s\"\n", make_model.c_str()); + } + } else { // The CameraConst already exist for this camera make/model -> we merge the values CameraConst *existingcc = existingccIter->second; @@ -451,6 +458,9 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) existingcc->update_dcrawMatrix(cc->get_dcrawMatrix()); // deleting all the existing levels, replaced by the new ones existingcc->update_Levels(cc); + if (settings->verbose) { + printf("Merging camera constants for \"%s\"\n", make_model.c_str()); + } } if (is_array) { ji = ji->next; @@ -501,6 +511,7 @@ CameraConstantsStore::get(const char make[], const char model[]) Glib::ustring key(make); key += " "; key += model; + key = key.uppercase(); std::map::iterator it; it = mCameraConstants.find(key); if (it == mCameraConstants.end()) { diff --git a/rtengine/camconst.json b/rtengine/camconst.json index 03d962a8c..2a10440aa 100644 --- a/rtengine/camconst.json +++ b/rtengine/camconst.json @@ -383,14 +383,17 @@ Quality X: unknown, ie we knowing to little about the camera properties to know "ranges": { "black": 512, "white": 16350 } }, - // Phase One: color matrices borrowed from Adobe DNG Converter, black/white levels tested on actual raw files + /* Phase One: color matrices borrowed from Adobe DNG Converter, black/white levels tested on actual raw files. + Note: the dcraw decoder makes black level subtraction when decoding from metadata in the IIQ format, so + what we see here is the result after that, ie black level is 0. (The actual black level is about 1024 with + white level at 0xfffc=65532) */ { // quality A "make_model": [ "Phase One P40+", "Phase One IQ140", "Phase One P65+", "Phase One IQ160" ], "dcraw_matrix": [ 8035,435,-962,-6001,13872,2320,-1159,3065,5434 ], "ranges": { "black": 0, "white": 64400 } }, { // quality A - "make_model": "Phase One IQ180", + "make_model": [ "Phase One IQ180", "Phase One IQ280" ], "dcraw_matrix": [ 6294,686,-712,-5435,13417,2211,-1006,2435,5042 ], "ranges": { "black": 0, "white": 64400 } }, @@ -410,7 +413,7 @@ Quality X: unknown, ie we knowing to little about the camera properties to know "ranges": { "black": 0, "white": 64400 } }, { // quality A - "make_model": [ "Phase One 45", "Phase One 45+" ], + "make_model": [ "Phase One P45", "Phase One P45+" ], "dcraw_matrix": [ 5053,-24,-117,-5685,14077,1703,-2619,4491,5850 ], "ranges": { "black": 0, "white": 64400 } }, diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index e5602de1d..c2309f922 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -239,6 +239,8 @@ int RawImage::loadRaw (bool loadData, bool closeFile) CameraConstantsStore* ccs = CameraConstantsStore::getInstance(); CameraConst *cc = ccs->get(make, model); + bool white_from_cc = false; + bool black_from_cc = false; if (cc) { for (int i = 0; i < 4; i++) { if (RT_blacklevel_from_constant) { @@ -253,12 +255,29 @@ int RawImage::loadRaw (bool loadData, bool closeFile) if (black_c4[0] == -1) { // RT constants not set, bring in the DCRAW single channel black constant for (int c=0; c < 4; c++) black_c4[c] = black; + } else { + black_from_cc = true; + } + if (maximum_c4[0] > 0) { + white_from_cc = true; } for (int c=0; c < 4; c++) { if (cblack[c] < black_c4[c]) { cblack[c] = black_c4[c]; } } + if (settings->verbose) { + if (cc) { + printf("constants exists for \"%s %s\" in camconst.json\n", make, model); + } else { + printf("no constants in camconst.json exists for \"%s %s\" (relying only on dcraw defaults)\n", make, model); + } + printf("black levels: R:%d G1:%d B:%d G2:%d (%s)\n", get_cblack(0), get_cblack(1), get_cblack(2), get_cblack(3), + black_from_cc ? "provided by camconst.json" : "provided by dcraw"); + printf("white levels: R:%d G1:%d B:%d G2:%d (%s)\n", get_white(0), get_white(1), get_white(2), get_white(3), + white_from_cc ? "provided by camconst.json" : "provided by dcraw"); + printf("color matrix provided by %s\n", (cc && cc->has_dcrawMatrix()) ? "camconst.json" : "dcraw"); + } } if ( closeFile ) {