Skip to content

Commit be8209e

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

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/libImaging/Paste.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,27 @@
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(
28+
Imaging imOut,
29+
Imaging imIn,
30+
int dy,
31+
int sy,
32+
int ysize,
33+
int *y,
34+
int *y_end,
35+
int *offset
36+
) {
37+
if (imOut == imIn && dy > sy) {
38+
*y = ysize - 1;
39+
*y_end = -1;
40+
*offset = -1;
41+
} else {
42+
*y = 0;
43+
*y_end = ysize;
44+
*offset = 1;
3645
}
46+
}
3747

3848
static inline void
3949
paste(
@@ -54,7 +64,8 @@ paste(
5464

5565
xsize *= pixelsize;
5666

57-
PREPARE_PASTE_LOOP();
67+
int y, y_end, offset;
68+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
5869
for (; y != y_end; y += offset) {
5970
memcpy(imOut->image[y + dy] + dx, imIn->image[y + sy] + sx, xsize);
6071
}
@@ -75,9 +86,8 @@ paste_mask_1(
7586
) {
7687
/* paste with mode "1" mask */
7788

78-
int x;
79-
80-
PREPARE_PASTE_LOOP();
89+
int x, y, y_end, offset;
90+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
8191
if (imOut->image8) {
8292
int in_i16 = strncmp(imIn->mode, "I;16", 4) == 0;
8393
int out_i16 = strncmp(imOut->mode, "I;16", 4) == 0;
@@ -138,10 +148,10 @@ paste_mask_L(
138148
) {
139149
/* paste with mode "L" matte */
140150

141-
int x;
151+
int x, y, y_end, offset;
142152
unsigned int tmp1;
143153

144-
PREPARE_PASTE_LOOP();
154+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
145155
if (imOut->image8) {
146156
for (; y != y_end; y += offset) {
147157
UINT8 *out = imOut->image8[y + dy] + dx;
@@ -187,10 +197,10 @@ paste_mask_RGBA(
187197
) {
188198
/* paste with mode "RGBA" matte */
189199

190-
int x;
200+
int x, y, y_end, offset;
191201
unsigned int tmp1;
192202

193-
PREPARE_PASTE_LOOP();
203+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
194204
if (imOut->image8) {
195205
for (; y != y_end; y += offset) {
196206
UINT8 *out = imOut->image8[y + dy] + dx;
@@ -236,10 +246,10 @@ paste_mask_RGBa(
236246
) {
237247
/* paste with mode "RGBa" matte */
238248

239-
int x;
249+
int x, y, y_end, offset;
240250
unsigned int tmp1;
241251

242-
PREPARE_PASTE_LOOP();
252+
prepare_paste_loop(imOut, imIn, dy, sy, ysize, &y, &y_end, &offset);
243253
if (imOut->image8) {
244254
for (; y != y_end; y += offset) {
245255
UINT8 *out = imOut->image8[y + dy] + dx;

0 commit comments

Comments
 (0)