From 033755b6df36201ddbcf3c9ad17ffd2fe50ad288 Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Mon, 9 Apr 2012 15:42:59 -0500 Subject: [PATCH] Code cleanup for min/max functions. Committed on behalf of lebedev.ri (thanks!). --- rtengine/CA_correct_RT.cc | 21 +- rtengine/EdgePreservingDecomposition.cc | 10 +- rtengine/PF_correct_RT.cc | 18 +- rtengine/amaze_demosaic_RT.cc | 20 +- rtengine/bilateral2.h | 10 +- rtengine/cfa_linedn_RT.cc | 34 +-- rtengine/color.cc | 19 +- rtengine/curves.cc | 19 +- rtengine/curves.h | 4 +- rtengine/dcp.cc | 5 +- rtengine/dcraw.cc | 47 ++-- rtengine/dcraw.patch | 308 ++++++++++++++++-------- rtengine/dcrop.cc | 2 +- rtengine/demosaic_algos.cc | 106 ++++---- rtengine/dirpyrLab_denoise.cc | 23 +- rtengine/dirpyrLab_equalizer.cc | 21 +- rtengine/dirpyr_equalizer.cc | 8 +- rtengine/fast_demo.cc | 17 +- rtengine/gamutbdy.cc | 2 +- rtengine/green_equil_RT.cc | 2 +- rtengine/hilite_recon.cc | 68 +++--- rtengine/hlmultipliers.cc | 24 +- rtengine/iccstore.cc | 2 +- rtengine/imageio.cc | 20 +- rtengine/improcfun.cc | 55 ++--- rtengine/improcfun.h | 2 +- rtengine/impulse_denoise.h | 22 +- rtengine/iplab2rgb.cc | 2 +- rtengine/ipresize.cc | 11 +- rtengine/ipsharpen.cc | 42 ++-- rtengine/iptcpairs.h | 2 +- rtengine/iptransform.cc | 15 +- rtengine/ipvibrance.cc | 13 +- rtengine/klt/base.h | 11 - rtengine/klt/klt.cc | 3 + rtengine/klt/klt_util.cc | 2 + rtengine/procparams.cc | 18 +- rtengine/rawimage.cc | 2 +- rtengine/rawimagesource.cc | 119 +++++---- rtengine/rawimagesource.h | 2 +- rtengine/rawimagesource_i.h | 8 +- rtengine/rt_math.h | 45 ++++ rtengine/rtengine.h | 2 +- rtengine/rtthumbnail.cc | 35 +-- rtengine/shmap.cc | 33 +-- rtengine/shmap.h | 2 +- rtengine/slicer.cc | 11 +- rtengine/utils.cc | 13 +- rtgui/batchqueue.cc | 12 +- rtgui/editorpanel.cc | 2 +- rtgui/filecatalog.cc | 13 +- rtgui/guiutils.cc | 6 +- rtgui/mydiagonalcurve.cc | 8 +- rtgui/navigator.cc | 9 +- rtgui/popupcommon.cc | 2 +- rtgui/profilepanel.cc | 28 +-- rtgui/profilepanel.h | 3 +- rtgui/rtwindow.cc | 7 + rtgui/rtwindow.h | 1 + rtgui/thumbbrowserbase.cc | 14 +- rtgui/whitebalance.cc | 2 +- 61 files changed, 767 insertions(+), 620 deletions(-) create mode 100644 rtengine/rt_math.h diff --git a/rtengine/CA_correct_RT.cc b/rtengine/CA_correct_RT.cc index 7434ae516..f144bca57 100644 --- a/rtengine/CA_correct_RT.cc +++ b/rtengine/CA_correct_RT.cc @@ -22,6 +22,14 @@ // //////////////////////////////////////////////////////////////// //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +#include "rtengine.h" +#include "rawimagesource.h" +#include "rt_math.h" + +using namespace std; +using namespace rtengine; + int RawImageSource::LinEqSolve(int nDim, float* pfMatr, float* pfVect, float* pfSolution) { //============================================================================== @@ -101,7 +109,6 @@ void RawImageSource::CA_correct_RT(double cared, double cablue) { //#define border2 16 #define PIX_SORT(a,b) { if ((a)>(b)) {temp=(a);(a)=(b);(b)=temp;} } - #define SQR(x) ((x)*(x)) // local variables int width=W, height=H; @@ -236,8 +243,8 @@ void RawImageSource::CA_correct_RT(double cared, double cablue) { vctr++; for (left=-border, hblock=1; left < width; left += TS-border2, hblock++) { hctr++; - int bottom = MIN( top+TS,height+border); - int right = MIN(left+TS, width+border); + int bottom = min(top+TS,height+border); + int right = min(left+TS, width+border); int rr1 = bottom - top; int cc1 = right - left; //t1_init = clock(); @@ -629,7 +636,7 @@ void RawImageSource::CA_correct_RT(double cared, double cablue) { }//c }//blocks - numblox[1]=MIN(numblox[0],numblox[2]); + numblox[1]=min(numblox[0],numblox[2]); //if too few data points, restrict the order of the fit to linear if (numblox[1]<32) { polyord=2; numpar=4; @@ -659,8 +666,8 @@ void RawImageSource::CA_correct_RT(double cared, double cablue) { //#pragma omp parallel for shared(image,height,width) private(top,left,indx,indx1) schedule(dynamic) for (top=-border, vblock=1; top < height; top += TS-border2, vblock++) for (left=-border, hblock=1; left < width; left += TS-border2, hblock++) { - int bottom = MIN( top+TS,height+border); - int right = MIN(left+TS, width+border); + int bottom = min(top+TS,height+border); + int right = min(left+TS, width+border); int rr1 = bottom - top; int cc1 = right - left; //t1_init = clock(); @@ -926,8 +933,6 @@ void RawImageSource::CA_correct_RT(double cared, double cablue) { //#undef border //#undef border2 #undef PIX_SORT -#undef SQR - } diff --git a/rtengine/EdgePreservingDecomposition.cc b/rtengine/EdgePreservingDecomposition.cc index 04b97f448..b8d35b8f8 100644 --- a/rtengine/EdgePreservingDecomposition.cc +++ b/rtengine/EdgePreservingDecomposition.cc @@ -1,12 +1,8 @@ +#include +#include + #include "EdgePreservingDecomposition.h" -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - - - - /* Solves A x = b by the conjugate gradient method, where instead of feeding it the matrix A you feed it a function which calculates A x where x is some vector. Stops when rms residual < RMSResidual or when maximum iterates is reached. Stops at n iterates if MaximumIterates = 0 since that many iterates gives exact solution. Applicable to symmetric positive diff --git a/rtengine/PF_correct_RT.cc b/rtengine/PF_correct_RT.cc index 8f409c640..3d35f0bf7 100644 --- a/rtengine/PF_correct_RT.cc +++ b/rtengine/PF_correct_RT.cc @@ -25,24 +25,23 @@ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -//#include "rtengine.h" -//#include #include "gauss.h" -//#include "bilateral2.h" #include "improcfun.h" #ifdef _OPENMP #include #endif -#define SQR(x) ((x)*(x)) +#include "rt_math.h" + +using namespace std; namespace rtengine { void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radius, int thresh) { int halfwin = ceil(2*radius)+1; -#define SQR(x) ((x)*(x)) +#include "rt_math.h" // local variables int width=src->W, height=src->H; @@ -57,7 +56,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu #pragma omp parallel #endif { - AlignedBuffer* buffer = new AlignedBuffer (MAX(src->W,src->H)); + AlignedBuffer* buffer = new AlignedBuffer (max(src->W,src->H)); gaussHorizontal (src->a, tmp1->a, buffer, src->W, src->H, radius, multiThread); gaussHorizontal (src->b, tmp1->b, buffer, src->W, src->H, radius, multiThread); gaussVertical (tmp1->a, tmp1->a, buffer, src->W, src->H, radius, multiThread); @@ -98,8 +97,8 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu float btot=0; float norm=0; float wt; - for (int i1=MAX(0,i-halfwin+1); i1a[i1][j1]; @@ -126,9 +125,6 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu delete tmp1; free(fringe); - -//#undef SQR - } } diff --git a/rtengine/amaze_demosaic_RT.cc b/rtengine/amaze_demosaic_RT.cc index 32e522d03..f99b1186a 100644 --- a/rtengine/amaze_demosaic_RT.cc +++ b/rtengine/amaze_demosaic_RT.cc @@ -24,17 +24,17 @@ // //////////////////////////////////////////////////////////////// +#include "rtengine.h" +#include "rawimagesource.h" +#include "rt_math.h" + using namespace rtengine; void RawImageSource::amaze_demosaic_RT(int winx, int winy, int winw, int winh) { - -#define SQR(x) ((x)*(x)) - //#define MIN(a,b) ((a) < (b) ? (a) : (b)) - //#define MAX(a,b) ((a) > (b) ? (a) : (b)) -#define LIM(x,min,max) MAX(min,MIN(x,max)) +#define LIM(x,MIN,MAX) max(MIN,min(x,MAX)) #define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) #define HCLIP(x) x //is this still necessary??? - //MIN(clip_pt,x) + //min(clip_pt,x) int width=winw, height=winh; @@ -218,9 +218,9 @@ void RawImageSource::amaze_demosaic_RT(int winx, int winy, int winw, int winh) { for (top=winy-16; top < winy+height; top += TS-32) for (left=winx-16; left < winx+width; left += TS-32) { //location of tile bottom edge - int bottom = MIN( top+TS,winy+height+16); + int bottom = min(top+TS,winy+height+16); //location of tile right edge - int right = MIN(left+TS, winx+width+16); + int right = min(left+TS, winx+width+16); //tile width (=TS except for right edge of image) int rr1 = bottom - top; //tile height (=TS except for bottom edge of image) @@ -476,8 +476,8 @@ void RawImageSource::amaze_demosaic_RT(int winx, int winy, int winw, int winh) { } //differences of interpolations in opposite directions - dgintv[indx]=MIN(SQR(guha-gdha),SQR(guar-gdar)); - dginth[indx]=MIN(SQR(glha-grha),SQR(glar-grar)); + dgintv[indx]=min(SQR(guha-gdha),SQR(guar-gdar)); + dginth[indx]=min(SQR(glha-grha),SQR(glar-grar)); } //t2_vcdhcd += clock() - t1_vcdhcd; diff --git a/rtengine/bilateral2.h b/rtengine/bilateral2.h index 24854baa5..0066acdbe 100644 --- a/rtengine/bilateral2.h +++ b/rtengine/bilateral2.h @@ -22,6 +22,8 @@ #include #include #include +#include + #include "alignedbuffer.h" #include "mytime.h" #include "gauss.h" @@ -30,6 +32,8 @@ #include #endif +using namespace std; + // This seems ugly, but way faster than any other solutions I tried #define ELEM(a,b) (src[i - a][j - b] * ec[src[i - a][j - b]-src[i][j]+65536.0f]) #define SULY(a,b) (ec[src[i - a][j - b]-src[i][j]+65536.0f]) @@ -460,7 +464,7 @@ template void bilateral (T** src, T** dst, int W, int H, int sigmar, do // calculate histogram at the beginning of the row rhist.clear(); - for (int x = MAX(0,row_from-r-1); x>TRANSBIT]++; @@ -481,10 +485,10 @@ template void bilateral (T** src, T** dst, int W, int H, int sigmar, do // substract pixels at the left and add pixels at the right if (j>r) - for (int x=MAX(0,i-r); x<=MIN(i+r,H-1); x++) + for (int x=max(0,i-r); x<=min(i+r,H-1); x++) hist[(int)(src[x][j-r-1])>>TRANSBIT]--; if (j>TRANSBIT]++; // calculate pixel value diff --git a/rtengine/cfa_linedn_RT.cc b/rtengine/cfa_linedn_RT.cc index 8b276add3..1a55f0866 100644 --- a/rtengine/cfa_linedn_RT.cc +++ b/rtengine/cfa_linedn_RT.cc @@ -22,36 +22,20 @@ // //////////////////////////////////////////////////////////////// +#include + +#include "rtengine.h" +#include "rawimagesource.h" +#include "rt_math.h" #define TS 512 // Tile size #define CLASS -/* -#include -#include -#include -#include -#include -#include -#include -#include -#include */ -#include - - -//#include "shrtdct_float.c" - - -#define SQR(x) ((x)*(x)) -//#define MIN(a,b) ((a) < (b) ? (a) : (b)) -//#define MAX(a,b) ((a) > (b) ? (a) : (b)) -//#define LIM(x,min,max) MAX(min,MIN(x,max)) -//#define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) -//#define CLIP(x) LIM(x,0,65535) - // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +using namespace std; +using namespace rtengine; // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -115,8 +99,8 @@ void RawImageSource::CLASS cfa_linedn(float noise) for (int top=0; top < height-16; top += TS-32) for (int left=0; left < width-16; left += TS-32) { - int bottom = MIN( top+TS,height); - int right = MIN(left+TS, width); + int bottom = min(top+TS,height); + int right = min(left+TS, width); int numrows = bottom - top; int numcols = right - left; int indx1; diff --git a/rtengine/color.cc b/rtengine/color.cc index 3701d47db..b1eeaf2ef 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -17,19 +17,16 @@ * along with RawTherapee. If not, see . */ +#include "rt_math.h" #include "color.h" #include "iccmatrices.h" +using namespace std; + namespace rtengine { #undef MAXVAL -#undef MAX -#undef MIN - #define MAXVAL 0xffff -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) -#define SQR(x) ((x)*(x)) #define eps_max 580.40756 //(MAXVAL* 216.0f/24389.0); #define kappa 903.29630 //24389.0/27.0; @@ -97,8 +94,8 @@ void Color::rgb2hsv (float r, float g, float b, float &h, float &s, float &v) { double var_G = g / 65535.0; double var_B = b / 65535.0; - double var_Min = MIN(MIN(var_R,var_G),var_B); - double var_Max = MAX(MAX(var_R,var_G),var_B); + double var_Min = min(var_R,var_G,var_B); + double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; v = var_Max; if (fabs(del_Max)<0.00001) { @@ -124,8 +121,8 @@ void Color::rgb2hsv (int r, int g, int b, float &h, float &s, float &v) { double var_G = g / 65535.0; double var_B = b / 65535.0; - double var_Min = MIN(MIN(var_R,var_G),var_B); - double var_Max = MAX(MAX(var_R,var_G),var_B); + double var_Min = min(var_R,var_G,var_B); + double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; v = var_Max; if (fabs(del_Max)<0.00001) { @@ -270,7 +267,7 @@ void Color::xyz2rgb (float x, float y, float z, float &r, float &g, float &b, fl void Color::calcGamma (double pwr, double ts, int mode, int imax, double &gamma0, double &gamma1, double &gamma2, double &gamma3, double &gamma4, double &gamma5) { //from Dcraw (D.Coffin) int i; - double g[6], bnd[2]={0,0}, r; + double g[6], bnd[2]={0,0}; g[0] = pwr; g[1] = ts; diff --git a/rtengine/curves.cc b/rtengine/curves.cc index f2846906d..0d6dec281 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -18,14 +18,17 @@ */ #include #include -#include "curves.h" #include #include -#include "mytime.h" #include +#include +#include "rt_math.h" + +#include "mytime.h" #include "array2D.h" #include "LUT.h" +#include "curves.h" #undef CLIPD #define CLIPD(a) ((a)>0.0f?((a)<1.0f?(a):1.0f):0.0f) @@ -311,9 +314,9 @@ namespace rtengine { brightcurvePoints.push_back(0.1+br/150.0); //value at toe point brightcurvePoints.push_back(0.7); //shoulder point - brightcurvePoints.push_back(MIN(1.0,0.7+br/300.0)); //value at shoulder point + brightcurvePoints.push_back(min(1.0,0.7+br/300.0)); //value at shoulder point } else { - brightcurvePoints.push_back(MAX(0.0,0.1-br/150.0)); //toe point + brightcurvePoints.push_back(max(0.0,0.1-br/150.0)); //toe point brightcurvePoints.push_back(0.1); //value at toe point brightcurvePoints.push_back(0.7-br/300.0); //shoulder point @@ -328,8 +331,8 @@ namespace rtengine { float exp_scale = a; float scale = 65536.0; - float comp = (MAX(0,ecomp) + 1.0)*hlcompr/100.0; - float shoulder = ((scale/MAX(1,exp_scale))*(hlcomprthresh/200.0))+0.1; + float comp = (max(0.0,ecomp) + 1.0)*hlcompr/100.0; + float shoulder = ((scale/max(1.0f,exp_scale))*(hlcomprthresh/200.0))+0.1; //printf("shoulder = %e\n",shoulder); //printf ("exp_scale= %f comp= %f def_mul=%f a= %f \n",exp_scale,comp,def_mul,a); @@ -513,12 +516,12 @@ namespace rtengine { brightcurvePoints.push_back(0.1+br/150.0); //value at toe point brightcurvePoints.push_back(0.7); // shoulder point - brightcurvePoints.push_back(MIN(1.0,0.7+br/300.0)); //value at shoulder point + brightcurvePoints.push_back(min(1.0,0.7+br/300.0)); //value at shoulder point } else { brightcurvePoints.push_back(0.1-br/150.0); // toe point brightcurvePoints.push_back(0.1); // value at toe point - brightcurvePoints.push_back(MIN(1.0,0.7-br/300.0)); // shoulder point + brightcurvePoints.push_back(min(1.0,0.7-br/300.0)); // shoulder point brightcurvePoints.push_back(0.7); // value at shoulder point } brightcurvePoints.push_back(1.); // white point diff --git a/rtengine/curves.h b/rtengine/curves.h index b86bc7797..7a1c16c1c 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -31,10 +31,12 @@ #define CURVES_MIN_POLY_POINTS 1000 -#define SQR(x) ((x)*(x)) +#include "rt_math.h" #define CLIPI(a) ((a)>0?((a)<65534?(a):65534):0) +using namespace std; + namespace rtengine { class CurveFactory { diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index a044039c0..407a7e6e0 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -16,15 +16,16 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include #include "dcp.h" -#include #include "safegtk.h" #include "iccmatrices.h" #include "iccstore.h" #include "rawimagesource.h" #include "improcfun.h" +using namespace std; using namespace rtengine; using namespace rtexif; @@ -402,7 +403,7 @@ void DCPStore::init (Glib::ustring rtProfileDir) { qDirs.push_front(rootDirName); - while (qDirs.size()) { + while (!qDirs.empty()) { // process directory Glib::ustring dirname = qDirs.back(); qDirs.pop_back(); diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index c7660b769..2a34ab281 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -3,6 +3,8 @@ /*RT*/#undef MAX /*RT*/#undef MIN /*RT*/#undef ABS +/*RT*/#include +/*RT*/#include "rt_math.h" /*RT*/#define NO_LCMS /*RT*/#define NO_JPEG /*RT*/#define NO_JASPER @@ -178,13 +180,15 @@ struct ph1 { #define FORC4 FORC(4) #define FORCC FORC(colors) -#define SQR(x) ((x)*(x)) +#define SQR(x) rtengine::SQR(x) #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MIN(a,b) rtengine::min(a,b) +#define MAX(a,b) rtengine::max(a,b) #define LIM(x,min,max) MAX(min,MIN(x,max)) #define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) #define CLIP(x) LIM(x,0,65535) +#define CLIPD(x) LIM(x,0.0,65535.0) +#define CLIPF(x) LIM(x,0.0f,65535.0f) #define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } /* @@ -1181,7 +1185,7 @@ void CLASS nikon_compressed_load_raw() else hpred[col & 1] += diff; if ((ushort)(hpred[col & 1] + min) >= max) derror(); if ((unsigned) (col-left_margin) < width) - BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; + BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],(short)0,(short)0x3fff)]; } } free (huff); @@ -1417,7 +1421,7 @@ void CLASS phase_one_flat_field (int is_float, int nc) c = nc > 2 ? FC(row,col) : 0; if (!(c & 1)) { c = BAYER(row,col) * mult[c]; - BAYER(row,col) = LIM(c,0,65535); + BAYER(row,col) = LIM(c,0u,65535u); } for (c=0; c < nc; c+=2) mult[c] += mult[c+1]; @@ -1461,7 +1465,7 @@ void CLASS phase_one_correct() poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; for (i=0; i < 0x10000; i++) { num = (poly[5]*i + poly[3])*i + poly[1]; - curve[i] = LIM(num,0,65535); + curve[i] = CLIPF(num); } goto apply; /* apply to right half */ } else if (tag == 0x41a) { /* Polynomial curve */ for (i=0; i < 4; i++) @@ -1469,7 +1473,7 @@ void CLASS phase_one_correct() for (i=0; i < 0x10000; i++) { for (num=0, j=4; j--; ) num = num * i + poly[j]; - curve[i] = LIM(num+i,0,65535); + curve[i] = CLIPF(num+i); } apply: /* apply to whole image */ for (row=0; row < height; row++) for (col = (tag & 1)*ph1.split_col; col < width; col++) @@ -3680,7 +3684,7 @@ void CLASS wavelet_denoise() hpass = lpass; } for (i=0; i < size; i++) - image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); + image[i][c] = CLIPF(SQR(fimg[i]+fimg[lpass+i])/0x10000); } if (filters && colors == 3) { /* pull G1 and G3 closer together */ for (row=0; row < 2; row++) { @@ -3706,7 +3710,7 @@ void CLASS wavelet_denoise() if (diff < -thold) diff += thold; else if (diff > thold) diff -= thold; else diff = 0; - BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); + BAYER(row,col) = CLIPD(SQR(avg+diff) + 0.5); } } } @@ -3726,8 +3730,8 @@ void CLASS scale_colors() memcpy (pre_mul, user_mul, sizeof pre_mul); if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { memset (dsum, 0, sizeof dsum); - bottom = MIN (greybox[1]+greybox[3], height); - right = MIN (greybox[0]+greybox[2], width); + bottom = MIN (greybox[1]+greybox[3], static_cast(height)); + right = MIN (greybox[0]+greybox[2], static_cast(width)); for (row=greybox[1]; row < bottom; row += 8) for (col=greybox[0]; col < right; col += 8) { memset (sum, 0, sizeof sum); @@ -3931,7 +3935,7 @@ void CLASS lin_interpolate() */ void CLASS vng_interpolate() { - static const signed char *cp, terms[] = { + static const signed short int *cp, terms[] = { -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, @@ -4081,7 +4085,7 @@ void CLASS ppg_interpolate() ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; } d = dir[i = diff[0] > diff[1]]; - pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); + pix[0][1] = ULIM(guess[i] >> 2, static_cast(pix[d][1]), static_cast(pix[-d][1])); } /* Calculate red and blue for each green pixel: */ for (row=1; row < height-1; row++) @@ -4154,10 +4158,10 @@ void CLASS ahd_interpolate() pix = image + row*width+col; val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 - pix[-2][c] - pix[2][c]) >> 2; - rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); + rgb[0][row-top][col-left][1] = ULIM(val,static_cast(pix[-1][1]),static_cast(pix[1][1])); val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 - pix[-2*width][c] - pix[2*width][c]) >> 2; - rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); + rgb[1][row-top][col-left][1] = ULIM(val,static_cast(pix[-width][1]),static_cast(pix[width][1])); } } /* Interpolate red and blue, and convert to CIELab: */ @@ -4288,7 +4292,7 @@ void CLASS blend_highlights() if (c == colors) continue; FORCC { cam[0][c] = image[row*width+col][c]; - cam[1][c] = MIN(cam[0][c],clip); + cam[1][c] = MIN(cam[0][c],static_cast(clip)); } for (i=0; i < 2; i++) { FORCC for (lab[i][c]=j=0; j < colors; j++) @@ -4787,7 +4791,7 @@ void CLASS parse_gps (int base) case 6: FORC(2) gpsdata[18+c] = get4(); break; case 18: case 29: - fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); + fgets ((char *) (gpsdata+14+tag/3), MIN(len,12u), ifp); } fseek (ifp, save, SEEK_SET); } @@ -6186,7 +6190,9 @@ void CLASS adobe_coeff (const char *make, const char *model) { static const struct { const char *prefix; - short black, maximum, trans[12]; + short black; + int maximum; + short trans[12]; } table[] = { { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, @@ -8806,7 +8812,7 @@ void CLASS tiff_head (struct tiff_hdr *th, int full) strncpy (th->desc, desc, 512); strncpy (th->make, make, 64); strncpy (th->model, model, 64); - strcpy (th->soft, "dcraw v"DCRAW_VERSION); + sprintf (th->soft, "dcraw v%s", DCRAW_VERSION); t = localtime (×tamp); sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); @@ -9262,3 +9268,6 @@ cleanup: return status; } */ +/*RT*/#undef MAX +/*RT*/#undef MIN +/*RT*/#undef ABS diff --git a/rtengine/dcraw.patch b/rtengine/dcraw.patch index b85001d4d..d2a1eabf8 100644 --- a/rtengine/dcraw.patch +++ b/rtengine/dcraw.patch @@ -1,11 +1,13 @@ ---- C:/GCC/RT/RTSrc/rtengine/dcraw.c Thu Dec 29 12:43:38 2011 -+++ C:/GCC/RT/RTSrc/rtengine/dcraw.cc Sun Mar 25 19:10:21 2012 -@@ -1,3 +1,14 @@ +--- dcraw.c 2012-04-06 17:30:26.000000000 +0400 ++++ dcraw.cc 2012-04-06 21:59:43.816583252 +0400 +@@ -1,3 +1,16 @@ +/*RT*/#include +/*RT*/#include +/*RT*/#undef MAX +/*RT*/#undef MIN +/*RT*/#undef ABS ++/*RT*/#include ++/*RT*/#include "rt_math.h" +/*RT*/#define NO_LCMS +/*RT*/#define NO_JPEG +/*RT*/#define NO_JASPER @@ -15,7 +17,7 @@ /* dcraw.c -- Dave Coffin's raw photo decoder Copyright 1997-2011 by Dave Coffin, dcoffin a cybercom o net -@@ -29,17 +40,17 @@ +@@ -29,17 +42,17 @@ #define _GNU_SOURCE #endif #define _USE_MATH_DEFINES @@ -43,7 +45,7 @@ #include #ifdef NODEPS -@@ -98,18 +109,16 @@ +@@ -98,18 +111,16 @@ #define LONG_BIT (8 * sizeof (long)) #endif @@ -67,7 +69,7 @@ FILE *ifp, *ofp; short order; const char *ifname; -@@ -137,13 +146,13 @@ +@@ -137,13 +148,13 @@ int output_color=1, output_bps=8, output_tiff=0, med_passes=0; int no_auto_bright=0; unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; @@ -84,7 +86,7 @@ void (*write_thumb)(), (*write_fun)(); void (*load_raw)(), (*thumb_load_raw)(); jmp_buf failure; -@@ -161,8 +170,8 @@ +@@ -161,21 +172,23 @@ int format, key_off, black, black_off, split_col, tag_21a; float tag_210; } ph1; @@ -95,7 +97,25 @@ #define FORC(cnt) for (c=0; c < cnt; c++) #define FORC3 FORC(3) -@@ -280,6 +289,7 @@ + #define FORC4 FORC(4) + #define FORCC FORC(colors) + +-#define SQR(x) ((x)*(x)) ++#define SQR(x) rtengine::SQR(x) + #define ABS(x) (((int)(x) ^ ((int)(x) >> 31)) - ((int)(x) >> 31)) +-#define MIN(a,b) ((a) < (b) ? (a) : (b)) +-#define MAX(a,b) ((a) > (b) ? (a) : (b)) ++#define MIN(a,b) rtengine::min(a,b) ++#define MAX(a,b) rtengine::max(a,b) + #define LIM(x,min,max) MAX(min,MIN(x,max)) + #define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) + #define CLIP(x) LIM(x,0,65535) ++#define CLIPD(x) LIM(x,0.0,65535.0) ++#define CLIPF(x) LIM(x,0.0f,65535.0f) + #define SWAP(a,b) { a=a+b; b=a-b; a=a-b; } + + /* +@@ -280,6 +293,7 @@ fprintf (stderr,_("Corrupt data near 0x%llx\n"), (INT64) ftello(ifp)); } data_error++; @@ -103,7 +123,7 @@ } ushort CLASS sget2 (uchar *s) -@@ -353,7 +363,7 @@ +@@ -353,7 +367,7 @@ { if (fread (pixel, 2, count, ifp) < count) derror(); if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) @@ -112,7 +132,7 @@ } void CLASS canon_600_fixed_wb (int temp) -@@ -545,10 +555,10 @@ +@@ -545,10 +559,10 @@ getbits(-1) initializes the buffer getbits(n) where 0 <= n <= 25 returns an n-bit integer */ @@ -126,7 +146,16 @@ unsigned c; if (nbits == -1) -@@ -1261,7 +1271,7 @@ +@@ -1171,7 +1185,7 @@ + else hpred[col & 1] += diff; + if ((ushort)(hpred[col & 1] + min) >= max) derror(); + if ((unsigned) (col-left_margin) < width) +- BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],0,0x3fff)]; ++ BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],(short)0,(short)0x3fff)]; + } + } + free (huff); +@@ -1261,7 +1275,7 @@ int i, nz; char tail[424]; @@ -135,7 +164,7 @@ fread (tail, 1, sizeof tail, ifp); for (nz=i=0; i < sizeof tail; i++) if (tail[i]) nz++; -@@ -1297,7 +1307,7 @@ +@@ -1297,7 +1311,7 @@ free (pixel); } @@ -144,7 +173,34 @@ void CLASS ppm_thumb() { -@@ -1573,10 +1583,10 @@ +@@ -1407,7 +1421,7 @@ + c = nc > 2 ? FC(row,col) : 0; + if (!(c & 1)) { + c = BAYER(row,col) * mult[c]; +- BAYER(row,col) = LIM(c,0,65535); ++ BAYER(row,col) = LIM(c,0u,65535u); + } + for (c=0; c < nc; c+=2) + mult[c] += mult[c+1]; +@@ -1451,7 +1465,7 @@ + poly[3] += (ph1.tag_210 - poly[7]) * poly[6] + 1; + for (i=0; i < 0x10000; i++) { + num = (poly[5]*i + poly[3])*i + poly[1]; +- curve[i] = LIM(num,0,65535); ++ curve[i] = CLIPF(num); + } goto apply; /* apply to right half */ + } else if (tag == 0x41a) { /* Polynomial curve */ + for (i=0; i < 4; i++) +@@ -1459,7 +1473,7 @@ + for (i=0; i < 0x10000; i++) { + for (num=0, j=4; j--; ) + num = num * i + poly[j]; +- curve[i] = LIM(num+i,0,65535); ++ curve[i] = CLIPF(num+i); + } apply: /* apply to whole image */ + for (row=0; row < height; row++) + for (col = (tag & 1)*ph1.split_col; col < width; col++) +@@ -1573,10 +1587,10 @@ phase_one_correct(); } @@ -158,7 +214,7 @@ unsigned c; if (nbits == -1) -@@ -1702,7 +1712,7 @@ +@@ -1702,7 +1716,7 @@ } } @@ -167,16 +223,7 @@ void CLASS sinar_4shot_load_raw() { -@@ -1731,7 +1741,7 @@ - if ((r = row-top_margin - (shot >> 1 & 1)) >= height) continue; - for (col=0; col < raw_width; col++) { - if ((c = col-left_margin - (shot & 1)) >= width) continue; -- image[r*width+c][FC(row,col)] = pixel[col]; -+ image[r*width+c][FC(row,col)] = pixel[col]; - } - } - } -@@ -1843,10 +1853,10 @@ +@@ -1843,10 +1857,10 @@ maximum = 0x3ff; } @@ -190,7 +237,7 @@ int byte; if (!nbits) return vbits=0; -@@ -2135,11 +2145,11 @@ +@@ -2135,11 +2149,11 @@ METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) { @@ -204,16 +251,7 @@ cinfo->src->next_input_byte = jpeg_buffer; cinfo->src->bytes_in_buffer = nbytes; return TRUE; -@@ -2215,7 +2225,7 @@ - for (col=0; col < raw_width; col++) { - val = curve[pixel[col]]; - if ((unsigned) (col-left_margin) < width) -- BAYER(row,col-left_margin) = val; -+ BAYER(row,col-left_margin) = val; - else lblack += val; - } - } -@@ -2411,9 +2421,9 @@ +@@ -2411,9 +2425,9 @@ maximum = (1 << (thumb_misc & 31)) - 1; } @@ -225,7 +263,7 @@ if (start) { for (p=0; p < 4; p++) -@@ -2712,7 +2722,7 @@ +@@ -2712,7 +2726,7 @@ void CLASS foveon_decoder (unsigned size, unsigned code) { @@ -234,16 +272,76 @@ struct decode *cur; int i, len; -@@ -3651,7 +3661,7 @@ - lpass = size*((lev & 1)+1); - for (row=0; row < iheight; row++) { - hat_transform (temp, fimg+hpass+row*iwidth, 1, iwidth, 1 << lev); -- for (col=0; col < iwidth; col++) -+ for (col=0; col < iwidth; col++) - fimg[lpass + row*iwidth + col] = temp[col] * 0.25; +@@ -3670,7 +3684,7 @@ + hpass = lpass; } - for (col=0; col < iwidth; col++) { -@@ -4397,7 +4407,7 @@ + for (i=0; i < size; i++) +- image[i][c] = CLIP(SQR(fimg[i]+fimg[lpass+i])/0x10000); ++ image[i][c] = CLIPF(SQR(fimg[i]+fimg[lpass+i])/0x10000); + } + if (filters && colors == 3) { /* pull G1 and G3 closer together */ + for (row=0; row < 2; row++) { +@@ -3696,7 +3710,7 @@ + if (diff < -thold) diff += thold; + else if (diff > thold) diff -= thold; + else diff = 0; +- BAYER(row,col) = CLIP(SQR(avg+diff) + 0.5); ++ BAYER(row,col) = CLIPD(SQR(avg+diff) + 0.5); + } + } + } +@@ -3716,8 +3730,8 @@ + memcpy (pre_mul, user_mul, sizeof pre_mul); + if (use_auto_wb || (use_camera_wb && cam_mul[0] == -1)) { + memset (dsum, 0, sizeof dsum); +- bottom = MIN (greybox[1]+greybox[3], height); +- right = MIN (greybox[0]+greybox[2], width); ++ bottom = MIN (greybox[1]+greybox[3], static_cast(height)); ++ right = MIN (greybox[0]+greybox[2], static_cast(width)); + for (row=greybox[1]; row < bottom; row += 8) + for (col=greybox[0]; col < right; col += 8) { + memset (sum, 0, sizeof sum); +@@ -3921,7 +3935,7 @@ + */ + void CLASS vng_interpolate() + { +- static const signed char *cp, terms[] = { ++ static const signed short int *cp, terms[] = { + -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, + -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, + -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, +@@ -4071,7 +4085,7 @@ + ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; + } + d = dir[i = diff[0] > diff[1]]; +- pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); ++ pix[0][1] = ULIM(guess[i] >> 2, static_cast(pix[d][1]), static_cast(pix[-d][1])); + } + /* Calculate red and blue for each green pixel: */ + for (row=1; row < height-1; row++) +@@ -4144,10 +4158,10 @@ + pix = image + row*width+col; + val = ((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 + - pix[-2][c] - pix[2][c]) >> 2; +- rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); ++ rgb[0][row-top][col-left][1] = ULIM(val,static_cast(pix[-1][1]),static_cast(pix[1][1])); + val = ((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 + - pix[-2*width][c] - pix[2*width][c]) >> 2; +- rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); ++ rgb[1][row-top][col-left][1] = ULIM(val,static_cast(pix[-width][1]),static_cast(pix[width][1])); + } + } + /* Interpolate red and blue, and convert to CIELab: */ +@@ -4278,7 +4292,7 @@ + if (c == colors) continue; + FORCC { + cam[0][c] = image[row*width+col][c]; +- cam[1][c] = MIN(cam[0][c],clip); ++ cam[1][c] = MIN(cam[0][c],static_cast(clip)); + } + for (i=0; i < 2; i++) { + FORCC for (lab[i][c]=j=0; j < colors; j++) +@@ -4397,7 +4411,7 @@ } } @@ -252,7 +350,7 @@ void CLASS parse_makernote (int base, int uptag) { -@@ -4528,12 +4538,12 @@ +@@ -4528,12 +4542,12 @@ cam_mul[0] = getreal(type); cam_mul[2] = getreal(type); } @@ -271,7 +369,16 @@ if (tag == 0x10 && type == 4) unique_id = get4(); if (tag == 0x11 && is_raw && !strncmp(make,"NIKON",5)) { -@@ -4912,8 +4922,8 @@ +@@ -4777,7 +4791,7 @@ + case 6: + FORC(2) gpsdata[18+c] = get4(); break; + case 18: case 29: +- fgets ((char *) (gpsdata+14+tag/3), MIN(len,12), ifp); ++ fgets ((char *) (gpsdata+14+tag/3), MIN(len,12u), ifp); + } + fseek (ifp, save, SEEK_SET); + } +@@ -4912,8 +4926,8 @@ } } @@ -282,7 +389,7 @@ int CLASS parse_tiff_ifd (int base) { -@@ -4927,7 +4937,7 @@ +@@ -4927,7 +4941,7 @@ unsigned sony_curve[] = { 0,0,0,0,0,4095 }; unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; struct jhead jh; @@ -291,7 +398,7 @@ if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) return 1; -@@ -4944,6 +4954,9 @@ +@@ -4944,6 +4958,9 @@ case 6: height = get2(); break; case 7: width += get2(); break; case 9: filters = get2(); break; @@ -301,7 +408,7 @@ case 17: case 18: if (type == 3 && len == 1) cam_mul[(tag-17)*2] = get2() / 256.0; -@@ -5347,12 +5360,13 @@ +@@ -5347,12 +5364,13 @@ fread (buf, sony_length, 1, ifp); sony_decrypt (buf, sony_length/4, 1, sony_key); sfp = ifp; @@ -320,7 +427,7 @@ ifp = sfp; free (buf); } -@@ -5377,6 +5391,8 @@ +@@ -5377,6 +5395,8 @@ { int doff; @@ -329,7 +436,7 @@ fseek (ifp, base, SEEK_SET); order = get2(); if (order != 0x4949 && order != 0x4d4d) return 0; -@@ -5551,7 +5567,7 @@ +@@ -5551,7 +5571,7 @@ { const char *file, *ext; char *jname, *jfile, *jext; @@ -338,14 +445,7 @@ ext = strrchr (ifname, '.'); file = strrchr (ifname, '/'); -@@ -5573,13 +5589,14 @@ - } else - while (isdigit(*--jext)) { - if (*jext != '9') { -- (*jext)++; -+ (*jext)++; - break; - } +@@ -5579,7 +5599,8 @@ *jext = '0'; } if (strcmp (jname, ifname)) { @@ -355,20 +455,30 @@ if (verbose) fprintf (stderr,_("Reading metadata from %s ...\n"), jname); parse_tiff (12); -@@ -5918,7 +5935,11 @@ +@@ -5918,7 +5939,11 @@ order = get2(); hlen = get4(); if (get4() == 0x48454150) /* "HEAP" */ -- parse_ciff (save+hlen, len-hlen); +/*RT*/ { +/*RT*/ ciff_base = save+hlen; +/*RT*/ ciff_len = len-hlen; -+ parse_ciff (save+hlen, len-hlen); + parse_ciff (save+hlen, len-hlen); +/*RT*/ } if (parse_tiff (save+6)) apply_tiff(); fseek (ifp, save+len, SEEK_SET); } -@@ -6181,36 +6202,36 @@ +@@ -6165,7 +6190,9 @@ + { + static const struct { + const char *prefix; +- short black, maximum, trans[12]; ++ short black; ++ int maximum; ++ short trans[12]; + } table[] = { + { "AGFAPHOTO DC-833m", 0, 0, /* DJC */ + { 11438,-3762,-1115,-2409,9914,2497,-1227,2295,5300 } }, +@@ -6181,36 +6208,36 @@ { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } }, { "Canon EOS 5D Mark II", 0, 0x3cf0, { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } }, @@ -419,7 +529,7 @@ { "Canon EOS 600D", 0, 0x3510, { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } }, { "Canon EOS 1000D", 0, 0xe43, -@@ -6223,8 +6244,8 @@ +@@ -6223,8 +6250,8 @@ { 6517,-602,-867,-8180,15926,2378,-1618,1771,7633 } }, { "Canon EOS-1D Mark IV", 0, 0x3bb0, { 6014,-220,-795,-4109,12014,2361,-561,1824,5787 } }, @@ -430,7 +540,7 @@ { "Canon EOS-1D Mark II N", 0, 0xe80, { 6240,-466,-822,-8180,15825,2500,-1801,1938,8042 } }, { "Canon EOS-1D Mark II", 0, 0xe80, -@@ -6241,12 +6262,12 @@ +@@ -6241,12 +6268,12 @@ { -5300,9846,1776,3436,684,3939,-5540,9879,6200,-1404,11175,217 } }, { "Canon PowerShot A5", 0, 0, { -4801,9475,1952,2926,1611,4094,-5259,10164,5947,-1554,10883,547 } }, @@ -447,16 +557,7 @@ { "Canon PowerShot G1", 0, 0, { -4778,9467,2172,4743,-1141,4344,-5146,9908,6077,-1566,11051,557 } }, { "Canon PowerShot G2", 0, 0, -@@ -6302,7 +6323,7 @@ - { "Canon PowerShot SX1 IS", 0, 0, - { 6578,-259,-502,-5974,13030,3309,-308,1058,4970 } }, - { "Canon PowerShot SX110 IS", 0, 0, /* DJC */ -- { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, -+ { 14134,-5576,-1527,-1991,10719,1273,-1158,1929,3581 } }, - { "CASIO EX-S20", 0, 0, /* DJC */ - { 11634,-3924,-1128,-4968,12954,2015,-1588,2648,7206 } }, - { "CASIO EX-Z750", 0, 0, /* DJC */ -@@ -6373,8 +6394,8 @@ +@@ -6373,8 +6400,8 @@ { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, { "FUJIFILM FinePix F600EXR", 0, 0, { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } }, @@ -467,7 +568,7 @@ { "FUJIFILM X10", 0, 0, { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } }, { "Imacon Ixpress", 0, 0, /* DJC */ -@@ -6475,22 +6496,22 @@ +@@ -6475,22 +6502,22 @@ { 7702,-2245,-975,-9114,17242,1875,-2679,3055,8521 } }, { "NIKON D1", 0, 0, /* multiplied by 2.218750, 1.0, 1.148438 */ { 16772,-4726,-2141,-7611,15713,1972,-2846,3494,9521 } }, @@ -498,7 +599,7 @@ { "NIKON D3", 0, 0, { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } }, { "NIKON D40X", 0, 0, -@@ -6505,10 +6526,10 @@ +@@ -6505,10 +6532,10 @@ { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, { "NIKON D60", 0, 0, { 8736,-2458,-935,-9075,16894,2251,-1354,1242,8263 } }, @@ -513,7 +614,7 @@ { "NIKON D70", 0, 0, { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } }, { "NIKON D80", 0, 0, -@@ -6569,8 +6590,8 @@ +@@ -6569,8 +6596,8 @@ { 7828,-1761,-348,-5788,14071,1830,-2853,4518,6557 } }, { "OLYMPUS E-330", 0, 0, { 8961,-2473,-1084,-7979,15990,2067,-2319,3035,8249 } }, @@ -524,7 +625,7 @@ { "OLYMPUS E-3", 0, 0xf99, { 9487,-2875,-1115,-7533,15606,2010,-1618,2100,7389 } }, { "OLYMPUS E-400", 0, 0, -@@ -6587,26 +6608,26 @@ +@@ -6587,26 +6614,26 @@ { 8785,-2529,-1033,-7639,15624,2112,-1783,2300,7817 } }, { "OLYMPUS E-520", 0, 0xfd2, { 8344,-2322,-1020,-7596,15635,2048,-1748,2269,7287 } }, @@ -567,7 +668,7 @@ { "OLYMPUS E-PM1", 0, 0, { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } }, { "OLYMPUS SP350", 0, 0, -@@ -6623,8 +6644,8 @@ +@@ -6623,8 +6650,8 @@ { 10915,-3677,-982,-5587,12986,2911,-1168,1968,6223 } }, { "OLYMPUS SP570UZ", 0, 0, { 11522,-4044,-1146,-4736,12172,2904,-988,1829,6039 } }, @@ -578,7 +679,7 @@ { "PENTAX *ist DL2", 0, 0, { 10504,-2438,-1189,-8603,16207,2531,-1022,863,12242 } }, { "PENTAX *ist DL", 0, 0, -@@ -6641,8 +6662,8 @@ +@@ -6641,8 +6668,8 @@ { 11095,-3157,-1324,-8377,15834,2720,-1108,947,11688 } }, { "PENTAX K20D", 0, 0, { 9427,-2714,-868,-7493,16092,1373,-2199,3264,7180 } }, @@ -589,7 +690,7 @@ { "PENTAX K2000", 0, 0, { 11057,-3604,-1155,-5152,13046,2329,-282,375,8104 } }, { "PENTAX K-m", 0, 0, -@@ -6699,34 +6720,36 @@ +@@ -6699,34 +6726,36 @@ { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, { "LEICA D-LUX 5", 143, 0, { 10909,-4295,-948,-1333,9306,2399,22,1738,4582 } }, @@ -646,7 +747,7 @@ { "Panasonic DMC-GX1", 143, 0, { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } }, { "Phase One H 20", 0, 0, /* DJC */ -@@ -6787,26 +6810,22 @@ +@@ -6787,26 +6816,22 @@ { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, { "SONY DSLR-A5", 128, 0xfeb, { 4950,-580,-103,-5228,12542,3029,-709,1435,7371 } }, @@ -685,7 +786,7 @@ { "SONY SLT-A33", 128, 0, { 6069,-1221,-366,-5221,12779,2734,-1024,2066,6834 } }, { "SONY SLT-A35", 128, 0, -@@ -6815,8 +6834,8 @@ +@@ -6815,8 +6840,8 @@ { 5932,-1492,-411,-4813,12285,2856,-741,1524,6739 } }, { "SONY SLT-A65", 128, 0, { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } }, @@ -696,7 +797,7 @@ }; double cam_xyz[4][3]; char name[130]; -@@ -7060,6 +7079,12 @@ +@@ -7060,6 +7085,12 @@ fread (head, 1, 32, ifp); fseek (ifp, 0, SEEK_END); flen = fsize = ftell(ifp); @@ -709,7 +810,7 @@ if ((cp = (char *) memmem (head, 32, "MMMM", 4)) || (cp = (char *) memmem (head, 32, "IIII", 4))) { parse_phase_one (cp-head); -@@ -7067,6 +7092,8 @@ +@@ -7067,6 +7098,8 @@ } else if (order == 0x4949 || order == 0x4d4d) { if (!memcmp (head+6,"HEAPCCDR",8)) { data_offset = hlen; @@ -718,7 +819,7 @@ parse_ciff (hlen, flen - hlen); } else if (parse_tiff(0)) apply_tiff(); } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && -@@ -7110,6 +7137,7 @@ +@@ -7110,6 +7143,7 @@ fseek (ifp, 100+28*(shot_select > 0), SEEK_SET); parse_tiff (data_offset = get4()); parse_tiff (thumb_offset+12); @@ -726,7 +827,7 @@ apply_tiff(); } else if (!memcmp (head,"RIFF",4)) { fseek (ifp, 0, SEEK_SET); -@@ -7155,8 +7183,7 @@ +@@ -7155,8 +7189,7 @@ parse_redcine(); load_raw = &CLASS redcine_load_raw; gamma_curve (1/2.4, 12.92, 1, 4095); @@ -736,7 +837,7 @@ parse_rollei(); else if (!memcmp (head,"PWAD",4)) parse_sinar_ia(); -@@ -7211,7 +7238,7 @@ +@@ -7211,7 +7244,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"))) @@ -745,16 +846,16 @@ if (width >= 4960 && !strcmp(model,"K-5")) { left_margin = 10; width = 4950; filters = 0x16161616; } if (width == 4736 && !strcmp(model,"K-7")) -@@ -8553,7 +8580,7 @@ - for (j=0; j < 3; j++) { - for (num = k=0; k < 3; k++) - num += xyzd50_srgb[i][k] * inverse[j][k]; -- oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; -+ oprof[pbody[j*3+23]/4+i+2] = num * 0x10000 + 0.5; - } - for (i=0; i < phead[0]/4; i++) - oprof[i] = htonl(oprof[i]); -@@ -8852,13 +8879,13 @@ +@@ -8779,7 +8812,7 @@ + strncpy (th->desc, desc, 512); + strncpy (th->make, make, 64); + strncpy (th->model, model, 64); +- strcpy (th->soft, "dcraw v"DCRAW_VERSION); ++ sprintf (th->soft, "dcraw v%s", DCRAW_VERSION); + t = localtime (×tamp); + sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", + t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); +@@ -8852,13 +8885,13 @@ FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) @@ -770,7 +871,7 @@ { int arg, status=0; int timestamp_only=0, thumbnail_only=0, identify_only=0; -@@ -8971,7 +8998,7 @@ +@@ -8971,7 +9004,7 @@ case 'i': identify_only = 1; break; case 'c': write_to_stdout = 1; break; case 'v': verbose = 1; break; @@ -779,8 +880,11 @@ case 'f': four_color_rgb = 1; break; case 'A': FORC4 greybox[c] = atoi(argv[arg++]); case 'a': use_auto_wb = 1; break; -@@ -9234,3 +9261,4 @@ +@@ -9234,3 +9267,7 @@ } return status; } +*/ ++/*RT*/#undef MAX ++/*RT*/#undef MIN ++/*RT*/#undef ABS diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 29b541eb5..c45954693 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -121,7 +121,7 @@ void Crop::update (int todo) { double shradius = params.sh.radius; if (!params.sh.hq) shradius *= radius / 1800.0; cshmap->update (baseCrop, shradius, parent->ipf.lumimul, params.sh.hq, skip); - cshmap->forceStat (parent->shmap->max, parent->shmap->min, parent->shmap->avg); + cshmap->forceStat (parent->shmap->max_f, parent->shmap->min_f, parent->shmap->avg); } // shadows & highlights & tone curve & convert to cielab diff --git a/rtengine/demosaic_algos.cc b/rtengine/demosaic_algos.cc index 9218acd6c..5004293cd 100644 --- a/rtengine/demosaic_algos.cc +++ b/rtengine/demosaic_algos.cc @@ -16,11 +16,13 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include +#include + #include "rawimagesource.h" #include "rawimagesource_i.h" #include "median.h" #include "rawimage.h" -#include #include "mytime.h" #include "iccmatrices.h" #include "iccstore.h" @@ -28,23 +30,21 @@ #include "curves.h" #include "dfmanager.h" #include "slicer.h" -#include +#include "rt_math.h" #ifdef _OPENMP #include #endif +using namespace std; + namespace rtengine { #undef ABS -#undef MAX -#undef MIN #undef DIST #define ABS(a) ((a)<0?-(a):(a)) -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) #define DIST(a,b) (ABS(a-b)) -#define CLIREF(x) LIM(x,-200000.0,200000.0) // avoid overflow : do not act directly on image[] or pix[] +#define CLIREF(x) LIM(x,-200000.0f,200000.0f) // avoid overflow : do not act directly on image[] or pix[] #define PIX_SORT(a,b) { if ((a)>(b)) {temp=(a);(a)=(b);(b)=temp;} } extern const Settings* settings; @@ -211,9 +211,9 @@ void RawImageSource::eahd_demosaic () { } } // compute eL & eC - int eL = MIN(MAX(dLmaph[3],dLmaph[5]),MAX(dLmapv[1],dLmapv[7])); - int eCa = MIN(MAX(dCamaph[3],dCamaph[5]),MAX(dCamapv[1],dCamapv[7])); - int eCb = MIN(MAX(dCbmaph[3],dCbmaph[5]),MAX(dCbmapv[1],dCbmapv[7])); + int eL = min(max(dLmaph[3],dLmaph[5]),max(dLmapv[1],dLmapv[7])); + int eCa = min(max(dCamaph[3],dCamaph[5]),max(dCamapv[1],dCamapv[7])); + int eCb = min(max(dCbmaph[3],dCbmaph[5]),max(dCbmapv[1],dCbmapv[7])); int wh = 0; for (int dmi=0; dmi<9; dmi++) @@ -311,13 +311,13 @@ void RawImageSource::eahd_demosaic () { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void RawImageSource::hphd_vertical (float** hpmap, int col_from, int col_to) { - float* temp = new float[MAX(W,H)]; - float* avg = new float[MAX(W,H)]; - float* dev = new float[MAX(W,H)]; + float* temp = new float[max(W,H)]; + float* avg = new float[max(W,H)]; + float* dev = new float[max(W,H)]; - memset (temp, 0, MAX(W,H)*sizeof(float)); - memset (avg, 0, MAX(W,H)*sizeof(float)); - memset (dev, 0, MAX(W,H)*sizeof(float)); + memset (temp, 0, max(W,H)*sizeof(float)); + memset (avg, 0, max(W,H)*sizeof(float)); + memset (dev, 0, max(W,H)*sizeof(float)); for (int k=col_from; kprefilters >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) typedef unsigned short ushort; void RawImageSource::vng4_demosaic () { - static const signed char *cp, terms[] = { + static const signed short int *cp, terms[] = { -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, @@ -749,7 +749,7 @@ void RawImageSource::vng4_demosaic () { #undef fc #define fc(row,col) \ (ri->get_filters() >> ((((row) << 1 & 14) + ((col) & 1)) << 1) & 3) -#define LIM(x,min,max) MAX(min,MIN(x,max)) +#define LIM(x,MIN,MAX) max(MIN,min(x,MAX)) #define ULIM(x,y,z) ((y) < (z) ? LIM(x,y,z) : LIM(x,z,y)) /* @@ -790,7 +790,7 @@ void RawImageSource::ppg_demosaic() ABS(pix[-3*d][1] - pix[-d][1]) ) * 2; } d = dir[i = diff[0] > diff[1]]; - pix[0][1] = ULIM(guess[i] >> 2, pix[d][1], pix[-d][1]); + pix[0][1] = ULIM(static_cast(guess[i] >> 2), pix[d][1], pix[-d][1]); } if(plistener) plistener->setProgress(0.33*row/(height-3)); } @@ -876,7 +876,6 @@ void RawImageSource::border_interpolate(int border, float (*image)[4], int start #define TS 256 /* Tile Size */ #define FORC(cnt) for (c=0; c < cnt; c++) #define FORC3 FORC(3) -#define SQR(x) ((x)*(x)) void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh) { @@ -884,12 +883,13 @@ void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh) float (*pix)[4], (*rix)[3]; static const int dir[4] = { -1, 1, -TS, TS }; float ldiff[2][4], abdiff[2][4], leps, abeps; - float r, xyz[3], xyz_cam[3][4]; + float xyz[3], xyz_cam[3][4]; float (*cbrt); float (*rgb)[TS][TS][3]; float (*lab)[TS][TS][3]; float (*lix)[3]; char (*homo)[TS][TS], *buffer; + double r; int width=W, height=H; float (*image)[4]; @@ -916,7 +916,7 @@ void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh) cbrt = (float (*)) calloc (0x10000, sizeof *cbrt); for (i=0; i < 0x10000; i++) { r = (double)i / 65535.0; - cbrt[i] = r > 0.008856 ? pow(r,1/3.0) : 7.787*r + 16/116.0; + cbrt[i] = r > 0.008856 ? pow(r,0.333333333) : 7.787*r + 16/116.0; } for (i=0; i < 3; i++) @@ -944,10 +944,10 @@ void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh) pix = image + (row*width+col); val = 0.25*((pix[-1][1] + pix[0][c] + pix[1][1]) * 2 - pix[-2][c] - pix[2][c]) ; - rgb[0][row-top][col-left][1] = ULIM(val,pix[-1][1],pix[1][1]); + rgb[0][row-top][col-left][1] = ULIM(static_cast(val),pix[-1][1],pix[1][1]); val = 0.25*((pix[-width][1] + pix[0][c] + pix[width][1]) * 2 - pix[-2*width][c] - pix[2*width][c]) ; - rgb[1][row-top][col-left][1] = ULIM(val,pix[-width][1],pix[width][1]); + rgb[1][row-top][col-left][1] = ULIM(static_cast(val),pix[-width][1],pix[width][1]); } } @@ -1007,10 +1007,10 @@ void RawImageSource::ahd_demosaic(int winx, int winy, int winw, int winh) + SQR(lix[0][2]-lix[dir[i]][2]); } } - leps = MIN(MAX(ldiff[0][0],ldiff[0][1]), - MAX(ldiff[1][2],ldiff[1][3])); - abeps = MIN(MAX(abdiff[0][0],abdiff[0][1]), - MAX(abdiff[1][2],abdiff[1][3])); + leps = min(max(ldiff[0][0],ldiff[0][1]), + max(ldiff[1][2],ldiff[1][3])); + abeps = min(max(abdiff[0][0],abdiff[0][1]), + max(abdiff[1][2],abdiff[1][3])); for (d=0; d < 2; d++) for (i=0; i < 4; i++) if (ldiff[d][i] <= leps && abdiff[d][i] <= abeps) @@ -1366,20 +1366,20 @@ void RawImageSource::dcb_hid(float (*image)[4],float (*bufferH)[3], float (*buff // Decide green pixels for (int row = rowMin; row < rowMax; row++) for (int col = colMin+(FC(y0-TILEBORDER+row,x0-TILEBORDER+colMin)&1),indx=row*CACHESIZE+col,c=FC(y0-TILEBORDER+row,x0-TILEBORDER+col),d=2-c; col < colMax; col+=2, indx+=2) { - float current = MAX(image[indx+v][c], MAX(image[indx-v][c], MAX(image[indx-2][c], image[indx+2][c]))) - - MIN(image[indx+v][c], MIN(image[indx-v][c], MIN(image[indx-2][c], image[indx+2][c]))) + - MAX(image[indx+1+u][d], MAX(image[indx+1-u][d], MAX(image[indx-1+u][d], image[indx-1-u][d]))) - - MIN(image[indx+1+u][d], MIN(image[indx+1-u][d], MIN(image[indx-1+u][d], image[indx-1-u][d]))); + float current = max(image[indx+v][c], image[indx-v][c], image[indx-2][c], image[indx+2][c]) - + min(image[indx+v][c], image[indx-v][c], image[indx-2][c], image[indx+2][c]) + + max(image[indx+1+u][d], image[indx+1-u][d], image[indx-1+u][d], image[indx-1-u][d]) - + min(image[indx+1+u][d], image[indx+1-u][d], image[indx-1+u][d], image[indx-1-u][d]); - float currentH = MAX(bufferH[indx+v][d], MAX(bufferH[indx-v][d], MAX(bufferH[indx-2][d], bufferH[indx+2][d]))) - - MIN(bufferH[indx+v][d], MIN(bufferH[indx-v][d], MIN(bufferH[indx-2][d], bufferH[indx+2][d]))) + - MAX(bufferH[indx+1+u][c], MAX(bufferH[indx+1-u][c], MAX(bufferH[indx-1+u][c], bufferH[indx-1-u][c]))) - - MIN(bufferH[indx+1+u][c], MIN(bufferH[indx+1-u][c], MIN(bufferH[indx-1+u][c], bufferH[indx-1-u][c]))); + float currentH = max(bufferH[indx+v][d], bufferH[indx-v][d], bufferH[indx-2][d], bufferH[indx+2][d]) - + min(bufferH[indx+v][d], bufferH[indx-v][d], bufferH[indx-2][d], bufferH[indx+2][d]) + + max(bufferH[indx+1+u][c], bufferH[indx+1-u][c], bufferH[indx-1+u][c], bufferH[indx-1-u][c]) - + min(bufferH[indx+1+u][c], bufferH[indx+1-u][c], bufferH[indx-1+u][c], bufferH[indx-1-u][c]); - float currentV = MAX(bufferV[indx+v][d], MAX(bufferV[indx-v][d], MAX(bufferV[indx-2][d], bufferV[indx+2][d]))) - - MIN(bufferV[indx+v][d], MIN(bufferV[indx-v][d], MIN(bufferV[indx-2][d], bufferV[indx+2][d]))) + - MAX(bufferV[indx+1+u][c], MAX(bufferV[indx+1-u][c], MAX(bufferV[indx-1+u][c], bufferV[indx-1-u][c]))) - - MIN(bufferV[indx+1+u][c], MIN(bufferV[indx+1-u][c], MIN(bufferV[indx-1+u][c], bufferV[indx-1-u][c]))); + float currentV = max(bufferV[indx+v][d], bufferV[indx-v][d], bufferV[indx-2][d], bufferV[indx+2][d]) - + min(bufferV[indx+v][d], bufferV[indx-v][d], bufferV[indx-2][d], bufferV[indx+2][d]) + + max(bufferV[indx+1+u][c], bufferV[indx+1-u][c], bufferV[indx-1+u][c], bufferV[indx-1-u][c]) - + min(bufferV[indx+1+u][c], bufferV[indx+1-u][c], bufferV[indx-1+u][c], bufferV[indx-1-u][c]); assert(indx>=0 && indx=0 && indx ( pix[-4] + pix[+4] + pix[-u] + pix[+u])/4 ) - image[indx][3] = ((MIN( pix[-4], pix[+4]) + pix[-4] + pix[+4] ) < (MIN( pix[-u], pix[+u]) + pix[-u] + pix[+u])); + image[indx][3] = ((min(pix[-4], pix[+4]) + pix[-4] + pix[+4] ) < (min(pix[-u], pix[+u]) + pix[-u] + pix[+u])); else - image[indx][3] = ((MAX( pix[-4], pix[+4]) + pix[-4] + pix[+4] ) > (MAX( pix[-u], pix[+u]) + pix[-u] + pix[+u])); + image[indx][3] = ((max(pix[-4], pix[+4]) + pix[-4] + pix[+4] ) > (max(pix[-u], pix[+u]) + pix[-u] + pix[+u])); } } } @@ -1572,7 +1572,7 @@ void RawImageSource::dcb_refinement(float (*image)[4], int x0, int y0) f[3] = 2.f * image[indx+u][1]/(2 + image[indx+v][c] + image[indx][c]); f[4] = (float)(image[indx+u][1] + image[indx+w][1])/(2.f + 2.f * image[indx+v][c]); - g1 = (f[0] + f[1] + f[2] + f[3] + f[4] - MAX(f[1], MAX(f[2], MAX(f[3], f[4]))) - MIN(f[1], MIN(f[2], MIN(f[3], f[4])))) / 3.f; + g1 = (f[0] + f[1] + f[2] + f[3] + f[4] - max(f[1], f[2], f[3], f[4]) - min(f[1], f[2], f[3], f[4])) / 3.f; f[0] = (float)(image[indx-1][1] + image[indx+1][1])/(2.f + 2.f * image[indx][c]); f[1] = 2.f * image[indx-1][1]/(2 + image[indx-2][c] + image[indx][c]); @@ -1580,16 +1580,16 @@ void RawImageSource::dcb_refinement(float (*image)[4], int x0, int y0) f[3] = 2.f * image[indx+1][1]/(2 + image[indx+2][c] + image[indx][c]); f[4] = (float)(image[indx+1][1] + image[indx+3][1])/(2.f + 2.f * image[indx+2][c]); - g2 = (f[0] + f[1] + f[2] + f[3] + f[4] - MAX(f[1], MAX(f[2], MAX(f[3], f[4]))) - MIN(f[1], MIN(f[2], MIN(f[3], f[4])))) / 3.f; + g2 = (f[0] + f[1] + f[2] + f[3] + f[4] - max(f[1], f[2], f[3], f[4]) - min(f[1], f[2], f[3], f[4])) / 3.f; assert(indx>=0 && indx #include #include "curves.h" #include "labimage.h" #include "improcfun.h" #include "array2D.h" +#include "rt_math.h" #ifdef _OPENMP #include #endif -#define SQR(x) ((x)*(x)) #define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b)) #define CLIPC(a) ((a)>-32000?((a)<32000?(a):32000):-32000) #define CLIP(a) (CLIPTO(a,0,65535)) @@ -103,7 +102,7 @@ namespace rtengine { void ImProcFunctions :: dirpyrLab_denoise(LabImage * src, LabImage * dst, const procparams::DirPyrDenoiseParams & dnparams ) { float gam = dnparams.gamma/3.0; - //float gam = 2.0;//MIN(3.0, 0.1*fabs(c[4])/3.0+0.001); + //float gam = 2.0;//min(3.0, 0.1*fabs(c[4])/3.0+0.001); float gamthresh = 0.03; float gamslope = exp(log((double)gamthresh)/gam)/gamthresh; @@ -300,7 +299,7 @@ namespace rtengine { int height = data_fine->H; //generate domain kernel - int halfwin = 3;//MIN(ceil(2*sig),3); + int halfwin = 3;//min(ceil(2*sig),3); int scalewin = halfwin*scale; #ifdef _OPENMP @@ -455,8 +454,8 @@ namespace rtengine { float nrfctrave=0; norm_l = 0;//if we do want to include the input pixel in the sum - for(int inbr=MAX(0,i-1); inbr<=MIN(height-1,i+1); inbr++) { - for (int jnbr=MAX(0,j-1); jnbr<=MIN(width-1,j+1); jnbr++) { + for(int inbr=max(0,i-1); inbr<=min(height-1,i+1); inbr++) { + for (int jnbr=max(0,j-1); jnbr<=min(width-1,j+1); jnbr++) { dirwt_l = DIRWT_L(inbr, jnbr, i, j); nrfctrave += dirwt_l*nrfactorL[inbr][jnbr]; norm_l += dirwt_l; @@ -534,8 +533,8 @@ namespace rtengine { //do midpoint first double norm=0.0,wtdsum[3]={0.0,0.0,0.0}; //wtdsum[0]=wtdsum[1]=wtdsum[2]=0.0; - for(int ix=i; ixL[ix][jx]; wtdsum[1] += smooth->a[ix][jx]; wtdsum[2] += smooth->b[ix][jx]; @@ -556,13 +555,13 @@ namespace rtengine { if (j+1==width) continue; double norm=0.0,wtdsum[3]={0.0,0.0,0.0}; - for (int jx=j; jxL[i][jx]; wtdsum[1] += smooth->a[i][jx]; wtdsum[2] += smooth->b[i][jx]; norm++; } - for (int ix=MAX(0,i-1); ixL[ix][j+1]; wtdsum[1] += smooth->a[ix][j+1]; wtdsum[2] += smooth->b[ix][j+1]; @@ -576,13 +575,13 @@ namespace rtengine { //now down neighbor if (i+1==height) continue; norm=0.0;wtdsum[0]=wtdsum[1]=wtdsum[2]=0.0; - for (int ix=i; ixL[ix][j]; wtdsum[1] += smooth->a[ix][j]; wtdsum[2] += smooth->b[ix][j]; norm++; } - for (int jx=MAX(0,j-1); jxL[i+1][jx]; wtdsum[1] += smooth->a[i+1][jx]; wtdsum[2] += smooth->b[i+1][jx]; diff --git a/rtengine/dirpyrLab_equalizer.cc b/rtengine/dirpyrLab_equalizer.cc index 8462f5d7b..76b5183bc 100644 --- a/rtengine/dirpyrLab_equalizer.cc +++ b/rtengine/dirpyrLab_equalizer.cc @@ -18,19 +18,18 @@ * */ -//#include "rtengine.h" #include #include #include "curves.h" #include "labimage.h" #include "improcfun.h" #include "rawimagesource.h" +#include "rt_math.h" #ifdef _OPENMP #include #endif -#define SQR(x) ((x)*(x)) #define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b)) #define CLIPC(a) ((a)>-32000?((a)<32000?(a):32000):-32000) #define CLIP(a) (CLIPTO(a,0,65535)) @@ -248,7 +247,7 @@ namespace rtengine { //generate domain kernel - int halfwin = 1;//MIN(ceil(2*sig),3); + int halfwin = 1;//min(ceil(2*sig),3); int scalewin = halfwin*scale; @@ -265,8 +264,8 @@ namespace rtengine { aout = 0; bout = 0; - for(int inbr=MAX(0,i-scalewin); inbr<=MIN(height-1,i+scalewin); inbr+=scale) { - for (int jnbr=MAX(0,j-scalewin); jnbr<=MIN(width-1,j+scalewin); jnbr+=scale) { + for(int inbr=max(0,i-scalewin); inbr<=min(height-1,i+scalewin); inbr+=scale) { + for (int jnbr=max(0,j-scalewin); jnbr<=min(width-1,j+scalewin); jnbr+=scale) { float dirwt = DIRWT(inbr, jnbr, i, j); Lout += dirwt*data_fine->L[inbr][jnbr]; aout += dirwt*data_fine->a[inbr][jnbr]; @@ -372,8 +371,8 @@ namespace rtengine { //do midpoint first norm=dirwt=0; wtdsum[0]=wtdsum[1]=wtdsum[2]=wtdsum[3]=wtdsum[4]=wtdsum[5]=0.0; - for(i1=i; i1L[i1][j1]; wtdsum[1] += dirwt*smooth->a[i1][j1]; @@ -400,7 +399,7 @@ namespace rtengine { if (j+1==width) continue; norm=dirwt=0; wtdsum[0]=wtdsum[1]=wtdsum[2]=wtdsum[3]=wtdsum[4]=wtdsum[5]=0.0; - for (j1=j; j1L[i][j1]; wtdsum[1] += dirwt*smooth->a[i][j1]; @@ -410,7 +409,7 @@ namespace rtengine { wtdsum[5] += dirwt*buffer[2][i*scale][j1*scale]; norm+=dirwt; } - for (i1=MAX(0,i-1); i1L[i1][j+1]; wtdsum[1] += dirwt*smooth->a[i1][j+1]; @@ -432,7 +431,7 @@ namespace rtengine { if (i+1==height) continue; norm=0; wtdsum[0]=wtdsum[1]=wtdsum[2]=wtdsum[3]=wtdsum[4]=wtdsum[5]=0.0; - for (i1=i; i1L[i1][j]; wtdsum[1] += dirwt*smooth->a[i1][j]; @@ -442,7 +441,7 @@ namespace rtengine { wtdsum[5] += dirwt*buffer[2][i1*scale][j*scale]; norm+=dirwt; } - for (j1=MAX(0,j-1); j1L[i+1][j1]; wtdsum[1] += dirwt*smooth->a[i+1][j1]; diff --git a/rtengine/dirpyr_equalizer.cc b/rtengine/dirpyr_equalizer.cc index 684cefdcf..2880dc822 100644 --- a/rtengine/dirpyr_equalizer.cc +++ b/rtengine/dirpyr_equalizer.cc @@ -31,7 +31,7 @@ #include #endif -#define SQR(x) ((x)*(x)) +#include "rt_math.h" #define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b)) #define CLIPC(a) ((a)>-32000?((a)<32000?(a):32000):-32000) #define CLIP(a) (CLIPTO(a,0,65535)) @@ -182,8 +182,8 @@ namespace rtengine { float val=0; float norm=0; - for(int inbr=MAX(0,i-scalewin); inbr<=MIN(height-1,i+scalewin); inbr+=scale) { - for (int jnbr=MAX(0,j-scalewin); jnbr<=MIN(width-1,j+scalewin); jnbr+=scale) { + for(int inbr=max(0,i-scalewin); inbr<=min(height-1,i+scalewin); inbr+=scale) { + for (int jnbr=max(0,j-scalewin); jnbr<=min(width-1,j+scalewin); jnbr+=scale) { float dirwt = DIRWT(inbr, jnbr, i, j); val += dirwt*data_fine[inbr][jnbr]; norm += dirwt; @@ -202,7 +202,7 @@ namespace rtengine { void ImProcFunctions::idirpyr_eq_channel(float ** data_coarse, float ** data_fine, float ** buffer, int width, int height, int level, const double * mult ) { - float noisehi = 1.33*noise*mult[4]/pow(3,level), noiselo = 0.66*noise*mult[4]/pow(3,level); + float noisehi = 1.33*noise*mult[4]/expf(level*log(3.0)), noiselo = 0.66*noise*mult[4]/expf(level*log(3.0)); LUTf irangefn (0x20000); for (int i=0; i<0x20000; i++) { diff --git a/rtengine/fast_demo.cc b/rtengine/fast_demo.cc index 2557f7dc5..ee6031863 100644 --- a/rtengine/fast_demo.cc +++ b/rtengine/fast_demo.cc @@ -22,7 +22,10 @@ // //////////////////////////////////////////////////////////////// - +#include +#include "rawimagesource.h" +using namespace std; +using namespace rtengine; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -198,10 +201,10 @@ void RawImageSource::fast_demosaic(int winx, int winy, int winw, int winh) { } else { //compute directional weights using image gradients - wtu=invGrad[(abs(rawData[i+1][j]-rawData[i-1][j])+abs(rawData[i][j]-rawData[i-2][j])+abs(rawData[i-1][j]-rawData[i-3][j])) >>2]; - wtd=invGrad[(abs(rawData[i-1][j]-rawData[i+1][j])+abs(rawData[i][j]-rawData[i+2][j])+abs(rawData[i+1][j]-rawData[i+3][j])) >>2]; - wtl=invGrad[(abs(rawData[i][j+1]-rawData[i][j-1])+abs(rawData[i][j]-rawData[i][j-2])+abs(rawData[i][j-1]-rawData[i][j-3])) >>2]; - wtr=invGrad[(abs(rawData[i][j-1]-rawData[i][j+1])+abs(rawData[i][j]-rawData[i][j+2])+abs(rawData[i][j+1]-rawData[i][j+3])) >>2]; + wtu=invGrad[(abs(rawData[i+1][j]-rawData[i-1][j])+abs(rawData[i][j]-rawData[i-2][j])+abs(rawData[i-1][j]-rawData[i-3][j])) /4]; + wtd=invGrad[(abs(rawData[i-1][j]-rawData[i+1][j])+abs(rawData[i][j]-rawData[i+2][j])+abs(rawData[i+1][j]-rawData[i+3][j])) /4]; + wtl=invGrad[(abs(rawData[i][j+1]-rawData[i][j-1])+abs(rawData[i][j]-rawData[i][j-2])+abs(rawData[i][j-1]-rawData[i][j-3])) /4]; + wtr=invGrad[(abs(rawData[i][j-1]-rawData[i][j+1])+abs(rawData[i][j]-rawData[i][j+2])+abs(rawData[i][j+1]-rawData[i][j+3])) /4]; //store in rgb array the interpolated G value at R/B grid points using directional weighted average green[i][j]=(wtu*rawData[i-1][j]+wtd*rawData[i+1][j]+wtl*rawData[i][j-1]+wtr*rawData[i][j+1]) / (wtu+wtd+wtl+wtr); @@ -226,10 +229,10 @@ void RawImageSource::fast_demosaic(int winx, int winy, int winw, int winh) { if (c==0) {//R site red[i][j] = rawData[i][j]; blue[i][j] = green[i][j] - 0.25f*((green[i-1][j-1]+green[i-1][j+1]+green[i+1][j+1]+green[i+1][j-1]) - - MIN(clip_pt,rawData[i-1][j-1]+rawData[i-1][j+1]+rawData[i+1][j+1]+rawData[i+1][j-1])); + min(static_cast(clip_pt),rawData[i-1][j-1]+rawData[i-1][j+1]+rawData[i+1][j+1]+rawData[i+1][j-1])); } else {//B site red[i][j] = green[i][j] - 0.25f*((green[i-1][j-1]+green[i-1][j+1]+green[i+1][j+1]+green[i+1][j-1]) - - MIN(clip_pt,rawData[i-1][j-1]+rawData[i-1][j+1]+rawData[i+1][j+1]+rawData[i+1][j-1])); + min(static_cast(clip_pt),rawData[i-1][j-1]+rawData[i-1][j+1]+rawData[i+1][j+1]+rawData[i+1][j-1])); blue[i][j] = rawData[i][j]; } } diff --git a/rtengine/gamutbdy.cc b/rtengine/gamutbdy.cc index c81e8e138..b6e75557d 100644 --- a/rtengine/gamutbdy.cc +++ b/rtengine/gamutbdy.cc @@ -23,7 +23,7 @@ //////////////////////////////////////////////////////////////// //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -#define SQR(x) ((x)*(x)) +#include "rt_math.h" #define D50x 0.96422 #define D50z 0.82521 diff --git a/rtengine/green_equil_RT.cc b/rtengine/green_equil_RT.cc index 742398d04..66ff90ffe 100644 --- a/rtengine/green_equil_RT.cc +++ b/rtengine/green_equil_RT.cc @@ -28,7 +28,7 @@ #include -#define SQR(x) ((x)*(x)) +#include "rt_math.h" //void green_equilibrate()//for dcraw implementation diff --git a/rtengine/hilite_recon.cc b/rtengine/hilite_recon.cc index c794b2983..718abdc75 100644 --- a/rtengine/hilite_recon.cc +++ b/rtengine/hilite_recon.cc @@ -36,10 +36,10 @@ #include #endif -#define SQR(x) ((x)*(x)) +#include "rt_math.h" + + -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) #define FOREACHCOLOR for (int c=0; c < ColorCount; c++) @@ -105,7 +105,7 @@ void RawImageSource::boxblur2(float** src, float** dst, int H, int W, int box ) } -void RawImageSource::boxblur_resamp(float **src, float **dst, float & max, int H, int W, int box, int samp ) +void RawImageSource::boxblur_resamp(float **src, float **dst, float & max_f, int H, int W, int box, int samp ) { array2D temp(W,H,ARRAY2D_CLEAR_DATA); @@ -121,28 +121,28 @@ void RawImageSource::boxblur_resamp(float **src, float **dst, float & max, int H for (int row = 0; row < H; row++) { int len = box + 1; temp[row][0] = src[row][0]/len; - maxtmp = MAX(maxtmp,src[row][0]); + maxtmp = max(maxtmp,src[row][0]); for (int j=1; j<=box; j++) { temp[row][0] += src[row][j]/len; - maxtmp = MAX(maxtmp,src[row][j]); + maxtmp = max(maxtmp,src[row][j]); } for (int col=1; col<=box; col++) { temp[row][col] = (temp[row][col-1]*len + src[row][col+box])/(len+1); - maxtmp = MAX(maxtmp,src[row][col]); + maxtmp = max(maxtmp,src[row][col]); len ++; } for (int col = box+1; col < W-box; col++) { temp[row][col] = temp[row][col-1] + (src[row][col+box] - src[row][col-box-1])/len; - maxtmp = MAX(maxtmp,src[row][col]); + maxtmp = max(maxtmp,src[row][col]); } for (int col=W-box; colget_white(); @@ -280,7 +280,7 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b //if one or more channels is highlight but none are blown, add to highlight accumulator if ((red[i][j]>thresh[0] || green[i][j]>thresh[1] || blue[i][j]>thresh[2]) && - (red[i][j] blendpt) rgb_blend[0]= rfrac*rgb[0]+(1-rfrac)*pixel[0]; if (pixel[1] > blendpt) rgb_blend[1]= gfrac*rgb[1]+(1-gfrac)*pixel[1]; if (pixel[2] > blendpt) rgb_blend[2]= bfrac*rgb[2]+(1-bfrac)*pixel[2]; @@ -548,7 +548,7 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b //end of HLRecovery_blend estimation //%%%%%%%%%%%%%%%%%%%%%%% - //float pixref[3]={MIN(Yclip,hfsize[0][i1][j1]),MIN(Yclip,hfsize[1][i1][j1]),MIN(Yclip,hfsize[2][i1][j1])}; + //float pixref[3]={min(Yclip,hfsize[0][i1][j1]),min(Yclip,hfsize[1][i1][j1]),min(Yclip,hfsize[2][i1][j1])}; //there are clipped highlights //first, determine weighted average of unclipped extensions (weighting is by 'hue' proximity) @@ -575,7 +575,7 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b //counts ++; //now correct clipped channels - if (pixel[0]>max[0] && pixel[1]>max[1] && pixel[2]>max[2]) { + if (pixel[0]>max_f[0] && pixel[1]>max_f[1] && pixel[2]>max_f[2]) { //all channels clipped float Y = (0.299*clipfix[0] + 0.587*clipfix[1] + 0.114*clipfix[2]); //float Y = (clipfix[0] + clipfix[1] + clipfix[2]); @@ -584,18 +584,18 @@ void RawImageSource :: HLRecovery_inpaint (float** red, float** green, float** b green[i][j] = clipfix[1]*factor; blue[i][j] = clipfix[2]*factor; } else {//some channels clipped - int notclipped[3] = {pixel[0]=0 && rec[co][i+x][j+y]!=INT_MAX && rec[c1][i+x][j+y]>=0 && rec[c1][i+x][j+y]!=INT_MAX && rec[c2][i+x][j+y]>0 && rec[c2][i+x][j+y]!=INT_MAX) { double ratt = (double)rec[c1][i+x][j+y] / rec[c2][i+x][j+y]; - if (ratt > rato*1.2 || ratt < rato / 1.2 || rec[co][i+x][j+y] rato*1.2 || ratt < rato / 1.2 || rec[co][i+x][j+y]=0 && rec[co][i+x][j+y]!=INT_MAX && rec[c1][i+x][j+y]>=0 && rec[c1][i+x][j+y]!=INT_MAX && rec[c2][i+x][j+y]>0 && rec[c2][i+x][j+y]!=INT_MAX) { double ratt = (double)rec[c1][i+x][j+y] / rec[c2][i+x][j+y]; - if (ratt > rato*1.05 || ratt < rato / 1.05 || rec[co][i+x][j+y] rato*1.05 || ratt < rato / 1.05 || rec[co][i+x][j+y]=0 && rec[co][i+x][j+y]!=INT_MAX && rec[c1][i+x][j+y]>=0 && rec[c1][i+x][j+y]!=INT_MAX && rec[c2][i+x][j+y]>0 && rec[c2][i+x][j+y]!=INT_MAX) { double ratt = (double)rec[c1][i+x][j+y] / rec[c2][i+x][j+y]; - if (ratt > rato*1.1 || ratt < rato / 1.1 || rec[co][i+x][j+y] rato*1.1 || ratt < rato / 1.1 || rec[co][i+x][j+y]=0 && rec[co][i+x][j+y]!=INT_MAX && rec[c1][i+x][j+y]>0 && rec[c1][i+x][j+y]!=INT_MAX) { - if ((phase==1 && rec[c1][i+x][j+y]=0 && rec[co][i+x][j+y]!=INT_MAX && rec[c2][i+x][j+y]>0 && rec[c2][i+x][j+y]!=INT_MAX) { - if ((phase==1 && rec[c2][i+x][j+y]=max[0] || green[HR_SCALE*i+j][k]>=max[1] || blues[j][k]>=max[2]) + if (reds[j][k]>=max_3[0] || green[HR_SCALE*i+j][k]>=max_3[1] || blues[j][k]>=max_3[2]) needhr[HR_SCALE*i+j][k] = 1; else needhr[HR_SCALE*i+j][k] = 0; @@ -325,7 +325,7 @@ void RawImageSource::updateHLRecoveryMap_ColorPropagation () { delete [] blues[i]; } - hlmultipliers (rec, max, dh, dw); + hlmultipliers (rec, max_3, dh, dw); if (hrmap[0]!=NULL) { freeArray (hrmap[0], dh); diff --git a/rtengine/iccstore.cc b/rtengine/iccstore.cc index 98f66289d..a2edf14d5 100644 --- a/rtengine/iccstore.cc +++ b/rtengine/iccstore.cc @@ -217,7 +217,7 @@ void ICCStore::loadICCs(Glib::ustring rootDirName, bool nameUpper, std::map #include -#include "imageio.h" -#include "safegtk.h" #include #include #include #include #include +#include +#include + #ifdef WIN32 #include #else #include #endif + +#include "imageio.h" +#include "safegtk.h" #include "iptcpairs.h" -#include - #include "iccjpeg.h" #include "jpeg.h" -Glib::ustring safe_locale_to_utf8 (const std::string& src); - +using namespace std; using namespace rtengine; using namespace rtengine::procparams; +Glib::ustring safe_locale_to_utf8 (const std::string& src); Glib::ustring ImageIO::errorMsg[6] = {"Success", "Cannot read file.", "Invalid header.","Error while reading header.","File reading error", "Image format not supported."}; // For only copying the raw input data @@ -91,7 +93,7 @@ void ImageIO::setMetadata (const rtexif::TagDirectory* eroot, const rtengine::pr IptcDataSet * ds = iptc_dataset_new (); iptc_dataset_set_tag (ds, IPTC_RECORD_APP_2, IPTC_TAG_KEYWORDS); std::string loc = safe_locale_to_utf8(i->second.at(j)); - iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), MIN(64,loc.size()), IPTC_DONT_VALIDATE); + iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), min(static_cast(64), loc.size()), IPTC_DONT_VALIDATE); iptc_data_add_dataset (iptc, ds); iptc_dataset_unref (ds); } @@ -102,7 +104,7 @@ void ImageIO::setMetadata (const rtexif::TagDirectory* eroot, const rtengine::pr IptcDataSet * ds = iptc_dataset_new (); iptc_dataset_set_tag (ds, IPTC_RECORD_APP_2, IPTC_TAG_SUPPL_CATEGORY); std::string loc = safe_locale_to_utf8(i->second.at(j)); - iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), MIN(32,loc.size()), IPTC_DONT_VALIDATE); + iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), min(static_cast(32), loc.size()), IPTC_DONT_VALIDATE); iptc_data_add_dataset (iptc, ds); iptc_dataset_unref (ds); } @@ -113,7 +115,7 @@ void ImageIO::setMetadata (const rtexif::TagDirectory* eroot, const rtengine::pr IptcDataSet * ds = iptc_dataset_new (); iptc_dataset_set_tag (ds, IPTC_RECORD_APP_2, strTags[j].tag); std::string loc = safe_locale_to_utf8(i->second.at(0)); - iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), MIN(strTags[j].size,loc.size()), IPTC_DONT_VALIDATE); + iptc_dataset_set_data (ds, (unsigned char*)loc.c_str(), min(strTags[j].size, loc.size()), IPTC_DONT_VALIDATE); iptc_data_add_dataset (iptc, ds); iptc_dataset_unref (ds); } diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index b30f7cd1a..bd1918835 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -16,24 +16,25 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include +#include +#include + #include "rtengine.h" #include "improcfun.h" #include "curves.h" -#include #include "colorclip.h" #include "gauss.h" #include "bilateral2.h" -#include "minmax.h" #include "mytime.h" -#include -#include #include "iccstore.h" #include "impulse_denoise.h" #include "imagesource.h" #include "rtthumbnail.h" -#include "../rtengine/utils.h" +#include "utils.h" #include "iccmatrices.h" #include "calc_distort.h" +#include "rt_math.h" #ifdef _OPENMP #include @@ -46,8 +47,8 @@ namespace rtengine { #undef MAXVAL #undef CMAXVAL #undef MAXL -#undef MAX -#undef MIN + + #undef ABS #undef CLIP #undef CLIPS @@ -57,8 +58,8 @@ namespace rtengine { #define MAXVAL 0xffff #define CMAXVAL 0xffff #define MAXL 0xffff -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) + + #define ABS(a) ((a)<0?-(a):(a)) #define CLIP(a) ((a)>0?((a)-32768?((a)<32767?(a):32767):-32768) @@ -212,8 +213,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone int h_th, s_th; if (shmap) { - h_th = shmap->max - params->sh.htonalwidth * (shmap->max - shmap->avg) / 100; - s_th = params->sh.stonalwidth * (shmap->avg - shmap->min) / 100; + h_th = shmap->max_f - params->sh.htonalwidth * (shmap->max_f - shmap->avg) / 100; + s_th = params->sh.stonalwidth * (shmap->avg - shmap->min_f) / 100; } bool processSH = params->sh.enabled && shmap!=NULL && (params->sh.highlights>0 || params->sh.shadows>0); @@ -222,7 +223,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone TMatrix wprof = iccStore->workingSpaceMatrix (params->icm.working); - float toxyz[3][3] = { + double toxyz[3][3] = { { ( wprof[0][0] / D50x), ( wprof[0][1] / D50x), @@ -268,8 +269,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone if (vCurveEnabled) vCurve = new FlatCurve(params->hsvequalizer.vcurve); const float exp_scale = pow (2.0, params->toneCurve.expcomp); - const float comp = (MAX(0,params->toneCurve.expcomp) + 1.0)*params->toneCurve.hlcompr/100.0; - const float shoulder = ((65536.0/MAX(1,exp_scale))*(params->toneCurve.hlcomprthresh/200.0))+0.1; + const float comp = (max(0.0, params->toneCurve.expcomp) + 1.0)*params->toneCurve.hlcompr/100.0; + const float shoulder = ((65536.0/max(1.0f,exp_scale))*(params->toneCurve.hlcomprthresh/200.0))+0.1; const float hlrange = 65536.0-shoulder; @@ -347,7 +348,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone float h,s,v; rgb2hsv(r,g,b,h,s,v); if (sat > 0.5) { - s = (1-(float)sat/100)*s+(float)sat/100*(1-SQR(SQR(1-MIN(s,1)))); + s = (1-(float)sat/100)*s+(float)sat/100*(1-SQR(SQR(1-min(s,1.0f)))); if (s<0) s=0; } else { if (sat < -0.5) @@ -365,7 +366,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone //shift saturation float satparam = (sCurve->getVal((double)h)-0.5) * 2; if (satparam > 0.00001) { - s = (1-satparam)*s+satparam*(1-SQR(1-MIN(s,1))); + s = (1-satparam)*s+satparam*(1-SQR(1-min(s,1.0f))); if (s<0) s=0; } else { if (satparam < -0.00001) @@ -378,7 +379,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, LUTf & hltone float valparam = vCurve->getVal((double)h)-0.5; valparam *= (1-SQR(SQR(1-s))); if (valparam > 0.00001) { - v = (1-valparam)*v+valparam*(1-SQR(1-MIN(v,1))); + v = (1-valparam)*v+valparam*(1-SQR(1-min(v,1.0f))); if (v<0) v=0; } else { if (valparam < -0.00001) @@ -703,7 +704,7 @@ fclose(f);*/ octile[count] += histogram[i]; if (octile[count]>sum/8 || (count==7 && octile[count]>sum/16)) { octile[count]=log(1+i)/log(2); - count++;// = MIN(count+1,7); + count++;// = min(count+1,7); } } if (i2 ? (octile[i+1]-octile[3]) : (octile[3]-octile[i]))); + ospread += (octile[i+1]-octile[i])/max(0.5f,(i>2 ? (octile[i+1]-octile[3]) : (octile[3]-octile[i]))); } ospread /= 5; @@ -774,7 +775,7 @@ fclose(f);*/ /*expcomp = (expcomp1*fabs(expcomp2)+expcomp2*fabs(expcomp1))/(fabs(expcomp1)+fabs(expcomp2)); if (expcomp<0) { - MIN(0.0f,MAX(expcomp1,expcomp2)); + min(0.0f,max(expcomp1,expcomp2)); }*/ expcomp = 0.5 * (expcomp1 + expcomp2); float gain = exp(expcomp*log(2)); @@ -791,8 +792,8 @@ fclose(f);*/ //this is a series approximation of the actual formula for comp, //which is a transcendental equation float comp = (gain*((float)whiteclip)/scale - 1)*2;//*(1-shoulder/scale); - hlcompr=(int)(100*comp/(MAX(0,expcomp) + 1.0)); - hlcompr = MAX(0,MIN(100,hlcompr)); + hlcompr=(int)(100*comp/(max(0.0,expcomp) + 1.0)); + hlcompr = max(0,min(100,hlcompr)); //now find brightness if gain didn't bring ave to midgray using //the envelope of the actual 'control cage' brightness curve for simplicity @@ -803,11 +804,11 @@ fclose(f);*/ bright = (midgray-midtmp)*15.0/(0.10833-0.0833*midtmp); } - bright = 0.25*/*(median/ave)*(hidev/lodev)*/MAX(0,bright); + bright = 0.25*/*(median/ave)*(hidev/lodev)*/max(0,bright); //compute contrast that spreads the average spacing of octiles contr = 50.0*(1.1-ospread); - contr = MAX(0,MIN(100,contr)); + contr = max(0,min(100,contr)); //diagnostics //printf ("**************** AUTO LEVELS ****************\n"); @@ -918,8 +919,8 @@ fclose(f);*/ double var_G = g / 65535.0; double var_B = b / 65535.0; - double var_Min = MIN(MIN(var_R,var_G),var_B); - double var_Max = MAX(MAX(var_R,var_G),var_B); + double var_Min = min(var_R,var_G,var_B); + double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; v = var_Max; if (fabs(del_Max)<0.00001) { @@ -989,7 +990,7 @@ fclose(f);*/ } - void ImProcFunctions::xyz2rgb (float x, float y, float z, float &r, float &g, float &b, float rgb_xyz[3][3]) { + void ImProcFunctions::xyz2rgb (float x, float y, float z, float &r, float &g, float &b, double rgb_xyz[3][3]) { //Transform to output color. Standard sRGB is D65, but internal representation is D50 //Note that it is only at this point that we should have need of clipping color data diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 07bb0db06..09dcf6f4e 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -165,7 +165,7 @@ class ImProcFunctions { static void rgb2hsv (float r, float g, float b, float &h, float &s, float &v); static void hsv2rgb (float h, float s, float v, float &r, float &g, float &b); void xyz2srgb (float x, float y, float z, float &r, float &g, float &b); - void xyz2rgb (float x, float y, float z, float &r, float &g, float &b, float rgb_xyz[3][3]); + void xyz2rgb (float x, float y, float z, float &r, float &g, float &b, double rgb_xyz[3][3]); void Lab2XYZ(float L, float a, float b, float &x, float &y, float &z); void XYZ2Lab(float X, float Y, float Z, float &L, float &a, float &b); void Lab2Yuv(float L, float a, float b, float &Y, float &u, float &v); diff --git a/rtengine/impulse_denoise.h b/rtengine/impulse_denoise.h index 0d3c8fe7c..a5922003c 100644 --- a/rtengine/impulse_denoise.h +++ b/rtengine/impulse_denoise.h @@ -17,14 +17,14 @@ * 2010 Emil Martinec * */ - -#define SQR(x) ((x)*(x)) - #include #include + +#include "rt_math.h" #include "labimage.h" #include "improcfun.h" +using namespace std; namespace rtengine { @@ -63,25 +63,25 @@ void ImProcFunctions::impulse_nr (LabImage* lab, double thresh) { //rangeblur (lab->L, lpf, impish /*used as buffer here*/, width, height, thresh, false); - AlignedBuffer* buffer = new AlignedBuffer (MAX(width,height)); + AlignedBuffer* buffer = new AlignedBuffer (max(width,height)); - gaussHorizontal (lab->L, lpf, buffer, width, height, MAX(2.0,thresh-1.0), false /*multiThread*/); - gaussVertical (lpf, lpf, buffer, width, height, MAX(2.0,thresh-1.0), false); + gaussHorizontal (lab->L, lpf, buffer, width, height, max(2.0,thresh-1.0), false /*multiThread*/); + gaussVertical (lpf, lpf, buffer, width, height, max(2.0,thresh-1.0), false); delete buffer; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - float impthr = MAX(1.0,5.5-thresh); + float impthr = max(1.0,5.5-thresh); for (int i=0; i < height; i++) for (int j=0; j < width; j++) { hpfabs = fabs(lab->L[i][j]-lpf[i][j]); //block average of high pass data - for (i1=MAX(0,i-2), hfnbrave=0; i1<=MIN(i+2,height-1); i1++ ) - for (j1=MAX(0,j-2); j1<=MIN(j+2,width-1); j1++ ) { + for (i1=max(0,i-2), hfnbrave=0; i1<=min(i+2,height-1); i1++ ) + for (j1=max(0,j-2); j1<=min(j+2,width-1); j1++ ) { hfnbrave += fabs(lab->L[i1][j1]-lpf[i1][j1]); } hfnbrave = (hfnbrave-hpfabs)/24; @@ -94,8 +94,8 @@ void ImProcFunctions::impulse_nr (LabImage* lab, double thresh) { if (!impish[i][j]) continue; norm=0.0; wtdsum[0]=wtdsum[1]=wtdsum[2]=0.0; - for (i1=MAX(0,i-2), hfnbrave=0; i1<=MIN(i+2,height-1); i1++ ) - for (j1=MAX(0,j-2); j1<=MIN(j+2,width-1); j1++ ) { + for (i1=max(0,i-2), hfnbrave=0; i1<=min(i+2,height-1); i1++ ) + for (j1=max(0,j-2); j1<=min(j+2,width-1); j1++ ) { if (i1==i && j1==j) continue; if (impish[i1][j1]) continue; dirwt = 1/(SQR(lab->L[i1][j1]-lab->L[i][j])+eps);//use more sophisticated rangefn??? diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index 2820b9362..e2ed27d5f 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -186,7 +186,7 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, cmsDeleteTransform(hTransform); } else { - float rgb_xyz[3][3]; + double rgb_xyz[3][3]; for (int i=0; i @@ -55,7 +56,7 @@ static void Lanczos(const Image16* src, Image16* dst, float scale) { const float delta = 1.0f / scale; const float a = 3.0f; - const float sc = std::min(scale, 1.0f); + const float sc = min(scale, 1.0f); const int support = static_cast(2.0f * a / sc) + 1; // storage for precomputed parameters for horisontal interpolation @@ -81,8 +82,8 @@ static void Lanczos(const Image16* src, Image16* dst, float scale) // sum of weights used for normalization float ws = 0.0f; - jj0[j] = std::max(0, static_cast(floorf(x0 - a / sc)) + 1); - jj1[j] = std::min(src->width, static_cast(floorf(x0 + a / sc)) + 1); + jj0[j] = max(0, static_cast(floorf(x0 - a / sc)) + 1); + jj1[j] = min(src->width, static_cast(floorf(x0 + a / sc)) + 1); // calculate weights for (int jj = jj0[j]; jj < jj1[j]; jj++) { @@ -111,8 +112,8 @@ static void Lanczos(const Image16* src, Image16* dst, float scale) // sum of weights used for normalization float ws= 0.0f; - int ii0 = std::max(0, static_cast(floorf(y0 - a / sc)) + 1); - int ii1 = std::min(src->height, static_cast(floorf(y0 + a / sc)) + 1); + int ii0 = max(0, static_cast(floorf(y0 - a / sc)) + 1); + int ii1 = min(src->height, static_cast(floorf(y0 + a / sc)) + 1); // calculate weights for vertical interpolation for (int ii = ii0; ii < ii1; ii++) { diff --git a/rtengine/ipsharpen.cc b/rtengine/ipsharpen.cc index 6fb6a25e4..1911ebe8d 100644 --- a/rtengine/ipsharpen.cc +++ b/rtengine/ipsharpen.cc @@ -18,12 +18,15 @@ */ #include "rtengine.h" #include "improcfun.h" +#include "gauss.h" +#include "bilateral2.h" +#include "rt_math.h" + #ifdef _OPENMP #include #endif -#include "minmax.h" -#include "gauss.h" -#include "bilateral2.h" + +using namespace std; namespace rtengine { @@ -34,8 +37,8 @@ namespace rtengine { #define CMAXVAL 0xffff #define CLIP(a) ((a)>0?((a)* buffer = new AlignedBuffer (MAX(W,H)); + AlignedBuffer* buffer = new AlignedBuffer (max(W,H)); float damping = params->sharpening.deconvdamping / 5.0; bool needdamp = params->sharpening.deconvdamping > 0; for (int k=0; ksharpening.deconviter; k++) { @@ -124,7 +127,7 @@ void ImProcFunctions::deconvsharpening (LabImage* lab, float** b2) { #endif for (int i=0; iL[i][j] = lab->L[i][j]*p1 + MAX(tmpI[i][j],0)*p2; + lab->L[i][j] = lab->L[i][j]*p1 + max(tmpI[i][j],0.0f)*p2; } // end parallel @@ -157,7 +160,7 @@ void ImProcFunctions::sharpening (LabImage* lab, float** b2) { { - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); + AlignedBuffer* buffer = new AlignedBuffer (max(W,H)); if (params->sharpening.edgesonly==false) { gaussHorizontal (lab->L, b2, buffer, W, H, params->sharpening.radius / scale, multiThread); @@ -203,7 +206,7 @@ void ImProcFunctions::sharpenHaloCtrl (LabImage* lab, float** blurmap, float** b float** nL = base; #pragma omp parallel for if (multiThread) for (int i=2; iL[i][j]; - if (max < labL) max = labL; - if (min > labL) min = labL; + if (max_ < labL) max_ = labL; + if (min_ > labL) min_ = labL; // deviation from the environment as measurement float diff = nL[i][j] - blurmap[i][j]; @@ -228,10 +232,10 @@ void ImProcFunctions::sharpenHaloCtrl (LabImage* lab, float** blurmap, float** b if (ABS(diff) > params->sharpening.threshold) { float newL = labL + sharpFac * diff; // applying halo control - if (newL > max) - newL = max + (newL-max) * scale; - else if (newL < min) - newL = min - (min-newL) * scale; + if (newL > max_) + newL = max_ + (newL-max_) * scale; + else if (newL < min_) + newL = min_ - (min_-newL) * scale; lab->L[i][j] = newL; } diff --git a/rtengine/iptcpairs.h b/rtengine/iptcpairs.h index d8256383d..018e7f1bf 100644 --- a/rtengine/iptcpairs.h +++ b/rtengine/iptcpairs.h @@ -22,7 +22,7 @@ struct IptcPair { IptcTag tag; - int size; + size_t size; Glib::ustring field; }; diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index 844d26750..374a43fbd 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -23,21 +23,24 @@ #endif #include "mytime.h" +#include "rt_math.h" + +using namespace std; + namespace rtengine { #undef CMAXVAL -#undef MAX -#undef MIN + + #undef CLIPTO #undef CLIPTOC -#undef SQR -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) + + + #define CLIPTO(a,b,c) ((a)>(b)?((a)<(c)?(a):(c)):(b)) #define CLIPTOC(a,b,c,d) ((a)>=(b)?((a)<=(c)?(a):(d=true,(c))):(d=true,(b))) #define RT_PI 3.141592653589 -#define SQR(x) ((x)*(x)) bool ImProcFunctions::transCoord (int W, int H, std::vector &src, std::vector &red, std::vector &green, std::vector &blue, double ascaleDef) { diff --git a/rtengine/ipvibrance.cc b/rtengine/ipvibrance.cc index 22aa82de9..64c7d5766 100644 --- a/rtengine/ipvibrance.cc +++ b/rtengine/ipvibrance.cc @@ -17,23 +17,26 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ + +#include + #include "rtengine.h" #include "improcfun.h" #include "iccstore.h" #include "mytime.h" +#include "rt_math.h" #ifdef _OPENMP #include #endif +using namespace std; + namespace rtengine { using namespace procparams; -#define MAXX3(a,b,c) MAX(a,MAX(b,c)) -#define MINN3(a,b,c) MIN(a,MIN(b,c)) - -#define SAT(a,b,c) ((float)MAXX3(a,b,c)-(float)MINN3(a,b,c))/(float)MAXX3(a,b,c) +#define SAT(a,b,c) ((float)max(a,b,c)-(float)min(a,b,c))/(float)max(a,b,c) #define D50x 0.96422 #define D50z 0.82521 @@ -2020,7 +2023,7 @@ void ImProcFunctions::vibrance (LabImage* lab) { float chromaSatur = (float) params->vibrance.saturated / 100.0f;// bool highlight = params->hlrecovery.enabled;//Get the value if "highlight reconstruction" is activated //inverse matrix user select - float wip[3][3] = { + double wip[3][3] = { {wiprof[0][0],wiprof[0][1],wiprof[0][2]}, {wiprof[1][0],wiprof[1][1],wiprof[1][2]}, {wiprof[2][0],wiprof[2][1],wiprof[2][2]} diff --git a/rtengine/klt/base.h b/rtengine/klt/base.h index 35d709447..453aa7623 100644 --- a/rtengine/klt/base.h +++ b/rtengine/klt/base.h @@ -24,15 +24,4 @@ #ifndef ulong #define ulong unsigned long #endif - -#ifndef max -#define max(a,b) ((a) > (b) ? (a) : (b)) #endif -#ifndef min -#define min(a,b) ((a) < (b) ? (a) : (b)) -#endif -#define max3(a,b,c) ((a) > (b) ? max((a),(c)) : max((b),(c))) -#define min3(a,b,c) ((a) < (b) ? min((a),(c)) : min((b),(c))) - -#endif - diff --git a/rtengine/klt/klt.cc b/rtengine/klt/klt.cc index 8e0c78d9b..d08999e62 100644 --- a/rtengine/klt/klt.cc +++ b/rtengine/klt/klt.cc @@ -8,6 +8,7 @@ #include #include /* logf() */ #include /* malloc() */ +#include /* Our includes */ #include "base.h" @@ -16,6 +17,7 @@ #include "klt.h" #include "pyramid.h" +using namespace std; static const int mindist = 10; static const int window_size = 7; @@ -232,6 +234,7 @@ KLT_FeatureTable KLTCreateFeatureTable( for (i = 0 ; i < nFrames ; i++) ft->feature[j][i] = first + j*nFrames + i; + free(first); /* Return feature table */ return(ft); } diff --git a/rtengine/klt/klt_util.cc b/rtengine/klt/klt_util.cc index ebf203ae2..2e8bb6cde 100644 --- a/rtengine/klt/klt_util.cc +++ b/rtengine/klt/klt_util.cc @@ -6,6 +6,7 @@ #include #include /* malloc() */ #include /* fabs() */ +#include /* Our includes */ #include "base.h" @@ -14,6 +15,7 @@ #include "klt.h" #include "klt_util.h" +using namespace std; /*********************************************************************/ diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 969c4796f..ca5430037 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -17,12 +17,14 @@ * along with RawTherapee. If not, see . */ #include -#include "safegtk.h" -#include "../rtgui/multilangmgr.h" -#include "procparams.h" #include #include #include +#include + +#include "safegtk.h" +#include "../rtgui/multilangmgr.h" +#include "procparams.h" #include "../rtgui/version.h" #include "../rtgui/ppversion.h" #include "../rtgui/mydiagonalcurve.h" @@ -34,6 +36,8 @@ #define APPVERSION VERSION +using namespace std; + namespace rtengine { namespace procparams { @@ -87,10 +91,10 @@ void WBParams::cleanup() { void CropParams::mapToResized(int resizedWidth, int resizedHeight, int scale, int &x1, int &x2, int &y1, int &y2) const { x1 = 0, x2 = resizedWidth, y1 = 0, y2 = resizedHeight; if (enabled) { - x1 = MIN(resizedWidth-1, MAX(0, x / scale)); - y1 = MIN(resizedHeight-1, MAX(0, y / scale)); - x2 = MIN(resizedWidth, MAX(0, (x+w) / scale)); - y2 = MIN(resizedHeight, MAX(0, (y+h) / scale)); + x1 = min(resizedWidth-1, max(0, x / scale)); + y1 = min(resizedHeight-1, max(0, y / scale)); + x2 = min(resizedWidth, max(0, (x+w) / scale)); + y2 = min(resizedHeight, max(0, (y+h) / scale)); } } diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 2c7e54850..8d42146e0 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -7,7 +7,7 @@ #include "rawimage.h" #include "settings.h" #include "colortemp.h" -#include "../rtengine/utils.h" +#include "utils.h" #ifdef WIN32 #include #else diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index c7652e211..4510fb9a3 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -16,11 +16,13 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include +#include +#include #include "rawimagesource.h" #include "rawimagesource_i.h" #include "median.h" #include "rawimage.h" -#include #include "mytime.h" #include "iccmatrices.h" #include "iccstore.h" @@ -29,10 +31,9 @@ #include "dfmanager.h" #include "ffmanager.h" #include "slicer.h" -#include #include "../rtgui/options.h" #include "dcp.h" - +#include "rt_math.h" #include "improcfun.h" @@ -44,14 +45,10 @@ namespace rtengine { extern const Settings* settings; #undef ABS -#undef MAX -#undef MIN #undef DIST #undef CLIP #define ABS(a) ((a)<0?-(a):(a)) -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) #define DIST(a,b) (ABS(a-b)) #define MAXVAL 0xffff #define CLIP(a) ((a)>0?((a)get_pre_mul(0) / pre_mul[0]; camwb_green = ri->get_pre_mul(1) / pre_mul[1]; camwb_blue = ri->get_pre_mul(2) / pre_mul[2]; - initialGain = 1.0 / MIN(MIN(pre_mul[0],pre_mul[1]),pre_mul[2]); + initialGain = 1.0 / min(pre_mul[0], pre_mul[1], pre_mul[2]); double cam_r = rgb_cam[0][0]*camwb_red + rgb_cam[0][1]*camwb_green + rgb_cam[0][2]*camwb_blue; double cam_g = rgb_cam[1][0]*camwb_red + rgb_cam[1][1]*camwb_green + rgb_cam[1][2]*camwb_blue; @@ -1191,7 +1188,7 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw if (riDark && W == riDark->get_width() && H == riDark->get_height()) { for (int row = 0; row < H; row++) { for (int col = 0; col < W; col++) { - rawData[row][col] = MAX (src->data[row][col]+ri->get_black() - riDark->data[row][col], 0); + rawData[row][col] = max(src->data[row][col]+ri->get_black() - riDark->data[row][col], 0); } } }else{ @@ -1227,14 +1224,14 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw //find center ave values by channel for (int m=0; m<2; m++) for (int n=0; n<2; n++) { - refcolor[m][n] = MAX(0,cfablur[(2*(H>>2)+m)*W+2*(W>>2)+n] - ri->get_black()); + refcolor[m][n] = max(0.0f,cfablur[(2*(H>>2)+m)*W+2*(W>>2)+n] - ri->get_black()); } for (int m=0; m<2; m++) for (int n=0; n<2; n++) { for (int row = 0; row+m < H; row+=2) for (int col = 0; col+n < W; col+=2) { - vignettecorr = ( refcolor[m][n]/MAX(1e-5,cfablur[(row+m)*W+col+n]-ri->get_black()) ); + vignettecorr = ( refcolor[m][n]/max(1e-5f,cfablur[(row+m)*W+col+n]-ri->get_black()) ); rawData[row+m][col+n] = (rawData[row+m][col+n]-ri->get_black()) * vignettecorr + ri->get_black(); } } @@ -1254,8 +1251,8 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw for (int n=0; n<2; n++) { for (int row = 0; row+m < H; row+=2) for (int col = 0; col+n < W; col+=2) { - hlinecorr = ( MAX(1e-5,cfablur[(row+m)*W+col+n]-ri->get_black())/MAX(1e-5,cfablur1[(row+m)*W+col+n]-ri->get_black()) ); - vlinecorr = ( MAX(1e-5,cfablur[(row+m)*W+col+n]-ri->get_black())/MAX(1e-5,cfablur2[(row+m)*W+col+n]-ri->get_black()) ); + hlinecorr = (max(1e-5f,cfablur[(row+m)*W+col+n]-ri->get_black())/max(1e-5f,cfablur1[(row+m)*W+col+n]-ri->get_black()) ); + vlinecorr = (max(1e-5f,cfablur[(row+m)*W+col+n]-ri->get_black())/max(1e-5f,cfablur2[(row+m)*W+col+n]-ri->get_black()) ); rawData[row+m][col+n] = ((rawData[row+m][col+n]-ri->get_black()) * hlinecorr * vlinecorr + ri->get_black()); } } @@ -1277,9 +1274,9 @@ void RawImageSource::copyOriginalPixels(const RAWParams &raw, RawImage *src, Raw if (riDark && W == riDark->get_width() && H == riDark->get_height()) { for (int row = 0; row < H; row++) { for (int col = 0; col < W; col++) { - rawData[row][3*col+0] = MAX (src->data[row][3*col+0]+ri->get_black() - riDark->data[row][3*col+0], 0); - rawData[row][3*col+1] = MAX (src->data[row][3*col+1]+ri->get_black() - riDark->data[row][3*col+1], 0); - rawData[row][3*col+2] = MAX (src->data[row][3*col+2]+ri->get_black() - riDark->data[row][3*col+2], 0); + rawData[row][3*col+0] = max(src->data[row][3*col+0]+ri->get_black() - riDark->data[row][3*col+0], 0); + rawData[row][3*col+1] = max(src->data[row][3*col+1]+ri->get_black() - riDark->data[row][3*col+1], 0); + rawData[row][3*col+2] = max(src->data[row][3*col+2]+ri->get_black() - riDark->data[row][3*col+2], 0); } } } else { @@ -1441,7 +1438,7 @@ black_lev[3]= raw.blackzero; val*=scale_mul[2];} rawData[row][col] = (val); - chmax[c] = MAX(chmax[c],val); + chmax[c] = max(chmax[c],val); } } }else{ @@ -1453,21 +1450,21 @@ black_lev[3]= raw.blackzero; val -= cblack[0]; val *= scale_mul[0]; rawData[row][3*col+0] = (val); - chmax[0] = MAX(chmax[0],val); + chmax[0] = max(chmax[0],val); } val = rawData[row][3*col+1]; if (val){ val -= cblack[1]; val *= scale_mul[1]; rawData[row][3*col+1] = (val); - chmax[1] = MAX(chmax[1],val); + chmax[1] = max(chmax[1],val); } val = rawData[row][3*col+2]; if (val){ val -= cblack[2]; val *= scale_mul[2]; rawData[row][3*col+2] = (val); - chmax[2] = MAX(chmax[2],val); + chmax[2] = max(chmax[2],val); } } } @@ -1737,9 +1734,9 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams #pragma omp parallel for for ( int h = 0; h < im->height; ++h ) for ( int w = 0; w < im->width; ++w ) { - im->r[h][w] = pow (MAX(im->r[h][w],0), gammaFac); - im->g[h][w] = pow (MAX(im->g[h][w],0), gammaFac); - im->b[h][w] = pow (MAX(im->b[h][w],0), gammaFac); + im->r[h][w] = pow (max(im->r[h][w],0.0f), gammaFac); + im->g[h][w] = pow (max(im->g[h][w],0.0f), gammaFac); + im->b[h][w] = pow (max(im->b[h][w],0.0f), gammaFac); } } @@ -1754,7 +1751,7 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams cmsHPROFILE out = iccStore->workingSpace (profi);//Prophoto TMatrix wprof = iccStore->workingSpaceMatrix (profi); TMatrix wiprof = iccStore->workingSpaceInverseMatrix (cmp.working);//sRGB .. Adobe...Wide... - float toxyz[3][3] = { + double toxyz[3][3] = { { ( wprof[0][0]), ( wprof[0][1]), @@ -1944,9 +1941,9 @@ TMatrix work = iccStore->workingSpaceInverseMatrix (cmp.working); #pragma omp parallel for for ( int h = 0; h < im->height; ++h ) for ( int w = 0; w < im->width; ++w ) { - im->r[h][w]= (int) (pow (im->r[h][w] / 65535.0, gammaFac) * 65535.0); - im->g[h][w]= (int) (pow (im->g[h][w] / 65535.0, gammaFac) * 65535.0); - im->b[h][w]= (int) (pow (im->b[h][w] / 65535.0, gammaFac) * 65535.0); + im->r[h][w]= (int) (pow ((double)(im->r[h][w] / 65535.0), (double)gammaFac) * 65535.0); + im->g[h][w]= (int) (pow ((double)(im->g[h][w] / 65535.0), (double)gammaFac) * 65535.0); + im->b[h][w]= (int) (pow ((double)(im->b[h][w] / 65535.0), (double)gammaFac) * 65535.0); } } @@ -2029,11 +2026,11 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi { { 1,1,1 }, { 1,-1,1 }, { 1,1,-1 } } }; #define FOREACHCOLOR for (int c=0; c < ColorCount; c++) -#define SQR(x) ((x)*(x)) +#include "rt_math.h" - float minpt=MIN(MIN(hlmax[0],hlmax[1]),hlmax[2]);//min of the raw clip points - //float maxpt=MAX(MAX(hlmax[0],hlmax[1]),hlmax[2]);//max of the raw clip points + float minpt=min(hlmax[0],hlmax[1],hlmax[2]);//min of the raw clip points + //float maxpt=max(hlmax[0],hlmax[1],hlmax[2]);//max of the raw clip points //float medpt=hlmax[0]+hlmax[1]+hlmax[2]-minpt-maxpt;//median of the raw clip points float maxave=(hlmax[0]+hlmax[1]+hlmax[2])/3;//ave of the raw clip points //some thresholds: @@ -2042,7 +2039,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi const float satthresh = 0.5; float clip[3]; - FOREACHCOLOR clip[c]=MIN(maxave,hlmax[c]); + FOREACHCOLOR clip[c]=min(maxave,hlmax[c]); // Determine the maximum level (clip) of all channels const float clippt = clipthresh*maxval; @@ -2064,13 +2061,13 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi if (c == ColorCount) continue; float clipfrac[3]; - FOREACHCOLOR clipfrac[c] = MIN(1,rgb[c]/maxave); + FOREACHCOLOR clipfrac[c] = min(1.0f,rgb[c]/maxave); // Initialize cam with raw input [0] and potentially clipped input [1] FOREACHCOLOR { - lratio += MIN(rgb[c],clip[c]); + lratio += min(rgb[c],clip[c]); cam[0][c] = rgb[c]; - cam[1][c] = MIN(cam[0][c],maxval); + cam[1][c] = min(cam[0][c],maxval); } // Calculate the lightness correction ratio (chratio) @@ -2102,16 +2099,16 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi // Copy converted pixel back if (rin[col] > fixpt) { - float rfrac = SQR((MIN(clip[0],rin[col])-fixpt)/(clip[0]-fixpt)); - rin[col]= MIN(maxave,rfrac*rgb[0]+(1-rfrac)*rin[col]); + float rfrac = SQR((min(clip[0],rin[col])-fixpt)/(clip[0]-fixpt)); + rin[col]= min(maxave,rfrac*rgb[0]+(1-rfrac)*rin[col]); } if (gin[col] > fixpt) { - float gfrac = SQR((MIN(clip[1],gin[col])-fixpt)/(clip[1]-fixpt)); - gin[col]= MIN(maxave,gfrac*rgb[1]+(1-gfrac)*gin[col]); + float gfrac = SQR((min(clip[1],gin[col])-fixpt)/(clip[1]-fixpt)); + gin[col]= min(maxave,gfrac*rgb[1]+(1-gfrac)*gin[col]); } if (bin[col] > fixpt) { - float bfrac = SQR((MIN(clip[2],bin[col])-fixpt)/(clip[2]-fixpt)); - bin[col]= MIN(maxave,bfrac*rgb[2]+(1-bfrac)*bin[col]); + float bfrac = SQR((min(clip[2],bin[col])-fixpt)/(clip[2]-fixpt)); + bin[col]= min(maxave,bfrac*rgb[2]+(1-bfrac)*bin[col]); } lratio /= (rin[col]+gin[col]+bin[col]); @@ -2123,7 +2120,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi bin[col] = L + H / 3.0; if ((L=(rin[col]+gin[col]+bin[col])/3) > desatpt) { - Lfrac = MAX(0,(maxave-L)/(maxave-desatpt)); + Lfrac = max(0.0f,(maxave-L)/(maxave-desatpt)); C = Lfrac * 1.732050808 * (rin[col] - gin[col]); H = Lfrac * (2 * bin[col] - rin[col] - gin[col]); rin[col] = L - H / 6.0 + C / 3.464101615; @@ -2138,9 +2135,9 @@ void RawImageSource::HLRecovery_Luminance (float* rin, float* gin, float* bin, f for (int i=0; imaxval || g>maxval || b>maxval) { - float ro = MIN (r, maxval); - float go = MIN (g, maxval); - float bo = MIN (b, maxval); + float ro = min(r, maxval); + float go = min(g, maxval); + float bo = min(b, maxval); double L = r + g + b; double C = 1.732050808 * (r - g); double H = 2 * b - r - g; @@ -2185,9 +2182,9 @@ void RawImageSource::HLRecovery_CIELab (float* rin, float* gin, float* bin, floa for (int i=0; imaxval || g>maxval || b>maxval) { - float ro = MIN (r, maxval); - float go = MIN (g, maxval); - float bo = MIN (b, maxval); + float ro = min(r, maxval); + float go = min(g, maxval); + float bo = min(b, maxval); float yy = xyz_cam[1][0]*r + xyz_cam[1][1]*g + xyz_cam[1][2]*b; float fy = (yy<65535.0 ? ImProcFunctions::cachef[yy]/327.68 : (exp(log(yy/MAXVAL)/3.0 ))); // compute LCH decompostion of the clipped pixel (only color information, thus C and H will be used) @@ -2323,7 +2320,7 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) { if (fuji) { int fw = ri->get_FujiWidth(); start = ABS(fw-x) + border; - end = MIN( H+ W-fw-x, fw+x) - border; + end = min(H+ W-fw-x, fw+x) - border; } else { start = border; @@ -2343,7 +2340,7 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) { for (int i=32; iget_FujiWidth(); int start = ABS(fw-i) + 32; - int end = MIN(H+W-fw-i, fw+i) - 32; + int end = min(H+W-fw-i, fw+i) - 32; for (int j=start; jisBayer()) { double d = CLIP(initialGain*(rawData[i][3*j])); @@ -2455,10 +2452,10 @@ void RawImageSource::getRowStartEnd (int x, int &start, int &end) { if (initialGain*(rawData[yr][3*xr] )>52500 || initialGain*(rawData[yg][3*xg+1])>52500 || initialGain*(rawData[yb][3*xb+2])>52500) continue; - xmin = MIN(xr,MIN(xg,xb)); - xmax = MAX(xr,MAX(xg,xb)); - ymin = MIN(yr,MIN(yg,yb)); - ymax = MAX(yr,MAX(yg,yb)); + xmin = min(xr,xg,xb); + xmax = max(xr,xg,xb); + ymin = min(yr,yg,yb); + ymax = max(yr,yg,yb); if (xmin>=0 && ymin>=0 && xmax1 && jmaxgh) gh = maxgh; else if (gh1 && imaxgv) gv = maxgv; else if (gv +#include + +#include "rtengine.h" + +namespace rtengine { + template + inline const _Tp SQR (_Tp x) { +// return std::pow(x,2); Slower than: + return (x*x); + } + + template + inline const _Tp& min(const _Tp& a, const _Tp& b) { + return std::min(a,b); + } + + template + inline const _Tp& max(const _Tp& a, const _Tp& b) { + return std::max(a,b); + } + + template + inline const _Tp& min(const _Tp& a, const _Tp& b, const _Tp& c) { + return std::min(c,std::min(a,b)); + } + + template + inline const _Tp& max(const _Tp& a, const _Tp& b, const _Tp& c) { + return std::max(c,std::max(a,b)); + } + + template + inline const _Tp& min(const _Tp& a, const _Tp& b, const _Tp& c, const _Tp& d) { + return std::min(d,std::min(c,std::min(a,b))); + } + + template + inline const _Tp& max(const _Tp& a, const _Tp& b, const _Tp& c, const _Tp& d) { + return std::max(d,std::max(c,std::max(a,b))); + } +} +#endif diff --git a/rtengine/rtengine.h b/rtengine/rtengine.h index 3fe8c1361..aeb46f598 100644 --- a/rtengine/rtengine.h +++ b/rtengine/rtengine.h @@ -28,7 +28,7 @@ #include "../rtexif/rtexif.h" #include "rawmetadatalocation.h" #include "iimage.h" -#include "../rtengine/utils.h" +#include "utils.h" #include "settings.h" #include "LUT.h" /** diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 5d033cff2..ad02e6add 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -25,7 +25,7 @@ #include "improcfun.h" #include "colortemp.h" #include "mytime.h" -#include "../rtengine/utils.h" +#include "utils.h" #include "iccstore.h" #include "iccmatrices.h" #include "rawimagesource.h" @@ -273,7 +273,7 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, RawMetaDataLocati tpp->camwbRed = tpp->redMultiplier / ri->get_pre_mul(0); tpp->camwbGreen = tpp->greenMultiplier / ri->get_pre_mul(1); tpp->camwbBlue = tpp->blueMultiplier / ri->get_pre_mul(2); - tpp->defGain= 1.0/ MIN(MIN(ri->get_pre_mul(0),ri->get_pre_mul(1)),ri->get_pre_mul(2)); + tpp->defGain= 1.0/ min(ri->get_pre_mul(0), ri->get_pre_mul(1), ri->get_pre_mul(2)); tpp->gammaCorrected = true; unsigned filter = ri->get_filters(); @@ -410,7 +410,7 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, RawMetaDataLocati if (ri->get_FujiWidth() != 0) { int fw = ri->get_FujiWidth(); start = ABS(fw-i) + 8; - end = MIN( height + width-fw-i, fw+i) - 8; + end = min(height + width-fw-i, fw+i) - 8; } else { start = 8; end = width - 8; @@ -435,7 +435,7 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, RawMetaDataLocati if (ri->get_FujiWidth() != 0) { int fw = ri->get_FujiWidth(); start = ABS(fw-i) + 32; - end = MIN( height + width-fw-i, fw+i) - 32; + end = min(height + width-fw-i, fw+i) - 32; } else { start = 32; end = width - 32; @@ -973,20 +973,21 @@ unsigned char* Thumbnail::getGrayscaleHistEQ (int trim_width) { // Go down till we cut off that many pixels unsigned long cutoff = thumbImg->height * thumbImg->height * 4 * BurnOffPct; - int max; unsigned long sum=0; - for (max=65535; max>16384 && sum16384 && sumheight; i++) for (int j=(thumbImg->width-trim_width)/2; jwidth-trim_width)/2; j++) { - int r= gammatab[MIN(thumbImg->r[i][j],max) * scaleForSave >> 13]; - int g= gammatab[MIN(thumbImg->g[i][j],max) * scaleForSave >> 13]; - int b= gammatab[MIN(thumbImg->b[i][j],max) * scaleForSave >> 13]; - tmpdata[ix++] = r*19595+g*38469+b*7472 >> 16; + int r= gammatab[min(thumbImg->r[i][j],static_cast(max_)) * scaleForSave >> 13]; + int g= gammatab[min(thumbImg->g[i][j],static_cast(max_)) * scaleForSave >> 13]; + int b= gammatab[min(thumbImg->b[i][j],static_cast(max_)) * scaleForSave >> 13]; + tmpdata[ix++] = (r*19595+g*38469+b*7472) >> 16; } } else { @@ -1068,19 +1069,19 @@ bool Thumbnail::writeImage (const Glib::ustring& fname, int format) { // Go down till we cut off that many pixels unsigned long cutoff = thumbImg->height * thumbImg->height * 4 * BurnOffPct; - int max; unsigned long sum=0; - for (max=65535; max>16384 && sum16384 && sumheight; i++) for (int j=0; jwidth; j++) { - tmpdata[ix++] = gammatab[MIN(thumbImg->r[i][j],max) * scaleForSave >> 13]; - tmpdata[ix++] = gammatab[MIN(thumbImg->g[i][j],max) * scaleForSave >> 13]; - tmpdata[ix++] = gammatab[MIN(thumbImg->b[i][j],max) * scaleForSave >> 13]; + tmpdata[ix++] = gammatab[min(thumbImg->r[i][j],static_cast(max_)) * scaleForSave >> 13]; + tmpdata[ix++] = gammatab[min(thumbImg->g[i][j],static_cast(max_)) * scaleForSave >> 13]; + tmpdata[ix++] = gammatab[min(thumbImg->b[i][j],static_cast(max_)) * scaleForSave >> 13]; } } else { diff --git a/rtengine/shmap.cc b/rtengine/shmap.cc index 186cc889c..18a2fdf1d 100644 --- a/rtengine/shmap.cc +++ b/rtengine/shmap.cc @@ -20,21 +20,12 @@ #include "gauss.h" #include "bilateral2.h" #include "rtengine.h" - -#include "rawimagesource.h"//for dirpyr - +#include "rt_math.h" +#include "rawimagesource.h" #undef MAXVAL -#undef MAX -#undef MIN -#undef SQR - #undef THREAD_PRIORITY_NORMAL #define MAXVAL 0xffff -#define SQR(x) ((x)*(x)) - -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) namespace rtengine { @@ -66,7 +57,7 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int #endif { if (!hq) { - AlignedBuffer* buffer = new AlignedBuffer (MAX(W,H)); + AlignedBuffer* buffer = new AlignedBuffer (max(W,H)); gaussHorizontal (map, map, buffer, W, H, radius, multiThread); gaussVertical (map, map, buffer, W, H, radius, multiThread); @@ -105,7 +96,7 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int for (int i=0; i<0x10000; i++) { //rangefn[i] = (int)(((thresh)/((double)(i) + (thresh)))*intfactor); - rangefn[i] = (int)(exp(-(MIN(10,((float)i*i) / (thresh*thresh))))*intfactor); + rangefn[i] = static_cast(exp(-(min(10.0f,(static_cast(i*i)) / (thresh*thresh))))*intfactor); //if (rangefn[i]<0 || rangefn[i]>intfactor) //printf("i=%d rangefn=%d arg=%f \n",i,rangefn[i], float(i*i) / (thresh*thresh)); } @@ -152,15 +143,15 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int // update average, minimum, maximum double _avg = 0; int n = 1; - min = 65535; - max = 0; + min_f = 65535; + max_f = 0; for (int i=32; i max) - max = val; + if (val < min_f) + min_f = val; + if (val > max_f) + max_f = val; _avg = 1.0/n * val + (1.0 - 1.0/n) * _avg; n++; } @@ -169,8 +160,8 @@ void SHMap::update (Imagefloat* img, double radius, double lumi[3], bool hq, int void SHMap::forceStat (float max_, float min_, float avg_) { - max = max_; - min = min_; + max_f = max_; + min_f = min_; avg = avg_; } diff --git a/rtengine/shmap.h b/rtengine/shmap.h index 1b4dba975..9d9cdf4fb 100644 --- a/rtengine/shmap.h +++ b/rtengine/shmap.h @@ -29,7 +29,7 @@ class SHMap { public: int W, H; float** map; - float max, min, avg; + float max_f, min_f, avg; bool multiThread; SHMap (int w, int h, bool multiThread); diff --git a/rtengine/slicer.cc b/rtengine/slicer.cc index 60e8c454f..e832b62e3 100644 --- a/rtengine/slicer.cc +++ b/rtengine/slicer.cc @@ -18,11 +18,16 @@ */ #include +#include +#include + +#include "slicer.h" + #ifdef _OPENMP #include #endif -#include "slicer.h" -#include + +using namespace std; // If no parameter set, everything = 0 -> process all the image Block::Block() { @@ -75,7 +80,7 @@ Slicer::Slicer(unsigned int imageWidth, unsigned int imageHeight, Block *subRegi //calculate the number of block blockNumber = (double(region.width*region.height) / (double)pixels); - blockNumber = int((MAX(blockNumber, 1) + (double)procNumber/2.)/procNumber)*procNumber; + blockNumber = int((max(blockNumber, 1U) + (double)procNumber/2.)/procNumber)*procNumber; vBlockNumber = (unsigned int)(sqrt((double)blockNumber / subRegionRatio)+0.5); vBlockNumber = CLAMP(vBlockNumber, 1, blockNumber); hBlockNumber = (double)blockNumber / (double)vBlockNumber; diff --git a/rtengine/utils.cc b/rtengine/utils.cc index 6f6bd15ab..fa7ba7eec 100644 --- a/rtengine/utils.cc +++ b/rtengine/utils.cc @@ -16,16 +16,15 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#include "../rtengine/utils.h" #include #include #include +#include -#undef MAX -#undef MIN +#include "utils.h" +#include "rt_math.h" -#define MAX(a,b) ((a)<(b)?(b):(a)) -#define MIN(a,b) ((a)>(b)?(b):(a)) +using namespace std; namespace rtengine { @@ -152,8 +151,8 @@ void rgb2hsv (int r, int g, int b, float &h, float &s, float &v) { double var_G = g / 65535.0; double var_B = b / 65535.0; - double var_Min = MIN(MIN(var_R,var_G),var_B); - double var_Max = MAX(MAX(var_R,var_G),var_B); + double var_Min = min(var_R,var_G,var_B); + double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; v = var_Max; if (fabs(del_Max)<0.00001) { diff --git a/rtgui/batchqueue.cc b/rtgui/batchqueue.cc index 3ce5dd70b..8672503f4 100644 --- a/rtgui/batchqueue.cc +++ b/rtgui/batchqueue.cc @@ -16,9 +16,12 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ -#include "batchqueue.h" #include #include +#include +#include + +#include "batchqueue.h" #include "multilangmgr.h" #include "filecatalog.h" #include "batchqueuebuttonset.h" @@ -26,8 +29,7 @@ #include "../rtengine/safegtk.h" #include "rtimage.h" -#include - +using namespace std; using namespace rtengine; BatchQueue::BatchQueue () : processing(NULL), listener(NULL) { @@ -66,7 +68,7 @@ BatchQueue::~BatchQueue () // Reduce the max size of a thumb, since thumb is processed synchronously on adding to queue // leading to very long waiting when adding more images int BatchQueue::calcMaxThumbnailHeight() { - return MIN(options.maxThumbnailHeight, 200); + return min(options.maxThumbnailHeight, 200); } // Function for virtual override in thumbbrowser base @@ -90,7 +92,7 @@ void BatchQueue::addEntries ( std::vector &entries, bool head) for( std::vector::iterator entry = entries.begin(); entry != entries.end();entry++ ){ (*entry)->setParent (this); - (*entry)->resize (MIN(options.thumbSize, getMaxThumbnailHeight())); // batch queue might have smaller, restricted size + (*entry)->resize (min(options.thumbSize, getMaxThumbnailHeight())); // batch queue might have smaller, restricted size Glib::ustring tempFile = getTempFilenameForParams( (*entry)->filename ); // recovery save diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index e194e6a76..cb7bc1ba3 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -407,7 +407,7 @@ void EditorPanel::open (Thumbnail* tmb, rtengine::InitialImage* isrc) { // initialize profile Glib::ustring defProf = openThm->getType()==FT_Raw ? options.defProfRaw : options.defProfImg; - profilep->initProfile (defProf, ldprof, NULL); + profilep->initProfile (defProf, ldprof); openThm->addThumbnailListener (this); info_toggled (); diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index 75bb63d5a..dc7be6d13 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -17,21 +17,24 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include +#include +#include +#include + #include "filecatalog.h" #include "filepanel.h" #include "options.h" #include "cachemanager.h" #include "multilangmgr.h" #include "guiutils.h" -#include -#include -#include #include "renamedlg.h" #include "thumbimageupdater.h" #include "../rtengine/safegtk.h" #include "batchqueue.h" #include "rtimage.h" +using namespace std; #define CHECKTIME 2000 @@ -1120,8 +1123,8 @@ void FileCatalog::categoryButtonToggled (Gtk::ToggleButton* b) { toggled_stars_count = 1; } if (toggled_stars_count == 1) { - int current_star=MIN(start_star,toggled_button); - int last_star =MAX(start_star,toggled_button); + int current_star=min(start_star,toggled_button); + int last_star =max(start_star,toggled_button); //we permute the start and the end star for the next loop for (; current_star <= last_star; current_star++) { //we toggle on all the star in the range diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 6c34d0853..22624fe00 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -15,11 +15,15 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include + #include "guiutils.h" #include "options.h" #include "../rtengine/utils.h" #include "rtimage.h" +using namespace std; + bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference) { Glib::ListHandle list = cont->get_children (); @@ -203,7 +207,7 @@ void drawCrop (Cairo::RefPtr cr, int imx, int imy, int imw, int else { int corners_from[4][2]; int corners_to[4][2]; - int mindim = MIN (rectx2-rectx1+1, recty2-recty1+1); + int mindim = min(rectx2-rectx1+1, recty2-recty1+1); corners_from[0][0] = rectx1; corners_from[0][1] = recty1; corners_to[0][0] = rectx1 + mindim; diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index c80b77d27..d7cd24771 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -169,10 +169,10 @@ void MyDiagonalCurve::draw (int handle) { cr->set_source_rgb (c.get_red_p(), c.get_green_p(), c.get_blue_p()); cr->set_antialias (Cairo::ANTIALIAS_NONE); for (int i = 0; i < 5; i++) { // + 0.5 to align well with f(x)=x so it will cut through the center - cr->move_to (RADIUS, MAX(0,i * (innerHeight + 0.5) / 4) + RADIUS); - cr->line_to (innerWidth + RADIUS, MAX(0,i * (innerHeight + 0.5) / 4) + RADIUS); - cr->move_to (MAX(0,i * innerWidth / 4) + RADIUS, RADIUS); - cr->line_to (MAX(0,i * innerWidth / 4) + RADIUS, innerHeight + RADIUS); + cr->move_to (RADIUS, max(0.0, i * (innerHeight + 0.5) / 4) + RADIUS); + cr->line_to (innerWidth + RADIUS, max(0.0,i * (innerHeight + 0.5) / 4) + RADIUS); + cr->move_to (max(0,i * innerWidth / 4) + RADIUS, RADIUS); + cr->line_to (max(0,i * innerWidth / 4) + RADIUS, innerHeight + RADIUS); } cr->stroke (); diff --git a/rtgui/navigator.cc b/rtgui/navigator.cc index 3ef3da1fe..6b5d81b94 100644 --- a/rtgui/navigator.cc +++ b/rtgui/navigator.cc @@ -21,6 +21,7 @@ #include "../rtengine/iccmatrices.h" #include "../rtengine/iccstore.h" #include "../rtengine/curves.h" +#include "../rtengine/rt_math.h" #define D50x 0.96422 #define D50z 0.82521 @@ -109,8 +110,8 @@ void Navigator::rgb2hsv (int r, int g, int b, int &h, int &s, int &v) { volatile double var_G = g / 255.0; volatile double var_B = b / 255.0; - /*volatile double var_Min = MIN(MIN(var_R,var_G),var_B); - volatile double var_Max = MAX(MAX(var_R,var_G),var_B); + /*volatile double var_Min = min(var_R,var_G,var_B); + volatile double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; double V = (var_Max + var_Min) / 2; double H, S; @@ -133,8 +134,8 @@ void Navigator::rgb2hsv (int r, int g, int b, int &h, int &s, int &v) { if ( H > 1 ) H -= 1; }*/ - double var_Min = MIN(MIN(var_R,var_G),var_B); - double var_Max = MAX(MAX(var_R,var_G),var_B); + double var_Min = rtengine::min(var_R,var_G,var_B); + double var_Max = rtengine::max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; double V = var_Max; double H, S; diff --git a/rtgui/popupcommon.cc b/rtgui/popupcommon.cc index 5efbdcbfb..45678b0ab 100644 --- a/rtgui/popupcommon.cc +++ b/rtgui/popupcommon.cc @@ -121,7 +121,7 @@ void PopUpCommon::entrySelected (int i) { * Set the button image with the selected item */ bool PopUpCommon::setSelected (int entryNum) { - if (entryNum < 0 || entryNum > (int)images.size()-1 || (int)entryNum == selected) + if (entryNum < 0 || entryNum > ((int)images.size()-1) || (int)entryNum == selected) return false; else { // Maybe we could do something better than loading the image file each time the selection is changed !? diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index 0b7edda1d..9744111bd 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -72,7 +72,6 @@ ProfilePanel::ProfilePanel (bool readOnly) { paste->signal_button_release_event().connect_notify( sigc::mem_fun(*this, &ProfilePanel::paste_clicked) ); custom = NULL; - lastphoto = NULL; lastsaved = NULL; dontupdate = false; @@ -94,7 +93,6 @@ ProfilePanel::~ProfilePanel () { if (custom) { custom->deleteInstance(); delete custom; } if (lastsaved) { lastsaved->deleteInstance(); delete lastsaved; } - if (lastphoto) { lastphoto->deleteInstance(); delete lastphoto; } } void ProfilePanel::refreshProfileList () { @@ -116,8 +114,6 @@ void ProfilePanel::refreshProfileList () { profiles->append_text (Glib::ustring("(") + M("PROFILEPANEL_PCUSTOM") + ")"); if (lastsaved) profiles->append_text (Glib::ustring("(") + M("PROFILEPANEL_PLASTSAVED") + ")"); - if (lastphoto) - profiles->append_text (Glib::ustring("(") + M("PROFILEPANEL_PLASTPHOTO") + ")"); profiles->set_active_text (oldsel); changeconn.block (false); @@ -194,8 +190,6 @@ void ProfilePanel::save_clicked (GdkEventButton* event) { toSave = custom; else if (profiles->get_active_text() == Glib::ustring("(") + M("PROFILEPANEL_PLASTSAVED") + ")") toSave = lastsaved; - else if (profiles->get_active_text() == Glib::ustring("(") + M("PROFILEPANEL_PLASTPHOTO") + ")") - toSave = lastphoto; else toSave = profileStore.getProfile (profiles->get_active_text()); @@ -239,8 +233,6 @@ void ProfilePanel::copy_clicked (GdkEventButton* event) { toSave = custom; else if (profiles->get_active_text() == Glib::ustring("(") + M("PROFILEPANEL_PLASTSAVED") + ")") toSave = lastsaved; - else if (profiles->get_active_text() == Glib::ustring("(") + M("PROFILEPANEL_PLASTPHOTO") + ")") - toSave = lastphoto; else toSave = profileStore.getProfile (profiles->get_active_text()); @@ -413,8 +405,6 @@ void ProfilePanel::selection_changed () { } else if (profiles->get_active_text() == (entry = Glib::ustring("(") + M("PROFILEPANEL_PLASTSAVED") + ")")) changeTo (lastsaved, entry); - else if (profiles->get_active_text() == (entry = Glib::ustring("(") + M("PROFILEPANEL_PLASTPHOTO") + ")")) - changeTo (lastphoto, entry); else { PartialProfile* s = profileStore.getProfile (profiles->get_active_text()); if (s) @@ -444,10 +434,7 @@ void ProfilePanel::procParamsChanged (rtengine::procparams::ProcParams* p, rteng *custom->pparams = *p; } -/* - * TODO: "lastPhoto" is not used anymore, a code cleanup should delete everything related to it - */ -void ProfilePanel::initProfile (const Glib::ustring& profname, ProcParams* lastSaved, ProcParams* lastPhoto) { +void ProfilePanel::initProfile (const Glib::ustring& profname, ProcParams* lastSaved) { changeconn.block (true); @@ -473,22 +460,9 @@ void ProfilePanel::initProfile (const Glib::ustring& profname, ProcParams* lastS lastsaved = new PartialProfile(lastSaved, pe); } - if (lastphoto) { - lastphoto->deleteInstance(); - delete lastphoto; lastphoto = NULL; - } - if (lastPhoto) { - ParamsEdited* pe = new ParamsEdited(); - pe->set(true); - lastphoto = new PartialProfile(lastPhoto, pe); - } - Glib::ustring defline = profname; PartialProfile* defprofile = profileStore.getProfile (profname); - if (lastphoto) - profiles->append_text (Glib::ustring("(") + M("PROFILEPANEL_PLASTPHOTO") + ")"); - if (lastsaved) { defline = Glib::ustring("(") + M("PROFILEPANEL_PLASTSAVED") + ")"; defprofile = lastsaved; diff --git a/rtgui/profilepanel.h b/rtgui/profilepanel.h index 51c2d0364..b9677e8e1 100644 --- a/rtgui/profilepanel.h +++ b/rtgui/profilepanel.h @@ -40,7 +40,6 @@ class ProfilePanel : public Gtk::VBox, public PParamsChangeListener { std::vector pparams; rtengine::procparams::PartialProfile* custom; rtengine::procparams::PartialProfile* lastsaved; - rtengine::procparams::PartialProfile* lastphoto; Glib::ustring old; ProfileChangeListener* tpc; bool dontupdate; @@ -60,7 +59,7 @@ class ProfilePanel : public Gtk::VBox, public PParamsChangeListener { static void init (); static void cleanup (); - void initProfile (const Glib::ustring& profname, rtengine::procparams::ProcParams* lastSaved, rtengine::procparams::ProcParams* lastPhoto); + void initProfile (const Glib::ustring& profname, rtengine::procparams::ProcParams* lastSaved); // PParamsChangeListener interface void procParamsChanged (rtengine::procparams::ProcParams* params, rtengine::ProcEvent ev, Glib::ustring descr, ParamsEdited* paramsEdited=NULL); diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 5e99fccfc..90e8d8090 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -205,6 +205,13 @@ RTWindow::RTWindow () if (!isSingleTabMode()&& !simpleEditor) epanel->hide_all(); } +RTWindow::~RTWindow() +{ + if(!simpleEditor) + delete pldBridge; + pldBridge = NULL; +} + void RTWindow::findVerNumbers(int* numbers, Glib::ustring versionStr) { numbers[0] = numbers[1] = numbers[2] = numbers[3] = 0; int n=0; diff --git a/rtgui/rtwindow.h b/rtgui/rtwindow.h index 9f7026e9a..b798613f9 100644 --- a/rtgui/rtwindow.h +++ b/rtgui/rtwindow.h @@ -52,6 +52,7 @@ class RTWindow : public Gtk::Window, public rtengine::ProgressListener{ public: RTWindow (); + ~RTWindow(); void addEditorPanel (EditorPanel* ep,const std::string &name); void remEditorPanel (EditorPanel* ep); diff --git a/rtgui/thumbbrowserbase.cc b/rtgui/thumbbrowserbase.cc index 6484f704f..53c5370fb 100644 --- a/rtgui/thumbbrowserbase.cc +++ b/rtgui/thumbbrowserbase.cc @@ -14,12 +14,16 @@ * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ +#include +#include + #include "thumbbrowserbase.h" -#include #include "multilangmgr.h" #include "options.h" #include "../rtengine/mytime.h" +using namespace std; + ThumbBrowserBase::ThumbBrowserBase () : lastClicked(NULL), previewHeight(options.thumbSize) { inTabMode=false; // corresponding to take thumbSize @@ -566,11 +570,11 @@ void ThumbBrowserBase::enableTabMode(bool enable) { // Tab mode is horizontal, file browser is vertical if (!selected.empty()) { if (inTabMode) { - int h=selected[0]->getStartX(); - hscroll.set_value (MIN(h, hscroll.get_adjustment()->get_upper())); + double h=selected[0]->getStartX(); + hscroll.set_value (min(h, hscroll.get_adjustment()->get_upper())); } else { - int v=selected[0]->getStartY(); - vscroll.set_value (MIN(v, vscroll.get_adjustment()->get_upper())); + double v=selected[0]->getStartY(); + vscroll.set_value (min(v, vscroll.get_adjustment()->get_upper())); } } diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index 49ee1b3b7..55207c47c 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -186,7 +186,7 @@ WhiteBalance::WhiteBalance () : Gtk::VBox(), FoldableToolPanel(this), wbp(NULL), } WhiteBalance::~WhiteBalance () { - delete custom_green; + delete[] custom_green; } void WhiteBalance::adjusterChanged (Adjuster* a, double newval) {