From 22fb7444c4f0877596d2c386e9dd43d2b0eab341 Mon Sep 17 00:00:00 2001 From: lordnn Date: Sun, 22 Mar 2026 21:35:30 +0300 Subject: [PATCH 1/5] Some C++20 format functions. --- Source/FreeImage/Plugin.cpp | 5 ++--- Source/Metadata/FIRational.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/FreeImage/Plugin.cpp b/Source/FreeImage/Plugin.cpp index 5eedf41..d8901be 100644 --- a/Source/FreeImage/Plugin.cpp +++ b/Source/FreeImage/Plugin.cpp @@ -34,6 +34,7 @@ #else #include #endif // _WIN32 +#include #include @@ -787,9 +788,7 @@ namespace { std::filesystem::path MakeRandomSuffix() { - std::stringstream strs{}; - strs << ".fitmp" << std::hex << static_cast(std::rand()); - return strs.str(); + return std::format(".fitmp{:x}", static_cast(std::rand())); } diff --git a/Source/Metadata/FIRational.cpp b/Source/Metadata/FIRational.cpp index a5f6c83..d1862ec 100644 --- a/Source/Metadata/FIRational.cpp +++ b/Source/Metadata/FIRational.cpp @@ -19,6 +19,7 @@ // Use at your own risk! // ========================================================== +#include #include "FreeImage.h" #include "Utilities.h" #include "FIRational.h" @@ -164,11 +165,11 @@ FIBOOL FIRational::isInteger() { /// Convert as "numerator/denominator" std::string FIRational::toString() { - std::ostringstream s; + std::string s; if (isInteger()) { - s << intValue(); + s = std::to_string(intValue()); } else { - s << _numerator << "/" << _denominator; + s = std::format("{}/{}", _numerator, _denominator); } - return s.str(); + return s; } From 72cca5672c0513bbe85d8adaddb817cd8e92cb26 Mon Sep 17 00:00:00 2001 From: lordnn Date: Sun, 22 Mar 2026 21:36:21 +0300 Subject: [PATCH 2/5] Minor cleanup. --- Source/Plugins/PluginTIFF.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Plugins/PluginTIFF.cpp b/Source/Plugins/PluginTIFF.cpp index 83e77a2..4c4295d 100644 --- a/Source/Plugins/PluginTIFF.cpp +++ b/Source/Plugins/PluginTIFF.cpp @@ -49,6 +49,7 @@ #include "../Metadata/FreeImageTag.h" #include "FreeImageIO.h" #include "PSDParser.h" +#include "yato/types.h" // -------------------------------------------------------------------------- // GeoTIFF profile (see XTIFF.cpp) @@ -1314,7 +1315,7 @@ template static void DecodeMonoStrip(const uint8_t *buf, const tms for (uint32_t l{}; l < strips; ++l) { uint8_t poffset{ offset }; const uint8_t *src_pixel = buf; - auto *dst_pixel = reinterpret_cast
(dst_line_begin); + auto *dst_pixel = yato::pointer_cast(dst_line_begin); uint32_t t{}, i{}; uint16_t stored_bits{}; while (i < dst_line) { @@ -1342,8 +1343,8 @@ template static void DecodeStrip(const uint const uint32_t bits_mask = (static_cast(1) << bitspersample) - 1; for (uint32_t l{}; l < strips; ++l) { - const auto* src_pixel = reinterpret_cast(buf); - auto *dst_pixel = reinterpret_cast(dst_line_begin) + sample; + const auto* src_pixel = yato::pointer_cast(buf); + auto *dst_pixel = yato::pointer_cast(dst_line_begin) + sample; uint32_t t{}, i{}; uint16_t stored_bits{}; while (i < dst_line) { @@ -1548,7 +1549,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // --------------------------------------------------------------------------------- // create a new 8-bit DIB - dib.reset(CreateImageType(header_only, image_type, width, height, bitspersample, MIN(2, samplesperpixel))); + dib.reset(CreateImageType(header_only, image_type, width, height, bitspersample, std::min(2, samplesperpixel))); if (!dib) { throw FI_MSG_ERROR_DIB_MEMORY; } @@ -2258,11 +2259,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { half half_value; - for (uint32_t l = 0; l < nrow; l++) { - uint16_t *src_pixel = (uint16_t*)(buf.get() + l * src_line); - float *dst_pixel = (float*)bits; + for (uint32_t l = 0; l < nrow; ++l) { + const uint16_t *src_pixel = yato::pointer_cast(buf.get() + l * src_line); + float *dst_pixel = yato::pointer_cast(bits); - for (tmsize_t x = 0; x < (tmsize_t)(src_line / sizeof(uint16_t)); x++) { + for (tmsize_t x = 0; x < (tmsize_t)(src_line / sizeof(uint16_t)); ++x) { half_value.setBits(src_pixel[x]); dst_pixel[x] = half_value; } From cb3a5bec0882141244feff2d48cdc67caac07afe Mon Sep 17 00:00:00 2001 From: lordnn Date: Sun, 22 Mar 2026 22:34:35 +0300 Subject: [PATCH 3/5] More std::min/max/clamp. --- Source/FreeImage/BitmapAccess.cpp | 2 +- Source/FreeImage/Conversion.cpp | 12 ++++++------ Source/FreeImage/ConversionFloat.cpp | 4 ++-- Source/FreeImage/ConversionRGBAF.cpp | 8 ++++---- Source/FreeImage/ConversionRGBF.cpp | 10 +++++----- Source/FreeImage/ConversionType.cpp | 2 +- Source/FreeImage/MNGHelper.cpp | 2 +- Source/FreeImage/tmoColorConvert.cpp | 2 +- Source/FreeImage/tmoFattal02.cpp | 6 +++--- Source/FreeImageToolkit/BSplineRotate.cpp | 2 +- Source/FreeImageToolkit/Background.cpp | 4 ++-- Source/FreeImageToolkit/ClassicRotate.cpp | 8 ++++---- Source/FreeImageToolkit/Colors.cpp | 10 +++++----- Source/FreeImageToolkit/JPEGTransform.cpp | 8 ++++---- Source/FreeImageToolkit/MultigridPoissonSolver.cpp | 4 ++-- Source/FreeImageToolkit/Resize.cpp | 6 +++--- Source/Metadata/TagConversion.cpp | 4 ++-- Source/Plugins/PSDParser.cpp | 2 +- Source/Plugins/PluginBMP.cpp | 8 ++++---- Source/Plugins/PluginEXR.cpp | 2 +- Source/Plugins/PluginIFF.cpp | 2 +- Source/Plugins/PluginJPEG.cpp | 12 ++++++------ Source/Plugins/PluginPCX.cpp | 2 +- Source/Plugins/PluginPNG.cpp | 4 ++-- Source/Plugins/PluginTARGA.cpp | 6 +++--- Source/Plugins/PluginWebP.cpp | 2 +- 26 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Source/FreeImage/BitmapAccess.cpp b/Source/FreeImage/BitmapAccess.cpp index a81a31f..9650b8c 100644 --- a/Source/FreeImage/BitmapAccess.cpp +++ b/Source/FreeImage/BitmapAccess.cpp @@ -1023,7 +1023,7 @@ FreeImage_GetTransparencyCount(FIBITMAP *dib) { void DLL_CALLCONV FreeImage_SetTransparencyTable(FIBITMAP *dib, uint8_t *table, int count) { if (dib) { - count = MAX(0, MIN(count, 256)); + count = std::clamp(count, 0, 256); if (FreeImage_GetBPP(dib) <= 8) { ((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE; ((FREEIMAGEHEADER *)dib->data)->transparency_count = count; diff --git a/Source/FreeImage/Conversion.cpp b/Source/FreeImage/Conversion.cpp index 76d7768..1be0c81 100644 --- a/Source/FreeImage/Conversion.cpp +++ b/Source/FreeImage/Conversion.cpp @@ -123,9 +123,9 @@ CMYKToRGB(T C, T M, T Y, T K, T* out) { unsigned b = (max_val - Y) * (max_val - K) / max_val; // clamp values to [0..max_val] - T red = (T)CLAMP(r, (unsigned)0, max_val); - T green = (T)CLAMP(g, (unsigned)0, max_val); - T blue = (T)CLAMP(b, (unsigned)0, max_val); + T red = (T)std::clamp(r, (unsigned)0, max_val); + T green = (T)std::clamp(g, (unsigned)0, max_val); + T blue = (T)std::clamp(b, (unsigned)0, max_val); assignRGB(red, green, blue, out); } @@ -276,9 +276,9 @@ CIELabToRGB(float L, float a, float b, T *rgb) { XYZToRGB(X, Y, Z, &R, &G, &B); // clamp values to [0..max_val] - T red = (T)CLAMP(R * max_val, 0.0F, max_val); - T green = (T)CLAMP(G * max_val, 0.0F, max_val); - T blue = (T)CLAMP(B * max_val, 0.0F, max_val); + T red = (T)std::clamp(R * max_val, 0.0F, max_val); + T green = (T)std::clamp(G * max_val, 0.0F, max_val); + T blue = (T)std::clamp(B * max_val, 0.0F, max_val); assignRGB(red, green, blue, rgb); } diff --git a/Source/FreeImage/ConversionFloat.cpp b/Source/FreeImage/ConversionFloat.cpp index 1b5d3fa..3da5fd6 100644 --- a/Source/FreeImage/ConversionFloat.cpp +++ b/Source/FreeImage/ConversionFloat.cpp @@ -185,7 +185,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) { case FIT_RGBF: if (scale_linear) { BitmapTransform(dst, src, [](const FIRGBF& p) { - return CLAMP(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); + return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); } else { BitmapTransform(dst, src, [](const FIRGBF& p) { @@ -196,7 +196,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) { case FIT_RGBAF: if (scale_linear) { BitmapTransform(dst, src, [](const FIRGBAF& p) { - return CLAMP(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); + return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); } else { BitmapTransform(dst, src, [](const FIRGBAF& p) { diff --git a/Source/FreeImage/ConversionRGBAF.cpp b/Source/FreeImage/ConversionRGBAF.cpp index 2f2ee00..d38c13b 100644 --- a/Source/FreeImage/ConversionRGBAF.cpp +++ b/Source/FreeImage/ConversionRGBAF.cpp @@ -258,7 +258,7 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert by copying greyscale channel to each R, G, B channels // assume float values are in [0..1] - const float value = CLAMP(src_pixel[x], 0.0F, 1.0F); + const float value = std::clamp(src_pixel[x], 0.0F, 1.0F); dst_pixel[x].red = value; dst_pixel[x].green = value; dst_pixel[x].blue = value; @@ -281,9 +281,9 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert pixels directly, while adding a "dummy" alpha of 1.0 - dst_pixel[x].red = CLAMP(src_pixel[x].red, 0.0F, 1.0F); - dst_pixel[x].green = CLAMP(src_pixel[x].green, 0.0F, 1.0F); - dst_pixel[x].blue = CLAMP(src_pixel[x].blue, 0.0F, 1.0F); + dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F); + dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F); + dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F); dst_pixel[x].alpha = 1.0F; } src_bits += src_pitch; diff --git a/Source/FreeImage/ConversionRGBF.cpp b/Source/FreeImage/ConversionRGBF.cpp index 5594cb2..df36da6 100644 --- a/Source/FreeImage/ConversionRGBF.cpp +++ b/Source/FreeImage/ConversionRGBF.cpp @@ -255,7 +255,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert by copying greyscale channel to each R, G, B channels // assume float values are in [0..1] - const float value = CLAMP(src_pixel[x], 0.0F, 1.0F); + const float value = std::clamp(src_pixel[x], 0.0F, 1.0F); dst_pixel[x].red = value; dst_pixel[x].green = value; dst_pixel[x].blue = value; @@ -278,7 +278,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert by copying greyscale channel to each R, G, B channels // assume float values are in [0..1] - const float value = static_cast(CLAMP(src_pixel[x], 0.0, 1.0)); + const float value = static_cast(std::clamp(src_pixel[x], 0.0, 1.0)); dst_pixel[x].red = value; dst_pixel[x].green = value; dst_pixel[x].blue = value; @@ -300,9 +300,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and skip alpha channel - dst_pixel[x].red = CLAMP(src_pixel[x].red, 0.0F, 1.0F); - dst_pixel[x].green = CLAMP(src_pixel[x].green, 0.0F, 1.0F); - dst_pixel[x].blue = CLAMP(src_pixel[x].blue, 0.0F, 1.0F); + dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F); + dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F); + dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F); } src_bits += src_pitch; dst_bits += dst_pitch; diff --git a/Source/FreeImage/ConversionType.cpp b/Source/FreeImage/ConversionType.cpp index 6f975a4..df7e0ca 100644 --- a/Source/FreeImage/ConversionType.cpp +++ b/Source/FreeImage/ConversionType.cpp @@ -134,7 +134,7 @@ CONVERT_TO_BYTE::convert(FIBITMAP *src, FIBOOL scale_linear) { for (x = 0; x < width; x++) { // rounding int q = int(src_bits[x] + 0.5); - dst_bits[x] = (uint8_t) MIN(255, MAX(0, q)); + dst_bits[x] = (uint8_t) std::clamp(q, 0, 255); } } } diff --git a/Source/FreeImage/MNGHelper.cpp b/Source/FreeImage/MNGHelper.cpp index da10b51..f2e5662 100644 --- a/Source/FreeImage/MNGHelper.cpp +++ b/Source/FreeImage/MNGHelper.cpp @@ -1206,7 +1206,7 @@ mng_WriteJNG(int format_id, FreeImageIO *io, FIBITMAP *dib, fi_handle handle, in // write chunks for (uint32_t k = 0; k < size_in_bytes;) { uint32_t bytes_left = size_in_bytes - k; - uint32_t chunk_size = MIN(JPEG_CHUNK_SIZE, bytes_left); + uint32_t chunk_size = std::min(JPEG_CHUNK_SIZE, bytes_left); mng_WriteChunk(mng_JDAT, &jpeg_data[k], chunk_size, hJngMemory); k += chunk_size; } diff --git a/Source/FreeImage/tmoColorConvert.cpp b/Source/FreeImage/tmoColorConvert.cpp index 6a06315..df89c18 100644 --- a/Source/FreeImage/tmoColorConvert.cpp +++ b/Source/FreeImage/tmoColorConvert.cpp @@ -243,7 +243,7 @@ LuminanceFromYxy(FIBITMAP *Yxy, float *maxLum, float *minLum, float *worldLum) { for (unsigned y = 0; y < height; y++) { auto *pixel = (const FIRGBF*)bits; for (unsigned x = 0; x < width; x++) { - const float Y = MAX(0.0F, pixel[x].red);// avoid negative values + const float Y = std::max(0.0F, pixel[x].red);// avoid negative values max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper diff --git a/Source/FreeImage/tmoFattal02.cpp b/Source/FreeImage/tmoFattal02.cpp index 243760c..44210f9 100644 --- a/Source/FreeImage/tmoFattal02.cpp +++ b/Source/FreeImage/tmoFattal02.cpp @@ -513,7 +513,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) { // get the number of levels for the pyramid const unsigned width = FreeImage_GetWidth(H); const unsigned height = FreeImage_GetHeight(H); - unsigned minsize = MIN(width, height); + unsigned minsize = std::min(width, height); while (minsize >= MIN_PYRAMID_SIZE) { nlevels++; minsize /= 2; @@ -607,8 +607,8 @@ Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and con FIBITMAP* DLL_CALLCONV FreeImage_TmoFattal02(FIBITMAP *dib, double color_saturation, double attenuation) { const float alpha = 0.1F; // parameter alpha = 0.1 - const float beta = (float)MAX(0.8, MIN(0.9, attenuation)); // parameter beta = [0.8..0.9] - const float s = (float)MAX(0.4, MIN(0.6, color_saturation));// exponent s controls color saturation = [0.4..0.6] + const float beta = (float)std::clamp(attenuation, 0.8, 0.9); // parameter beta = [0.8..0.9] + const float s = (float)std::clamp(color_saturation, 0.4, 0.6);// exponent s controls color saturation = [0.4..0.6] FIBITMAP *src{}; FIBITMAP *Yin{}; diff --git a/Source/FreeImageToolkit/BSplineRotate.cpp b/Source/FreeImageToolkit/BSplineRotate.cpp index a69a190..8c08b86 100644 --- a/Source/FreeImageToolkit/BSplineRotate.cpp +++ b/Source/FreeImageToolkit/BSplineRotate.cpp @@ -624,7 +624,7 @@ Rotate8Bit(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x p = (double)InterpolatedValue(ImageRasterArray, width, height, x1, y1, spline); } // clamp and convert to uint8_t - dst_bits[x] = (uint8_t)MIN(MAX((int)0, (int)(p + 0.5)), (int)255); + dst_bits[x] = (uint8_t)std::clamp((int)(p + 0.5), 0, 255); } } diff --git a/Source/FreeImageToolkit/Background.cpp b/Source/FreeImageToolkit/Background.cpp index 0b490f5..aedd6cd 100644 --- a/Source/FreeImageToolkit/Background.cpp +++ b/Source/FreeImageToolkit/Background.cpp @@ -853,8 +853,8 @@ FreeImage_EnlargeCanvas(FIBITMAP *src, int left, int top, int right, int bottom, unsigned srcPitch = FreeImage_GetPitch(src); unsigned dstPitch = FreeImage_GetPitch(dst); - int lineWidth = bytespp * (width + MIN(0, left) + MIN(0, right)); - int lines = height + MIN(0, top) + MIN(0, bottom); + int lineWidth = bytespp * (width + std::min(0, left) + std::min(0, right)); + int lines = height + std::min(0, top) + std::min(0, bottom); if (left <= 0) { srcPtr += (-left * bytespp); diff --git a/Source/FreeImageToolkit/ClassicRotate.cpp b/Source/FreeImageToolkit/ClassicRotate.cpp index fa9eda4..b7c7190 100644 --- a/Source/FreeImageToolkit/ClassicRotate.cpp +++ b/Source/FreeImageToolkit/ClassicRotate.cpp @@ -388,13 +388,13 @@ Rotate90(FIBITMAP *src) { for (unsigned xs = 0; xs < dst_width; xs += RBLOCK) { // y-segment for (unsigned ys = 0; ys < dst_height; ys += RBLOCK) { - for (unsigned y = ys; y < MIN(dst_height, ys + RBLOCK); y++) { // do rotation + for (unsigned y = ys; y < std::min(dst_height, ys + RBLOCK); y++) { // do rotation const unsigned y2 = dst_height - y - 1; // point to src pixel at (y2, xs) const uint8_t *src_bits = bsrc + (xs * src_pitch) + (y2 * bytespp); // point to dst pixel at (xs, y) uint8_t *dst_bits = bdest + (y * dst_pitch) + (xs * bytespp); - for (unsigned x = xs; x < MIN(dst_width, xs + RBLOCK); x++) { + for (unsigned x = xs; x < std::min(dst_width, xs + RBLOCK); x++) { // dst.SetPixel(x, y, src.GetPixel(y2, x)); AssignPixel(dst_bits, src_bits, bytespp); dst_bits += bytespp; @@ -580,13 +580,13 @@ Rotate270(FIBITMAP *src) { for (unsigned xs = 0; xs < dst_width; xs += RBLOCK) { // y-segment for (unsigned ys = 0; ys < dst_height; ys += RBLOCK) { - for (unsigned x = xs; x < MIN(dst_width, xs + RBLOCK); x++) { // do rotation + for (unsigned x = xs; x < std::min(dst_width, xs + RBLOCK); x++) { // do rotation x2 = dst_width - x - 1; // point to src pixel at (ys, x2) const uint8_t *src_bits = bsrc + (x2 * src_pitch) + (ys * bytespp); // point to dst pixel at (x, ys) uint8_t *dst_bits = bdest + (ys * dst_pitch) + (x * bytespp); - for (unsigned y = ys; y < MIN(dst_height, ys + RBLOCK); y++) { + for (unsigned y = ys; y < std::min(dst_height, ys + RBLOCK); y++) { // dst.SetPixel(x, y, src.GetPixel(y, x2)); AssignPixel(dst_bits, src_bits, bytespp); src_bits += bytespp; diff --git a/Source/FreeImageToolkit/Colors.cpp b/Source/FreeImageToolkit/Colors.cpp index 0d99078..d102bed 100644 --- a/Source/FreeImageToolkit/Colors.cpp +++ b/Source/FreeImageToolkit/Colors.cpp @@ -312,7 +312,7 @@ FreeImage_AdjustBrightness(FIBITMAP *src, double percentage) { const double scale = (100 + percentage) / 100; for (int i = 0; i < 256; i++) { value = i * scale; - value = MAX(0.0, MIN(value, 255.0)); + value = std::clamp(value, 0.0, 255.0); LUT[i] = (uint8_t)floor(value + 0.5); } return FreeImage_AdjustCurve(src, LUT, FICC_RGB); @@ -338,7 +338,7 @@ FreeImage_AdjustContrast(FIBITMAP *src, double percentage) { const double scale = (100 + percentage) / 100; for (int i = 0; i < 256; i++) { value = 128 + (i - 128) * scale; - value = MAX(0.0, MIN(value, 255.0)); + value = std::clamp(value, 0.0, 255.0); LUT[i] = (uint8_t)floor(value + 0.5); } return FreeImage_AdjustCurve(src, LUT, FICC_RGB); @@ -1019,7 +1019,7 @@ FreeImage_GetAdjustColorsLookupTable(uint8_t *LUT, double brightness, double con const double v = (100.0 + contrast) / 100.0; for (int i = 0; i < 256; i++) { value = 128 + (dblLUT[i] - 128) * v; - dblLUT[i] = MAX(0.0, MIN(value, 255.0)); + dblLUT[i] = std::clamp(value, 0.0, 255.0); } result++; } @@ -1029,7 +1029,7 @@ FreeImage_GetAdjustColorsLookupTable(uint8_t *LUT, double brightness, double con const double v = (100.0 + brightness) / 100.0; for (int i = 0; i < 256; i++) { value = dblLUT[i] * v; - dblLUT[i] = MAX(0.0, MIN(value, 255.0)); + dblLUT[i] = std::clamp(value, 0.0, 255.0); } result++; } @@ -1040,7 +1040,7 @@ FreeImage_GetAdjustColorsLookupTable(uint8_t *LUT, double brightness, double con const double v = 255.0 * (double)pow((double)255, -exponent); for (int i = 0; i < 256; i++) { value = pow(dblLUT[i], exponent) * v; - dblLUT[i] = MAX(0.0, MIN(value, 255.0)); + dblLUT[i] = std::clamp(value, 0.0, 255.0); } result++; } diff --git a/Source/FreeImageToolkit/JPEGTransform.cpp b/Source/FreeImageToolkit/JPEGTransform.cpp index 8a2a660..542b8d0 100644 --- a/Source/FreeImageToolkit/JPEGTransform.cpp +++ b/Source/FreeImageToolkit/JPEGTransform.cpp @@ -112,8 +112,8 @@ getCropString(char* crop, size_t cropSize, int* left, int* top, int* right, int* return FALSE; } - *left = CLAMP(*left, 0, width); - *top = CLAMP(*top, 0, height); + *left = std::clamp(*left, 0, width); + *top = std::clamp(*top, 0, height); // negative/zero right and bottom count from the edges inwards @@ -124,8 +124,8 @@ getCropString(char* crop, size_t cropSize, int* left, int* top, int* right, int* *bottom = height + *bottom; } - *right = CLAMP(*right, 0, width); - *bottom = CLAMP(*bottom, 0, height); + *right = std::clamp(*right, 0, width); + *bottom = std::clamp(*bottom, 0, height); // test for empty rect diff --git a/Source/FreeImageToolkit/MultigridPoissonSolver.cpp b/Source/FreeImageToolkit/MultigridPoissonSolver.cpp index fffb8dd..fd71445 100644 --- a/Source/FreeImageToolkit/MultigridPoissonSolver.cpp +++ b/Source/FreeImageToolkit/MultigridPoissonSolver.cpp @@ -469,10 +469,10 @@ FreeImage_MultigridPoissonSolver(FIBITMAP *Laplacian, int ncycle) { const int height = FreeImage_GetHeight(Laplacian); // get nearest larger dimension length that is acceptable by the algorithm - int n = MAX(width, height); + int n = std::max(width, height); int size = 0; while ((n >>= 1) > 0) size++; - if ((1 << size) < MAX(width, height)) { + if ((1 << size) < std::max(width, height)) { size++; } // size must be of the form 2^j + 1 for some integer j diff --git a/Source/FreeImageToolkit/Resize.cpp b/Source/FreeImageToolkit/Resize.cpp index 03947bc..e539748 100644 --- a/Source/FreeImageToolkit/Resize.cpp +++ b/Source/FreeImageToolkit/Resize.cpp @@ -125,7 +125,7 @@ GetRGBAPalette(FIBITMAP *dib, FIRGBA8 * const buffer) { } memcpy(buffer, FreeImage_GetPalette(dib), ncolors * sizeof(FIRGBA8)); // merge the transparency table - const unsigned ntransp = MIN(ncolors, FreeImage_GetTransparencyCount(dib)); + const unsigned ntransp = std::min(ncolors, FreeImage_GetTransparencyCount(dib)); const uint8_t * const tt = FreeImage_GetTransparencyTable(dib); for (unsigned i = 0; i < ntransp; i++) { buffer[i].alpha = tt[i]; @@ -180,8 +180,8 @@ CWeightsTable::CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigne const double dCenter = (double)u / dScale + dOffset; // find the significant edge points that affect the pixel - const int iLeft = MAX(0, (int)(dCenter - dWidth + 0.5)); - const int iRight = MIN((int)(dCenter + dWidth + 0.5), int(uSrcSize)); + const int iLeft = std::max(0, (int)(dCenter - dWidth + 0.5)); + const int iRight = std::min((int)(dCenter + dWidth + 0.5), int(uSrcSize)); m_WeightTable[u].Left = iLeft; m_WeightTable[u].Right = iRight; diff --git a/Source/Metadata/TagConversion.cpp b/Source/Metadata/TagConversion.cpp index 7bfb477..1e3550e 100644 --- a/Source/Metadata/TagConversion.cpp +++ b/Source/Metadata/TagConversion.cpp @@ -238,7 +238,7 @@ ConvertAnyTag(FITAG *tag) { case FIDT_UNDEFINED:// 8-bit untyped data default: { - int max_size = MIN((int)FreeImage_GetTagLength(tag), (int)MAX_TEXT_EXTENT); + int max_size = std::min((int)FreeImage_GetTagLength(tag), (int)MAX_TEXT_EXTENT); if (max_size == MAX_TEXT_EXTENT) max_size--; memcpy(format, (char*)FreeImage_GetTagValue(tag), max_size); @@ -337,7 +337,7 @@ ConvertExifTag(FITAG *tag) { { const char *componentStrings[7] = {"", "Y", "Cb", "Cr", "R", "G", "B"}; auto *pvalue = (const uint8_t*)FreeImage_GetTagValue(tag); - for (uint32_t i = 0; i < MIN((uint32_t)4, FreeImage_GetTagCount(tag)); i++) { + for (uint32_t i = 0; i < std::min((uint32_t)4, FreeImage_GetTagCount(tag)); i++) { int j = pvalue[i]; if (j > 0 && j < 7) buffer += componentStrings[j]; diff --git a/Source/Plugins/PSDParser.cpp b/Source/Plugins/PSDParser.cpp index e136243..3e8b855 100644 --- a/Source/Plugins/PSDParser.cpp +++ b/Source/Plugins/PSDParser.cpp @@ -1253,7 +1253,7 @@ bool psdParser::ReadImageResources(FreeImageIO *io, fi_handle handle, int32_t le default: { // skip resource - unsigned skip_length = MIN(oResource._Size, nTotalBytes - nBytes); + unsigned skip_length = std::min(oResource._Size, nTotalBytes - nBytes); io->seek_proc(handle, skip_length, SEEK_CUR); nBytes += skip_length; } diff --git a/Source/Plugins/PluginBMP.cpp b/Source/Plugins/PluginBMP.cpp index d398cb8..d62dbdc 100644 --- a/Source/Plugins/PluginBMP.cpp +++ b/Source/Plugins/PluginBMP.cpp @@ -229,7 +229,7 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI throw(1); } if (status_byte != 0) { - status_byte = (int)MIN((size_t)status_byte, (size_t)(end - q)); + status_byte = (int)std::min((size_t)status_byte, (size_t)(end - q)); // Encoded mode if (io->read_proc(&second_byte, sizeof(uint8_t), 1, handle) != 1) { throw(1); @@ -284,7 +284,7 @@ LoadPixelDataRLE4(FreeImageIO *io, fi_handle handle, int width, int height, FIBI default: { // Absolute mode - status_byte = (int)MIN((size_t)status_byte, (size_t)(end - q)); + status_byte = (int)std::min((size_t)status_byte, (size_t)(end - q)); for (int i = 0; i < status_byte; i++) { if ((i & 0x01) == 0) { if (io->read_proc(&second_byte, sizeof(uint8_t), 1, handle) != 1) { @@ -399,7 +399,7 @@ LoadPixelDataRLE8(FreeImageIO *io, fi_handle handle, int width, int height, FIBI return TRUE; } - int count = MIN((int)status_byte, width - bits); + int count = std::min((int)status_byte, width - bits); uint8_t *sline = FreeImage_GetScanLine(dib, scanline); @@ -429,7 +429,7 @@ LoadPixelDataRLE8(FreeImageIO *io, fi_handle handle, int width, int height, FIBI return TRUE; } - int count = MIN((int)status_byte, width - bits); + int count = std::min((int)status_byte, width - bits); uint8_t *sline = FreeImage_GetScanLine(dib, scanline); diff --git a/Source/Plugins/PluginEXR.cpp b/Source/Plugins/PluginEXR.cpp index 0bfa5da..04d5a00 100644 --- a/Source/Plugins/PluginEXR.cpp +++ b/Source/Plugins/PluginEXR.cpp @@ -372,7 +372,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { while (dw.min.y <= dw.max.y) { // read a chunk rgbaFile.setFrameBuffer (&chunk[0][0] - dw.min.x - dw.min.y * width, 1, width); - rgbaFile.readPixels (dw.min.y, MIN(dw.min.y + chunk_size - 1, dw.max.y)); + rgbaFile.readPixels (dw.min.y, std::min(dw.min.y + chunk_size - 1, dw.max.y)); // fill the dib const int y_max = ((dw.max.y - dw.min.y) <= chunk_size) ? (dw.max.y - dw.min.y) : chunk_size; for ( int y = 0; y < y_max; y++) { diff --git a/Source/Plugins/PluginIFF.cpp b/Source/Plugins/PluginIFF.cpp index 75b137e..b55ad71 100644 --- a/Source/Plugins/PluginIFF.cpp +++ b/Source/Plugins/PluginIFF.cpp @@ -279,7 +279,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FIRGBA8 *pal = FreeImage_GetPalette(dib.get()); if (pal) { - unsigned palette_entries = MIN((unsigned)ch_size / 3, FreeImage_GetColorsUsed(dib.get())); + unsigned palette_entries = std::min((unsigned)ch_size / 3, FreeImage_GetColorsUsed(dib.get())); for (unsigned k = 0; k < palette_entries; k++) { io->read_proc(&pal[k].red, 1, 1, handle ); io->read_proc(&pal[k].green, 1, 1, handle ); diff --git a/Source/Plugins/PluginJPEG.cpp b/Source/Plugins/PluginJPEG.cpp index 7bef160..9c1fded 100644 --- a/Source/Plugins/PluginJPEG.cpp +++ b/Source/Plugins/PluginJPEG.cpp @@ -765,7 +765,7 @@ jpeg_write_comment(j_compress_ptr cinfo, FIBITMAP *dib) { if (tag_value) { for (long i = 0; i < (long)strlen(tag_value); i+= MAX_BYTES_IN_MARKER) { - jpeg_write_marker(cinfo, JPEG_COM, (uint8_t*)tag_value + i, MIN((long)strlen(tag_value + i), MAX_BYTES_IN_MARKER)); + jpeg_write_marker(cinfo, JPEG_COM, (uint8_t*)tag_value + i, std::min((long)strlen(tag_value + i), MAX_BYTES_IN_MARKER)); } return TRUE; } @@ -791,7 +791,7 @@ jpeg_write_icc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { memcpy(profile, icc_signature, 12); for (long i = 0; i < (long)iccProfile->size; i += MAX_DATA_BYTES_IN_MARKER) { - unsigned length = MIN((long)(iccProfile->size - i), MAX_DATA_BYTES_IN_MARKER); + unsigned length = std::min((long)(iccProfile->size - i), MAX_DATA_BYTES_IN_MARKER); // sequence number profile[12] = (uint8_t) ((i / MAX_DATA_BYTES_IN_MARKER) + 1); // number of markers @@ -827,7 +827,7 @@ jpeg_write_iptc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { // write the profile for (long i = 0; i < (long)profile_size; i += 65517L) { - unsigned length = MIN((long)profile_size - i, 65517L); + unsigned length = std::min((long)profile_size - i, 65517L); unsigned roundup = length & 0x01; // needed for Photoshop auto *iptc_profile = (uint8_t*)malloc(length + roundup + tag_length); if (!iptc_profile) break; @@ -882,7 +882,7 @@ jpeg_write_xmp_profile(j_compress_ptr cinfo, FIBITMAP *dib) { memcpy(profile, xmp_signature, xmp_header_size); for (uint32_t i = 0; i < tag_length; i += 65504L) { - unsigned length = MIN((long)(tag_length - i), 65504L); + unsigned length = std::min((long)(tag_length - i), 65504L); memcpy(profile + xmp_header_size, tag_value + i, length); jpeg_write_marker(cinfo, EXIF_MARKER, profile, (length + xmp_header_size)); @@ -925,7 +925,7 @@ jpeg_write_exif_profile_raw(j_compress_ptr cinfo, FIBITMAP *dib) { if (!profile) return FALSE; for (uint32_t i = 0; i < tag_length; i += 65504L) { - unsigned length = MIN((long)(tag_length - i), 65504L); + unsigned length = std::min((long)(tag_length - i), 65504L); memcpy(profile, tag_value + i, length); jpeg_write_marker(cinfo, EXIF_MARKER, profile, length); @@ -1194,7 +1194,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { if (requested_size > 0) { // the JPEG codec can perform x2, x4 or x8 scaling on loading // try to find the more appropriate scaling according to user's need - double scale = MAX((double)cinfo.image_width, (double)cinfo.image_height) / (double)requested_size; + double scale = std::max((double)cinfo.image_width, (double)cinfo.image_height) / (double)requested_size; if (scale >= 8) { scale_denom = 8; } else if (scale >= 4) { diff --git a/Source/Plugins/PluginPCX.cpp b/Source/Plugins/PluginPCX.cpp index a3f1a56..aee163c 100644 --- a/Source/Plugins/PluginPCX.cpp +++ b/Source/Plugins/PluginPCX.cpp @@ -522,7 +522,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { // do a safe copy of the scanline into 'line' written = readLine(io, handle, line.get(), lineLength, bIsRLE, ReadBuf.get(), ReadPos); // sometimes (already encountered), PCX images can have a lineLength > pitch - memcpy(bits, line.get(), MIN(pitch, lineLength)); + memcpy(bits, line.get(), std::min(pitch, lineLength)); // skip trailing garbage at the end of the scanline diff --git a/Source/Plugins/PluginPNG.cpp b/Source/Plugins/PluginPNG.cpp index 82de837..65f206a 100644 --- a/Source/Plugins/PluginPNG.cpp +++ b/Source/Plugins/PluginPNG.cpp @@ -116,7 +116,7 @@ ReadMetadata(png_structp png_ptr, png_infop info_ptr, FIBITMAP *dib) { std::unique_ptr tag(FreeImage_CreateTag(), &FreeImage_DeleteTag); if (!tag) return FALSE; - uint32_t tag_length = (uint32_t) MAX(text_ptr[i].text_length, text_ptr[i].itxt_length); + uint32_t tag_length = (uint32_t) std::max(text_ptr[i].text_length, text_ptr[i].itxt_length); FreeImage_SetTagLength(tag.get(), tag_length); FreeImage_SetTagCount(tag.get(), tag_length); @@ -586,7 +586,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { png_get_PLTE(png_ptr.get(),info_ptr.get(), &png_palette, &palette_entries); - palette_entries = MIN((unsigned)palette_entries, FreeImage_GetColorsUsed(dib.get())); + palette_entries = std::min((unsigned)palette_entries, FreeImage_GetColorsUsed(dib.get())); // store the palette diff --git a/Source/Plugins/PluginTARGA.cpp b/Source/Plugins/PluginTARGA.cpp index 5f579f9..fd25321 100644 --- a/Source/Plugins/PluginTARGA.cpp +++ b/Source/Plugins/PluginTARGA.cpp @@ -729,7 +729,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { case 16: { uint16_t *rgb555 = static_cast(static_cast(cmap.get())); unsigned start = (unsigned)header.cm_first_entry; - unsigned stop = MIN((unsigned)256, (unsigned)header.cm_length); + unsigned stop = std::min((unsigned)256, (unsigned)header.cm_length); for (count = start; count < stop; count++) { palette[count].red = (uint8_t)((((*rgb555 & FI16_555_RED_MASK) >> FI16_555_RED_SHIFT) * 0xFF) / 0x1F); @@ -743,7 +743,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { case 24: { FILE_BGR *bgr = static_cast(static_cast(cmap.get())); unsigned start = (unsigned)header.cm_first_entry; - unsigned stop = MIN((unsigned)256, (unsigned)header.cm_length); + unsigned stop = std::min((unsigned)256, (unsigned)header.cm_length); for (count = start; count < stop; count++) { palette[count].blue = bgr->b; @@ -762,7 +762,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { FILE_BGRA *bgra = static_cast(static_cast(cmap.get())); unsigned start = (unsigned)header.cm_first_entry; - unsigned stop = MIN((unsigned)256, (unsigned)header.cm_length); + unsigned stop = std::min((unsigned)256, (unsigned)header.cm_length); for (count = start; count < stop; count++) { palette[count].blue = bgra->b; diff --git a/Source/Plugins/PluginWebP.cpp b/Source/Plugins/PluginWebP.cpp index b29e68f..25f2d98 100644 --- a/Source/Plugins/PluginWebP.cpp +++ b/Source/Plugins/PluginWebP.cpp @@ -435,7 +435,7 @@ EncodeImage(FIMEMORY *hmem, FIBITMAP *dib, int flags) { } // check format limits - if (MAX(width, height) > WEBP_MAX_DIMENSION) { + if (std::max(width, height) > WEBP_MAX_DIMENSION) { FreeImage_OutputMessageProc(s_format_id, "Unsupported image size: width x height = %d x %d", width, height); return FALSE; } From 45bf053eb5fbed1116f102cfb2befb2056084daf Mon Sep 17 00:00:00 2001 From: lordnn Date: Sun, 22 Mar 2026 22:59:24 +0300 Subject: [PATCH 4/5] More std::swap/clamp. --- Source/FreeImage/Conversion.cpp | 8 +- Source/FreeImage/ConversionFloat.cpp | 4 +- Source/FreeImage/ConversionRGBAF.cpp | 42 ++-- Source/FreeImage/ConversionRGBF.cpp | 28 +-- Source/FreeImage/ConversionType.cpp | 2 +- Source/FreeImage/tmoColorConvert.cpp | 12 +- Source/FreeImageToolkit/CopyPaste.cpp | 8 +- Source/FreeImageToolkit/JPEGTransform.cpp | 4 +- .../MultigridPoissonSolver.cpp | 6 +- Source/FreeImageToolkit/Rescale.cpp | 4 +- Source/FreeImageToolkit/Resize.cpp | 196 +++++++++--------- Source/Plugins/PSDParser.cpp | 2 +- Source/Plugins/PluginBMP.cpp | 4 +- Source/Plugins/PluginDDS.cpp | 4 +- Source/Plugins/PluginICO.cpp | 4 +- Source/Plugins/PluginIFF.cpp | 2 +- Source/Plugins/PluginJPEG.cpp | 4 +- Source/Plugins/PluginJXR.cpp | 28 +-- Source/Plugins/PluginPFM.cpp | 2 +- Source/Plugins/PluginTARGA.cpp | 2 +- Source/Plugins/PluginTIFF.cpp | 2 +- Source/Utilities.h | 15 -- 22 files changed, 184 insertions(+), 199 deletions(-) diff --git a/Source/FreeImage/Conversion.cpp b/Source/FreeImage/Conversion.cpp index 1be0c81..a8fc01c 100644 --- a/Source/FreeImage/Conversion.cpp +++ b/Source/FreeImage/Conversion.cpp @@ -80,7 +80,7 @@ SwapRedBlue32(FIBITMAP* dib) { uint8_t* line = FreeImage_GetBits(dib); for (unsigned y = 0; y < height; ++y, line += pitch) { for (uint8_t* pixel = line; pixel < line + lineSize ; pixel += bytesperpixel) { - INPLACESWAP(pixel[0], pixel[2]); + std::swap(pixel[0], pixel[2]); } } @@ -276,9 +276,9 @@ CIELabToRGB(float L, float a, float b, T *rgb) { XYZToRGB(X, Y, Z, &R, &G, &B); // clamp values to [0..max_val] - T red = (T)std::clamp(R * max_val, 0.0F, max_val); - T green = (T)std::clamp(G * max_val, 0.0F, max_val); - T blue = (T)std::clamp(B * max_val, 0.0F, max_val); + T red = (T)std::clamp(R * max_val, 0.F, max_val); + T green = (T)std::clamp(G * max_val, 0.F, max_val); + T blue = (T)std::clamp(B * max_val, 0.F, max_val); assignRGB(red, green, blue, rgb); } diff --git a/Source/FreeImage/ConversionFloat.cpp b/Source/FreeImage/ConversionFloat.cpp index 3da5fd6..3f12d8a 100644 --- a/Source/FreeImage/ConversionFloat.cpp +++ b/Source/FreeImage/ConversionFloat.cpp @@ -185,7 +185,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) { case FIT_RGBF: if (scale_linear) { BitmapTransform(dst, src, [](const FIRGBF& p) { - return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); + return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.F, 1.F); }); } else { BitmapTransform(dst, src, [](const FIRGBF& p) { @@ -196,7 +196,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) { case FIT_RGBAF: if (scale_linear) { BitmapTransform(dst, src, [](const FIRGBAF& p) { - return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); }); + return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.F, 1.F); }); } else { BitmapTransform(dst, src, [](const FIRGBAF& p) { diff --git a/Source/FreeImage/ConversionRGBAF.cpp b/Source/FreeImage/ConversionRGBAF.cpp index d38c13b..f1709ac 100644 --- a/Source/FreeImage/ConversionRGBAF.cpp +++ b/Source/FreeImage/ConversionRGBAF.cpp @@ -121,10 +121,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { auto *dst_pixel = (FIRGBAF*)dst_bits; for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F; - dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F; - dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F; - dst_pixel->alpha = (float)(src_pixel[FI_RGBA_ALPHA]) / 255.0F; + dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.F; + dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.F; + dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.F; + dst_pixel->alpha = (float)(src_pixel[FI_RGBA_ALPHA]) / 255.F; src_pixel += bytespp; dst_pixel++; @@ -146,11 +146,11 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - const float dst_value = (float)src_pixel[x] / 65535.0F; + const float dst_value = (float)src_pixel[x] / 65535.F; dst_pixel[x].red = dst_value; dst_pixel[x].green = dst_value; dst_pixel[x].blue = dst_value; - dst_pixel[x].alpha = 1.0F; + dst_pixel[x].alpha = 1.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -169,10 +169,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; - dst_pixel[x].alpha = 1.0F; + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F; + dst_pixel[x].alpha = 1.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -191,10 +191,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; - dst_pixel[x].alpha = (float)(src_pixel[x].alpha) / 65535.0F; + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F; + dst_pixel[x].alpha = (float)(src_pixel[x].alpha) / 65535.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -216,7 +216,7 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { dst_pixel[x].red = (float)(src_pixel[x].red / static_cast(std::numeric_limits::max())); dst_pixel[x].green = (float)(src_pixel[x].green / static_cast(std::numeric_limits::max())); dst_pixel[x].blue = (float)(src_pixel[x].blue / static_cast(std::numeric_limits::max())); - dst_pixel[x].alpha = 1.0F; + dst_pixel[x].alpha = 1.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -258,11 +258,11 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert by copying greyscale channel to each R, G, B channels // assume float values are in [0..1] - const float value = std::clamp(src_pixel[x], 0.0F, 1.0F); + const float value = std::clamp(src_pixel[x], 0.F, 1.F); dst_pixel[x].red = value; dst_pixel[x].green = value; dst_pixel[x].blue = value; - dst_pixel[x].alpha = 1.0F; + dst_pixel[x].alpha = 1.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -281,10 +281,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert pixels directly, while adding a "dummy" alpha of 1.0 - dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F); - dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F); - dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F); - dst_pixel[x].alpha = 1.0F; + dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.F, 1.F); + dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.F, 1.F); + dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.F, 1.F); + dst_pixel[x].alpha = 1.F; } src_bits += src_pitch; dst_bits += dst_pitch; diff --git a/Source/FreeImage/ConversionRGBF.cpp b/Source/FreeImage/ConversionRGBF.cpp index df36da6..db75683 100644 --- a/Source/FreeImage/ConversionRGBF.cpp +++ b/Source/FreeImage/ConversionRGBF.cpp @@ -124,9 +124,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { auto *dst_pixel = (FIRGBF*)dst_bits; for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F; - dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F; - dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F; + dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.F; + dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.F; + dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.F; src_pixel += bytespp; dst_pixel ++; @@ -148,7 +148,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - const float dst_value = (float)src_pixel[x] / 65535.0F; + const float dst_value = (float)src_pixel[x] / 65535.F; dst_pixel[x].red = dst_value; dst_pixel[x].green = dst_value; dst_pixel[x].blue = dst_value; @@ -170,9 +170,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -191,9 +191,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and scale to the range [0..1] - dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F; - dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F; - dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F; + dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F; + dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F; + dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F; } src_bits += src_pitch; dst_bits += dst_pitch; @@ -255,7 +255,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert by copying greyscale channel to each R, G, B channels // assume float values are in [0..1] - const float value = std::clamp(src_pixel[x], 0.0F, 1.0F); + const float value = std::clamp(src_pixel[x], 0.F, 1.F); dst_pixel[x].red = value; dst_pixel[x].green = value; dst_pixel[x].blue = value; @@ -300,9 +300,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) { for (unsigned x = 0; x < width; x++) { // convert and skip alpha channel - dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F); - dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F); - dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F); + dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.F, 1.F); + dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.F, 1.F); + dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.F, 1.F); } src_bits += src_pitch; dst_bits += dst_pitch; diff --git a/Source/FreeImage/ConversionType.cpp b/Source/FreeImage/ConversionType.cpp index df7e0ca..02fe4e6 100644 --- a/Source/FreeImage/ConversionType.cpp +++ b/Source/FreeImage/ConversionType.cpp @@ -67,7 +67,7 @@ CONVERT_TYPE::convert(FIBITMAP *src, FREE_IMAGE_TYPE dst_type) { /** Convert a greyscale image of type Tsrc to a 8-bit grayscale dib. Conversion is done using either a linear scaling from [min, max] to [0, 255] - or a rounding from src_pixel to (uint8_t) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5); + or a rounding from src_pixel to (uint8_t) clamp(q, 0, 255) where int q = int(src_pixel + 0.5); */ template class CONVERT_TO_BYTE diff --git a/Source/FreeImage/tmoColorConvert.cpp b/Source/FreeImage/tmoColorConvert.cpp index df89c18..993b555 100644 --- a/Source/FreeImage/tmoColorConvert.cpp +++ b/Source/FreeImage/tmoColorConvert.cpp @@ -243,9 +243,9 @@ LuminanceFromYxy(FIBITMAP *Yxy, float *maxLum, float *minLum, float *worldLum) { for (unsigned y = 0; y < height; y++) { auto *pixel = (const FIRGBF*)bits; for (unsigned x = 0; x < width; x++) { - const float Y = std::max(0.0F, pixel[x].red);// avoid negative values - max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene - min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene + const float Y = std::max(0.F, pixel[x].red);// avoid negative values + max_lum = std::max(max_lum, Y); // max Luminance in the scene + min_lum = std::min(min_lum, Y); // min Luminance in the scene sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper } // next line @@ -292,9 +292,9 @@ ClampConvertRGBFTo24(FIBITMAP *src) { const float green = (src_pixel[x].green > 1) ? 1 : src_pixel[x].green; const float blue = (src_pixel[x].blue > 1) ? 1 : src_pixel[x].blue; - dst_pixel[FI_RGBA_RED] = (uint8_t)(255.0F * red + 0.5F); - dst_pixel[FI_RGBA_GREEN] = (uint8_t)(255.0F * green + 0.5F); - dst_pixel[FI_RGBA_BLUE] = (uint8_t)(255.0F * blue + 0.5F); + dst_pixel[FI_RGBA_RED] = (uint8_t)(255.F * red + 0.5F); + dst_pixel[FI_RGBA_GREEN] = (uint8_t)(255.F * green + 0.5F); + dst_pixel[FI_RGBA_BLUE] = (uint8_t)(255.F * blue + 0.5F); dst_pixel += 3; } src_bits += src_pitch; diff --git a/Source/FreeImageToolkit/CopyPaste.cpp b/Source/FreeImageToolkit/CopyPaste.cpp index 1ad902d..82aa6c2 100644 --- a/Source/FreeImageToolkit/CopyPaste.cpp +++ b/Source/FreeImageToolkit/CopyPaste.cpp @@ -498,10 +498,10 @@ FreeImage_Copy(FIBITMAP *src, int left, int top, int right, int bottom) { // normalize the rectangle if (right < left) { - INPLACESWAP(left, right); + std::swap(left, right); } if (bottom < top) { - INPLACESWAP(top, bottom); + std::swap(top, bottom); } // check the size of the sub image const int src_width = FreeImage_GetWidth(src); @@ -790,10 +790,10 @@ FreeImage_CreateView(FIBITMAP *dib, unsigned left, unsigned top, unsigned right, // normalize the rectangle if (right < left) { - INPLACESWAP(left, right); + std::swap(left, right); } if (bottom < top) { - INPLACESWAP(top, bottom); + std::swap(top, bottom); } // check the size of the sub image diff --git a/Source/FreeImageToolkit/JPEGTransform.cpp b/Source/FreeImageToolkit/JPEGTransform.cpp index 542b8d0..97c47ad 100644 --- a/Source/FreeImageToolkit/JPEGTransform.cpp +++ b/Source/FreeImageToolkit/JPEGTransform.cpp @@ -136,10 +136,10 @@ getCropString(char* crop, size_t cropSize, int* left, int* top, int* right, int* // normalize the rectangle if (*right < *left) { - INPLACESWAP(*left, *right); + std::swap(*left, *right); } if (*bottom < *top) { - INPLACESWAP(*top, *bottom); + std::swap(*top, *bottom); } // test for "noop" rect diff --git a/Source/FreeImageToolkit/MultigridPoissonSolver.cpp b/Source/FreeImageToolkit/MultigridPoissonSolver.cpp index fd71445..cd83544 100644 --- a/Source/FreeImageToolkit/MultigridPoissonSolver.cpp +++ b/Source/FreeImageToolkit/MultigridPoissonSolver.cpp @@ -182,7 +182,7 @@ u[0..n-1][0..n-1], using the right-hand side function rhs[0..n-1][0..n-1]. */ static void fmg_relaxation(FIBITMAP *U, FIBITMAP *RHS, int n) { int row, col, ipass, isw, jsw; - const float h = 1.0F / (n - 1); + const float h = 1.F / (n - 1); const float h2 = h*h; const int u_pitch = FreeImage_GetPitch(U) / sizeof(float); @@ -218,8 +218,8 @@ rhs[0..n-1][0..n-1], while res[0..n-1][0..n-1] is returned. static void fmg_residual(FIBITMAP *RES, FIBITMAP *U, FIBITMAP *RHS, int n) { int row, col; - const float h = 1.0F / (n-1); - const float h2i = 1.0F / (h*h); + const float h = 1.F / (n-1); + const float h2i = 1.F / (h*h); const int res_pitch = FreeImage_GetPitch(RES) / sizeof(float); const int u_pitch = FreeImage_GetPitch(U) / sizeof(float); diff --git a/Source/FreeImageToolkit/Rescale.cpp b/Source/FreeImageToolkit/Rescale.cpp index fe7452f..9e7e774 100644 --- a/Source/FreeImageToolkit/Rescale.cpp +++ b/Source/FreeImageToolkit/Rescale.cpp @@ -35,10 +35,10 @@ FreeImage_RescaleRect(FIBITMAP *src, int dst_width, int dst_height, int src_left // normalize the rectangle if (src_right < src_left) { - INPLACESWAP(src_left, src_right); + std::swap(src_left, src_right); } if (src_bottom < src_top) { - INPLACESWAP(src_top, src_bottom); + std::swap(src_top, src_bottom); } // check the size of the sub image diff --git a/Source/FreeImageToolkit/Resize.cpp b/Source/FreeImageToolkit/Resize.cpp index e539748..fe00c82 100644 --- a/Source/FreeImageToolkit/Resize.cpp +++ b/Source/FreeImageToolkit/Resize.cpp @@ -543,7 +543,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[x] = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits[x] = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); } } } else { @@ -568,7 +568,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig value *= 0xFF; // clamp and place result in destination pixel - dst_bits[x] = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits[x] = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); } } } @@ -604,9 +604,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -632,7 +632,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig value *= 0xFF; // clamp and place result in destination pixel - const uint8_t bval = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + const uint8_t bval = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits[FI_RGBA_RED] = bval; dst_bits[FI_RGBA_GREEN] = bval; dst_bits[FI_RGBA_BLUE] = bval; @@ -673,10 +673,10 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += 4; } } @@ -714,7 +714,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[x] = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits[x] = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); } } } @@ -749,9 +749,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -788,10 +788,10 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += 4; } } @@ -830,7 +830,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[x] = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits[x] = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); } } } else { @@ -855,7 +855,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[x] = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + dst_bits[x] = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); } } } @@ -891,9 +891,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -920,7 +920,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - const uint8_t bval = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + const uint8_t bval = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits[FI_RGBA_RED] = bval; dst_bits[FI_RGBA_GREEN] = bval; dst_bits[FI_RGBA_BLUE] = bval; @@ -960,10 +960,10 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += 4; } } @@ -1002,9 +1002,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -1034,9 +1034,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -1071,9 +1071,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += 3; } } @@ -1108,10 +1108,10 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += 4; } } @@ -1148,7 +1148,7 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(value + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(value + 0.5), 0, 0xFFFF); dst_bits += wordspp; } } @@ -1184,9 +1184,9 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (uint16_t)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (uint16_t)CLAMP((int)(b + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (uint16_t)std::clamp((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (uint16_t)std::clamp((int)(b + 0.5), 0, 0xFFFF); dst_bits += wordspp; } } @@ -1223,10 +1223,10 @@ void CResizeEngine::horizontalFilter(FIBITMAP *const src, unsigned height, unsig } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (uint16_t)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (uint16_t)CLAMP((int)(b + 0.5), 0, 0xFFFF); - dst_bits[3] = (uint16_t)CLAMP((int)(a + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (uint16_t)std::clamp((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (uint16_t)std::clamp((int)(b + 0.5), 0, 0xFFFF); + dst_bits[3] = (uint16_t)std::clamp((int)(a + 0.5), 0, 0xFFFF); dst_bits += wordspp; } } @@ -1324,7 +1324,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned value *= 0xFF; // clamp and place result in destination pixel - *dst_bits = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + *dst_bits = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1353,7 +1353,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned value *= 0xFF; // clamp and place result in destination pixel - *dst_bits = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + *dst_bits = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1393,9 +1393,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1424,7 +1424,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned value *= 0xFF; // clamp and place result in destination pixel - const uint8_t bval = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + const uint8_t bval = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits[FI_RGBA_RED] = bval; dst_bits[FI_RGBA_GREEN] = bval; dst_bits[FI_RGBA_BLUE] = bval; @@ -1467,10 +1467,10 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1512,7 +1512,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - *dst_bits = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + *dst_bits = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1549,9 +1549,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1589,10 +1589,10 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1633,7 +1633,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - *dst_bits = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + *dst_bits = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1659,7 +1659,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - *dst_bits = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + *dst_bits = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1696,9 +1696,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1724,7 +1724,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - const uint8_t bval = (uint8_t)CLAMP((int)(value + 0.5), 0, 0xFF); + const uint8_t bval = (uint8_t)std::clamp((int)(value + 0.5), 0, 0xFF); dst_bits[FI_RGBA_RED] = bval; dst_bits[FI_RGBA_GREEN] = bval; dst_bits[FI_RGBA_BLUE] = bval; @@ -1764,10 +1764,10 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int)(a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int)(a + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1808,9 +1808,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(((g * 0xFF) / 0x3F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1839,9 +1839,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int)(((r * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int)(((g * 0xFF) / 0x1F) + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int)(((b * 0xFF) / 0x1F) + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1879,9 +1879,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int) (r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int) (g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int) (b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int) (r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int) (g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int) (b + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1919,10 +1919,10 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[FI_RGBA_RED] = (uint8_t)CLAMP((int) (r + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_GREEN] = (uint8_t)CLAMP((int) (g + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_BLUE] = (uint8_t)CLAMP((int) (b + 0.5), 0, 0xFF); - dst_bits[FI_RGBA_ALPHA] = (uint8_t)CLAMP((int) (a + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_RED] = (uint8_t)std::clamp((int) (r + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_GREEN] = (uint8_t)std::clamp((int) (g + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_BLUE] = (uint8_t)std::clamp((int) (b + 0.5), 0, 0xFF); + dst_bits[FI_RGBA_ALPHA] = (uint8_t)std::clamp((int) (a + 0.5), 0, 0xFF); dst_bits += dst_pitch; } } @@ -1965,7 +1965,7 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(value + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(value + 0.5), 0, 0xFFFF); dst_bits += dst_pitch; } @@ -2009,9 +2009,9 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (uint16_t)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (uint16_t)CLAMP((int)(b + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (uint16_t)std::clamp((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (uint16_t)std::clamp((int)(b + 0.5), 0, 0xFFFF); dst_bits += dst_pitch; } @@ -2056,10 +2056,10 @@ void CResizeEngine::verticalFilter(FIBITMAP *const src, unsigned width, unsigned } // clamp and place result in destination pixel - dst_bits[0] = (uint16_t)CLAMP((int)(r + 0.5), 0, 0xFFFF); - dst_bits[1] = (uint16_t)CLAMP((int)(g + 0.5), 0, 0xFFFF); - dst_bits[2] = (uint16_t)CLAMP((int)(b + 0.5), 0, 0xFFFF); - dst_bits[3] = (uint16_t)CLAMP((int)(a + 0.5), 0, 0xFFFF); + dst_bits[0] = (uint16_t)std::clamp((int)(r + 0.5), 0, 0xFFFF); + dst_bits[1] = (uint16_t)std::clamp((int)(g + 0.5), 0, 0xFFFF); + dst_bits[2] = (uint16_t)std::clamp((int)(b + 0.5), 0, 0xFFFF); + dst_bits[3] = (uint16_t)std::clamp((int)(a + 0.5), 0, 0xFFFF); dst_bits += dst_pitch; } diff --git a/Source/Plugins/PSDParser.cpp b/Source/Plugins/PSDParser.cpp index 3e8b855..c561775 100644 --- a/Source/Plugins/PSDParser.cpp +++ b/Source/Plugins/PSDParser.cpp @@ -1451,7 +1451,7 @@ FIBITMAP* psdParser::ReadImageData(FreeImageIO* io, fi_handle handle) { case PSDP_CMYK : case PSDP_MULTICHANNEL : // force PSDP_MULTICHANNEL CMY as CMYK - dstCh = (mode == PSDP_MULTICHANNEL && !header_only) ? 4 : MIN(nChannels, 4); + dstCh = (mode == PSDP_MULTICHANNEL && !header_only) ? 4 : std::min(nChannels, 4); if (dstCh < 3) { throw "Invalid number of channels"; } diff --git a/Source/Plugins/PluginBMP.cpp b/Source/Plugins/PluginBMP.cpp index d62dbdc..12bc92c 100644 --- a/Source/Plugins/PluginBMP.cpp +++ b/Source/Plugins/PluginBMP.cpp @@ -186,7 +186,7 @@ LoadPixelData(FreeImageIO *io, fi_handle handle, FIBITMAP *dib, int height, unsi for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { auto *pixel = FreeImage_GetScanLine(dib, y); for (unsigned x = 0; x < FreeImage_GetWidth(dib); x++) { - INPLACESWAP(pixel[0], pixel[2]); + std::swap(pixel[0], pixel[2]); pixel += (bit_count >> 3); } } @@ -518,7 +518,7 @@ LoadWindowsBMP(FreeImageIO *io, fi_handle handle, int flags, unsigned bitmap_bit #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB FIRGBA8 *pal = FreeImage_GetPalette(dib.get()); for (unsigned int i = 0; i < used_colors; i++) { - INPLACESWAP(pal[i].red, pal[i].blue); + std::swap(pal[i].red, pal[i].blue); } #endif diff --git a/Source/Plugins/PluginDDS.cpp b/Source/Plugins/PluginDDS.cpp index 072602b..72bbb6b 100644 --- a/Source/Plugins/PluginDDS.cpp +++ b/Source/Plugins/PluginDDS.cpp @@ -574,7 +574,7 @@ template void DecodeDXTBlock (uint8_t *dstData, const uint8_t *s decoder.GetColor(x, color); #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB - INPLACESWAP(dst[FI_RGBA_RED], dst[FI_RGBA_BLUE]); + std::swap(dst[FI_RGBA_RED], dst[FI_RGBA_BLUE]); #endif dst += 4; } @@ -660,7 +660,7 @@ LoadRGB(const DDSURFACEDESC2 *desc, FreeImageIO *io, fi_handle handle) { for (int y = 0; y < height; y++) { uint8_t *pixels = FreeImage_GetScanLine(dib.get(), y); for (int x = 0; x < width; x++) { - INPLACESWAP(pixels[FI_RGBA_RED], pixels[FI_RGBA_BLUE]); + std::swap(pixels[FI_RGBA_RED], pixels[FI_RGBA_BLUE]); pixels += bytespp; } } diff --git a/Source/Plugins/PluginICO.cpp b/Source/Plugins/PluginICO.cpp index e13bea6..254a3f7 100644 --- a/Source/Plugins/PluginICO.cpp +++ b/Source/Plugins/PluginICO.cpp @@ -314,7 +314,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, FIBOOL header_onl #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_RGB FIRGBA8 *pal = FreeImage_GetPalette(dib.get()); for (unsigned i = 0; i < CalculateUsedPaletteEntries(bit_count); i++) { - INPLACESWAP(pal[i].red, pal[i].blue); + std::swap(pal[i].red, pal[i].blue); } #endif } @@ -349,7 +349,7 @@ LoadStandardIcon(FreeImageIO *io, fi_handle handle, int flags, FIBOOL header_onl for (int y = 0; y < height; y++) { uint8_t *pixel = FreeImage_GetScanLine(dib.get(), y); for (int x = 0; x < width; x++) { - INPLACESWAP(pixel[0], pixel[2]); + std::swap(pixel[0], pixel[2]); pixel += (bit_count>>3); } } diff --git a/Source/Plugins/PluginIFF.cpp b/Source/Plugins/PluginIFF.cpp index b55ad71..f5e6322 100644 --- a/Source/Plugins/PluginIFF.cpp +++ b/Source/Plugins/PluginIFF.cpp @@ -405,7 +405,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR if (depth == 24) { for (unsigned x = 0; x < width; ++x){ - INPLACESWAP(dest[x * 3], dest[x * 3 + 2]); + std::swap(dest[x * 3], dest[x * 3 + 2]); } } #endif diff --git a/Source/Plugins/PluginJPEG.cpp b/Source/Plugins/PluginJPEG.cpp index 9c1fded..a3eb310 100644 --- a/Source/Plugins/PluginJPEG.cpp +++ b/Source/Plugins/PluginJPEG.cpp @@ -1588,7 +1588,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // swap R and B channels uint8_t *target_p = target; for (unsigned x = 0; x < cinfo.image_width; x++) { - INPLACESWAP(target_p[0], target_p[2]); + std::swap(target_p[0], target_p[2]); target_p += 3; } #endif @@ -1648,7 +1648,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // swap R and B channels uint8_t *target_p = target; for (unsigned x = 0; x < cinfo.image_width; x++) { - INPLACESWAP(target_p[0], target_p[2]); + std::swap(target_p[0], target_p[2]); target_p += 3; } #endif diff --git a/Source/Plugins/PluginJXR.cpp b/Source/Plugins/PluginJXR.cpp index c703a92..e58a21d 100644 --- a/Source/Plugins/PluginJXR.cpp +++ b/Source/Plugins/PluginJXR.cpp @@ -1227,7 +1227,7 @@ ImageQuality Q (BD==1) Q (BD==8) Q (BD==16) Q (BD==32F) Subsample Overlap */ static void SetCompression(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, float fltImageQuality) { - if (fltImageQuality < 1.0F) { + if (fltImageQuality < 1.F) { // overlap if (fltImageQuality >= 0.5F) { wmiSCP->olOverlap = OL_ONE; @@ -1243,7 +1243,7 @@ SetCompression(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, float fl // bit depth if (pixelInfo->bdBitDepth == BD_1) { - wmiSCP->uiDefaultQPIndex = (U8)(8 - 5.0F * fltImageQuality + 0.5F); + wmiSCP->uiDefaultQPIndex = (U8)(8 - 5.F * fltImageQuality + 0.5F); } else { // remap [0.8, 0.866, 0.933, 1.0] to [0.8, 0.9, 1.0, 1.1] @@ -1252,8 +1252,8 @@ SetCompression(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, float fl fltImageQuality = 0.8F + (fltImageQuality - 0.8F) * 1.5F; } - const int qi = (int) (10.0F * fltImageQuality); - const float qf = 10.0F * fltImageQuality - (float)qi; + const int qi = (int) (10.F * fltImageQuality); + const float qf = 10.F * fltImageQuality - (float)qi; const int *pQPs = (wmiSCP->cfColorFormat == YUV_420 || wmiSCP->cfColorFormat == YUV_422) ? @@ -1263,14 +1263,14 @@ SetCompression(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, float fl (pixelInfo->bdBitDepth == BD_16F ? DPK_QPS_16f[qi] : DPK_QPS_32f[qi]))); - wmiSCP->uiDefaultQPIndex = (U8) (0.5F + (float) pQPs[0] * (1.0F - qf) + (float) (pQPs + 6)[0] * qf); - wmiSCP->uiDefaultQPIndexU = (U8) (0.5F + (float) pQPs[1] * (1.0F - qf) + (float) (pQPs + 6)[1] * qf); - wmiSCP->uiDefaultQPIndexV = (U8) (0.5F + (float) pQPs[2] * (1.0F - qf) + (float) (pQPs + 6)[2] * qf); - wmiSCP->uiDefaultQPIndexYHP = (U8) (0.5F + (float) pQPs[3] * (1.0F - qf) + (float) (pQPs + 6)[3] * qf); - wmiSCP->uiDefaultQPIndexUHP = (U8) (0.5F + (float) pQPs[4] * (1.0F - qf) + (float) (pQPs + 6)[4] * qf); - wmiSCP->uiDefaultQPIndexVHP = (U8) (0.5F + (float) pQPs[5] * (1.0F - qf) + (float) (pQPs + 6)[5] * qf); + wmiSCP->uiDefaultQPIndex = (U8) (0.5F + (float) pQPs[0] * (1.F - qf) + (float) (pQPs + 6)[0] * qf); + wmiSCP->uiDefaultQPIndexU = (U8) (0.5F + (float) pQPs[1] * (1.F - qf) + (float) (pQPs + 6)[1] * qf); + wmiSCP->uiDefaultQPIndexV = (U8) (0.5F + (float) pQPs[2] * (1.F - qf) + (float) (pQPs + 6)[2] * qf); + wmiSCP->uiDefaultQPIndexYHP = (U8) (0.5F + (float) pQPs[3] * (1.F - qf) + (float) (pQPs + 6)[3] * qf); + wmiSCP->uiDefaultQPIndexUHP = (U8) (0.5F + (float) pQPs[4] * (1.F - qf) + (float) (pQPs + 6)[4] * qf); + wmiSCP->uiDefaultQPIndexVHP = (U8) (0.5F + (float) pQPs[5] * (1.F - qf) + (float) (pQPs + 6)[5] * qf); } - } // fltImageQuality < 1.0F + } // fltImageQuality < 1.F else { // lossless mode wmiSCP->uiDefaultQPIndex = 1; @@ -1286,7 +1286,7 @@ Set encoder parameters */ static void SetEncoderParameters(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, int flags, FIBOOL bHasAlpha) { - float fltImageQuality = 1.0F; + float fltImageQuality = 1.F; // all values have been set to zero by the API // update default values for some attributes @@ -1317,10 +1317,10 @@ SetEncoderParameters(CWMIStrCodecParam *wmiSCP, const PKPixelInfo *pixelInfo, in // defaut to 0.80 fltImageQuality = 0.8F; } else if ((flags & JXR_LOSSLESS) == JXR_LOSSLESS) { - fltImageQuality = 1.0F; + fltImageQuality = 1.F; } else { quality = (quality >= 100) ? 100 : quality; - fltImageQuality = quality / 100.0F; + fltImageQuality = quality / 100.F; } SetCompression(wmiSCP, pixelInfo, fltImageQuality); diff --git a/Source/Plugins/PluginPFM.cpp b/Source/Plugins/PluginPFM.cpp index 3ce075e..e4c3b72 100644 --- a/Source/Plugins/PluginPFM.cpp +++ b/Source/Plugins/PluginPFM.cpp @@ -333,7 +333,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void const unsigned lineWidth = FreeImage_GetLine(dib); // save image as Little Endian - const float scalefactor = -1.0F; + const float scalefactor = -1.F; char buffer[PFM_MAXLINE]; // temporary buffer whose size should be enough for what we need diff --git a/Source/Plugins/PluginTARGA.cpp b/Source/Plugins/PluginTARGA.cpp index fd25321..7aab0f8 100644 --- a/Source/Plugins/PluginTARGA.cpp +++ b/Source/Plugins/PluginTARGA.cpp @@ -533,7 +533,7 @@ _assignPixel<32>(uint8_t* bits, const uint8_t* val, FIBOOL as24bit) { } else { #if FREEIMAGE_COLORORDER == FREEIMAGE_COLORORDER_BGR *(reinterpret_cast(bits)) = *(reinterpret_cast (val)); -#else // NOTE This is faster then doing reinterpret_cast to int + INPLACESWAP ! +#else // NOTE This is faster then doing reinterpret_cast to int + std::swap ! bits[FI_RGBA_BLUE] = val[0]; bits[FI_RGBA_GREEN] = val[1]; bits[FI_RGBA_RED] = val[2]; diff --git a/Source/Plugins/PluginTIFF.cpp b/Source/Plugins/PluginTIFF.cpp index 4c4295d..9b093fe 100644 --- a/Source/Plugins/PluginTIFF.cpp +++ b/Source/Plugins/PluginTIFF.cpp @@ -2609,7 +2609,7 @@ SaveOneTIFF(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flag auto *pBuf = static_cast(buffer.get()); for (uint32_t x = 0; x < width; x++) { - INPLACESWAP(pBuf[0], pBuf[2]); + std::swap(pBuf[0], pBuf[2]); pBuf += samplesperpixel; } } diff --git a/Source/Utilities.h b/Source/Utilities.h index 32a2f57..cbee6fb 100644 --- a/Source/Utilities.h +++ b/Source/Utilities.h @@ -144,21 +144,6 @@ template T MAX(const T &a, const T &b) { return (a > b) ? a: b; } -/// Min function -template T MIN(const T &a, const T &b) { - return (a < b) ? a: b; -} - -/// INPLACESWAP adopted from codeguru.com -template void INPLACESWAP(T& a, T& b) { - a ^= b; b ^= a; a ^= b; -} - -/// Clamp function -template T CLAMP(const T &value, const T &min_value, const T &max_value) { - return ((value < min_value) ? min_value : (value > max_value) ? max_value : value); -} - /** This procedure computes minimum min and maximum max of n numbers using only (3n/2) - 2 comparisons. min = L[i1] and max = L[i2]. From 1f4ce88f96e63c7572c9dd84d2b28471b7d540eb Mon Sep 17 00:00:00 2001 From: lordnn Date: Wed, 1 Apr 2026 01:45:15 +0300 Subject: [PATCH 5/5] More `std::unique_ptr`'s. --- Source/Plugins/PluginJPEG.cpp | 95 ++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/Source/Plugins/PluginJPEG.cpp b/Source/Plugins/PluginJPEG.cpp index a3eb310..474843c 100644 --- a/Source/Plugins/PluginJPEG.cpp +++ b/Source/Plugins/PluginJPEG.cpp @@ -433,10 +433,11 @@ jpeg_read_comment(FIBITMAP *dib, const uint8_t *dataptr, unsigned int datalen) { uint8_t *profile = (uint8_t*)dataptr; // read the comment - std::unique_ptr safeValue(malloc((length + 1) * sizeof(char)), &free); - if (!safeValue) return FALSE; - auto *value = static_cast(safeValue.get()); - memcpy(value, profile, length); + std::unique_ptr value(new(std::nothrow) char[length + 1]); + if (!value) { + return FALSE; + } + memcpy(value.get(), profile, length); value[length] = '\0'; bool bSuccess{}; @@ -449,7 +450,7 @@ jpeg_read_comment(FIBITMAP *dib, const uint8_t *dataptr, unsigned int datalen) { bSuccess = bSuccess && FreeImage_SetTagLength(tag.get(), count); bSuccess = bSuccess && FreeImage_SetTagCount(tag.get(), count); bSuccess = bSuccess && FreeImage_SetTagType(tag.get(), FIDT_ASCII); - bSuccess = bSuccess && FreeImage_SetTagValue(tag.get(), value); + bSuccess = bSuccess && FreeImage_SetTagValue(tag.get(), value.get()); // store the tag bSuccess = bSuccess && FreeImage_SetMetadata(FIMD_COMMENTS, dib, FreeImage_GetTagKey(tag.get()), tag.get()); @@ -506,7 +507,6 @@ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr, unsigned *i jpeg_saved_marker_ptr marker; int num_markers = 0; int seq_no; - JOCTET *icc_data; unsigned total_length; const int MAX_SEQ_NO = 255; // sufficient since marker numbers are bytes @@ -563,13 +563,16 @@ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr, unsigned *i total_length += data_length[seq_no]; } - if (total_length <= 0) - return FALSE; // found only empty markers ? + if (total_length <= 0) { + return FALSE; // found only empty markers ? + } // allocate space for assembled data - icc_data = (JOCTET *) malloc(total_length * sizeof(JOCTET)); - if (!icc_data) - return FALSE; // out of memory + std::unique_ptr safeIcc(malloc(total_length * sizeof(JOCTET), &free); + auto *icc_data = static_cast(safeIcc.get()); + if (!icc_data) { + return FALSE; // out of memory + } // and fill it in for (marker = cinfo->marker_list; marker; marker = marker->next) { @@ -589,6 +592,7 @@ jpeg_read_icc_profile(j_decompress_ptr cinfo, JOCTET **icc_data_ptr, unsigned *i *icc_data_ptr = icc_data; *icc_data_len = total_length; + safeIcc.release(); return TRUE; } @@ -786,9 +790,11 @@ jpeg_write_icc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { if (iccProfile->size && iccProfile->data) { // ICC_HEADER_SIZE: ICC signature is 'ICC_PROFILE' + 2 bytes - auto *profile = (uint8_t*)malloc((iccProfile->size + ICC_HEADER_SIZE) * sizeof(uint8_t)); - if (!profile) return FALSE; - memcpy(profile, icc_signature, 12); + std::unique_ptr profile(new(std::nothrow) uint8_t[iccProfile->size + ICC_HEADER_SIZE]); + if (!profile) { + return FALSE; + } + memcpy(profile.get(), icc_signature, 12); for (long i = 0; i < (long)iccProfile->size; i += MAX_DATA_BYTES_IN_MARKER) { unsigned length = std::min((long)(iccProfile->size - i), MAX_DATA_BYTES_IN_MARKER); @@ -797,12 +803,10 @@ jpeg_write_icc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { // number of markers profile[13] = (uint8_t) (iccProfile->size / MAX_DATA_BYTES_IN_MARKER + 1); - memcpy(profile + ICC_HEADER_SIZE, (uint8_t*)iccProfile->data + i, length); - jpeg_write_marker(cinfo, ICC_MARKER, profile, (length + ICC_HEADER_SIZE)); + memcpy(profile.get() + ICC_HEADER_SIZE, (uint8_t *)iccProfile->data + i, length); + jpeg_write_marker(cinfo, ICC_MARKER, profile.get(), (length + ICC_HEADER_SIZE)); } - free(profile); - return TRUE; } @@ -829,8 +833,10 @@ jpeg_write_iptc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { for (long i = 0; i < (long)profile_size; i += 65517L) { unsigned length = std::min((long)profile_size - i, 65517L); unsigned roundup = length & 0x01; // needed for Photoshop - auto *iptc_profile = (uint8_t*)malloc(length + roundup + tag_length); - if (!iptc_profile) break; + std::unique_ptr iptc_profile(new(std::nothrow) uint8_t[length + roundup + tag_length]); + if (!iptc_profile) { + break; + } // Photoshop identification string memcpy(&iptc_profile[0], "Photoshop 3.0\x0", 14); // 8BIM segment type @@ -842,8 +848,7 @@ jpeg_write_iptc_profile(j_compress_ptr cinfo, FIBITMAP *dib) { memcpy(&iptc_profile[tag_length], &profile[i], length); if (roundup) iptc_profile[length + tag_length] = 0; - jpeg_write_marker(cinfo, IPTC_MARKER, iptc_profile, length + roundup + tag_length); - free(iptc_profile); + jpeg_write_marker(cinfo, IPTC_MARKER, iptc_profile.get(), length + roundup + tag_length); } // release profile @@ -877,19 +882,19 @@ jpeg_write_xmp_profile(j_compress_ptr cinfo, FIBITMAP *dib) { uint32_t tag_length = FreeImage_GetTagLength(tag_xmp); - auto *profile = (uint8_t*)malloc((tag_length + xmp_header_size) * sizeof(uint8_t)); - if (!profile) return FALSE; - memcpy(profile, xmp_signature, xmp_header_size); + std::unique_ptr profile(new(std::nothrow) uint8_t[tag_length + xmp_header_size]); + if (!profile) { + return FALSE; + } + memcpy(profile.get(), xmp_signature, xmp_header_size); for (uint32_t i = 0; i < tag_length; i += 65504L) { unsigned length = std::min((long)(tag_length - i), 65504L); - memcpy(profile + xmp_header_size, tag_value + i, length); - jpeg_write_marker(cinfo, EXIF_MARKER, profile, (length + xmp_header_size)); + memcpy(profile.get() + xmp_header_size, tag_value + i, length); + jpeg_write_marker(cinfo, EXIF_MARKER, profile.get(), (length + xmp_header_size)); } - free(profile); - return TRUE; } } @@ -921,18 +926,18 @@ jpeg_write_exif_profile_raw(j_compress_ptr cinfo, FIBITMAP *dib) { if (tag_value) { uint32_t tag_length = FreeImage_GetTagLength(tag_exif); - auto *profile = (uint8_t*)malloc(tag_length * sizeof(uint8_t)); - if (!profile) return FALSE; + std::unique_ptr profile(new(std::nothrow) uint8_t[tag_length]); + if (!profile) { + return FALSE; + } for (uint32_t i = 0; i < tag_length; i += 65504L) { unsigned length = std::min((long)(tag_length - i), 65504L); - memcpy(profile, tag_value + i, length); - jpeg_write_marker(cinfo, EXIF_MARKER, profile, length); + memcpy(profile.get(), tag_value + i, length); + jpeg_write_marker(cinfo, EXIF_MARKER, profile.get(), length); } - free(profile); - return TRUE; } } @@ -1576,8 +1581,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void if (color_type == FIC_RGB) { // 24-bit RGB image : need to swap red and blue channels unsigned pitch = FreeImage_GetPitch(dib); - auto *target = (uint8_t*)malloc(pitch * sizeof(uint8_t)); - if (!target) { + std::unique_ptr safeTarget(new(std::nothrow) uint8_t[pitch]); + auto *target{ safeTarget.get() }; + if (target) { throw FI_MSG_ERROR_MEMORY; } @@ -1595,11 +1601,11 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // write the scanline jpeg_write_scanlines(&cinfo, &target, 1); } - free(target); } else if (color_type == FIC_CMYK) { unsigned pitch = FreeImage_GetPitch(dib); - auto *target = (uint8_t*)malloc(pitch * sizeof(uint8_t)); + std::unique_ptr safeTarget(new(std::nothrow) uint8_t[pitch]); + auto *target{ safeTarget.get() }; if (!target) { throw FI_MSG_ERROR_MEMORY; } @@ -1622,7 +1628,6 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void // write the scanline jpeg_write_scanlines(&cinfo, &target, 1); } - free(target); } else if (color_type == FIC_MINISBLACK) { // 8-bit standard greyscale images @@ -1635,7 +1640,8 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void else if (color_type == FIC_PALETTE) { // 8-bit palettized images are converted to 24-bit images FIRGBA8 *palette = FreeImage_GetPalette(dib); - auto *target = (uint8_t*)malloc(cinfo.image_width * 3); + std::unique_ptr safeTarget(new(std::nothrow) uint8_t[cinfo.image_width * 3]); + auto *target{ safeTarget.get() }; if (!target) { throw FI_MSG_ERROR_MEMORY; } @@ -1656,14 +1662,13 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void jpeg_write_scanlines(&cinfo, &target, 1); } - - free(target); } else if (color_type == FIC_MINISWHITE) { // reverse 8-bit greyscale image, so reverse grey value on the fly unsigned i; uint8_t reverse[256]; - auto *target = (uint8_t *)malloc(cinfo.image_width); + std::unique_ptr safeTarget(new(std::nothrow) uint8_t[cinfo.image_width]); + auto *target{ safeTarget.get() }; if (!target) { throw FI_MSG_ERROR_MEMORY; } @@ -1679,8 +1684,6 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void } jpeg_write_scanlines(&cinfo, &target, 1); } - - free(target); } // Step 8: Finish compression