diff --git a/rtengine/camconst.cc b/rtengine/camconst.cc index c7a6412be..8b8ce099d 100644 --- a/rtengine/camconst.cc +++ b/rtengine/camconst.cc @@ -558,10 +558,20 @@ CameraConstantsStore::parse_camera_constants_file(Glib::ustring filename_) while ((ret = fread(&buf[datasize], 1, bufsize - datasize, stream)) != 0) { datasize += ret; - if (datasize == bufsize) { + if (datasize == bufsize) { // we need more memory bufsize += increment; - buf = (char *)realloc(buf, bufsize); - increment *= 2; + void *temp = realloc(buf, bufsize); // try to realloc buffer with new size + if(!temp) { // realloc failed + temp = malloc(bufsize); // alloc now buffer + if (temp) { // alloc worked + memcpy(temp, buf, bufsize - increment); // copy old buffer content to new buffer + free(buf); // free old buffer + } else { // alloc didn't work, break + break; + } + } + buf = (char *)temp; // assign new buffer + increment *= 2; // double increment } } diff --git a/rtengine/color.cc b/rtengine/color.cc index 6dda2c8b8..4982d36b5 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -542,7 +542,7 @@ void Color::rgb2hsl(float r, float g, float b, float &h, float &s, float &l) h_ = 4. + (var_R - var_G) / C; } - h = float(h_ /= 6.0); + h = float(h_ / 6.0); if ( h < 0.f ) { h += 1.f; @@ -923,7 +923,7 @@ void Color::hsv2rgb (float h, float s, float v, int &r, int &g, int &b) r1 = t; g1 = p; b1 = v; - } else if (i == 5) { + } else /*if (i == 5)*/ { r1 = v; g1 = p; b1 = q; @@ -1996,7 +1996,6 @@ void Color::skinred ( double J, double h, double sres, double Sp, float dred, fl float factorskin, factorsat, factor, factorskinext, interm; float scale = 100.0f / 100.1f; //reduction in normal zone float scaleext = 1.0f; //reduction in transition zone - float protect_redh; float deltaHH = 0.3f; //HH value transition : I have choice 0.3 radians float HH; bool doskin = false; @@ -2077,7 +2076,6 @@ void Color::skinredfloat ( float J, float h, float sres, float Sp, float dred, f if(doskin) { float factorskin, factorsat, factor, factorskinext; - float protect_redh; float deltaHH = 0.3f; //HH value transition : I have choice 0.3 radians float chromapro = sres / Sp; diff --git a/rtengine/ipretinex.cc b/rtengine/ipretinex.cc index 06f779875..2dbdbafb1 100644 --- a/rtengine/ipretinex.cc +++ b/rtengine/ipretinex.cc @@ -140,8 +140,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e { if (deh.enabled) {//enabled - float mean, stddv, maxtr, mintr; - float delta; + float maxtr, mintr; constexpr float eps = 2.f; bool useHsl = deh.retinexcolorspace == "HSLLOG"; bool useHslLin = deh.retinexcolorspace == "HSLLIN"; @@ -551,8 +550,8 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e delete [] buffer; delete [] srcBuffer; - mean = 0.f; - stddv = 0.f; + float mean = 0.f; + float stddv = 0.f; // I call mean_stddv2 instead of mean_stddv ==> logBetaGain mean_stddv2( luminance, mean, stddv, W_L, H_L, maxtr, mintr); @@ -658,7 +657,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e maxi = maxtr - epsil; } - delta = maxi - mini; + float delta = maxi - mini; //printf("maxi=%f mini=%f mean=%f std=%f delta=%f maxtr=%f mintr=%f\n", maxi, mini, mean, stddv, delta, maxtr, mintr); if ( !delta ) { @@ -691,7 +690,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e // I call mean_stddv2 instead of mean_stddv ==> logBetaGain mean_stddv2( luminance, mean, stddv, W_L, H_L, maxtr, mintr); - float asig, bsig, amax, bmax, amin, bmin; + float asig = 0.f, bsig = 0.f, amax = 0.f, bmax = 0.f, amin = 0.f, bmin = 0.f; if (dehagaintransmissionCurve && mean != 0.f && stddv != 0.f) { //if curve asig = 0.166666f / stddv; diff --git a/rtengine/processingjob.h b/rtengine/processingjob.h index fbf56234f..0613ccdeb 100644 --- a/rtengine/processingjob.h +++ b/rtengine/processingjob.h @@ -37,7 +37,7 @@ public: : fname(fn), isRaw(iR), initialImage(NULL), pparams(pp) {} ProcessingJobImpl (InitialImage* iImage, const procparams::ProcParams& pp) - : fname(""), initialImage(iImage), pparams(pp) + : fname(""), isRaw(true), initialImage(iImage), pparams(pp) { iImage->increaseRef(); } diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 8f91f8f4b..cb1c2a9c9 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -25,6 +25,7 @@ RawImage::RawImage( const Glib::ustring &name ) , filename(name) , profile_data(NULL) , allocation(NULL) + , rotate_deg(0) { memset(maximum_c4, 0, sizeof(maximum_c4)); RT_matrix_from_constant = 0; diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 31deac244..8c44f8fc4 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -1453,10 +1453,9 @@ void RawImageSource::getFullSize (int& w, int& h, int tr) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void RawImageSource::getSize (int tran, PreviewProps pp, int& w, int& h) +void RawImageSource::getSize (PreviewProps pp, int& w, int& h) { - tran = defTransform (tran); w = pp.w / pp.skip + (pp.w % pp.skip > 0); h = pp.h / pp.skip + (pp.h % pp.skip > 0); } @@ -2123,7 +2122,7 @@ void RawImageSource::retinexPrepareBuffers(ColorManagementParams cmp, RetinexPar #endif for (; j < W - border; j++) { - float H, S, L; + float L; //rgb=>lab Color::rgb2hslfloat(red[i][j], green[i][j], blue[i][j], conversionBuffer[0][i - border][j - border], conversionBuffer[1][i - border][j - border], L); L *= 32768.f; @@ -2296,7 +2295,6 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC float **temp = conversionBuffer[2]; // one less dereference LUTf dLcurve; LUTu hist16RET; - float val; if(dehacontlutili && histLRETI) { hist16RET(32768); @@ -2369,7 +2367,7 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC // hist16RET.compressTo(histLRETI); // also remove declaration and init of dLcurve some lines above then and finally remove this comment :) for (int i = 0; i < 32768; i++) { - val = (double)i / 32767.0; + float val = (double)i / 32767.0; dLcurve[i] = val; } @@ -2393,14 +2391,8 @@ void RawImageSource::retinex(ColorManagementParams cmp, RetinexParams deh, ToneC for (; j < W - border; j++) { - float valp; - // if(chutili) { // c=f(H) - { - valp = float((chcurve->getVal(conversionBuffer[3][i - border][j - border]) - 0.5f)); - - conversionBuffer[1][i - border][j - border] *= (1.f + 2.f * valp); - } - // } + float valp = (chcurve->getVal(conversionBuffer[3][i - border][j - border]) - 0.5f); + conversionBuffer[1][i - border][j - border] *= (1.f + 2.f * valp); } } @@ -2822,7 +2814,7 @@ void RawImageSource::processFlatField(const RAWParams &raw, RawImage *riFlatFile if(raw.ff_AutoClipControl) { // determine maximum calculated value to avoid clipping - int clipControlGui = 0; +// int clipControlGui = 0; float maxval = 0.f; // xtrans files have only one black level actually, so we can simplify the code a bit #ifdef _OPENMP @@ -2857,7 +2849,7 @@ void RawImageSource::processFlatField(const RAWParams &raw, RawImage *riFlatFile // there's only one white level for xtrans if(maxval + black[0] > ri->get_white(0)) { limitFactor = ri->get_white(0) / (maxval + black[0]); - clipControlGui = (1.f - limitFactor) * 100.f; // this value can be used to set the clip control slider in gui +// clipControlGui = (1.f - limitFactor) * 100.f; // this value can be used to set the clip control slider in gui } } else { limitFactor = max((float)(100 - raw.ff_clipControl) / 100.f, 0.01f); @@ -4202,7 +4194,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi for (int col = 0; col < width; col++) { float rgb[ColorCount], cam[2][ColorCount], lab[2][ColorCount], sum[2], chratio, lratio = 0; - float L, C, H, Lfrac; + float L, C, H; // Copy input pixel to rgb so it's easier to access in loops rgb[0] = rin[col]; @@ -4290,7 +4282,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.0f, (maxave - L) / (maxave - desatpt)); + float 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; @@ -4887,11 +4879,11 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vectorgetSensorType() != ST_BAYER) { if(ri->getSensorType() == ST_FUJI_XTRANS) { int d[9][2] = {{0, 0}, { -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; - double rloc, gloc, bloc; - int rnbrs, gnbrs, bnbrs; for (size_t i = 0; i < red.size(); i++) { transformPosition (red[i].x, red[i].y, tran, x, y); + double rloc, gloc, bloc; + int rnbrs, gnbrs, bnbrs; rloc = gloc = bloc = rnbrs = gnbrs = bnbrs = 0; for (int k = 0; k < 9; k++) { @@ -4959,11 +4951,11 @@ ColorTemp RawImageSource::getSpotWB (std::vector &red, std::vectorget_rotateDegree(); diff --git a/rtengine/rawimagesource_i.h b/rtengine/rawimagesource_i.h index f5685b0ef..4e953becb 100644 --- a/rtengine/rawimagesource_i.h +++ b/rtengine/rawimagesource_i.h @@ -140,7 +140,7 @@ inline void RawImageSource::interpolate_row_g (float* agh, float* agv, int i) inline void RawImageSource::interpolate_row_rb (float* ar, float* ab, float* pg, float* cg, float* ng, int i) { - if (ri->ISRED(i, 0) || ri->ISRED(i, 1)) { + if ((ri->ISRED(i, 0) || ri->ISRED(i, 1)) && pg && ng) { // RGRGR or GRGRGR line for (int j = 0; j < W; j++) { if (ri->ISRED(i, j)) { @@ -172,7 +172,7 @@ inline void RawImageSource::interpolate_row_rb (float* ar, float* ab, float* pg, b = cg[j] + b / n; ab[j] = b; - } else { + } else if(ng && pg) { // linear R-G interp. horizontally int r; @@ -199,7 +199,7 @@ inline void RawImageSource::interpolate_row_rb (float* ar, float* ab, float* pg, ab[j] = b; } } - } else { + } else if(ng && pg) { // BGBGB or GBGBGB line for (int j = 0; j < W; j++) { if (ri->ISBLUE(i, j)) { @@ -265,7 +265,7 @@ inline void RawImageSource::interpolate_row_rb (float* ar, float* ab, float* pg, inline void RawImageSource::interpolate_row_rb_mul_pp (float* ar, float* ab, float* pg, float* cg, float* ng, int i, float r_mul, float g_mul, float b_mul, int x1, int width, int skip) { - if (ri->ISRED(i, 0) || ri->ISRED(i, 1)) { + if ((ri->ISRED(i, 0) || ri->ISRED(i, 1)) && pg && ng) { // RGRGR or GRGRGR line for (int j = x1, jx = 0; jx < width; j += skip, jx++) { if (ri->ISRED(i, j)) { @@ -324,7 +324,7 @@ inline void RawImageSource::interpolate_row_rb_mul_pp (float* ar, float* ab, flo ab[jx] = b; } } - } else { + } else if(pg && ng) { // BGBGB or GBGBGB line for (int j = x1, jx = 0; jx < width; j += skip, jx++) { if (ri->ISBLUE(i, j)) { diff --git a/rtengine/rtthumbnail.h b/rtengine/rtthumbnail.h index bc367522d..18e72fc19 100644 --- a/rtengine/rtthumbnail.h +++ b/rtengine/rtthumbnail.h @@ -107,7 +107,7 @@ public: static ImageIO* resizeToSameType(int nw, int nh, TypeInterpolation interp, ImageIO* srcImg) { - ImageIO* imgPtr; + ImageIO* imgPtr = nullptr; if (srcImg->getType() == sImage8) { Image8* castedSrcImg = static_cast(srcImg); diff --git a/rtengine/shmap.cc b/rtengine/shmap.cc index bb8e96c11..65c1070a2 100644 --- a/rtengine/shmap.cc +++ b/rtengine/shmap.cc @@ -30,7 +30,7 @@ namespace rtengine extern const Settings* settings; -SHMap::SHMap (int w, int h, bool multiThread) : W(w), H(h), multiThread(multiThread) +SHMap::SHMap (int w, int h, bool multiThread) : max_f(0.f), min_f(0.f), avg(0.f), W(w), H(h), multiThread(multiThread) { map = new float*[H]; diff --git a/rtengine/stdimagesource.cc b/rtengine/stdimagesource.cc index e422d23b2..3db0d06ac 100644 --- a/rtengine/stdimagesource.cc +++ b/rtengine/stdimagesource.cc @@ -51,7 +51,7 @@ template T** allocArray (int W, int H) } #define HR_SCALE 2 -StdImageSource::StdImageSource () : ImageSource(), img(NULL), plistener(NULL) +StdImageSource::StdImageSource () : ImageSource(), img(NULL), plistener(NULL), full(false), max{}, rgbSourceModified(false) { hrmap[0] = NULL;