Skip to content

Commit c72b892

Browse files
committed
Replaced #define with function
1 parent 47528e4 commit c72b892

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/libImaging/Paste.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323

2424
#include "Imaging.h"
2525

26-
#define PREPARE_PASTE_LOOP() \
27-
int y, y_end, offset; \
28-
if (imOut == imIn && dy > sy) { \
29-
y = ysize - 1; \
30-
y_end = -1; \
31-
offset = -1; \
32-
} else { \
33-
y = 0; \
34-
y_end = ysize; \
35-
offset = 1; \
26+
static inline void
27+
prepare_paste_loop(Imaging imOut, Imaging imIn, int dy, int sy, int ysize, int *y, int *y_end, int *offset) {
28+
if (imOut == imIn && dy > sy) {
29+
*y = ysize - 1;
30+
*y_end = -1;
31+
*offset = -1;
32+
} else {
33+
*y = 0;
34+
*y_end = ysize;
35+
*offset = 1;
3636
}
37+
}
3738

3839
static inline void
3940
paste(
@@ -54,7 +55,8 @@ paste(
5455

5556
xsize *= pixelsize;
5657

57-
PREPARE_PASTE_LOOP();
58+
int y, y_end, offset;
59+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
5860
for (; y != y_end; y += offset) {
5961
memcpy(imOut->image[y + dy] + dx, imIn->image[y + sy] + sx, xsize);
6062
}
@@ -75,9 +77,8 @@ paste_mask_1(
7577
) {
7678
/* paste with mode "1" mask */
7779

78-
int x;
79-
80-
PREPARE_PASTE_LOOP();
80+
int x, y, y_end, offset;
81+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
8182
if (imOut->image8) {
8283
int in_i16 = strncmp(imIn->mode, "I;16", 4) == 0;
8384
int out_i16 = strncmp(imOut->mode, "I;16", 4) == 0;
@@ -138,10 +139,10 @@ paste_mask_L(
138139
) {
139140
/* paste with mode "L" matte */
140141

141-
int x;
142+
int x, y, y_end, offset;
142143
unsigned int tmp1;
143144

144-
PREPARE_PASTE_LOOP();
145+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
145146
if (imOut->image8) {
146147
for (; y != y_end; y += offset) {
147148
UINT8 *out = imOut->image8[y + dy] + dx;
@@ -187,10 +188,10 @@ paste_mask_RGBA(
187188
) {
188189
/* paste with mode "RGBA" matte */
189190

190-
int x;
191+
int x, y, y_end, offset;
191192
unsigned int tmp1;
192193

193-
PREPARE_PASTE_LOOP();
194+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
194195
if (imOut->image8) {
195196
for (; y != y_end; y += offset) {
196197
UINT8 *out = imOut->image8[y + dy] + dx;
@@ -236,10 +237,10 @@ paste_mask_RGBa(
236237
) {
237238
/* paste with mode "RGBa" matte */
238239

239-
int x;
240+
int x, y, y_end, offset;
240241
unsigned int tmp1;
241242

242-
PREPARE_PASTE_LOOP();
243+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
243244
if (imOut->image8) {
244245
for (; y != y_end; y += offset) {
245246
UINT8 *out = imOut->image8[y + dy] + dx;

0 commit comments

Comments
 (0)