diff options
Diffstat (limited to 'content/handlers/image/ico.c')
-rw-r--r-- | content/handlers/image/ico.c | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/content/handlers/image/ico.c b/content/handlers/image/ico.c index 85aab9f64..6bca2a137 100644 --- a/content/handlers/image/ico.c +++ b/content/handlers/image/ico.c @@ -16,8 +16,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** \file - * Content for image/ico (implementation) +/** + * \file + * implementation for image/ico content handler */ #include <stdbool.h> @@ -31,7 +32,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/image.h" #include "image/ico.h" @@ -39,8 +42,7 @@ typedef struct nsico_content { struct content base; - struct ico_collection *ico; /** ICO collection data */ - + struct ico_collection *ico; /** ICO collection data */ } nsico_content; /** @@ -53,12 +55,12 @@ typedef struct nsico_content { */ static void *nsico_bitmap_create(int width, int height, unsigned int bmp_state) { - unsigned int bitmap_state = BITMAP_NEW; + unsigned int bitmap_state = BITMAP_NONE; /* set bitmap state based on bmp state */ bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0; bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ? - BITMAP_CLEAR_MEMORY : 0; + BITMAP_CLEAR : 0; /* return the created bitmap */ return guit->bitmap->create(width, height, bitmap_state); @@ -70,12 +72,11 @@ static nserror nsico_create_ico_data(nsico_content *c) .bitmap_create = nsico_bitmap_create, .bitmap_destroy = guit->bitmap->destroy, .bitmap_get_buffer = guit->bitmap->get_buffer, - .bitmap_get_bpp = guit->bitmap->get_bpp }; - c->ico = calloc(sizeof(ico_collection), 1); + c->ico = calloc(1, sizeof(ico_collection)); if (c->ico == NULL) { - content_broadcast_errorcode(&c->base, NSERROR_NOMEM); + content_broadcast_error(&c->base, NSERROR_NOMEM, NULL); return NSERROR_NOMEM; } ico_collection_create(c->ico, &bmp_bitmap_callbacks); @@ -83,7 +84,7 @@ static nserror nsico_create_ico_data(nsico_content *c) } -static nserror nsico_create(const content_handler *handler, +static nserror nsico_create(const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c) @@ -120,8 +121,8 @@ static bool nsico_convert(struct content *c) nsico_content *ico = (nsico_content *) c; struct bmp_image *bmp; bmp_result res; - const char *data; - unsigned long size; + const uint8_t *data; + size_t size; char *title; /* set the ico data */ @@ -134,11 +135,11 @@ static bool nsico_convert(struct content *c) case BMP_OK: break; case BMP_INSUFFICIENT_MEMORY: - content_broadcast_errorcode(c, NSERROR_NOMEM); + content_broadcast_error(c, NSERROR_NOMEM, NULL); return false; case BMP_INSUFFICIENT_DATA: case BMP_DATA_ERROR: - content_broadcast_errorcode(c, NSERROR_ICO_ERROR); + content_broadcast_error(c, NSERROR_ICO_ERROR, NULL); return false; } @@ -172,6 +173,23 @@ static bool nsico_convert(struct content *c) return true; } +static bool nsico__decode(struct bmp_image *ico) +{ + if (ico->decoded == false) { + NSLOG(netsurf, DEBUG, "Decoding ICO %p", ico); + if (bmp_decode(ico) != BMP_OK) { + return false; + } + + bitmap_format_to_client(ico->bitmap, &(bitmap_fmt_t) { + .layout = BITMAP_LAYOUT_R8G8B8A8, + }); + guit->bitmap->modified(ico->bitmap); + + } + + return true; +} static bool nsico_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx) @@ -188,14 +206,8 @@ static bool nsico_redraw(struct content *c, struct content_redraw_data *data, } /* ensure its decided */ - if (bmp->decoded == false) { - if (bmp_decode(bmp) != BMP_OK) { - return false; - } else { - NSLOG(netsurf, INFO, "Decoding bitmap"); - guit->bitmap->modified(bmp->bitmap); - } - + if (!nsico__decode(bmp)) { + return false; } return image_bitmap_plot(bmp->bitmap, data, clip, ctx); @@ -250,7 +262,7 @@ static void *nsico_get_internal(const struct content *c, void *context) nsico_content *ico = (nsico_content *) c; /* TODO: Pick best size for purpose. * Currently assumes it's for a URL bar. */ - struct bmp_image *bmp; + struct bmp_image *bmp; bmp = ico_find(ico->ico, 16, 16); if (bmp == NULL) { @@ -259,12 +271,8 @@ static void *nsico_get_internal(const struct content *c, void *context) return NULL; } - if (bmp->decoded == false) { - if (bmp_decode(bmp) != BMP_OK) { - return NULL; - } else { - guit->bitmap->modified(bmp->bitmap); - } + if (!nsico__decode(bmp)) { + return NULL; } return bmp->bitmap; @@ -275,6 +283,29 @@ static content_type nsico_content_type(void) return CONTENT_IMAGE; } +static bool nsico_is_opaque(struct content *c) +{ + nsico_content *ico = (nsico_content *) c; + struct bmp_image *bmp; + + /** + * \todo Pick best size for purpose. Currently assumes + * it's for a URL bar. + */ + bmp = ico_find(ico->ico, 16, 16); + if (bmp == NULL) { + /* return error */ + NSLOG(netsurf, INFO, "Failed to select icon"); + return false; + } + + if (!nsico__decode(bmp)) { + return false; + } + + return guit->bitmap->get_opaque(bmp->bitmap); +} + static const content_handler nsico_content_handler = { .create = nsico_create, .data_complete = nsico_convert, @@ -283,6 +314,7 @@ static const content_handler nsico_content_handler = { .clone = nsico_clone, .get_internal = nsico_get_internal, .type = nsico_content_type, + .is_opaque = nsico_is_opaque, .no_share = false, }; |