Skip to content

Commit 517f16b

Browse files
committed
MIN and MAX macros in ImagingUtils
1 parent b67f018 commit 517f16b

File tree

7 files changed

+17
-27
lines changed

7 files changed

+17
-27
lines changed

src/_imagingmath.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
#define SUB(type, v1, v2) (v1) - (v2)
6161
#define MUL(type, v1, v2) (v1) * (v2)
6262

63-
#define MIN(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
64-
#define MAX(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
63+
#define MINOP(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
64+
#define MAXOP(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
6565

6666
#define AND(type, v1, v2) (v1) & (v2)
6767
#define OR(type, v1, v2) (v1) | (v2)
@@ -131,8 +131,8 @@ BINOP(xor_I, XOR, INT32)
131131
BINOP(lshift_I, LSHIFT, INT32)
132132
BINOP(rshift_I, RSHIFT, INT32)
133133

134-
BINOP(min_I, MIN, INT32)
135-
BINOP(max_I, MAX, INT32)
134+
BINOP(min_I, MINOP, INT32)
135+
BINOP(max_I, MAXOP, INT32)
136136

137137
BINOP(eq_I, EQ, INT32)
138138
BINOP(ne_I, NE, INT32)
@@ -152,8 +152,8 @@ BINOP(mod_F, MOD_F, FLOAT32)
152152
BINOP(pow_F, POW_F, FLOAT32)
153153
BINOP(diff_F, DIFF_F, FLOAT32)
154154

155-
BINOP(min_F, MIN, FLOAT32)
156-
BINOP(max_F, MAX, FLOAT32)
155+
BINOP(min_F, MINOP, FLOAT32)
156+
BINOP(max_F, MAXOP, FLOAT32)
157157

158158
BINOP(eq_F, EQ, FLOAT32)
159159
BINOP(ne_F, NE, FLOAT32)

src/libImaging/BoxBlur.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "Imaging.h"
22

3-
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
4-
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
5-
63
typedef UINT8 pixel[4];
74

85
void static inline ImagingLineBoxBlur32(

src/libImaging/Convert.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434

3535
#include "Imaging.h"
3636

37-
#define MAX(a, b) (a) > (b) ? (a) : (b)
38-
#define MIN(a, b) (a) < (b) ? (a) : (b)
39-
4037
#define CLIP16(v) ((v) <= 0 ? 0 : (v) >= 65535 ? 65535 : (v))
4138

4239
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */

src/libImaging/ImagingUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#define MASK_UINT32_CHANNEL_3 0xff000000
1515
#endif
1616

17+
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
18+
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
19+
1720
#define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8)
1821

1922
/* like (a * b + 127) / 255), but much faster on most platforms */

src/libImaging/QuantOctree.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ typedef struct _ColorCube {
4949
ColorBucket buckets;
5050
} *ColorCube;
5151

52-
#define MAX(a, b) (a) > (b) ? (a) : (b)
53-
5452
static ColorCube
5553
new_color_cube(int r, int g, int b, int a) {
5654
ColorCube cube;

src/libImaging/TiffDecode.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
6969
);
7070
return 0;
7171
}
72-
to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
72+
to_read = MIN(size, MIN(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
7373
TRACE(("to_read: %d\n", (int)to_read));
7474

7575
_TIFFmemcpy(buf, (UINT8 *)state->data + state->loc, to_read);
@@ -87,7 +87,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
8787
TRACE(("_tiffWriteProc: %d \n", (int)size));
8888
dump_state(state);
8989

90-
to_write = min(size, state->size - (tsize_t)state->loc);
90+
to_write = MIN(size, state->size - (tsize_t)state->loc);
9191
if (state->flrealloc && size > to_write) {
9292
tdata_t new_data;
9393
tsize_t newsize = state->size;
@@ -114,7 +114,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
114114

115115
_TIFFmemcpy((UINT8 *)state->data + state->loc, buf, to_write);
116116
state->loc += (toff_t)to_write;
117-
state->eof = max(state->loc, state->eof);
117+
state->eof = MAX(state->loc, state->eof);
118118

119119
dump_state(state);
120120
return to_write;
@@ -333,7 +333,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
333333

334334
for (; state->y < state->ysize; state->y += rows_per_block) {
335335
img.row_offset = state->y;
336-
rows_to_read = min(rows_per_block, img.height - state->y);
336+
rows_to_read = MIN(rows_per_block, img.height - state->y);
337337

338338
if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read)) {
339339
TRACE(("Decode Error, y: %d\n", state->y));
@@ -349,7 +349,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
349349

350350
// iterate over each row in the strip and stuff data into image
351351
for (current_row = 0;
352-
current_row < min((INT32)rows_per_block, state->ysize - state->y);
352+
current_row < MIN((INT32)rows_per_block, state->ysize - state->y);
353353
current_row++) {
354354
TRACE(("Writing data into line %d ; \n", state->y + current_row));
355355

@@ -452,8 +452,8 @@ _decodeTile(
452452

453453
TRACE(("Read tile at %dx%d; \n\n", x, y));
454454

455-
current_tile_width = min((INT32)tile_width, state->xsize - x);
456-
current_tile_length = min((INT32)tile_length, state->ysize - y);
455+
current_tile_width = MIN((INT32)tile_width, state->xsize - x);
456+
current_tile_length = MIN((INT32)tile_length, state->ysize - y);
457457
// iterate over each line in the tile and stuff data into image
458458
for (tile_y = 0; tile_y < current_tile_length; tile_y++) {
459459
TRACE(
@@ -566,7 +566,7 @@ _decodeStrip(
566566

567567
// iterate over each row in the strip and stuff data into image
568568
for (strip_row = 0;
569-
strip_row < min((INT32)rows_per_strip, state->ysize - state->y);
569+
strip_row < MIN((INT32)rows_per_strip, state->ysize - state->y);
570570
strip_row++) {
571571
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
572572

src/libImaging/TiffDecode.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
#include <tiff.h>
1414
#endif
1515

16-
#ifndef min
17-
#define min(x, y) ((x > y) ? y : x)
18-
#define max(x, y) ((x < y) ? y : x)
19-
#endif
20-
2116
#ifndef _PIL_LIBTIFF_
2217
#define _PIL_LIBTIFF_
2318

0 commit comments

Comments
 (0)