Skip to content

Commit 45bf053

Browse files
committed
More std::swap/clamp.
1 parent cb3a5be commit 45bf053

22 files changed

Lines changed: 184 additions & 199 deletions

Source/FreeImage/Conversion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ SwapRedBlue32(FIBITMAP* dib) {
8080
uint8_t* line = FreeImage_GetBits(dib);
8181
for (unsigned y = 0; y < height; ++y, line += pitch) {
8282
for (uint8_t* pixel = line; pixel < line + lineSize ; pixel += bytesperpixel) {
83-
INPLACESWAP(pixel[0], pixel[2]);
83+
std::swap(pixel[0], pixel[2]);
8484
}
8585
}
8686

@@ -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)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);
279+
T red = (T)std::clamp(R * max_val, 0.F, max_val);
280+
T green = (T)std::clamp(G * max_val, 0.F, max_val);
281+
T blue = (T)std::clamp(B * max_val, 0.F, 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 std::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.F, 1.F); });
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 std::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.F, 1.F); });
200200
}
201201
else {
202202
BitmapTransform<float, FIRGBAF>(dst, src, [](const FIRGBAF& p) {

Source/FreeImage/ConversionRGBAF.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
121121
auto *dst_pixel = (FIRGBAF*)dst_bits;
122122
for (unsigned x = 0; x < width; x++) {
123123
// convert and scale to the range [0..1]
124-
dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F;
125-
dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F;
126-
dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F;
127-
dst_pixel->alpha = (float)(src_pixel[FI_RGBA_ALPHA]) / 255.0F;
124+
dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.F;
125+
dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.F;
126+
dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.F;
127+
dst_pixel->alpha = (float)(src_pixel[FI_RGBA_ALPHA]) / 255.F;
128128

129129
src_pixel += bytespp;
130130
dst_pixel++;
@@ -146,11 +146,11 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
146146

147147
for (unsigned x = 0; x < width; x++) {
148148
// convert and scale to the range [0..1]
149-
const float dst_value = (float)src_pixel[x] / 65535.0F;
149+
const float dst_value = (float)src_pixel[x] / 65535.F;
150150
dst_pixel[x].red = dst_value;
151151
dst_pixel[x].green = dst_value;
152152
dst_pixel[x].blue = dst_value;
153-
dst_pixel[x].alpha = 1.0F;
153+
dst_pixel[x].alpha = 1.F;
154154
}
155155
src_bits += src_pitch;
156156
dst_bits += dst_pitch;
@@ -169,10 +169,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
169169

170170
for (unsigned x = 0; x < width; x++) {
171171
// convert and scale to the range [0..1]
172-
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F;
173-
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F;
174-
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F;
175-
dst_pixel[x].alpha = 1.0F;
172+
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F;
173+
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F;
174+
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F;
175+
dst_pixel[x].alpha = 1.F;
176176
}
177177
src_bits += src_pitch;
178178
dst_bits += dst_pitch;
@@ -191,10 +191,10 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
191191

192192
for (unsigned x = 0; x < width; x++) {
193193
// convert and scale to the range [0..1]
194-
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F;
195-
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F;
196-
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F;
197-
dst_pixel[x].alpha = (float)(src_pixel[x].alpha) / 65535.0F;
194+
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F;
195+
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F;
196+
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F;
197+
dst_pixel[x].alpha = (float)(src_pixel[x].alpha) / 65535.F;
198198
}
199199
src_bits += src_pitch;
200200
dst_bits += dst_pitch;
@@ -216,7 +216,7 @@ FreeImage_ConvertToRGBAF(FIBITMAP *dib) {
216216
dst_pixel[x].red = (float)(src_pixel[x].red / static_cast<double>(std::numeric_limits<uint32_t>::max()));
217217
dst_pixel[x].green = (float)(src_pixel[x].green / static_cast<double>(std::numeric_limits<uint32_t>::max()));
218218
dst_pixel[x].blue = (float)(src_pixel[x].blue / static_cast<double>(std::numeric_limits<uint32_t>::max()));
219-
dst_pixel[x].alpha = 1.0F;
219+
dst_pixel[x].alpha = 1.F;
220220
}
221221
src_bits += src_pitch;
222222
dst_bits += dst_pitch;
@@ -258,11 +258,11 @@ 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 = std::clamp(src_pixel[x], 0.0F, 1.0F);
261+
const float value = std::clamp(src_pixel[x], 0.F, 1.F);
262262
dst_pixel[x].red = value;
263263
dst_pixel[x].green = value;
264264
dst_pixel[x].blue = value;
265-
dst_pixel[x].alpha = 1.0F;
265+
dst_pixel[x].alpha = 1.F;
266266
}
267267
src_bits += src_pitch;
268268
dst_bits += dst_pitch;
@@ -281,10 +281,10 @@ 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 = 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);
287-
dst_pixel[x].alpha = 1.0F;
284+
dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.F, 1.F);
285+
dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.F, 1.F);
286+
dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.F, 1.F);
287+
dst_pixel[x].alpha = 1.F;
288288
}
289289
src_bits += src_pitch;
290290
dst_bits += dst_pitch;

Source/FreeImage/ConversionRGBF.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
124124
auto *dst_pixel = (FIRGBF*)dst_bits;
125125
for (unsigned x = 0; x < width; x++) {
126126
// convert and scale to the range [0..1]
127-
dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.0F;
128-
dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.0F;
129-
dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.0F;
127+
dst_pixel->red = (float)(src_pixel[FI_RGBA_RED]) / 255.F;
128+
dst_pixel->green = (float)(src_pixel[FI_RGBA_GREEN]) / 255.F;
129+
dst_pixel->blue = (float)(src_pixel[FI_RGBA_BLUE]) / 255.F;
130130

131131
src_pixel += bytespp;
132132
dst_pixel ++;
@@ -148,7 +148,7 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
148148

149149
for (unsigned x = 0; x < width; x++) {
150150
// convert and scale to the range [0..1]
151-
const float dst_value = (float)src_pixel[x] / 65535.0F;
151+
const float dst_value = (float)src_pixel[x] / 65535.F;
152152
dst_pixel[x].red = dst_value;
153153
dst_pixel[x].green = dst_value;
154154
dst_pixel[x].blue = dst_value;
@@ -170,9 +170,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
170170

171171
for (unsigned x = 0; x < width; x++) {
172172
// convert and scale to the range [0..1]
173-
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F;
174-
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F;
175-
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F;
173+
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F;
174+
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F;
175+
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F;
176176
}
177177
src_bits += src_pitch;
178178
dst_bits += dst_pitch;
@@ -191,9 +191,9 @@ FreeImage_ConvertToRGBF(FIBITMAP *dib) {
191191

192192
for (unsigned x = 0; x < width; x++) {
193193
// convert and scale to the range [0..1]
194-
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.0F;
195-
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.0F;
196-
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.0F;
194+
dst_pixel[x].red = (float)(src_pixel[x].red) / 65535.F;
195+
dst_pixel[x].green = (float)(src_pixel[x].green) / 65535.F;
196+
dst_pixel[x].blue = (float)(src_pixel[x].blue) / 65535.F;
197197
}
198198
src_bits += src_pitch;
199199
dst_bits += dst_pitch;
@@ -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 = std::clamp(src_pixel[x], 0.0F, 1.0F);
258+
const float value = std::clamp(src_pixel[x], 0.F, 1.F);
259259
dst_pixel[x].red = value;
260260
dst_pixel[x].green = value;
261261
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 = 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);
303+
dst_pixel[x].red = std::clamp(src_pixel[x].red, 0.F, 1.F);
304+
dst_pixel[x].green = std::clamp(src_pixel[x].green, 0.F, 1.F);
305+
dst_pixel[x].blue = std::clamp(src_pixel[x].blue, 0.F, 1.F);
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
@@ -67,7 +67,7 @@ CONVERT_TYPE<Tdst, Tsrc>::convert(FIBITMAP *src, FREE_IMAGE_TYPE dst_type) {
6767

6868
/** Convert a greyscale image of type Tsrc to a 8-bit grayscale dib.
6969
Conversion is done using either a linear scaling from [min, max] to [0, 255]
70-
or a rounding from src_pixel to (uint8_t) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5);
70+
or a rounding from src_pixel to (uint8_t) clamp(q, 0, 255) where int q = int(src_pixel + 0.5);
7171
*/
7272
template<class Tsrc>
7373
class CONVERT_TO_BYTE

Source/FreeImage/tmoColorConvert.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ 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 = std::max(0.0F, pixel[x].red);// avoid negative values
247-
max_lum = (max_lum < Y) ? Y : max_lum; // max Luminance in the scene
248-
min_lum = (min_lum < Y) ? min_lum : Y; // min Luminance in the scene
246+
const float Y = std::max(0.F, pixel[x].red);// avoid negative values
247+
max_lum = std::max(max_lum, Y); // max Luminance in the scene
248+
min_lum = std::min(min_lum, Y); // min Luminance in the scene
249249
sum += log(2.3e-5F + Y); // contrast constant in Tumblin paper
250250
}
251251
// next line
@@ -292,9 +292,9 @@ ClampConvertRGBFTo24(FIBITMAP *src) {
292292
const float green = (src_pixel[x].green > 1) ? 1 : src_pixel[x].green;
293293
const float blue = (src_pixel[x].blue > 1) ? 1 : src_pixel[x].blue;
294294

295-
dst_pixel[FI_RGBA_RED] = (uint8_t)(255.0F * red + 0.5F);
296-
dst_pixel[FI_RGBA_GREEN] = (uint8_t)(255.0F * green + 0.5F);
297-
dst_pixel[FI_RGBA_BLUE] = (uint8_t)(255.0F * blue + 0.5F);
295+
dst_pixel[FI_RGBA_RED] = (uint8_t)(255.F * red + 0.5F);
296+
dst_pixel[FI_RGBA_GREEN] = (uint8_t)(255.F * green + 0.5F);
297+
dst_pixel[FI_RGBA_BLUE] = (uint8_t)(255.F * blue + 0.5F);
298298
dst_pixel += 3;
299299
}
300300
src_bits += src_pitch;

Source/FreeImageToolkit/CopyPaste.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ FreeImage_Copy(FIBITMAP *src, int left, int top, int right, int bottom) {
498498

499499
// normalize the rectangle
500500
if (right < left) {
501-
INPLACESWAP(left, right);
501+
std::swap(left, right);
502502
}
503503
if (bottom < top) {
504-
INPLACESWAP(top, bottom);
504+
std::swap(top, bottom);
505505
}
506506
// check the size of the sub image
507507
const int src_width = FreeImage_GetWidth(src);
@@ -790,10 +790,10 @@ FreeImage_CreateView(FIBITMAP *dib, unsigned left, unsigned top, unsigned right,
790790

791791
// normalize the rectangle
792792
if (right < left) {
793-
INPLACESWAP(left, right);
793+
std::swap(left, right);
794794
}
795795
if (bottom < top) {
796-
INPLACESWAP(top, bottom);
796+
std::swap(top, bottom);
797797
}
798798

799799
// check the size of the sub image

Source/FreeImageToolkit/JPEGTransform.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ getCropString(char* crop, size_t cropSize, int* left, int* top, int* right, int*
136136
// normalize the rectangle
137137

138138
if (*right < *left) {
139-
INPLACESWAP(*left, *right);
139+
std::swap(*left, *right);
140140
}
141141
if (*bottom < *top) {
142-
INPLACESWAP(*top, *bottom);
142+
std::swap(*top, *bottom);
143143
}
144144

145145
// test for "noop" rect

Source/FreeImageToolkit/MultigridPoissonSolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ u[0..n-1][0..n-1], using the right-hand side function rhs[0..n-1][0..n-1].
182182
*/
183183
static void fmg_relaxation(FIBITMAP *U, FIBITMAP *RHS, int n) {
184184
int row, col, ipass, isw, jsw;
185-
const float h = 1.0F / (n - 1);
185+
const float h = 1.F / (n - 1);
186186
const float h2 = h*h;
187187

188188
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.
218218
static void fmg_residual(FIBITMAP *RES, FIBITMAP *U, FIBITMAP *RHS, int n) {
219219
int row, col;
220220

221-
const float h = 1.0F / (n-1);
222-
const float h2i = 1.0F / (h*h);
221+
const float h = 1.F / (n-1);
222+
const float h2i = 1.F / (h*h);
223223

224224
const int res_pitch = FreeImage_GetPitch(RES) / sizeof(float);
225225
const int u_pitch = FreeImage_GetPitch(U) / sizeof(float);

Source/FreeImageToolkit/Rescale.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ FreeImage_RescaleRect(FIBITMAP *src, int dst_width, int dst_height, int src_left
3535

3636
// normalize the rectangle
3737
if (src_right < src_left) {
38-
INPLACESWAP(src_left, src_right);
38+
std::swap(src_left, src_right);
3939
}
4040
if (src_bottom < src_top) {
41-
INPLACESWAP(src_top, src_bottom);
41+
std::swap(src_top, src_bottom);
4242
}
4343

4444
// check the size of the sub image

0 commit comments

Comments
 (0)