From ec9db1d6af76c053f5e1c746057554e0b0dbcc9b Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Fri, 29 Apr 2005 01:35:52 +0000 Subject: [project @ 2005-04-29 01:35:52 by rjw] Only initialise canvases if we need to. svn path=/import/netsurf/; revision=1699 --- gtk/gtk_bitmap.c | 3 ++- image/bitmap.h | 2 +- image/gifread.c | 4 ++-- image/jpeg.c | 2 +- image/mng.c | 5 ++++- riscos/bitmap.c | 11 ++++++++--- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gtk/gtk_bitmap.c b/gtk/gtk_bitmap.c index 0121963fe..f1c184a4f 100644 --- a/gtk/gtk_bitmap.c +++ b/gtk/gtk_bitmap.c @@ -32,10 +32,11 @@ struct bitmap; * * \param width width of image in pixels * \param height width of image in pixels + * \param clear whether to clear the image ready for use * \return an opaque struct bitmap, or NULL on memory exhaustion */ -struct bitmap *bitmap_create(int width, int height) +struct bitmap *bitmap_create(int width, int height, bool clear) { GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height); diff --git a/image/bitmap.h b/image/bitmap.h index 9d442c214..1e68761b3 100644 --- a/image/bitmap.h +++ b/image/bitmap.h @@ -25,7 +25,7 @@ struct content; /** An opaque image. */ struct bitmap; -struct bitmap *bitmap_create(int width, int height); +struct bitmap *bitmap_create(int width, int height, bool clear); void bitmap_set_opaque(struct bitmap *bitmap, bool opaque); bool bitmap_test_opaque(struct bitmap *bitmap); bool bitmap_get_opaque(struct bitmap *bitmap); diff --git a/image/gifread.c b/image/gifread.c index fc49bfcb7..80ea97d24 100644 --- a/image/gifread.c +++ b/image/gifread.c @@ -202,7 +202,7 @@ int gif_initialise(struct gif_animation *gif) { /* Initialise the sprite header */ - if ((gif->frame_image = bitmap_create(gif->width, gif->height)) == NULL) { + if ((gif->frame_image = bitmap_create(gif->width, gif->height, false)) == NULL) { gif_finalise(gif); return GIF_INSUFFICIENT_MEMORY; } @@ -280,7 +280,7 @@ static int gif_initialise_sprite(struct gif_animation *gif, unsigned int width, /* Allocate some more memory */ - if ((buffer = bitmap_create(max_width, max_height)) == NULL) + if ((buffer = bitmap_create(max_width, max_height, false)) == NULL) return GIF_INSUFFICIENT_MEMORY; bitmap_destroy(gif->frame_image); gif->frame_image = buffer; diff --git a/image/jpeg.c b/image/jpeg.c index 7f57d62b2..0482aa912 100644 --- a/image/jpeg.c +++ b/image/jpeg.c @@ -94,7 +94,7 @@ bool nsjpeg_convert(struct content *c, int w, int h) width = cinfo.output_width; height = cinfo.output_height; - bitmap = bitmap_create(width, height); + bitmap = bitmap_create(width, height, false); if (!bitmap) { jpeg_destroy_decompress(&cinfo); diff --git a/image/mng.c b/image/mng.c index c19873283..fadd6a3af 100644 --- a/image/mng.c +++ b/image/mng.c @@ -188,7 +188,7 @@ mng_bool nsmng_processheader(mng_handle mng, mng_uint32 width, mng_uint32 height LOG(("processing header (%p) %d, %d", c, width, height)); - c->bitmap = bitmap_create(width, height); + c->bitmap = bitmap_create(width, height, false); if (!c->bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -297,6 +297,9 @@ bool nsmng_convert(struct content *c, int width, int height) { /* Optimise the plotting of JNG/PNGs */ c->data.mng.opaque_test_pending = (c->type == CONTENT_PNG) || (c->type == CONTENT_JNG); + if (c->data.mng.opaque_test_pending) + bitmap_set_opaque(c->bitmap, false); + return true; } diff --git a/riscos/bitmap.c b/riscos/bitmap.c index 7bdf1bde4..2f2416550 100644 --- a/riscos/bitmap.c +++ b/riscos/bitmap.c @@ -29,10 +29,11 @@ * * \param width width of image in pixels * \param height width of image in pixels + * \param clear whether to clear the image ready for use * \return an opaque struct bitmap, or NULL on memory exhaustion */ -struct bitmap *bitmap_create(int width, int height) +struct bitmap *bitmap_create(int width, int height, bool clear) { unsigned int area_size; struct bitmap *bitmap; @@ -43,7 +44,10 @@ struct bitmap *bitmap_create(int width, int height) return NULL; area_size = 16 + 44 + width * height * 4; - bitmap = calloc(sizeof(struct bitmap) + area_size, 1); + if (clear) + bitmap = calloc(sizeof(struct bitmap) + area_size, 1); + else + bitmap = malloc(sizeof(struct bitmap) + area_size); if (!bitmap) return NULL; @@ -61,7 +65,8 @@ struct bitmap *bitmap_create(int width, int height) /* sprite control block */ sprite = (osspriteop_header *) (sprite_area + 1); sprite->size = area_size - 16; -/* memset(sprite->name, 0x00, 12); */ + if (!clear) + memset(sprite->name, 0x00, 12); strncpy(sprite->name, "bitmap", 12); sprite->width = width - 1; sprite->height = height - 1; -- cgit v1.2.3