Skip to content

Commit 03355c9

Browse files
committed
Apply hoist optimizations to single-band getextrema
1 parent dd4f59d commit 03355c9

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/libImaging/GetBBox.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ ImagingGetProjection(Imaging im, UINT8 *xproj, UINT8 *yproj) {
147147

148148
int
149149
ImagingGetExtrema(Imaging im, void *extrema) {
150-
int x, y;
150+
int xsize = im->xsize, ysize = im->ysize;
151151
INT32 imin, imax;
152152
FLOAT32 fmin, fmax;
153153

@@ -156,16 +156,16 @@ ImagingGetExtrema(Imaging im, void *extrema) {
156156
return -1; /* mismatch */
157157
}
158158

159-
if (!im->xsize || !im->ysize) {
159+
if (!xsize || !ysize) {
160160
return 0; /* zero size */
161161
}
162162

163163
switch (im->type) {
164164
case IMAGING_TYPE_UINT8:
165165
imin = imax = im->image8[0][0];
166-
for (y = 0; y < im->ysize; y++) {
166+
for (int y = 0; y < ysize; y++) {
167167
UINT8 *in = im->image8[y];
168-
for (x = 0; x < im->xsize; x++) {
168+
for (int x = 0; x < xsize; x++) {
169169
imin = imin < in[x] ? imin : in[x];
170170
imax = imax > in[x] ? imax : in[x];
171171
}
@@ -178,9 +178,9 @@ ImagingGetExtrema(Imaging im, void *extrema) {
178178
break;
179179
case IMAGING_TYPE_INT32:
180180
imin = imax = im->image32[0][0];
181-
for (y = 0; y < im->ysize; y++) {
181+
for (int y = 0; y < ysize; y++) {
182182
INT32 *in = im->image32[y];
183-
for (x = 0; x < im->xsize; x++) {
183+
for (int x = 0; x < xsize; x++) {
184184
imin = imin < in[x] ? imin : in[x];
185185
imax = imax > in[x] ? imax : in[x];
186186
}
@@ -190,9 +190,9 @@ ImagingGetExtrema(Imaging im, void *extrema) {
190190
break;
191191
case IMAGING_TYPE_FLOAT32:
192192
fmin = fmax = ((FLOAT32 *)im->image32[0])[0];
193-
for (y = 0; y < im->ysize; y++) {
193+
for (int y = 0; y < ysize; y++) {
194194
FLOAT32 *in = (FLOAT32 *)im->image32[y];
195-
for (x = 0; x < im->xsize; x++) {
195+
for (int x = 0; x < xsize; x++) {
196196
// Kept as if/else (unlike the integer branches above),
197197
// since float min/max isn't vectorisable due to NaN semantics.
198198
if (fmin > in[x]) {
@@ -215,8 +215,8 @@ ImagingGetExtrema(Imaging im, void *extrema) {
215215
memcpy(&v, pixel, sizeof(v));
216216
#endif
217217
imin = imax = v;
218-
for (y = 0; y < im->ysize; y++) {
219-
for (x = 0; x < im->xsize; x++) {
218+
for (int y = 0; y < ysize; y++) {
219+
for (int x = 0; x < xsize; x++) {
220220
pixel = (UINT8 *)im->image[y] + x * sizeof(v);
221221
#ifdef WORDS_BIGENDIAN
222222
v = pixel[0] + ((UINT16)pixel[1] << 8);

0 commit comments

Comments
 (0)