summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2010-10-16 14:37:37 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2010-10-16 14:37:37 +0000
commit49b70147d174a834d4d7e11407565bf927228e4e (patch)
tree5ff67e976a79a6a0639446a9002d858b2eebfd13 /image
parent20c9a28710a9d97b8c20d7bfa94d319496c8d2b5 (diff)
downloadnetsurf-49b70147d174a834d4d7e11407565bf927228e4e.tar.gz
netsurf-49b70147d174a834d4d7e11407565bf927228e4e.tar.bz2
Make properly endian-safe
Fix warnings svn path=/trunk/netsurf/; revision=10888
Diffstat (limited to 'image')
-rw-r--r--image/webp.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/image/webp.c b/image/webp.c
index 3da1af7a7..ea96c1e43 100644
--- a/image/webp.c
+++ b/image/webp.c
@@ -44,16 +44,18 @@
bool webp_convert(struct content *c)
{
union content_msg_data msg_data;
- const char *data;
+ const uint8 *data;
+ unsigned char *imagebuf = NULL;
+ uint32 *imagebufptr = NULL;
unsigned long size;
uint8 *Y = NULL, *U = NULL, *V = NULL;
- uint32 width = 0, height = 0;
- uint32 x = 0, y = 0, offset = 0;
+ int width = 0, height = 0;
+ long x = 0, y = 0, offset = 0;
uint8 r, g, b, a;
char title[100];
WebPResult res = webp_success;
- data = content__get_source_data(c, &size);
+ data = (uint8 *)content__get_source_data(c, &size);
res = WebPDecode(data, size, &Y, &U, &V, &width, &height);
if (res != webp_success) {
@@ -70,7 +72,7 @@ bool webp_convert(struct content *c)
if(Y) free(Y);
return false;
}
- unsigned char* imagebuf = bitmap_get_buffer(c->bitmap);
+ imagebuf = bitmap_get_buffer(c->bitmap);
if (!imagebuf) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
@@ -79,24 +81,24 @@ bool webp_convert(struct content *c)
}
unsigned int row_width = bitmap_get_rowstride(c->bitmap) / 4;
- YUV420toRGBA(Y, U, V, row_width, width, height, imagebuf);
+ YUV420toRGBA(Y, U, V, row_width, width, height, (uint32 *)imagebuf);
if(Y) free(Y);
- /* Data is RGBA on both big- and little-endian platforms,
- * so reverse the byte order. */
+ /* Decoded data is RGBA on both big- and little-endian platforms,
+ * so ensure correct byte order. */
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
offset = 4 * (y * width + x);
- r = imagebuf[offset+3];
- g = imagebuf[offset+2];
- b = imagebuf[offset+1];
- a = imagebuf[offset];
- imagebuf[offset] = r;
- imagebuf[offset+1] = g;
- imagebuf[offset+2] = b;
- imagebuf[offset+3] = a;
+ imagebufptr = imagebuf + offset;
+
+ a = imagebuf[offset+3];
+ b = imagebuf[offset+2];
+ g = imagebuf[offset+1];
+ r = imagebuf[offset];
+
+ *imagebufptr = r << 24 | g << 16 | b << 8 | a;
}
}
@@ -109,6 +111,7 @@ bool webp_convert(struct content *c)
bitmap_modified(c->bitmap);
c->status = CONTENT_STATUS_DONE;
+ content_set_status(c, "");
return true;
}