diff options
author | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-24 18:09:28 +0000 |
---|---|---|
committer | Michael Drake <tlsa@netsurf-browser.org> | 2022-03-24 18:09:28 +0000 |
commit | 002c3c1a7c2ae7229afac3f1966892fd42895aec (patch) | |
tree | bc9c769b176981296b5e92233fd623b3164a4513 /frontends | |
parent | c2d72d1e9361b3017872e5aff16cfe9a894f3048 (diff) | |
download | netsurf-002c3c1a7c2ae7229afac3f1966892fd42895aec.tar.gz netsurf-002c3c1a7c2ae7229afac3f1966892fd42895aec.tar.bz2 |
Bitmap API: Clean up creation flags.
Diffstat (limited to 'frontends')
-rw-r--r-- | frontends/amiga/bitmap.c | 5 | ||||
-rwxr-xr-x | frontends/amiga/bitmap.h | 6 | ||||
-rw-r--r-- | frontends/amiga/dt_anim.c | 2 | ||||
-rw-r--r-- | frontends/amiga/dt_picture.c | 2 | ||||
-rw-r--r-- | frontends/amiga/icon.c | 2 | ||||
-rw-r--r-- | frontends/atari/bitmap.c | 32 | ||||
-rw-r--r-- | frontends/atari/bitmap.h | 2 | ||||
-rw-r--r-- | frontends/atari/plot/font_freetype.c | 1 | ||||
-rw-r--r-- | frontends/atari/plot/font_internal.c | 1 | ||||
-rw-r--r-- | frontends/beos/bitmap.cpp | 18 | ||||
-rw-r--r-- | frontends/framebuffer/bitmap.c | 13 | ||||
-rw-r--r-- | frontends/gtk/bitmap.c | 8 | ||||
-rw-r--r-- | frontends/monkey/bitmap.c | 27 | ||||
-rw-r--r-- | frontends/riscos/bitmap.c | 14 | ||||
-rw-r--r-- | frontends/riscos/bitmap.h | 9 | ||||
-rw-r--r-- | frontends/riscos/save.c | 2 | ||||
-rw-r--r-- | frontends/riscos/window.c | 2 | ||||
-rw-r--r-- | frontends/windows/bitmap.c | 14 | ||||
-rw-r--r-- | frontends/windows/bitmap.h | 2 |
19 files changed, 77 insertions, 85 deletions
diff --git a/frontends/amiga/bitmap.c b/frontends/amiga/bitmap.c index ec1a90a24..c39f3842c 100644 --- a/frontends/amiga/bitmap.c +++ b/frontends/amiga/bitmap.c @@ -108,7 +108,7 @@ static APTR pool_bitmap = NULL; static bool guigfx_warned = false; /* exported function documented in amiga/bitmap.h */ -void *amiga_bitmap_create(int width, int height, unsigned int state) +void *amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; @@ -139,8 +139,7 @@ void *amiga_bitmap_create(int width, int height, unsigned int state) bitmap->width = width; bitmap->height = height; - if(state & BITMAP_OPAQUE) bitmap->opaque = true; - else bitmap->opaque = false; + bitmap->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; bitmap->nativebm = NULL; bitmap->nativebmwidth = 0; diff --git a/frontends/amiga/bitmap.h b/frontends/amiga/bitmap.h index aaec26ac2..ae072c0cd 100755 --- a/frontends/amiga/bitmap.h +++ b/frontends/amiga/bitmap.h @@ -25,6 +25,8 @@ #include <intuition/classusr.h> #include <libraries/Picasso96.h> +#include "netsurf/bitmap.h" + #define AMI_BITMAP_FORMAT RGBFB_R8G8B8A8 #define AMI_BITMAP_SCALE_ICON 0xFF @@ -101,10 +103,10 @@ void ami_bitmap_fini(void); * * \param width width of image in pixels * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *amiga_bitmap_create(int width, int height, unsigned int state); +void *amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags); /** * Return a pointer to the pixel data in a bitmap. diff --git a/frontends/amiga/dt_anim.c b/frontends/amiga/dt_anim.c index a9fe809cf..1162d7214 100644 --- a/frontends/amiga/dt_anim.c +++ b/frontends/amiga/dt_anim.c @@ -173,7 +173,7 @@ bool amiga_dt_anim_convert(struct content *c) size_t size; UBYTE *bm_buffer; struct BitMapHeader *bmh; - unsigned int bm_flags = BITMAP_NEW | BITMAP_OPAQUE; + unsigned int bm_flags = BITMAP_OPAQUE; struct adtFrame adt_frame; APTR clut; diff --git a/frontends/amiga/dt_picture.c b/frontends/amiga/dt_picture.c index ed1272bc1..f84e0e016 100644 --- a/frontends/amiga/dt_picture.c +++ b/frontends/amiga/dt_picture.c @@ -187,7 +187,7 @@ static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) if((dto = amiga_dt_picture_newdtobject(adt))) { - bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NEW); + bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NONE); if (!bitmap) { msg_data.errordata.errorcode = NSERROR_NOMEM; msg_data.errordata.errormsg = messages_get("NoMemory"); diff --git a/frontends/amiga/icon.c b/frontends/amiga/icon.c index 001874c86..2b7f61281 100644 --- a/frontends/amiga/icon.c +++ b/frontends/amiga/icon.c @@ -201,7 +201,7 @@ bool amiga_icon_convert(struct content *c) return false; } - icon_c->bitmap = amiga_bitmap_create(width, height, BITMAP_NEW); + icon_c->bitmap = amiga_bitmap_create(width, height, BITMAP_NONE); if (!icon_c->bitmap) { msg_data.errordata.errorcode = NSERROR_NOMEM; msg_data.errordata.errormsg = messages_get("NoMemory"); diff --git a/frontends/atari/bitmap.c b/frontends/atari/bitmap.c index 5ac15ad4f..8c467c7d6 100644 --- a/frontends/atari/bitmap.c +++ b/frontends/atari/bitmap.c @@ -77,36 +77,36 @@ int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out ) * \param pixdata NULL or an memory address to use as the bitmap pixdata * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, unsigned int state, void * pixdata ) +static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, enum gui_bitmap_flags flags, void * pixdata ) { - struct bitmap * bitmap; + struct bitmap * bitmap; - NSLOG(netsurf, INFO, - "width %d (rowstride: %d, bpp: %d), height %d, state %u", w, - rowstride, bpp, h, state); + NSLOG(netsurf, INFO, + "width %d (rowstride: %d, bpp: %d), height %d, flags %u", w, + rowstride, bpp, h, (unsigned)flags); if( rowstride == 0) { rowstride = bpp * w; } assert( rowstride >= (w * bpp) ); - bitmap = calloc(1 , sizeof(struct bitmap) ); - if (bitmap) { + bitmap = calloc(1 , sizeof(struct bitmap) ); + if (bitmap) { if( pixdata == NULL) { - bitmap->pixdata = calloc(1, (rowstride * h)+128); + bitmap->pixdata = calloc(1, (rowstride * h)+128); } else { bitmap->pixdata = pixdata; } - if (bitmap->pixdata != NULL) { + if (bitmap->pixdata != NULL) { bitmap->width = w; bitmap->height = h; - bitmap->opaque = (state & BITMAP_OPAQUE) ? true : false; + bitmap->opaque = (flags & BITMAP_OPAQUE) ? true : false; bitmap->bpp = bpp; bitmap->resized = NULL; bitmap->rowstride = rowstride; - } else { + } else { free(bitmap); bitmap=NULL; NSLOG(netsurf, INFO, "Out of memory!"); @@ -118,9 +118,9 @@ static void *atari_bitmap_create_ex( int w, int h, short bpp, int rowstride, uns /* exported interface documented in atari/bitmap.h */ -void *atari_bitmap_create(int w, int h, unsigned int state) +void *atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags) { - return atari_bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, state, NULL ); + return atari_bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, flags, NULL ); } /** @@ -347,7 +347,7 @@ int atari_bitmap_get_height(void *bitmap) bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh) { - unsigned int state = 0; + enum gui_bitmap_flags flags = 0; short bpp = img->bpp; int stride = atari_bitmap_get_rowstride( img ); int err; @@ -364,9 +364,9 @@ bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, /* allocate the mem for resized bitmap */ if (img->opaque == true) { - state |= BITMAP_OPAQUE; + flags |= BITMAP_OPAQUE; } - img->resized = atari_bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); + img->resized = atari_bitmap_create_ex( nw, nh, bpp, nw*bpp, flags, NULL ); if( img->resized == NULL ) { printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp); assert(img->resized); diff --git a/frontends/atari/bitmap.h b/frontends/atari/bitmap.h index 72bad555e..88985ad3c 100644 --- a/frontends/atari/bitmap.h +++ b/frontends/atari/bitmap.h @@ -90,7 +90,7 @@ int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out ); * \param state a flag word indicating the initial state * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *atari_bitmap_create(int w, int h, unsigned int state); +void *atari_bitmap_create(int w, int h, enum gui_bitmap_flags flags); /** * Find the width of a pixel row in bytes. diff --git a/frontends/atari/plot/font_freetype.c b/frontends/atari/plot/font_freetype.c index f8109f6f2..3ff4ab115 100644 --- a/frontends/atari/plot/font_freetype.c +++ b/frontends/atari/plot/font_freetype.c @@ -25,6 +25,7 @@ #include "utils/log.h" #include "utils/nsoption.h" #include "netsurf/mouse.h" +#include "netsurf/bitmap.h" #include "netsurf/plot_style.h" #include "atari/gui.h" diff --git a/frontends/atari/plot/font_internal.c b/frontends/atari/plot/font_internal.c index 709697f74..11732c5ea 100644 --- a/frontends/atari/plot/font_internal.c +++ b/frontends/atari/plot/font_internal.c @@ -25,6 +25,7 @@ #include "utils/utf8.h" #include "utils/log.h" #include "netsurf/mouse.h" +#include "netsurf/bitmap.h" #include "netsurf/plot_style.h" #include "atari/gui.h" diff --git a/frontends/beos/bitmap.cpp b/frontends/beos/bitmap.cpp index 7b6d00d1a..83e69fce5 100644 --- a/frontends/beos/bitmap.cpp +++ b/frontends/beos/bitmap.cpp @@ -114,28 +114,28 @@ static inline void nsbeos_rgba_to_bgra(void *src, * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param bflags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap)); if (bmp == NULL) return NULL; - int32 flags = 0; - if (state & BITMAP_CLEAR_MEMORY) - flags |= B_BITMAP_CLEAR_TO_WHITE; + int32 Bflags = 0; + if (flags & BITMAP_CLEAR) + Bflags |= B_BITMAP_CLEAR_TO_WHITE; BRect frame(0, 0, width - 1, height - 1); //XXX: bytes per row ? - bmp->primary = new BBitmap(frame, flags, B_RGBA32); - bmp->shadow = new BBitmap(frame, flags, B_RGBA32); + bmp->primary = new BBitmap(frame, Bflags, B_RGBA32); + bmp->shadow = new BBitmap(frame, Bflags, B_RGBA32); bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL; - bmp->opaque = (state & BITMAP_OPAQUE) != 0; + bmp->opaque = (flags & BITMAP_OPAQUE) != 0; return bmp; } diff --git a/frontends/framebuffer/bitmap.c b/frontends/framebuffer/bitmap.c index 7b522f262..9fb5db159 100644 --- a/frontends/framebuffer/bitmap.c +++ b/frontends/framebuffer/bitmap.c @@ -47,19 +47,16 @@ * \param state a flag word indicating the initial state * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { - nsfb_t *bm; - - NSLOG(netsurf, INFO, "width %d, height %d, state %u", width, height, - state); + nsfb_t *bm; bm = nsfb_new(NSFB_SURFACE_RAM); if (bm == NULL) { return NULL; } - if ((state & BITMAP_OPAQUE) == 0) { + if ((flags & BITMAP_OPAQUE) == 0) { nsfb_set_geometry(bm, width, height, NSFB_FMT_ABGR8888); } else { nsfb_set_geometry(bm, width, height, NSFB_FMT_XBGR8888); @@ -70,9 +67,7 @@ static void *bitmap_create(int width, int height, unsigned int state) return NULL; } - NSLOG(netsurf, INFO, "bitmap %p", bm); - - return bm; + return bm; } diff --git a/frontends/gtk/bitmap.c b/frontends/gtk/bitmap.c index cafe22262..1f1a6dcd2 100644 --- a/frontends/gtk/bitmap.c +++ b/frontends/gtk/bitmap.c @@ -45,17 +45,17 @@ * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *gbitmap; gbitmap = calloc(1, sizeof(struct bitmap)); if (gbitmap != NULL) { - if ((state & BITMAP_OPAQUE) != 0) { + if ((flags & BITMAP_OPAQUE) != 0) { gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height); } else { gbitmap->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); diff --git a/frontends/monkey/bitmap.c b/frontends/monkey/bitmap.c index ba3b83cf5..36016988c 100644 --- a/frontends/monkey/bitmap.c +++ b/frontends/monkey/bitmap.c @@ -31,26 +31,26 @@ struct bitmap { size_t rowstride; int width; int height; - unsigned int state; + bool opaque; }; -static void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *ret = calloc(sizeof(*ret), 1); if (ret == NULL) return NULL; - + ret->width = width; ret->height = height; - ret->state = state; - + ret->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; + ret->ptr = calloc(width, height * 4); - + if (ret->ptr == NULL) { free(ret); return NULL; } - + return ret; } @@ -64,11 +64,8 @@ static void bitmap_destroy(void *bitmap) static void bitmap_set_opaque(void *bitmap, bool opaque) { struct bitmap *bmap = bitmap; - - if (opaque) - bmap->state |= (BITMAP_OPAQUE); - else - bmap->state &= ~(BITMAP_OPAQUE); + + bmap->opaque = opaque; } static bool bitmap_test_opaque(void *bitmap) @@ -79,8 +76,8 @@ static bool bitmap_test_opaque(void *bitmap) static bool bitmap_get_opaque(void *bitmap) { struct bitmap *bmap = bitmap; - - return (bmap->state & BITMAP_OPAQUE) == BITMAP_OPAQUE; + + return bmap->opaque; } static unsigned char *bitmap_get_buffer(void *bitmap) @@ -98,7 +95,7 @@ static size_t bitmap_get_rowstride(void *bitmap) static void bitmap_modified(void *bitmap) { - struct bitmap *bmap = bitmap; + return; } static int bitmap_get_width(void *bitmap) diff --git a/frontends/riscos/bitmap.c b/frontends/riscos/bitmap.c index e724d443f..3454c66e5 100644 --- a/frontends/riscos/bitmap.c +++ b/frontends/riscos/bitmap.c @@ -91,7 +91,7 @@ static bool bitmap_initialise(struct bitmap *bitmap) assert(!bitmap->sprite_area); area_size = 16 + 44 + bitmap->width * bitmap->height * 4; - if (bitmap->state & BITMAP_CLEAR_MEMORY) + if (bitmap->clear) bitmap->sprite_area = calloc(1, area_size); else bitmap->sprite_area = malloc(area_size); @@ -123,7 +123,7 @@ static bool bitmap_initialise(struct bitmap *bitmap) /* exported interface documented in riscos/bitmap.h */ -void *riscos_bitmap_create(int width, int height, unsigned int state) +void *riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; @@ -135,7 +135,8 @@ void *riscos_bitmap_create(int width, int height, unsigned int state) return NULL; bitmap->width = width; bitmap->height = height; - bitmap->state = state; + bitmap->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE; + bitmap->clear = (flags & BITMAP_CLEAR) == BITMAP_CLEAR; return bitmap; } @@ -172,10 +173,7 @@ static void bitmap_set_opaque(void *vbitmap, bool opaque) struct bitmap *bitmap = (struct bitmap *) vbitmap; assert(bitmap); - if (opaque) - bitmap->state |= BITMAP_OPAQUE; - else - bitmap->state &= ~BITMAP_OPAQUE; + bitmap->opaque = opaque; } @@ -246,7 +244,7 @@ bool riscos_bitmap_get_opaque(void *vbitmap) { struct bitmap *bitmap = (struct bitmap *) vbitmap; assert(bitmap); - return (bitmap->state & BITMAP_OPAQUE); + return bitmap->opaque; } diff --git a/frontends/riscos/bitmap.h b/frontends/riscos/bitmap.h index f66ebb317..dd3904d67 100644 --- a/frontends/riscos/bitmap.h +++ b/frontends/riscos/bitmap.h @@ -37,7 +37,8 @@ struct bitmap { int width; /**< width of bitmap */ int height; /**< height of bitmap */ - unsigned int state; /**< The bitmap attributes (opaque/dirty etc.) */ + bool opaque; /**< Whether the bitmap is opaque. */ + bool clear; /**< Whether the bitmap should be initialised to zeros. */ struct osspriteop_area *sprite_area; /**< Uncompressed data, or NULL */ }; @@ -71,11 +72,11 @@ void riscos_bitmap_overlay_sprite(struct bitmap *bitmap, const struct osspriteop * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state the state to create the bitmap in. + * \param height height of image in pixels + * \param flags flags for bitmap creation. * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *riscos_bitmap_create(int width, int height, unsigned int state); +void *riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags); /** * Free a bitmap. diff --git a/frontends/riscos/save.c b/frontends/riscos/save.c index 86797602b..85fefead3 100644 --- a/frontends/riscos/save.c +++ b/frontends/riscos/save.c @@ -243,7 +243,7 @@ ro_gui_save_create_thumbnail(struct hlcache_handle *h, const char *name) struct bitmap *bitmap; osspriteop_area *area; - bitmap = riscos_bitmap_create(34, 34, BITMAP_NEW | BITMAP_OPAQUE | BITMAP_CLEAR_MEMORY); + bitmap = riscos_bitmap_create(34, 34, BITMAP_OPAQUE | BITMAP_CLEAR); if (!bitmap) { NSLOG(netsurf, INFO, "Thumbnail initialisation failed."); return false; diff --git a/frontends/riscos/window.c b/frontends/riscos/window.c index 28ef06fa9..cb1e5484b 100644 --- a/frontends/riscos/window.c +++ b/frontends/riscos/window.c @@ -4568,7 +4568,7 @@ ro_gui_window_iconise(struct gui_window *g, wimp_full_message_window_info *wi) /* create the thumbnail sprite */ bitmap = riscos_bitmap_create(width, height, - BITMAP_NEW | BITMAP_OPAQUE | BITMAP_CLEAR_MEMORY); + BITMAP_OPAQUE | BITMAP_CLEAR); if (!bitmap) { NSLOG(netsurf, INFO, "Thumbnail initialisation failed."); return; diff --git a/frontends/windows/bitmap.c b/frontends/windows/bitmap.c index 82b902db2..26bc807ce 100644 --- a/frontends/windows/bitmap.c +++ b/frontends/windows/bitmap.c @@ -41,19 +41,19 @@ * Create a bitmap. * * \param width width of image in pixels - * \param height width of image in pixels - * \param state a flag word indicating the initial state + * \param height height of image in pixels + * \param state flags flags for bitmap creation * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void *win32_bitmap_create(int width, int height, unsigned int state) +static void *win32_bitmap_create(int width, int height, enum gui_bitmap_flags flags) { struct bitmap *bitmap; BITMAPV5HEADER *pbmi; HBITMAP windib; uint8_t *pixdata; - NSLOG(netsurf, INFO, "width %d, height %d, state %u", width, height, - state); + NSLOG(netsurf, INFO, "width %d, height %d, flags %u", width, height, + (unsigned)flags); pbmi = calloc(1, sizeof(BITMAPV5HEADER)); if (pbmi == NULL) { @@ -91,7 +91,7 @@ void *win32_bitmap_create(int width, int height, unsigned int state) bitmap->windib = windib; bitmap->pbmi = pbmi; bitmap->pixdata = pixdata; - if ((state & BITMAP_OPAQUE) != 0) { + if ((flags & BITMAP_OPAQUE) != 0) { bitmap->opaque = true; } else { bitmap->opaque = false; @@ -327,7 +327,7 @@ bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content) } /* create a full size bitmap and plot into it */ - fsbitmap = win32_bitmap_create(width, height, BITMAP_NEW | BITMAP_CLEAR_MEMORY | BITMAP_OPAQUE); + fsbitmap = win32_bitmap_create(width, height, BITMAP_CLEAR | BITMAP_OPAQUE); SelectObject(bufferdc, fsbitmap->windib); diff --git a/frontends/windows/bitmap.h b/frontends/windows/bitmap.h index c57061d77..a370dd619 100644 --- a/frontends/windows/bitmap.h +++ b/frontends/windows/bitmap.h @@ -33,8 +33,6 @@ struct bitmap { struct bitmap *bitmap_scale(struct bitmap *prescale, int width, int height); -void *win32_bitmap_create(int width, int height, unsigned int state); - void win32_bitmap_destroy(void *bitmap); #endif |