Skip to content

Commit 4c290ee

Browse files
authored
Merge pull request #136 from radarhere/optimize-getbbox
Add braces
2 parents 25aa635 + cd44e02 commit 4c290ee

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/libImaging/GetBBox.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,56 @@ ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) {
3131
bbox[2] = bbox[3] = 0;
3232

3333
#define GETBBOX(image, mask) \
34-
/* first stage: looking for any px from top */ \
34+
/* first stage: looking for any pixels from top */ \
3535
for (y = 0; y < im->ysize; y++) { \
3636
has_data = 0; \
37-
for (x = 0; x < im->xsize; x++) \
37+
for (x = 0; x < im->xsize; x++) { \
3838
if (im->image[y][x] & mask) { \
3939
has_data = 1; \
4040
bbox[0] = x; \
4141
bbox[1] = y; \
4242
break; \
4343
} \
44-
if (has_data) \
44+
} \
45+
if (has_data) { \
4546
break; \
47+
} \
4648
} \
47-
/* Check that we got a box */ \
48-
if (bbox[1] < 0) \
49+
/* Check that we have a box */ \
50+
if (bbox[1] < 0) { \
4951
return 0; /* no data */ \
50-
/* second stage: looking for any px from bottom */ \
52+
} \
53+
/* second stage: looking for any pixels from bottom */ \
5154
for (y = im->ysize - 1; y >= bbox[1]; y--) { \
5255
has_data = 0; \
53-
for (x = 0; x < im->xsize; x++) \
56+
for (x = 0; x < im->xsize; x++) { \
5457
if (im->image[y][x] & mask) { \
5558
has_data = 1; \
56-
if (x < bbox[0]) \
59+
if (x < bbox[0]) { \
5760
bbox[0] = x; \
61+
} \
5862
bbox[3] = y + 1; \
5963
break; \
6064
} \
61-
if (has_data) \
65+
} \
66+
if (has_data) { \
6267
break; \
68+
} \
6369
} \
6470
/* third stage: looking for left and right boundaries */ \
6571
for (y = bbox[1]; y < bbox[3]; y++) { \
66-
for (x = 0; x < bbox[0]; x++) \
72+
for (x = 0; x < bbox[0]; x++) { \
6773
if (im->image[y][x] & mask) { \
6874
bbox[0] = x; \
6975
break; \
7076
} \
71-
for (x = im->xsize - 1; x >= bbox[2]; x--) \
77+
} \
78+
for (x = im->xsize - 1; x >= bbox[2]; x--) { \
7279
if (im->image[y][x] & mask) { \
7380
bbox[2] = x + 1; \
7481
break; \
7582
} \
83+
} \
7684
}
7785

7886
if (im->image8) {

0 commit comments

Comments
 (0)