summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2016-08-22 13:48:07 (GMT)
committer Michael Drake <tlsa@netsurf-browser.org>2016-08-22 13:48:35 (GMT)
commit6454650532ae2f109fb668f716317fdda3ee7d20 (patch)
tree91c37d4ed6c3db8c22a7b034881a2147f83d2cfe
parent4fd92297e0a144881f37ffdb1c19fab6b0d3e47d (diff)
downloadlibnsbmp-6454650532ae2f109fb668f716317fdda3ee7d20.tar.gz
libnsbmp-6454650532ae2f109fb668f716317fdda3ee7d20.tar.bz2
Decode: Account for row padding at end of row, rather than start.
-rw-r--r--src/libnsbmp.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libnsbmp.c b/src/libnsbmp.c
index c03d34b..dc18a50 100644
--- a/src/libnsbmp.c
+++ b/src/libnsbmp.c
@@ -529,8 +529,6 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
}
for (y = 0; y < bmp->height; y++) {
- while (addr != (((intptr_t)data) & 3))
- data++;
if ((data + (4 * bmp->width)) > end)
return BMP_INSUFFICIENT_DATA;
if (bmp->reversed)
@@ -566,6 +564,8 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] = read_uint32((uint8_t *)&scanline[x],0);
}
}
+ while (addr != (((intptr_t)data) & 3))
+ data++;
}
*start = data;
return BMP_OK;
@@ -615,10 +615,6 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
}
for (y = 0; y < bmp->height; y++) {
- while (addr != (((intptr_t)data) & 3)) {
- data++;
- }
-
if ((data + (3 * bmp->width)) > end) {
return BMP_INSUFFICIENT_DATA;
}
@@ -640,6 +636,9 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] = read_uint32((uint8_t *)&scanline[x],0);
}
+ while (addr != (((intptr_t)data) & 3)) {
+ data++;
+ }
}
*start = data;
return BMP_OK;
@@ -683,8 +682,6 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
}
for (y = 0; y < bmp->height; y++) {
- while (addr != (((intptr_t)data) & 3))
- data += 2;
if ((data + (2 * bmp->width)) > end)
return BMP_INSUFFICIENT_DATA;
if (bmp->reversed)
@@ -726,6 +723,8 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] = read_uint32((uint8_t *)&scanline[x],0);
}
}
+ while (addr != (((intptr_t)data) & 3))
+ data += 2;
}
*start = data;
return BMP_OK;
@@ -775,8 +774,6 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
}
for (y = 0; y < bmp->height; y++) {
- while (addr != (((intptr_t)data) & 3))
- data++;
bit = 8;
if ((data + (bmp->width / ppb)) > end)
return BMP_INSUFFICIENT_DATA;
@@ -800,6 +797,8 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
}
}
}
+ while (addr != (((intptr_t)data) & 3))
+ data++;
}
*start = data;
return BMP_OK;
@@ -828,11 +827,10 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
return BMP_INSUFFICIENT_MEMORY;
bottom = top + (uint64_t)swidth * (bmp->height - 1);
end = data + bytes;
+
addr = ((intptr_t)data) & 3;
for (y = 0; y < bmp->height; y++) {
- while (addr != (((intptr_t)data) & 3))
- data++;
if ((data + (bmp->width >> 3)) > end)
return BMP_INSUFFICIENT_DATA;
scanline = (void *)(bottom - (y * swidth));
@@ -848,6 +846,8 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
scanline[x] = read_uint32((uint8_t *)&scanline[x], 0);
cur_byte = cur_byte << 1;
}
+ while (addr != (((intptr_t)data) & 3))
+ data++;
}
return BMP_OK;
}