Skip to content

Commit 4e64675

Browse files
committed
Get rid of the additional loop of reversing the order of rows
...we can do this by correcting the addressing in the resulting buffer filling loops so that the image rows end up in the right place from the beginning
1 parent 1255ed7 commit 4e64675

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/imageio/imageio_pfm.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ DT_OMP_FOR(collapse(2))
9999
dt_aligned_pixel_t pix = {0.0f, 0.0f, 0.0f, 0.0f};
100100
for_three_channels(c)
101101
{
102-
value.f = readbuf[3 * (j * img->width + i) + c];
102+
value.f = readbuf[3 * ((img->height - 1 - j) * img->width + i) + c];
103103
if(swap_byte_order) value.i = GUINT32_SWAP_LE_BE(value.i);
104104
pix[c] = value.f;
105105
}
@@ -114,25 +114,13 @@ DT_OMP_FOR(collapse(2))
114114
for(size_t j = 0; j < img->height; j++)
115115
for(size_t i = 0; i < img->width; i++)
116116
{
117-
value.f = readbuf[(j * img->width + i)];
117+
value.f = readbuf[((img->height - 1 - j) * img->width + i)];
118118
if(swap_byte_order) value.i = GUINT32_SWAP_LE_BE(value.i);
119119
buf[4 * (img->width * j + i) + 2] = buf[4 * (img->width * j + i) + 1]
120120
= buf[4 * (img->width * j + i) + 0] = value.f;
121121
}
122122
}
123123

124-
float *line = (float *)calloc(4 * img->width, sizeof(float));
125-
if(line == NULL) goto error_cache_full;
126-
127-
for(size_t j = 0; j < img->height / 2; j++)
128-
{
129-
memcpy(line, buf + img->width * j * 4, sizeof(float) * 4 * img->width);
130-
memcpy(buf + img->width * j * 4, buf + img->width * (img->height - 1 - j) * 4,
131-
sizeof(float) * 4 * img->width);
132-
memcpy(buf + img->width * (img->height - 1 - j) * 4, line, sizeof(float) * 4 * img->width);
133-
}
134-
135-
free(line);
136124
fclose(f);
137125
dt_free_align(readbuf);
138126

0 commit comments

Comments
 (0)