summaryrefslogtreecommitdiff
path: root/content/handlers/image/bmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/image/bmp.c')
-rw-r--r--content/handlers/image/bmp.c46
1 files changed, 32 insertions, 14 deletions
diff --git a/content/handlers/image/bmp.c b/content/handlers/image/bmp.c
index 48a37fb24..3fec2cc75 100644
--- a/content/handlers/image/bmp.c
+++ b/content/handlers/image/bmp.c
@@ -33,7 +33,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/bmp.h"
@@ -56,12 +58,12 @@ typedef struct nsbmp_content {
*/
static void *nsbmp_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);
@@ -73,12 +75,11 @@ static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
.bitmap_create = nsbmp_bitmap_create,
.bitmap_destroy = guit->bitmap->destroy,
.bitmap_get_buffer = guit->bitmap->get_buffer,
- .bitmap_get_bpp = guit->bitmap->get_bpp
};
bmp->bmp = calloc(sizeof(struct bmp_image), 1);
if (bmp->bmp == NULL) {
- content_broadcast_errorcode(&bmp->base, NSERROR_NOMEM);
+ content_broadcast_error(&bmp->base, NSERROR_NOMEM, NULL);
return NSERROR_NOMEM;
}
@@ -87,10 +88,14 @@ static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
return NSERROR_OK;
}
-static nserror nsbmp_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)
+static nserror
+nsbmp_create(const struct content_handler *handler,
+ lwc_string *imime_type,
+ const struct http_parameter *params,
+ llcache_handle *llcache,
+ const char *fallback_charset,
+ bool quirks,
+ struct content **c)
{
nsbmp_content *bmp;
nserror error;
@@ -122,8 +127,8 @@ static bool nsbmp_convert(struct content *c)
nsbmp_content *bmp = (nsbmp_content *) c;
bmp_result res;
uint32_t swidth;
- const char *data;
- unsigned long size;
+ const uint8_t *data;
+ size_t size;
char *title;
/* set the bmp data */
@@ -135,19 +140,18 @@ static bool nsbmp_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_BMP_ERROR);
+ content_broadcast_error(c, NSERROR_BMP_ERROR, NULL);
return false;
}
/* Store our content width and description */
c->width = bmp->bmp->width;
c->height = bmp->bmp->height;
- swidth = bmp->bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bmp->bitmap) *
- bmp->bmp->width;
+ swidth = sizeof(uint32_t) * bmp->bmp->width;
c->size += (swidth * bmp->bmp->height) + 16 + 44;
/* set title text */
@@ -186,6 +190,9 @@ static bool nsbmp_redraw(struct content *c, struct content_redraw_data *data,
return false;
}
+ bitmap_format_to_client(bmp->bitmap, &(bitmap_fmt_t) {
+ .layout = BITMAP_LAYOUT_R8G8B8A8,
+ });
guit->bitmap->modified(bmp->bitmap);
}
@@ -259,6 +266,16 @@ static content_type nsbmp_content_type(void)
return CONTENT_IMAGE;
}
+static bool nsbmp_content_is_opaque(struct content *c)
+{
+ nsbmp_content *bmp = (nsbmp_content *)c;
+
+ if (bmp->bitmap != NULL) {
+ return guit->bitmap->get_opaque(bmp->bitmap);
+ }
+
+ return false;
+}
static const content_handler nsbmp_content_handler = {
.create = nsbmp_create,
@@ -268,6 +285,7 @@ static const content_handler nsbmp_content_handler = {
.clone = nsbmp_clone,
.get_internal = nsbmp_get_internal,
.type = nsbmp_content_type,
+ .is_opaque = nsbmp_content_is_opaque,
.no_share = false,
};