From b5bf0a8c88762c12b06d39d5c15f03def3907be7 Mon Sep 17 00:00:00 2001 From: natureh Date: Wed, 11 Jan 2012 02:06:23 +0100 Subject: [PATCH] Solving issue 1001: "Auto WB is saved as Custom in profile files" and 929: "Crash on image open with WB method = Auto" with a different workaround --- rtengine/imagesource.h | 1 + rtengine/improccoordinator.cc | 11 +++++-- rtengine/improccoordinator.h | 58 +++++++++++++++++------------------ rtengine/procparams.cc | 7 +---- rtengine/rawimagesource.h | 33 ++++++++++---------- rtengine/rtengine.h | 2 +- rtengine/stdimagesource.h | 1 + rtgui/whitebalance.cc | 31 +++++++++++++------ 8 files changed, 81 insertions(+), 63 deletions(-) diff --git a/rtengine/imagesource.h b/rtengine/imagesource.h index 6a1ade221..65986e14a 100644 --- a/rtengine/imagesource.h +++ b/rtengine/imagesource.h @@ -78,6 +78,7 @@ class ImageSource : public InitialImage { virtual bool IsrgbSourceModified() =0; // tracks whether cached rgb output of demosaic has been modified virtual void getImage (ColorTemp ctemp, int tran, Imagefloat* image, PreviewProps pp, HRecParams hlp, ColorManagementParams cmp, RAWParams raw) {} + virtual bool isWBProviderReady () =0; virtual ColorTemp getWB () =0; virtual ColorTemp getAutoWB () =0; virtual ColorTemp getSpotWB (std::vector red, std::vector green, std::vector& blue, int tran) =0; diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 6bc3f43b1..fba4ce1d3 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -354,6 +354,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { imageListener->setImage (previmg, scale, params.crop); } if (imageListener) + // TODO: The WB tool should be advertised too in order to get the AutoWB's temp and green values imageListener->imageReady (params.crop); readyphase++; @@ -487,9 +488,9 @@ void ImProcCoordinator::progress (Glib::ustring str, int pr) { }*/ } -void ImProcCoordinator::getAutoWB (double& temp, double& green) { +bool ImProcCoordinator::getAutoWB (double& temp, double& green) { - if (imgsrc) { + if (imgsrc && imgsrc->isWBProviderReady()) { if (!awbComputed) { minit.lock (); autoWB = imgsrc->getAutoWB (); @@ -498,6 +499,12 @@ void ImProcCoordinator::getAutoWB (double& temp, double& green) { } temp = autoWB.getTemp (); green = autoWB.getGreen (); + return true; + } + else { + temp = -1.0; + green = -1.0; + return false; } } diff --git a/rtengine/improccoordinator.h b/rtengine/improccoordinator.h index 089517d6b..de19ad737 100644 --- a/rtengine/improccoordinator.h +++ b/rtengine/improccoordinator.h @@ -46,12 +46,12 @@ class ImProcCoordinator : public StagedImageProcessor { LabImage *oprevl; LabImage *nprevl; Image8 *previmg; - Image8 *workimg; + Image8 *workimg; ImageSource* imgsrc; - + SHMap* shmap; - + ColorTemp currWB; ColorTemp autoWB; @@ -62,33 +62,33 @@ class ImProcCoordinator : public StagedImageProcessor { int scale; bool lastHighDetail; // was the last update running in high detail? bool allocated; - + void freeAll (); - LUTf hltonecurve; - LUTf shtonecurve; - LUTf tonecurve; - - LUTf lumacurve; - LUTf chroma_acurve; - LUTf chroma_bcurve; - LUTf satcurve; - - LUTf rCurve; - LUTf gCurve; - LUTf bCurve; + LUTf hltonecurve; + LUTf shtonecurve; + LUTf tonecurve; - LUTu rcurvehist, rcurvehistCropped, rbeforehist; - LUTu gcurvehist, gcurvehistCropped, gbeforehist; - LUTu bcurvehist, bcurvehistCropped, bbeforehist; + LUTf lumacurve; + LUTf chroma_acurve; + LUTf chroma_bcurve; + LUTf satcurve; - LUTu vhist16; - LUTu lhist16,lhist16Cropped; + LUTf rCurve; + LUTf gCurve; + LUTf bCurve; + + LUTu rcurvehist, rcurvehistCropped, rbeforehist; + LUTu gcurvehist, gcurvehistCropped, gbeforehist; + LUTu bcurvehist, bcurvehistCropped, bbeforehist; + + LUTu vhist16; + LUTu lhist16,lhist16Cropped; LUTu histCropped; - - LUTu histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, bcabhist; + + LUTu histRed, histGreen, histBlue, histLuma, histToneCurve, histLCurve, bcabhist; LUTu histRedRaw, histGreenRaw, histBlueRaw; - + int fw, fh, tr, fullw, fullh; int pW, pH; @@ -97,11 +97,11 @@ class ImProcCoordinator : public StagedImageProcessor { AutoExpListener* aeListener; HistogramListener* hListener; std::vector sizeListeners; - + std::vector crops; - + bool resultValid; - + Glib::Mutex minit; void progress (Glib::ustring str, int pr); @@ -124,7 +124,7 @@ class ImProcCoordinator : public StagedImageProcessor { void startProcessing (); void process (); - + public: ImProcCoordinator (); @@ -153,7 +153,7 @@ class ImProcCoordinator : public StagedImageProcessor { DetailedCrop* createCrop (); - void getAutoWB (double& temp, double& green); + bool getAutoWB (double& temp, double& green); void getCamWB (double& temp, double& green); void getSpotWB (int x, int y, int rectSize, double& temp, double& green); void getAutoCrop (double ratio, int &x, int &y, int &w, int &h); diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 4971324d6..95bec374b 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -443,12 +443,7 @@ int ProcParams::save (Glib::ustring fname, Glib::ustring fname2) const { keyFile.set_double ("Color Boost", "SaturationLimit", colorBoost.saturationlimit); // save wb - if (wb.method=="Auto") - // note that "Auto" has been ruled out. It's just custom. - keyFile.set_string ("White Balance", "Setting", "Custom"); - else - keyFile.set_string ("White Balance", "Setting", wb.method); - + keyFile.set_string ("White Balance", "Setting", wb.method); keyFile.set_integer ("White Balance", "Temperature", wb.temperature); keyFile.set_double ("White Balance", "Green", wb.green); diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index 10787bce4..efff60f6a 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -57,7 +57,7 @@ template void freeArray2 (T** a, int H) { class RawImageSource : public ImageSource { - private: + private: static LUTf invGrad; // for fast_demosaic static LUTf initInvGrad (); static bool findInputProfile(Glib::ustring inProfile, cmsHPROFILE embedded, std::string camName, cmsHPROFILE& in); @@ -69,10 +69,10 @@ class RawImageSource : public ImageSource { ColorTemp wb; ProgressListener* plistener; float scale_mul[4]; // multiplier for each color - float cblack[4];// black - float scale_mu_l[4];// copy of scale_mul, for saturation - float c_black[4]; // copy of cblack Dcraw for black level - float cblacksom[4]; + float cblack[4];// black + float scale_mu_l[4];// copy of scale_mul, for saturation + float c_black[4]; // copy of cblack Dcraw for black level + float cblacksom[4]; double camwb_red; double camwb_green; double camwb_blue; @@ -86,8 +86,8 @@ class RawImageSource : public ImageSource { //char** hpmap; float** hrmap[3]; // for color propagation char** needhr; // for color propagation - int max[3]; - float chmax[4],hlmax[4]; + int max[3]; + float chmax[4],hlmax[4]; double initialGain; // initial gain calculated after scale_colors double defGain; bool full; @@ -96,7 +96,7 @@ class RawImageSource : public ImageSource { bool rgbSourceModified; RawImage* ri; // Copy of raw pixels, NOT corrected for initial gain, blackpoint etc. - + // to accelerate CIELAB conversion: double lc00, lc01, lc02, lc10, lc11, lc12, lc20, lc21, lc22; double* cache; @@ -149,6 +149,7 @@ class RawImageSource : public ImageSource { ColorTemp getWB () { return wb; } ColorTemp getAutoWB (); ColorTemp getSpotWB (std::vector red, std::vector green, std::vector& blue, int tran); + bool isWBProviderReady () { return rawData != NULL; }; double getDefGain () { return defGain; } @@ -166,17 +167,17 @@ class RawImageSource : public ImageSource { static void colorSpaceConversion (Imagefloat* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], std::string camName, double& defgain); static void inverse33 (double (*coeff)[3], double (*icoeff)[3]); - void boxblur2(float** src, float** dst, int H, int W, int box ); - void boxblur_resamp(float **src, float **dst, float & max, int H, int W, int box, int samp ); + void boxblur2(float** src, float** dst, int H, int W, int box ); + void boxblur_resamp(float **src, float **dst, float & max, int H, int W, int box, int samp ); + + //void boxblur_resamp(float **red, float **green, float **blue, int H, int W, float thresh[3], float max[3], + // multi_array2D & hfsize, multi_array2D & hilite, int box ); + void HLRecovery_inpaint (float** red, float** green, float** blue); + //void HLRecovery_inpaint (); - //void boxblur_resamp(float **red, float **green, float **blue, int H, int W, float thresh[3], float max[3], \ - multi_array2D & hfsize, multi_array2D & hilite, int box ); - void HLRecovery_inpaint (float** red, float** green, float** blue); - //void HLRecovery_inpaint (); - static void HLRecovery_Luminance (float* rin, float* gin, float* bin, float* rout, float* gout, float* bout, int width, float maxval); static void HLRecovery_CIELab (float* rin, float* gin, float* bin, float* rout, float* gout, float* bout, int width, float maxval, double cam[3][3], double icam[3][3]); - static void HLRecovery_blend (float* rin, float* gin, float* bin, int width, float maxval, float* pre_mul, const RAWParams &raw, float* hlmax); + static void HLRecovery_blend (float* rin, float* gin, float* bin, int width, float maxval, float* pre_mul, const RAWParams &raw, float* hlmax); protected: typedef unsigned short ushort; diff --git a/rtengine/rtengine.h b/rtengine/rtengine.h index 7cbd553a4..c15cf910c 100644 --- a/rtengine/rtengine.h +++ b/rtengine/rtengine.h @@ -296,7 +296,7 @@ namespace rtengine { /** Creates and returns a Crop instance that acts as a window on the image */ virtual DetailedCrop* createCrop () =0; - virtual void getAutoWB (double& temp, double& green) =0; + virtual bool getAutoWB (double& temp, double& green) =0; virtual void getCamWB (double& temp, double& green) =0; virtual void getSpotWB (int x, int y, int rectSize, double& temp, double& green) =0; virtual void getAutoCrop (double ratio, int &x, int &y, int &w, int &h) =0; diff --git a/rtengine/stdimagesource.h b/rtengine/stdimagesource.h index 5828bdfa2..e16597f00 100644 --- a/rtengine/stdimagesource.h +++ b/rtengine/stdimagesource.h @@ -46,6 +46,7 @@ class StdImageSource : public ImageSource { ColorTemp getWB () { return wb; } ColorTemp getAutoWB (); ColorTemp getSpotWB (std::vector red, std::vector green, std::vector& blue, int tran); + bool isWBProviderReady () { return true; }; void getAutoExpHistogram (LUTu &histogram, int& histcompr); diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index da144bc17..49ee1b3b7 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -264,8 +264,10 @@ void WhiteBalance::optChanged () { if (wbp) { double ctemp, cgreen; wbp->getAutoWB (ctemp, cgreen); - temp->setValue (temp->getAddMode() ? 0.0 : (int)ctemp); - green->setValue (green->getAddMode() ? 0.0 : cgreen); + if (ctemp != -1.0) { + temp->setValue (temp->getAddMode() ? 0.0 : (int)ctemp); + green->setValue (green->getAddMode() ? 0.0 : cgreen); + } if (batchMode) { temp->setEditedState (UnEdited); green->setEditedState (UnEdited); @@ -371,10 +373,12 @@ void WhiteBalance::read (const ProcParams* pp, const ParamsEdited* pedited) { double ctemp; double cgreen; wbp->getAutoWB (ctemp, cgreen); - // Set the automatics temperature value, or 0.0 if in ADD mode - temp->setValue (temp->getAddMode() ? 0.0 : ctemp); - // Set the automatics green value, or 0.0 if in ADD mode - green->setValue (green->getAddMode() ? 0.0 : cgreen); + if (ctemp != -1.0) { + // Set the automatics temperature value, or 0.0 if in ADD mode + temp->setValue (temp->getAddMode() ? 0.0 : ctemp); + // Set the automatics green value, or 0.0 if in ADD mode + green->setValue (green->getAddMode() ? 0.0 : cgreen); + } //cache_customWB ((int)ctemp, cgreen); // this will be used to set initial Custom WB setting } @@ -420,7 +424,7 @@ void WhiteBalance::write (ProcParams* pp, ParamsEdited* pedited) { WBEntry* ppMethod = findWBEntry (row[methodColumns.colLabel], WBLT_GUI); if (ppMethod) - pp->wb.method = ppMethod->ppLabel == "Auto" ? "Custom" : ppMethod->ppLabel; + pp->wb.method = ppMethod->ppLabel; pp->wb.temperature = temp->getIntValue (); pp->wb.green = green->getValue (); @@ -435,10 +439,19 @@ void WhiteBalance::setDefaults (const ProcParams* defParams, const ParamsEdited* green->setDefault (green->getAddMode() ? 0 : cgreen); } else if (wbp && defParams->wb.method == "Auto") { + // this setDefaults method is called too early ; the wbp has been set, + // but wbp is not ready to provide! double ctemp; double cgreen; wbp->getAutoWB (ctemp, cgreen); - temp->setDefault (temp->getAddMode() ? 0 : (int)ctemp); - green->setDefault (green->getAddMode() ? 0 : cgreen); + if (ctemp != -1.0) { + temp->setDefault (temp->getAddMode() ? 0 : (int)ctemp); + green->setDefault (green->getAddMode() ? 0 : cgreen); + } + else { + // 6504 & 1.0 = same values as in ProcParams::setDefaults + temp->setDefault (temp->getAddMode() ? 0 : 6504); + green->setDefault (green->getAddMode() ? 0 : 1.0); + } } else { temp->setDefault (defParams->wb.temperature);