Skip to content

Commit cb3a5be

Browse files
committed
More std::min/max/clamp.
1 parent 72cca56 commit cb3a5be

26 files changed

Lines changed: 67 additions & 67 deletions

Source/FreeImage/BitmapAccess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ FreeImage_GetTransparencyCount(FIBITMAP *dib) {
10231023
void DLL_CALLCONV
10241024
FreeImage_SetTransparencyTable(FIBITMAP *dib, uint8_t *table, int count) {
10251025
if (dib) {
1026-
count = MAX(0, MIN(count, 256));
1026+
count = std::clamp(count, 0, 256);
10271027
if (FreeImage_GetBPP(dib) <= 8) {
10281028
((FREEIMAGEHEADER *)dib->data)->transparent = (count > 0) ? TRUE : FALSE;
10291029
((FREEIMAGEHEADER *)dib->data)->transparency_count = count;

Source/FreeImage/Conversion.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ CMYKToRGB(T C, T M, T Y, T K, T* out) {
123123
unsigned b = (max_val - Y) * (max_val - K) / max_val;
124124

125125
// clamp values to [0..max_val]
126-
T red = (T)CLAMP(r, (unsigned)0, max_val);
127-
T green = (T)CLAMP(g, (unsigned)0, max_val);
128-
T blue = (T)CLAMP(b, (unsigned)0, max_val);
126+
T red = (T)std::clamp(r, (unsigned)0, max_val);
127+
T green = (T)std::clamp(g, (unsigned)0, max_val);
128+
T blue = (T)std::clamp(b, (unsigned)0, max_val);
129129

130130
assignRGB(red, green, blue, out);
131131
}
@@ -276,9 +276,9 @@ CIELabToRGB(float L, float a, float b, T *rgb) {
276276
XYZToRGB(X, Y, Z, &R, &G, &B);
277277

278278
// clamp values to [0..max_val]
279-
T red = (T)CLAMP(R * max_val, 0.0F, max_val);
280-
T green = (T)CLAMP(G * max_val, 0.0F, max_val);
281-
T blue = (T)CLAMP(B * max_val, 0.0F, max_val);
279+
T red = (T)std::clamp(R * max_val, 0.0F, max_val);
280+
T green = (T)std::clamp(G * max_val, 0.0F, max_val);
281+
T blue = (T)std::clamp(B * max_val, 0.0F, max_val);
282282

283283
assignRGB(red, green, blue, rgb);
284284
}

Source/FreeImage/ConversionFloat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) {
185185
case FIT_RGBF:
186186
if (scale_linear) {
187187
BitmapTransform<float, FIRGBF>(dst, src, [](const FIRGBF& p) {
188-
return CLAMP(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); });
188+
return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); });
189189
}
190190
else {
191191
BitmapTransform<float, FIRGBF>(dst, src, [](const FIRGBF& p) {
@@ -196,7 +196,7 @@ FreeImage_ConvertToFloat(FIBITMAP *dib, FIBOOL scale_linear) {
196196
case FIT_RGBAF:
197197
if (scale_linear) {
198198
BitmapTransform<float, FIRGBAF>(dst, src, [](const FIRGBAF& p) {
199-
return CLAMP(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); });
199+
return std::clamp(LUMA_REC709(p.red, p.green, p.blue), 0.0F, 1.0F); });
200200
}
201201
else {
202202
BitmapTransform<float, FIRGBAF>(dst, src, [](const FIRGBAF& p) {

Source/FreeImage/ConversionRGBAF.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
258258
for (unsigned x = 0; x < width; x++) {
259259
// convert by copying greyscale channel to each R, G, B channels
260260
// assume float values are in [0..1]
261-
const float value = CLAMP(src_pixel[x], 0.0F, 1.0F);
261+
const float value = std::clamp(src_pixel[x], 0.0F, 1.0F);
262262
dst_pixel[x].red = value;
263263
dst_pixel[x].green = value;
264264
dst_pixel[x].blue = value;
@@ -281,9 +281,9 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
281281

282282
for (unsigned x = 0; x < width; x++) {
283283
// convert pixels directly, while adding a "dummy" alpha of 1.0
284-
dst_pixel[x].red = CLAMP(src_pixel[x].red, 0.0F, 1.0F);
285-
dst_pixel[x].green = CLAMP(src_pixel[x].green, 0.0F, 1.0F);
286-
dst_pixel[x].blue = CLAMP(src_pixel[x].blue, 0.0F, 1.0F);
284+
dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F);
285+
dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F);
286+
dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F);
287287
dst_pixel[x].alpha = 1.0F;
288288
}
289289
src_bits += src_pitch;

Source/FreeImage/ConversionRGBF.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
255255
for (unsigned x = 0; x < width; x++) {
256256
// convert by copying greyscale channel to each R, G, B channels
257257
// assume float values are in [0..1]
258-
const float value = CLAMP(src_pixel[x], 0.0F, 1.0F);
258+
const float value = std::clamp(src_pixel[x], 0.0F, 1.0F);
259259
dst_pixel[x].red = value;
260260
dst_pixel[x].green = value;
261261
dst_pixel[x].blue = value;
@@ -278,7 +278,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
278278
for (unsigned x = 0; x < width; x++) {
279279
// convert by copying greyscale channel to each R, G, B channels
280280
// assume float values are in [0..1]
281-
const float value = static_cast<float>(CLAMP(src_pixel[x], 0.0, 1.0));
281+
const float value = static_cast<float>(std::clamp(src_pixel[x], 0.0, 1.0));
282282
dst_pixel[x].red = value;
283283
dst_pixel[x].green = value;
284284
dst_pixel[x].blue = value;
@@ -300,9 +300,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
300300

301301
for (unsigned x = 0; x < width; x++) {
302302
// convert and skip alpha channel
303-
dst_pixel[x].red = CLAMP(src_pixel[x].red, 0.0F, 1.0F);
304-
dst_pixel[x].green = CLAMP(src_pixel[x].green, 0.0F, 1.0F);
305-
dst_pixel[x].blue = CLAMP(src_pixel[x].blue, 0.0F, 1.0F);
303+
dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.0F, 1.0F);
304+
dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.0F, 1.0F);
305+
dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.0F, 1.0F);
306306
}
307307
src_bits += src_pitch;
308308
dst_bits += dst_pitch;

Source/FreeImage/ConversionType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ CONVERT_TO_BYTE<Tsrc>::convert(FIBITMAP *src, FIBOOL scale_linear) {
134134
for (x = 0; x < width; x++) {
135135
// rounding
136136
int q = int(src_bits[x] + 0.5);
137-
dst_bits[x] = (uint8_t) MIN(255, MAX(0, q));
137+
dst_bits[x] = (uint8_t) std::clamp(q, 0, 255);
138138
}
139139
}
140140
}

Source/FreeImage/MNGHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ mng_WriteJNG(int format_id, FreeImageIO *io, FIBITMAP *dib, fi_handle handle, in
12061206
// write chunks
12071207
for (uint32_t k = 0; k < size_in_bytes;) {
12081208
uint32_t bytes_left = size_in_bytes - k;
1209-
uint32_t chunk_size = MIN(JPEG_CHUNK_SIZE, bytes_left);
1209+
uint32_t chunk_size = std::min(JPEG_CHUNK_SIZE, bytes_left);
12101210
mng_WriteChunk(mng_JDAT, &jpeg_data[k], chunk_size, hJngMemory);
12111211
k += chunk_size;
12121212
}

Source/FreeImage/tmoColorConvert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ LuminanceFromYxy(FIBITMAP *Yxy, float *maxLum, float *minLum, float *worldLum) {
243243
for (unsigned y = 0; y < height; y++) {
244244
auto *pixel = (const FIRGBF*)bits;
245245
for (unsigned x = 0; x < width; x++) {
246-
const float Y = MAX(0.0F, pixel[x].red);// avoid negative values
246+
const float Y = std::max(0.0F, pixel[x].red);// avoid negative values
247247
max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene
248248
min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene
249249
sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper

Source/FreeImage/tmoFattal02.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static FIBITMAP* tmoFattal02(FIBITMAP *Y, float alpha, float beta) {
513513
// get the number of levels for the pyramid
514514
const unsigned width = FreeImage_GetWidth(H);
515515
const unsigned height = FreeImage_GetHeight(H);
516-
unsigned minsize = MIN(width, height);
516+
unsigned minsize = std::min(width, height);
517517
while (minsize >= MIN_PYRAMID_SIZE) {
518518
nlevels++;
519519
minsize /= 2;
@@ -607,8 +607,8 @@ Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and con
607607
FIBITMAP* DLL_CALLCONV
608608
FreeImage_TmoFattal02(FIBITMAP *dib, double color_saturation, double attenuation) {
609609
const float alpha = 0.1F; // parameter alpha = 0.1
610-
const float beta = (float)MAX(0.8, MIN(0.9, attenuation)); // parameter beta = [0.8..0.9]
611-
const float s = (float)MAX(0.4, MIN(0.6, color_saturation));// exponent s controls color saturation = [0.4..0.6]
610+
const float beta = (float)std::clamp(attenuation, 0.8, 0.9); // parameter beta = [0.8..0.9]
611+
const float s = (float)std::clamp(color_saturation, 0.4, 0.6);// exponent s controls color saturation = [0.4..0.6]
612612

613613
FIBITMAP *src{};
614614
FIBITMAP *Yin{};

Source/FreeImageToolkit/BSplineRotate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ Rotate8Bit(FIBITMAP *dib, double angle, double x_shift, double y_shift, double x
624624
p = (double)InterpolatedValue(ImageRasterArray, width, height, x1, y1, spline);
625625
}
626626
// clamp and convert to uint8_t
627-
dst_bits[x] = (uint8_t)MIN(MAX((int)0, (int)(p + 0.5)), (int)255);
627+
dst_bits[x] = (uint8_t)std::clamp((int)(p + 0.5), 0, 255);
628628
}
629629
}
630630

0 commit comments

Comments
 (0)