Skip to content

Commit 29314c7

Browse files
committed
Chops: hoist size vars and add restrict in CHOP/CHOP2 macros
1 parent e234120 commit 29314c7

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

src/libImaging/Chops.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818

1919
#include "Imaging.h"
2020

21+
// restrict safety: imIn1/imIn2 are read-only, and imOut is always freshly allocated
2122
#define CHOP(operation) \
2223
int x, y; \
2324
Imaging imOut; \
2425
imOut = create(imIn1, imIn2, IMAGING_MODE_UNKNOWN); \
2526
if (!imOut) { \
2627
return NULL; \
2728
} \
28-
for (y = 0; y < imOut->ysize; y++) { \
29-
UINT8 *out = (UINT8 *)imOut->image[y]; \
30-
UINT8 *in1 = (UINT8 *)imIn1->image[y]; \
31-
UINT8 *in2 = (UINT8 *)imIn2->image[y]; \
32-
for (x = 0; x < imOut->linesize; x++) { \
29+
int ysize = imOut->ysize; \
30+
int linesize = imOut->linesize; \
31+
for (y = 0; y < ysize; y++) { \
32+
UINT8 *restrict out = (UINT8 *)imOut->image[y]; \
33+
UINT8 *restrict in1 = (UINT8 *)imIn1->image[y]; \
34+
UINT8 *restrict in2 = (UINT8 *)imIn2->image[y]; \
35+
for (x = 0; x < linesize; x++) { \
3336
int temp = operation; \
3437
if (temp <= 0) { \
3538
out[x] = 0; \
@@ -42,21 +45,24 @@
4245
} \
4346
return imOut;
4447

45-
#define CHOP2(operation, mode) \
46-
int x, y; \
47-
Imaging imOut; \
48-
imOut = create(imIn1, imIn2, mode); \
49-
if (!imOut) { \
50-
return NULL; \
51-
} \
52-
for (y = 0; y < imOut->ysize; y++) { \
53-
UINT8 *out = (UINT8 *)imOut->image[y]; \
54-
UINT8 *in1 = (UINT8 *)imIn1->image[y]; \
55-
UINT8 *in2 = (UINT8 *)imIn2->image[y]; \
56-
for (x = 0; x < imOut->linesize; x++) { \
57-
out[x] = operation; \
58-
} \
59-
} \
48+
// restrict safety: imIn1/imIn2 are read-only, and imOut is always freshly allocated
49+
#define CHOP2(operation, mode) \
50+
int x, y; \
51+
Imaging imOut; \
52+
imOut = create(imIn1, imIn2, mode); \
53+
if (!imOut) { \
54+
return NULL; \
55+
} \
56+
int ysize = imOut->ysize; \
57+
int linesize = imOut->linesize; \
58+
for (y = 0; y < ysize; y++) { \
59+
UINT8 *restrict out = (UINT8 *)imOut->image[y]; \
60+
UINT8 *restrict in1 = (UINT8 *)imIn1->image[y]; \
61+
UINT8 *restrict in2 = (UINT8 *)imIn2->image[y]; \
62+
for (x = 0; x < linesize; x++) { \
63+
out[x] = operation; \
64+
} \
65+
} \
6066
return imOut;
6167

6268
static Imaging

0 commit comments

Comments
 (0)