diff options
Diffstat (limited to 'content/handlers/image/nssprite.c')
-rw-r--r-- | content/handlers/image/nssprite.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/content/handlers/image/nssprite.c b/content/handlers/image/nssprite.c index 269c24356..c18f49063 100644 --- a/content/handlers/image/nssprite.c +++ b/content/handlers/image/nssprite.c @@ -23,6 +23,8 @@ #include <stdbool.h> #include <stdlib.h> +#include <string.h> + #include <librosprite.h> #include "utils/utils.h" @@ -33,7 +35,9 @@ #include "netsurf/content.h" #include "content/llcache.h" #include "content/content_protected.h" +#include "content/content_factory.h" #include "desktop/gui_internal.h" +#include "desktop/bitmap.h" #include "image/nssprite.h" @@ -98,8 +102,8 @@ static bool nssprite_convert(struct content *c) struct rosprite_mem_context* ctx = NULL; - const char *data; - unsigned long size; + const uint8_t *data; + size_t size; char *title; data = content__get_source_data(c, &size); @@ -115,31 +119,19 @@ static bool nssprite_convert(struct content *c) struct rosprite* sprite = sprite_area->sprites[0]; - nssprite->bitmap = guit->bitmap->create(sprite->width, sprite->height, BITMAP_NEW); + nssprite->bitmap = guit->bitmap->create(sprite->width, sprite->height, BITMAP_NONE); if (!nssprite->bitmap) { - content_broadcast_errorcode(c, NSERROR_NOMEM); + content_broadcast_error(c, NSERROR_NOMEM, NULL); return false; } - uint32_t* imagebuf = (uint32_t *)guit->bitmap->get_buffer(nssprite->bitmap); + uint32_t* imagebuf = (uint32_t *)(void *)guit->bitmap->get_buffer(nssprite->bitmap); if (!imagebuf) { - content_broadcast_errorcode(c, NSERROR_NOMEM); + content_broadcast_error(c, NSERROR_NOMEM, NULL); return false; } unsigned char *spritebuf = (unsigned char *)sprite->image; - /* reverse byte order of each word */ - for (uint32_t y = 0; y < sprite->height; y++) { - for (uint32_t x = 0; x < sprite->width; x++) { - int offset = 4 * (y * sprite->width + x); - - *imagebuf = (spritebuf[offset] << 24) | - (spritebuf[offset + 1] << 16) | - (spritebuf[offset + 2] << 8) | - (spritebuf[offset + 3]); - - imagebuf++; - } - } + memcpy(imagebuf, spritebuf, sprite->width * sprite->height * 4); c->width = sprite->width; c->height = sprite->height; @@ -153,6 +145,9 @@ static bool nssprite_convert(struct content *c) free(title); } + bitmap_format_to_client(nssprite->bitmap, &(bitmap_fmt_t) { + .layout = BITMAP_LAYOUT_A8B8G8R8, + }); guit->bitmap->modified(nssprite->bitmap); content_set_ready(c); @@ -165,7 +160,7 @@ ro_sprite_error: if (ctx != NULL) { rosprite_destroy_mem_context(ctx); } - content_broadcast_errorcode(c, NSERROR_SPRITE_ERROR); + content_broadcast_error(c, NSERROR_SPRITE_ERROR, NULL); return false; } @@ -257,6 +252,17 @@ static content_type nssprite_content_type(void) } +static bool nssprite_content_is_opaque(struct content *c) +{ + nssprite_content *nssprite = (nssprite_content *) c; + + if (nssprite->bitmap != NULL) { + return guit->bitmap->get_opaque(nssprite->bitmap); + } + + return false; +} + static const content_handler nssprite_content_handler = { .create = nssprite_create, .data_complete = nssprite_convert, @@ -265,6 +271,7 @@ static const content_handler nssprite_content_handler = { .clone = nssprite_clone, .get_internal = nssprite_get_internal, .type = nssprite_content_type, + .is_opaque = nssprite_content_is_opaque, .no_share = false, }; |