diff options
author | Richard Wilson <rjw@netsurf-browser.org> | 2006-02-21 20:49:12 +0000 |
---|---|---|
committer | Richard Wilson <rjw@netsurf-browser.org> | 2006-02-21 20:49:12 +0000 |
commit | 4cc85469cb26f8ea1a8f14f17bddb6a5cbea1e88 (patch) | |
tree | 2a8287146412196c1ded7a187afae58469d5f641 /riscos | |
parent | b6c6d7777277caf99ade1389c180f4a428b4a1c6 (diff) | |
download | netsurf-4cc85469cb26f8ea1a8f14f17bddb6a5cbea1e88.tar.gz netsurf-4cc85469cb26f8ea1a8f14f17bddb6a5cbea1e88.tar.bz2 |
[project @ 2006-02-21 20:49:11 by rjw]
Allow any content to be used as a background. Simplify bitmap code.
svn path=/import/netsurf/; revision=2087
Diffstat (limited to 'riscos')
-rw-r--r-- | riscos/bitmap.c | 66 | ||||
-rw-r--r-- | riscos/bitmap.h | 9 | ||||
-rw-r--r-- | riscos/history.c | 3 | ||||
-rw-r--r-- | riscos/save.c | 2 |
4 files changed, 46 insertions, 34 deletions
diff --git a/riscos/bitmap.c b/riscos/bitmap.c index fdbb4b6ea..e482452c9 100644 --- a/riscos/bitmap.c +++ b/riscos/bitmap.c @@ -74,7 +74,7 @@ struct bitmap_compressed_header { char bitmap_filename[256]; -static bool bitmap_initialise(struct bitmap *bitmap, bool clear); +static bool bitmap_initialise(struct bitmap *bitmap); static void bitmap_decompress(struct bitmap *bitmap); static void bitmap_compress(struct bitmap *bitmap); static void bitmap_load_file(struct bitmap *bitmap); @@ -145,7 +145,8 @@ void bitmap_quit(void) struct bitmap *bitmap; for (bitmap = bitmap_head; bitmap; bitmap = bitmap->next) - if ((bitmap->persistent) && (bitmap->filename[0] == '\0')) + if ((bitmap->persistent) && ((bitmap->modified) || + (bitmap->filename[0] == '\0'))) bitmap_save_file(bitmap); } @@ -159,7 +160,7 @@ void bitmap_quit(void) * \return an opaque struct bitmap, or NULL on memory exhaustion */ -struct bitmap *bitmap_create(int width, int height, bool clear) +struct bitmap *bitmap_create(int width, int height, bitmap_state state) { struct bitmap *bitmap; @@ -172,10 +173,15 @@ struct bitmap *bitmap_create(int width, int height, bool clear) bitmap->width = width; bitmap->height = height; bitmap->opaque = false; - if (clear) - bitmap->init = BITMAP_INITIALISE_FULL; - else - bitmap->init = BITMAP_INITIALISE_QUICK; + switch (state) { + case BITMAP_CLEAR_MEMORY: + case BITMAP_ALLOCATE_MEMORY: + bitmap->state = state; + break; + default: + LOG(("Invalid bitmap state")); + assert(false); + } /* link into our list of bitmaps at the head */ if (bitmap_head) { @@ -207,7 +213,7 @@ struct bitmap *bitmap_create_file(char *file) return NULL; bitmap->opaque = true; bitmap->persistent = true; - bitmap->init = BITMAP_INITIALISE_DONE; + bitmap->state = BITMAP_READY; strcpy(bitmap->filename, file); /* link in at the head */ @@ -227,21 +233,30 @@ struct bitmap *bitmap_create_file(char *file) * \param clear whether to clear the image ready for use */ -bool bitmap_initialise(struct bitmap *bitmap, bool clear) +bool bitmap_initialise(struct bitmap *bitmap) { unsigned int area_size; osspriteop_area *sprite_area; osspriteop_header *sprite; area_size = 16 + 44 + bitmap->width * bitmap->height * 4; - if (clear) - bitmap->sprite_area = calloc(1, area_size); - else - bitmap->sprite_area = malloc(area_size); - if (!bitmap->sprite_area) { - return false; + switch (bitmap->state) { + case BITMAP_CLEAR_MEMORY: + bitmap->sprite_area = calloc(1, area_size); + if (!bitmap->sprite_area) + return false; + bitmap->state = BITMAP_READY; + break; + case BITMAP_ALLOCATE_MEMORY: + bitmap->sprite_area = malloc(area_size); + if (!bitmap->sprite_area) + return false; + bitmap->state = BITMAP_READY; + break; + default: + LOG(("Invalid bitmap state")); + assert(false); } - bitmap->init = BITMAP_INITIALISE_DONE; bitmap_direct_used += area_size; /* area control block */ @@ -254,8 +269,7 @@ bool bitmap_initialise(struct bitmap *bitmap, bool clear) /* sprite control block */ sprite = (osspriteop_header *) (sprite_area + 1); sprite->size = area_size - 16; - if (!clear) - memset(sprite->name, 0x00, 12); + memset(sprite->name, 0x00, 12); strncpy(sprite->name, "bitmap", 12); sprite->width = bitmap->width - 1; sprite->height = bitmap->height - 1; @@ -346,8 +360,6 @@ bool bitmap_get_opaque(struct bitmap *bitmap) char *bitmap_get_buffer(struct bitmap *bitmap) { - bool clear; - assert(bitmap); /* move to the head of the list */ @@ -363,10 +375,14 @@ char *bitmap_get_buffer(struct bitmap *bitmap) } /* dynamically create the buffer */ - if (bitmap->init != BITMAP_INITIALISE_DONE) { - clear = (bitmap->init == BITMAP_INITIALISE_FULL); - if (!bitmap_initialise(bitmap, clear)) - return NULL; + switch (bitmap->state) { + case BITMAP_ALLOCATE_MEMORY: + case BITMAP_CLEAR_MEMORY: + if (!bitmap_initialise(bitmap)) + return NULL; + break; + default: + break; } /* image is already decompressed, no change to image states */ @@ -591,7 +607,7 @@ void bitmap_decompress(struct bitmap *bitmap) } /* create the image memory/header to decompress to */ - if (!bitmap_initialise(bitmap, false)) + if (!bitmap_initialise(bitmap)) return; /* decompress the data */ diff --git a/riscos/bitmap.h b/riscos/bitmap.h index 7360b03b9..910c201bb 100644 --- a/riscos/bitmap.h +++ b/riscos/bitmap.h @@ -9,22 +9,17 @@ #define _NETSURF_RISCOS_BITMAP_H_ #include "oslib/osspriteop.h" +#include "netsurf/image/bitmap.h" struct osspriteop_area; -typedef enum { - BITMAP_INITIALISE_DONE, /** Initialisation has been done */ - BITMAP_INITIALISE_QUICK, /** Just allocate memory */ - BITMAP_INITIALISE_FULL /** Clear the sprite buffer */ -} bitmap_initialisation; - struct bitmap { int width; int height; bool opaque; bool modified; bool persistent; - bitmap_initialisation init; + bitmap_state state; osspriteop_area *sprite_area; /** Uncompressed data, or NULL */ char *compressed; /** Compressed data, or NULL */ diff --git a/riscos/history.c b/riscos/history.c index 4cb5c7e73..46ef458bf 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -178,7 +178,8 @@ void history_add(struct history *history, struct content *content, char *frag_id * loading */ bitmap = url_store_get_thumbnail(url); if (!bitmap) { - bitmap = bitmap_create(WIDTH / 2, HEIGHT / 2, false); + bitmap = bitmap_create(WIDTH / 2, HEIGHT / 2, + BITMAP_ALLOCATE_MEMORY); if (!bitmap) { LOG(("Thumbnail initialisation failed.")); return; diff --git a/riscos/save.c b/riscos/save.c index 50335e948..7792e6ccc 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -1007,7 +1007,7 @@ bool ro_gui_save_create_thumbnail(struct content *c, const char *name) struct bitmap *bitmap; osspriteop_area *area; - bitmap = bitmap_create(34, 34, false); + bitmap = bitmap_create(34, 34, BITMAP_CLEAR_MEMORY); if (!bitmap) { LOG(("Thumbnail initialisation failed.")); return false; |