diff --git a/rtengine/FTblockDN.cc b/rtengine/FTblockDN.cc index fca26987f..a2929acbb 100644 --- a/rtengine/FTblockDN.cc +++ b/rtengine/FTblockDN.cc @@ -2108,17 +2108,17 @@ float ImProcFunctions::Mad(const float * DataList, const int datalen) } //find median of histogram - int median = 0, count = 0; + int lmedian = 0, count = 0; while (count < datalen / 2) { - count += histo[median]; - ++median; + count += histo[lmedian]; + ++lmedian; } - int count_ = count - histo[median - 1]; + int count_ = count - histo[lmedian - 1]; // interpolate - return (((median - 1) + (datalen / 2 - count_) / (static_cast(count - count_))) / 0.6745f); + return ((lmedian - 1) + (datalen / 2 - count_) / (static_cast(count - count_))) / 0.6745f; } float ImProcFunctions::MadRgb(const float * DataList, const int datalen) @@ -2141,18 +2141,18 @@ float ImProcFunctions::MadRgb(const float * DataList, const int datalen) } //find median of histogram - int median = 0, count = 0; + int lmedian = 0, count = 0; while (count < datalen / 2) { - count += histo[median]; - ++median; + count += histo[lmedian]; + ++lmedian; } - int count_ = count - histo[median - 1]; + int count_ = count - histo[lmedian - 1]; // interpolate delete[] histo; - return (((median - 1) + (datalen / 2 - count_) / (static_cast(count - count_))) / 0.6745f); + return ((lmedian - 1) + (datalen / 2 - count_) / (static_cast(count - count_))) / 0.6745f; } diff --git a/rtengine/ashift_lsd.c b/rtengine/ashift_lsd.c index a884da437..3a0ec5aba 100644 --- a/rtengine/ashift_lsd.c +++ b/rtengine/ashift_lsd.c @@ -1770,10 +1770,10 @@ static void region_grow( int x, int y, image_double angles, struct point * reg, int xx,yy,i; /* check parameters */ - if( x < 0 || y < 0 || x >= (int) angles->xsize || y >= (int) angles->ysize ) - error("region_grow: (x,y) out of the image."); if( angles == NULL || angles->data == NULL ) error("region_grow: invalid image 'angles'."); + if( x < 0 || y < 0 || x >= (int) angles->xsize || y >= (int) angles->ysize ) + error("region_grow: (x,y) out of the image."); if( reg == NULL ) error("region_grow: invalid 'reg'."); if( reg_size == NULL ) error("region_grow: invalid pointer 'reg_size'."); if( reg_angle == NULL ) error("region_grow: invalid pointer 'reg_angle'."); diff --git a/rtengine/color.cc b/rtengine/color.cc index 11668451e..413fb2f90 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -1189,48 +1189,26 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u float koymcp = 0.f; if(setting == "ROYGCBPM-Abs" || setting == "ROYGCBPM-Rel") { - float obM = 0.f; - float ogM = 0.f; - float orM = 0.f; - - float ybM = 0.f; - float yrM = 0.f; - float ygM = 0.f; - - float mgM = 0.f; - float mrM = 0.f; - float mbM = 0.f; - - float pgM = 0.f; - float prM = 0.f; - float pbM = 0.f; - - float crM = 0.f; - float cgM = 0.f; - float cbM = 0.f; - //printf("mixred=%f\n",mixerRed); - float fcompl = 1.f; - if(complement && algo == "SP") { + if (complement && algo == "SP") { fcompl = 3.f; //special - } else if(complement && algo == "LI") { + } else if (complement && algo == "LI") { fcompl = 1.5f; //linear } // ponderate filters: report to R=G=B=33 // I ponder RGB channel, not only orange or yellow or cyan, etc...it's my choice ! - if(mixerOrange != 33) { - if (algo == "SP") { //special - if (mixerOrange >= 33) { - orM = fcompl * (mixerOrange * 0.67f - 22.11f) / 100.f; - } else { - orM = fcompl * (-0.3f * mixerOrange + 9.9f) / 100.f; - } + if (mixerOrange != 33.f) { + float ogM = 0.f; + float orM = 0.f; - if (mixerOrange >= 33) { + if (algo == "SP") { //special + if (mixerOrange > 33.f) { + orM = fcompl * (mixerOrange * 0.67f - 22.11f) / 100.f; ogM = fcompl * (-0.164f * mixerOrange + 5.412f) / 100.f; } else { + orM = fcompl * (-0.3f * mixerOrange + 9.9f) / 100.f; ogM = fcompl * (0.4f * mixerOrange - 13.2f) / 100.f; } } else if (algo == "LI") { //linear @@ -1238,30 +1216,24 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u ogM = fcompl * (0.5f * mixerOrange - 16.5f) / 100.f; } - if(complement) { - obM = (-0.492f * mixerOrange + 16.236f) / 100.f; - } + const float obM = complement ? (-0.492f * mixerOrange + 16.236f) / 100.f : 0.f; - mixerRed += orM; + mixerRed += orM; mixerGreen += ogM; - mixerBlue += obM; + mixerBlue += obM; koymcp += (orM + ogM + obM); - // printf("mixred+ORange=%f\n",mixerRed); - } - if(mixerYellow != 33) { + if (mixerYellow != 33.f) { + float yrM = 0.f; if (algo == "SP") { yrM = fcompl * (-0.134f * mixerYellow + 4.422f) / 100.f; //22.4 } else if (algo == "LI") { yrM = fcompl * (0.5f * mixerYellow - 16.5f) / 100.f; //22.4 } - ygM = fcompl * (0.5f * mixerYellow - 16.5f ) / 100.f; - - if(complement) { - ybM = (-0.492f * mixerYellow + 16.236f) / 100.f; - } + const float ygM = fcompl * (0.5f * mixerYellow - 16.5f ) / 100.f; + const float ybM = complement ? (-0.492f * mixerYellow + 16.236f) / 100.f : 0.f; mixerRed += yrM; mixerGreen += ygM; @@ -1269,17 +1241,15 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u koymcp += (yrM + ygM + ybM); } - if(mixerMagenta != 33) { + if (mixerMagenta != 33.f) { + float mrM = 0.f; + float mbM = 0.f; if (algo == "SP") { - if(mixerMagenta >= 33) { + if (mixerMagenta > 33.f) { mrM = fcompl * ( 0.67f * mixerMagenta - 22.11f) / 100.f; - } else { - mrM = fcompl * (-0.3f * mixerMagenta + 9.9f) / 100.f; - } - - if(mixerMagenta >= 33) { mbM = fcompl * (-0.164f * mixerMagenta + 5.412f) / 100.f; } else { + mrM = fcompl * (-0.3f * mixerMagenta + 9.9f) / 100.f; mbM = fcompl * ( 0.4f * mixerMagenta - 13.2f) / 100.f; } } else if (algo == "LI") { @@ -1287,9 +1257,7 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u mbM = fcompl * (0.5f * mixerMagenta - 16.5f) / 100.f; } - if(complement) { - mgM = (-0.492f * mixerMagenta + 16.236f) / 100.f; - } + const float mgM = complement ? (-0.492f * mixerMagenta + 16.236f) / 100.f : 0.f; mixerRed += mrM; mixerGreen += mgM; @@ -1297,18 +1265,16 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u koymcp += (mrM + mgM + mbM); } - if(mixerPurple != 33) { + if (mixerPurple != 33.f) { + float prM = 0.f; if (algo == "SP") { prM = fcompl * (-0.134f * mixerPurple + 4.422f) / 100.f; } else if (algo == "LI") { prM = fcompl * (0.5f * mixerPurple - 16.5f) / 100.f; } - pbM = fcompl * (0.5f * mixerPurple - 16.5f) / 100.f; - - if(complement) { - pgM = (-0.492f * mixerPurple + 16.236f) / 100.f; - } + const float pbM = fcompl * (0.5f * mixerPurple - 16.5f) / 100.f; + const float pgM = complement ? (-0.492f * mixerPurple + 16.236f) / 100.f : 0.f; mixerRed += prM; mixerGreen += pgM; @@ -1316,18 +1282,16 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u koymcp += (prM + pgM + pbM); } - if(mixerCyan != 33) { + if(mixerCyan != 33.f) { + float cgM = 0.f; if (algo == "SP") { cgM = fcompl * (-0.134f * mixerCyan + 4.422f) / 100.f; } else if (algo == "LI") { cgM = fcompl * (0.5f * mixerCyan - 16.5f) / 100.f; } - cbM = fcompl * (0.5f * mixerCyan - 16.5f) / 100.f; - - if(complement) { - crM = (-0.492f * mixerCyan + 16.236f) / 100.f; - } + const float cbM = fcompl * (0.5f * mixerCyan - 16.5f) / 100.f; + const float crM = complement ? (-0.492f * mixerCyan + 16.236f) / 100.f : 0.f; mixerRed += crM; mixerGreen += cgM; @@ -1347,7 +1311,7 @@ void Color::computeBWMixerConstants (const Glib::ustring &setting, const Glib::u filblue = 1.f; filcor = 1.f; - if (filter == "None") { + if (filter == "None") { filred = 1.f; filgreen = 1.f; filblue = 1.f; @@ -1496,100 +1460,78 @@ void Color::interpolateRGBColor (float realL, float iplow, float iphigh, int alg const float xl, const float yl, const float zl, const float x2, const float y2, const float z2, const double xyz_rgb[3][3], const double rgb_xyz[3][3], float &ro, float &go, float &bo) { - float X1, Y1, Z1, X2, Y2, Z2, X, Y, Z, XL, YL, ZL; - float L1 = 0.f, L2, LL, a_1 = 0.f, b_1 = 0.f, a_2 = 0.f, b_2 = 0.f, a_L, b_L; + float L1 = 0.f, a_1 = 0.f, b_1 = 0.f, a_2 = 0.f, b_2 = 0.f, a_L, b_L; - // converting color 1 to Lab (image) - Color::rgbxyz(r1, g1, b1, X1, Y1, Z1, xyz_rgb); - - if(algm == 1) {//use H interpolate + if (algm == 1) {//use H interpolate + // converting color 1 to Lab (image) + float X1, Y1, Z1; + Color::rgbxyz(r1, g1, b1, X1, Y1, Z1, xyz_rgb); Color::XYZ2Lab(X1, Y1, Z1, L1, a_1, b_1); - //Color::Lab2Lch(a_1, b_1, c_1, h_1) ; } // converting color l lab(low) first color - if(twoc == 0) { // 2 colours - //Color::rgbxyz(rl, gl, bl, XL, YL, ZL, xyz_rgb); - XL = xl; - YL = yl; - ZL = zl; - - if(algm <= 1) {//use H interpolate - Color::XYZ2Lab(XL, YL, ZL, LL, a_L, b_L); + if (twoc == 0) { // 2 colours + if (algm == 1) {//use H interpolate + float unused; + Color::XYZ2Lab(xl, yl, zl, unused, a_L, b_L); } } // converting color 2 to lab (universal or high) - X2 = x2; - Y2 = y2; - Z2 = z2; - - if(algm == 1 ) { - Color::XYZ2Lab(X2, Y2, Z2, L2, a_2, b_2); - //Color::Lab2Lch(a_2, b_2, c_2, h_2) ; + if (algm == 1) { + float unused; + Color::XYZ2Lab(x2, y2, z2, unused, a_2, b_2); } - float cal, calH, calm; - cal = calH = calm = 1.f - chromat; - float med = 1.f; - float medH = 0.f; - - float calan; - calan = chromat; - - float calby; - calby = luma; - - if(twoc == 0) { // 2 colours - calan = chromat; + float cal, calH; + cal = calH = 1.f - chromat; + if (twoc == 0) { // 2 colours //calculate new balance chroma - if (realL > iplow && realL <= med) { - cal = realL * calan / (iplow - med) - med * calan / (iplow - med); + constexpr float med = 1.f; + if (realL > iplow && realL <= med) { + cal = realL * chromat / (iplow - med) - chromat / (iplow - med); } else if (realL <= iplow) { - cal = realL * calan / iplow; + cal = realL * chromat / iplow; } - if (realL > medH && realL <= iphigh) { - calH = realL * calan / (iphigh - medH) - medH * calan / (iphigh - medH); + if (realL > 0.f && realL <= iphigh) { + calH = realL * chromat / iphigh; } else if (realL > iphigh) { - calH = realL * calan; //*(iphigh-1.f) - calan*(iphigh-1.f);//it is better without transition in highlight + calH = realL * chromat; //*(iphigh-1.f) - chromat*(iphigh-1.f);//it is better without transition in highlight } } - float aaH, bbH; - - if(algm <= 1) { - if(twoc == 0 && metchrom == 3) { // 2 colours only with special "ab" - if(algm == 1) { - aaH = a_1 + (a_2 - a_1) * calH; - bbH = b_1 + (b_2 - b_1) * calH; //pass to line after + if (algm <= 1) { + if (twoc == 0 && metchrom == 3) { // 2 colours only with special "ab" + if (algm == 1) { + const float aaH = a_1 + (a_2 - a_1) * calH; + const float bbH = b_1 + (b_2 - b_1) * calH; //pass to line after a_1 = aaH + (a_L - aaH) * cal * balance; b_1 = bbH + (b_L - bbH) * cal * balance; } - } else if(twoc == 1) { - if(metchrom == 0) { + } else if (twoc == 1) { + if (metchrom == 0) { a_1 = a_1 + (a_2 - a_1) * balance; b_1 = b_1 + (b_2 - b_1) * balance; - } else if(metchrom == 1) { - a_1 = a_1 + (a_2 - a_1) * calan * balance; - b_1 = b_1 + (b_2 - b_1) * calan * balance; - } else if(metchrom == 2) { - a_1 = a_1 + (a_2 - a_1) * calan * balance; - b_1 = b_1 + (b_2 - b_1) * calby * balance; + } else if (metchrom == 1) { + a_1 = a_1 + (a_2 - a_1) * chromat * balance; + b_1 = b_1 + (b_2 - b_1) * chromat * balance; + } else if (metchrom == 2) { + a_1 = a_1 + (a_2 - a_1) * chromat * balance; + b_1 = b_1 + (b_2 - b_1) * luma * balance; } } } + float X, Y, Z; Color::Lab2XYZ(L1, a_1, b_1, X, Y, Z); - Color::xyz2rgb(X, Y, Z, ro, go, bo, rgb_xyz);// ro go bo in gamut } void Color::calcGamma (double pwr, double ts, int mode, GammaValues &gamma) { //from Dcraw (D.Coffin) - int i; double g[6], bnd[2] = {0., 0.}; g[0] = pwr; @@ -1598,7 +1540,7 @@ void Color::calcGamma (double pwr, double ts, int mode, GammaValues &gamma) bnd[g[1] >= 1.] = 1.; if (g[1] && (g[1] - 1.) * (g[0] - 1.) <= 0.) { - for (i = 0; i < 99; i++) { + for (int i = 0; i < 99; i++) { g[2] = (bnd[0] + bnd[1]) / 2.; if (g[0]) { @@ -1621,7 +1563,7 @@ void Color::calcGamma (double pwr, double ts, int mode, GammaValues &gamma) g[5] = 1. / (g[1] * SQR(g[3]) / 2. + 1. - g[2] - g[3] - g[2] * g[3] * (log(g[3]) - 1.)) - 1.; } - if (!mode--) { + if (!mode) { gamma[0] = g[0]; gamma[1] = g[1]; gamma[2] = g[2]; @@ -2039,7 +1981,7 @@ void Color::Lch2Luv(float c, float h, float &u, float &v) * columns of the matrix p=xyz_rgb are RGB tristimulus primaries in XYZ * c is the color fixed on the boundary; and m=0 for c=0, m=1 for c=255 */ -void Color::gamutmap(float &X, float &Y, float &Z, const double p[3][3]) +void Color::gamutmap(float &X, float Y, float &Z, const double p[3][3]) { float u = 4 * X / (X + 15 * Y + 3 * Z) - u0; float v = 9 * Y / (X + 15 * Y + 3 * Z) - v0; @@ -2078,15 +2020,11 @@ void Color::gamutmap(float &X, float &Y, float &Z, const double p[3][3]) void Color::skinred ( double J, double h, double sres, double Sp, float dred, float protect_red, int sk, float rstprotection, float ko, double &s) { - 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 deltaHH = 0.3f; //HH value transition : I have choice 0.3 radians + float HH; bool doskin = false; - //rough correspondence between h (JC) and H (lab) that has relatively little importance because transitions that blur the correspondence is not linear - if ((float)h > 8.6f && (float)h <= 74.f ) { + if ((float)h > 8.6f && (float)h <= 74.f ) { HH = (1.15f / 65.4f) * (float)h - 0.0012f; //H > 0.15 H<1.3 doskin = true; } else if((float)h > 0.f && (float)h <= 8.6f ) { @@ -2101,6 +2039,9 @@ void Color::skinred ( double J, double h, double sres, double Sp, float dred, fl } if(doskin) { + float scale = 100.0f / 100.1f; //reduction in normal zone + float scaleext = 1.0f; //reduction in transition zone + float factorskin; float chromapro = sres / Sp; if(sk == 1) { //in C mode to adapt dred to J @@ -2117,12 +2058,14 @@ void Color::skinred ( double J, double h, double sres, double Sp, float dred, fl } } - if(chromapro > 0.0) { + constexpr float deltaHH = 0.3f; //HH value transition : I have choice 0.3 radians + if(chromapro > 0.f) { Color::scalered ( rstprotection, chromapro, 0.0, HH, deltaHH, scale, scaleext); //Scale factor } - if(chromapro > 1.0) { - interm = (chromapro - 1.0f) * 100.0f; + float factorskinext; + if(chromapro > 1.f) { + const float interm = (chromapro - 1.0f) * 100.0f; factorskin = 1.0f + (interm * scale) / 100.0f; factorskinext = 1.0f + (interm * scaleext) / 100.0f; } else { @@ -2130,9 +2073,8 @@ void Color::skinred ( double J, double h, double sres, double Sp, float dred, fl factorskinext = chromapro ; } - factorsat = chromapro; - factor = factorsat; - Color::transitred ( HH, s, dred, factorskin, protect_red, factorskinext, deltaHH, factorsat, factor); //transition + float factor = chromapro; + Color::transitred ( HH, s, dred, factorskin, protect_red, factorskinext, deltaHH, chromapro, factor); //transition s *= factor; } else { s = ko * sres; @@ -2262,32 +2204,21 @@ void Color::transitred (const float HH, float const Chprov1, const float dred, c void Color::AllMunsellLch(bool lumaMuns, float Lprov1, float Loldd, float HH, float Chprov1, float CC, float &correctionHuechroma, float &correctlum) { - bool contin1, contin2; - float correctionHue = 0.0, correctionHueLum = 0.0; - bool correctL; + if (CC >= 6.f && CC < 140.f) { //if C > 140 we say C=140 (only in Prophoto ...with very large saturation) + constexpr float huelimit[8] = { -2.48f, -0.55f, 0.44f, 1.52f, 1.87f, 3.09f, -0.27f, 0.44f}; //limits hue of blue-purple, red-yellow, green-yellow, red-purple - if(CC >= 6.0 && CC < 140) { //if C > 140 we say C=140 (only in Prophoto ...with very large saturation) - static const float huelimit[8] = { -2.48, -0.55, 0.44, 1.52, 1.87, 3.09, -0.27, 0.44}; //limits hue of blue-purple, red-yellow, green-yellow, red-purple + Chprov1 = rtengine::LIM(Chprov1, 6.f, 140.f); - if (Chprov1 > 140.f) { - Chprov1 = 139.f; //limits of LUTf - } - - if (Chprov1 < 6.f) { - Chprov1 = 6.f; - } - - for(int zo = 1; zo <= 4; zo++) { - if(HH > huelimit[2 * zo - 2] && HH < huelimit[2 * zo - 1]) { - //zone=zo; - contin1 = contin2 = false; - correctL = false; + for (int zo = 1; zo <= 4; ++zo) { + if (HH > huelimit[2 * zo - 2] && HH < huelimit[2 * zo - 1]) { + bool correctL = false; + float correctionHue = 0.f, correctionHueLum = 0.f; MunsellLch (Lprov1, HH, Chprov1, CC, correctionHue, zo, correctionHueLum, correctL); //munsell chroma correction correctionHuechroma = correctionHue; //preserve if(lumaMuns) { + bool contin1 = false; float correctlumprov = 0.f; - float correctlumprov2 = 0.f; if(correctL) { //for Munsell luminance correction @@ -2296,26 +2227,19 @@ void Color::AllMunsellLch(bool lumaMuns, float Lprov1, float Loldd, float HH, fl correctL = false; } - correctionHueLum = 0.0; - correctionHue = 0.0; - - if(fabs(Lprov1 - Loldd) > 6.0) { + if (std::fabs(Lprov1 - Loldd) > 6.f) { + correctionHueLum = 0.f; + correctionHue = 0.f; // correction if delta L significative..Munsell luminance MunsellLch (Loldd, HH, Chprov1, Chprov1, correctionHue, zo, correctionHueLum, correctL); - if(correctL) { - correctlumprov2 = correctionHueLum; - contin2 = true; - correctL = false; - } - - correctionHueLum = 0.0; - - if(contin1 && contin2) { - correctlum = correctlumprov2 - correctlumprov; + if(contin1) { + correctlum = correctionHueLum - correctlumprov; + } } } } + break; } } } @@ -2337,9 +2261,6 @@ void Color::AllMunsellLch(bool lumaMuns, float Lprov1, float Loldd, float HH, fl void Color::AllMunsellLch(float Lprov1, float HH, float Chprov1, float CC, float &correctionHuechroma) { - float correctionHue = 0.f, correctionHueLum = 0.f; - bool correctL; - if(CC >= 6.f && CC < 140.f) { //if C > 140 we say C=140 (only in Prophoto ...with very large saturation) static const float huelimit[8] = { -2.48f, -0.55f, 0.44f, 1.52f, 1.87f, 3.09f, -0.27f, 0.44f}; //limits hue of blue-purple, red-yellow, green-yellow, red-purple @@ -2352,7 +2273,8 @@ void Color::AllMunsellLch(float Lprov1, float HH, float Chprov1, float CC, float for(int zo = 1; zo <= 4; zo++) { if(HH > huelimit[2 * zo - 2] && HH < huelimit[2 * zo - 1]) { //zone=zo; - correctL = false; + float correctionHue = 0.f, correctionHueLum = 0.f; + bool correctL = false; MunsellLch (Lprov1, HH, Chprov1, CC, correctionHue, zo, correctionHueLum, correctL); //munsell chroma correction correctionHuechroma = correctionHue; //preserve break; @@ -2761,8 +2683,6 @@ void Color::gamutLchonly (float2 sincosval, float &Lprov1, float &Chprov1, const */ void Color::LabGamutMunsell(float *labL, float *laba, float *labb, const int N, bool corMunsell, bool lumaMuns, bool isHLEnabled, bool gamut, const double wip[3][3]) { - float correctlum = 0.f; - float correctionHuechroma = 0.f; #ifdef __SSE2__ // precalculate H and C using SSE float HHBuffer[N]; @@ -2815,8 +2735,8 @@ void Color::LabGamutMunsell(float *labL, float *laba, float *labb, const int N, } labL[j] = Lprov1 * 327.68f; - correctionHuechroma = 0.f; - correctlum = 0.f; + float correctionHuechroma = 0.f; + float correctlum = 0.f; if(corMunsell) AllMunsellLch(lumaMuns, Lprov1, Loldd, HH, Chprov1, Coldd, correctionHuechroma, correctlum); diff --git a/rtengine/color.h b/rtengine/color.h index 55ef52e36..91c0c7a59 100644 --- a/rtengine/color.h +++ b/rtengine/color.h @@ -1805,7 +1805,7 @@ public: * @param Z Z channel input value and corrected output value [0 ; 65535] * @param p working profile */ - static void gamutmap(float &X, float &Y, float &Z, const double p[3][3]); + static void gamutmap(float &X, float Y, float &Z, const double p[3][3]); /** diff --git a/rtengine/imagefloat.h b/rtengine/imagefloat.h index cd08daf70..c7000d4b8 100644 --- a/rtengine/imagefloat.h +++ b/rtengine/imagefloat.h @@ -109,35 +109,35 @@ public: } tmp; tmp.f = f; - int32_t sign = (tmp.i >> 16) & 0x00008000; + const int32_t lsign = (tmp.i >> 16) & 0x00008000; int32_t exponent = ((tmp.i >> 23) & 0x000000ff) - (127 - 15); - int32_t mantissa = tmp.i & 0x007fffff; + int32_t mantissa = tmp.i & 0x007fffff; if (exponent <= 0) { if (exponent < -10) { - return (uint16_t)sign; + return (uint16_t)lsign; } mantissa = (mantissa | 0x00800000) >> (1 - exponent); if (mantissa & 0x00001000) mantissa += 0x00002000; - return (uint16_t)(sign | (mantissa >> 13)); + return (uint16_t)(lsign | (mantissa >> 13)); } else if (exponent == 0xff - (127 - 15)) { if (mantissa == 0) { - return (uint16_t)(sign | 0x7c00); + return (uint16_t)(lsign | 0x7c00); } else { - return (uint16_t)(sign | 0x7c00 | (mantissa >> 13)); + return (uint16_t)(lsign | 0x7c00 | (mantissa >> 13)); } } if (mantissa & 0x00001000) { mantissa += 0x00002000; if (mantissa & 0x00800000) { - mantissa = 0; // overflow in significand, + mantissa = 0; // overflow in significand, exponent += 1; // adjust exponent } } if (exponent > 30) { - return (uint16_t)(sign | 0x7c00); // infinity with the same sign as f. + return (uint16_t)(lsign | 0x7c00); // infinity with the same sign as f. } - return (uint16_t)(sign | (exponent << 10) | (mantissa >> 13)); + return (uint16_t)(lsign | (exponent << 10) | (mantissa >> 13)); } // From DNG SDK dng_utils.h @@ -148,13 +148,13 @@ public: uint32_t i; } tmp; - int32_t sign = (halfValue >> 15) & 0x00000001; + const int32_t lsign = (halfValue >> 15) & 0x00000001; int32_t exponent = (halfValue >> 10) & 0x0000001f; - int32_t mantissa = halfValue & 0x000003ff; + int32_t mantissa = halfValue & 0x000003ff; if (exponent == 0) { if (mantissa == 0) { // Plus or minus zero - tmp.i = (uint32_t) (sign << 31); + tmp.i = (uint32_t) (lsign << 31); return tmp.f; } else { // Denormalized number -- renormalize it @@ -168,7 +168,7 @@ public: } else if (exponent == 31) { if (mantissa == 0) { // Positive or negative infinity, convert to maximum (16 bit) values. - tmp.i = (uint32_t)((sign << 31) | ((0x1eL + 127 - 15) << 23) | (0x3ffL << 13)); + tmp.i = (uint32_t)((lsign << 31) | ((0x1eL + 127 - 15) << 23) | (0x3ffL << 13)); return tmp.f; } else { // Nan -- Just set to zero. @@ -179,32 +179,32 @@ public: exponent += (127 - 15); mantissa <<= 13; // Assemble sign, exponent and mantissa. - tmp.i = (uint32_t) ((sign << 31) | (exponent << 23) | mantissa); + tmp.i = (uint32_t) ((lsign << 31) | (exponent << 23) | mantissa); return tmp.f; } inline uint32_t DNG_FP24ToFloat(const uint8_t * input) { - int32_t sign = (input [0] >> 7) & 0x01; - int32_t exponent = (input [0] ) & 0x7F; - int32_t mantissa = (((int32_t) input [1]) << 8) | input[2]; + const int32_t lsign = (input[0] >> 7) & 0x01; + int32_t exponent = input[0] & 0x7F; + int32_t mantissa = (((int32_t) input[1]) << 8) | input[2]; if (exponent == 0) { if (mantissa == 0) { // Plus or minus zero - return (uint32_t) (sign << 31); + return (uint32_t) (lsign << 31); } else { // Denormalized number -- renormalize it while (!(mantissa & 0x00010000)) { - mantissa <<= 1; - exponent -= 1; - } - exponent += 1; - mantissa &= ~0x00010000; + mantissa <<= 1; + exponent -= 1; + } + exponent += 1; + mantissa &= ~0x00010000; } } else if (exponent == 127) { if (mantissa == 0) { // Positive or negative infinity, convert to maximum (24 bit) values. - return (uint32_t) ((sign << 31) | ((0x7eL + 128 - 64) << 23) | (0xffffL << 7)); + return (uint32_t) ((lsign << 31) | ((0x7eL + 128 - 64) << 23) | (0xffffL << 7)); } else { // Nan -- Just set to zero. return 0; @@ -214,7 +214,7 @@ public: exponent += (128 - 64); mantissa <<= 7; // Assemble sign, exponent and mantissa. - return (uint32_t) ((sign << 31) | (exponent << 23) | mantissa); + return (uint32_t) ((lsign << 31) | (exponent << 23) | mantissa); } void normalizeFloat(float srcMinVal, float srcMaxVal) override;