From fb0bd7994491da2a7fa6913c5b5666ed49c6e153 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 16 Apr 2015 22:36:29 +0100 Subject: update amiga frontend to use bitmap operation table --- amiga/bitmap.c | 139 +++++++++++++++++++++-------------------------------- amiga/bitmap.h | 80 +++++++++++++++++++++++++++++- amiga/dt_anim.c | 30 ++++++------ amiga/dt_picture.c | 32 ++++++------ amiga/file.c | 2 +- amiga/gui.c | 7 +-- amiga/icon.c | 18 ++++--- amiga/plotters.c | 2 +- amiga/theme.c | 2 +- 9 files changed, 184 insertions(+), 128 deletions(-) diff --git a/amiga/bitmap.c b/amiga/bitmap.c index 633d8d0c1..67e7b15ea 100644 --- a/amiga/bitmap.c +++ b/amiga/bitmap.c @@ -35,6 +35,7 @@ #include "utils/messages.h" #include "desktop/mouse.h" #include "desktop/gui_window.h" +#include "image/bitmap.h" #include "amiga/gui.h" #include "amiga/bitmap.h" @@ -42,16 +43,8 @@ #include "amiga/misc.h" #include "amiga/rtg.h" -/** - * 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 - * \return an opaque struct bitmap, or NULL on memory exhaustion - */ - -void *bitmap_create(int width, int height, unsigned int state) +/* exported function documented in amiga/bitmap.h */ +void *amiga_bitmap_create(int width, int height, unsigned int state) { struct bitmap *bitmap; @@ -70,31 +63,15 @@ void *bitmap_create(int width, int height, unsigned int state) } -/** - * Return a pointer to the pixel data in a bitmap. - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \return pointer to the pixel buffer - * - * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end - * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). - */ - -unsigned char *bitmap_get_buffer(void *bitmap) +/* exported function documented in amiga/bitmap.h */ +unsigned char *amiga_bitmap_get_buffer(void *bitmap) { struct bitmap *bm = bitmap; return bm->pixdata; } - -/** - * Find the width of a pixel row in bytes. - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \return width of a pixel row in the bitmap - */ - -size_t bitmap_get_rowstride(void *bitmap) +/* exported function documented in amiga/bitmap.h */ +size_t amiga_bitmap_get_rowstride(void *bitmap) { struct bitmap *bm = bitmap; @@ -109,13 +86,8 @@ size_t bitmap_get_rowstride(void *bitmap) } -/** - * Free a bitmap. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ - -void bitmap_destroy(void *bitmap) +/* exported function documented in amiga/bitmap.h */ +void amiga_bitmap_destroy(void *bitmap) { struct bitmap *bm = bitmap; @@ -142,16 +114,8 @@ void bitmap_destroy(void *bitmap) } -/** - * Save a bitmap in the platform's native format. - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \param path pathname for file - * \param flags flags controlling how the bitmap is saved. - * \return true on success, false on error and error reported - */ - -bool bitmap_save(void *bitmap, const char *path, unsigned flags) +/* exported function documented in amiga/bitmap.h */ +bool amiga_bitmap_save(void *bitmap, const char *path, unsigned flags) { int err = 0; Object *dto = NULL; @@ -171,12 +135,9 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags) } -/** - * The bitmap image has changed, so flush any persistant cache. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -void bitmap_modified(void *bitmap) { +/* exported function documented in amiga/bitmap.h */ +void amiga_bitmap_modified(void *bitmap) +{ struct bitmap *bm = bitmap; if((bm->nativebm) && (bm->dto == NULL)) @@ -189,13 +150,9 @@ void bitmap_modified(void *bitmap) { bm->native_mask = NULL; } -/** - * Sets whether a bitmap should be plotted opaque - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \param opaque whether the bitmap should be plotted opaque - */ -void bitmap_set_opaque(void *bitmap, bool opaque) + +/* exported function documented in amiga/bitmap.h */ +void amiga_bitmap_set_opaque(void *bitmap, bool opaque) { struct bitmap *bm = bitmap; assert(bitmap); @@ -203,13 +160,8 @@ void bitmap_set_opaque(void *bitmap, bool opaque) } -/** - * Tests whether a bitmap has an opaque alpha channel - * - * \param bitmap a bitmap, as returned by bitmap_create() - * \return whether the bitmap is opaque - */ -bool bitmap_test_opaque(void *bitmap) +/* exported function documented in amiga/bitmap.h */ +bool amiga_bitmap_test_opaque(void *bitmap) { struct bitmap *bm = bitmap; uint32 p = bm->width * bm->height; @@ -227,19 +179,18 @@ bool bitmap_test_opaque(void *bitmap) } -/** - * Gets whether a bitmap should be plotted opaque - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -bool bitmap_get_opaque(void *bitmap) +/* exported function documented in amiga/bitmap.h */ +bool amiga_bitmap_get_opaque(void *bitmap) { struct bitmap *bm = bitmap; assert(bitmap); return bm->opaque; } -int bitmap_get_width(void *bitmap) +/** + * get width of a bitmap. + */ +static int bitmap_get_width(void *bitmap) { struct bitmap *bm = bitmap; @@ -253,7 +204,10 @@ int bitmap_get_width(void *bitmap) } } -int bitmap_get_height(void *bitmap) +/** + * get height of a bitmap. + */ +static int bitmap_get_height(void *bitmap) { struct bitmap *bm = bitmap; @@ -274,8 +228,7 @@ int bitmap_get_height(void *bitmap) * \param vbitmap a bitmap, as returned by bitmap_create() * \return bytes per pixel */ - -size_t bitmap_get_bpp(void *vbitmap) +static size_t bitmap_get_bpp(void *vbitmap) { struct bitmap *bitmap = (struct bitmap *)vbitmap; assert(bitmap); @@ -318,7 +271,7 @@ Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap) bmhd->bmh_Width = (UWORD)bitmap_get_width(bitmap); bmhd->bmh_Height = (UWORD)bitmap_get_height(bitmap); bmhd->bmh_Depth = (UBYTE)bitmap_get_bpp(bitmap) * 8; - if(!bitmap_get_opaque(bitmap)) bmhd->bmh_Masking = mskHasAlpha; + if(!amiga_bitmap_get_opaque(bitmap)) bmhd->bmh_Masking = mskHasAlpha; } SetDTAttrs(dto,NULL,NULL, @@ -330,8 +283,8 @@ Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap) PDTA_SourceMode,PMODE_V43, TAG_DONE); - IDoMethod(dto, PDTM_WRITEPIXELARRAY, bitmap_get_buffer(bitmap), - PBPAFMT_RGBA, bitmap_get_rowstride(bitmap), 0, 0, + IDoMethod(dto, PDTM_WRITEPIXELARRAY, amiga_bitmap_get_buffer(bitmap), + PBPAFMT_RGBA, amiga_bitmap_get_rowstride(bitmap), 0, 0, bitmap_get_width(bitmap), bitmap_get_height(bitmap)); } @@ -353,13 +306,13 @@ struct bitmap *ami_bitmap_from_datatype(char *filename) if(GetDTAttrs(dto, PDTA_BitMapHeader, &bmh, TAG_DONE)) { - bm = bitmap_create(bmh->bmh_Width, bmh->bmh_Height, 0); + bm = amiga_bitmap_create(bmh->bmh_Width, bmh->bmh_Height, 0); - IDoMethod(dto, PDTM_READPIXELARRAY, bitmap_get_buffer(bm), - PBPAFMT_RGBA, bitmap_get_rowstride(bm), 0, 0, + IDoMethod(dto, PDTM_READPIXELARRAY, amiga_bitmap_get_buffer(bm), + PBPAFMT_RGBA, amiga_bitmap_get_rowstride(bm), 0, 0, bmh->bmh_Width, bmh->bmh_Height); - bitmap_set_opaque(bm, bitmap_test_opaque(bm)); + amiga_bitmap_set_opaque(bm, amiga_bitmap_test_opaque(bm)); } DisposeDTObject(dto); } @@ -477,7 +430,7 @@ PLANEPTR ami_bitmap_get_mask(struct bitmap *bitmap, int width, int y, x, bpr; if((height != bitmap->height) || (width != bitmap->width)) return NULL; - if(bitmap_get_opaque(bitmap) == true) return NULL; + if(amiga_bitmap_get_opaque(bitmap) == true) return NULL; if(bitmap->native_mask) return bitmap->native_mask; bm_width = GetBitMapAttr(n_bm, BMA_WIDTH); @@ -552,3 +505,19 @@ struct BitMap *ami_bitmap_get_native(struct bitmap *bitmap, } } +static struct gui_bitmap_table bitmap_table = { + .create = amiga_bitmap_create, + .destroy = amiga_bitmap_destroy, + .set_opaque = amiga_bitmap_set_opaque, + .get_opaque = amiga_bitmap_get_opaque, + .test_opaque = amiga_bitmap_test_opaque, + .get_buffer = amiga_bitmap_get_buffer, + .get_rowstride = amiga_bitmap_get_rowstride, + .get_width = bitmap_get_width, + .get_height = bitmap_get_height, + .get_bpp = bitmap_get_bpp, + .save = amiga_bitmap_save, + .modified = amiga_bitmap_modified, +}; + +struct gui_bitmap_table *amiga_bitmap_table = &bitmap_table; diff --git a/amiga/bitmap.h b/amiga/bitmap.h index 6657d2f8a..63969ecaa 100755 --- a/amiga/bitmap.h +++ b/amiga/bitmap.h @@ -18,7 +18,6 @@ #ifndef AMIGA_BITMAP_H #define AMIGA_BITMAP_H -#include "image/bitmap.h" #include #include @@ -28,6 +27,8 @@ #define AMI_BITMAP_FORMAT RGBFB_R8G8B8A8 #define AMI_BITMAP_FORCE_OVERWRITE 0xFF +struct gui_bitmap_table *amiga_bitmap_table; + struct bitmap { int width; int height; @@ -55,4 +56,81 @@ struct bitmap *ami_bitmap_from_datatype(char *filename); void ami_bitmap_argb_to_rgba(struct bitmap *bm); #endif +/** + * 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 + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ +void *amiga_bitmap_create(int width, int height, unsigned int state); + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ +unsigned char *amiga_bitmap_get_buffer(void *bitmap); + +/** + * Find the width of a pixel row in bytes. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ +size_t amiga_bitmap_get_rowstride(void *bitmap); + +/** + * Free a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +void amiga_bitmap_destroy(void *bitmap); + +/** + * Save a bitmap in the platform's native format. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \param flags flags controlling how the bitmap is saved. + * \return true on success, false on error and error reported + */ +bool amiga_bitmap_save(void *bitmap, const char *path, unsigned flags); + +/** + * The bitmap image has changed, so flush any persistant cache. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +void amiga_bitmap_modified(void *bitmap); + +/** + * Sets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param opaque whether the bitmap should be plotted opaque + */ +void amiga_bitmap_set_opaque(void *bitmap, bool opaque); + +/** + * Tests whether a bitmap has an opaque alpha channel + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return whether the bitmap is opaque + */ +bool amiga_bitmap_test_opaque(void *bitmap); + +/** + * Gets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +bool amiga_bitmap_get_opaque(void *bitmap); + + #endif diff --git a/amiga/dt_anim.c b/amiga/dt_anim.c index f69af31b9..723bd1348 100644 --- a/amiga/dt_anim.c +++ b/amiga/dt_anim.c @@ -23,16 +23,6 @@ #ifdef WITH_AMIGA_DATATYPES #include "amiga/os3support.h" -#include "amiga/filetype.h" -#include "amiga/datatypes.h" -#include "amiga/misc.h" -#include "amiga/plotters.h" -#include "content/content_protected.h" -#include "desktop/plotters.h" -#include "image/bitmap.h" -#include "utils/log.h" -#include "utils/messages.h" - #include #include #include @@ -44,6 +34,18 @@ #endif #include +#include "utils/log.h" +#include "utils/messages.h" +#include "content/content_protected.h" +#include "desktop/plotters.h" +#include "image/bitmap.h" + +#include "amiga/bitmap.h" +#include "amiga/filetype.h" +#include "amiga/datatypes.h" +#include "amiga/misc.h" +#include "amiga/plotters.h" + typedef struct amiga_dt_anim_content { struct content base; @@ -183,14 +185,14 @@ bool amiga_dt_anim_convert(struct content *c) width = (int)bmh->bmh_Width; height = (int)bmh->bmh_Height; - plugin->bitmap = bitmap_create(width, height, bm_flags); + plugin->bitmap = amiga_bitmap_create(width, height, bm_flags); if (!plugin->bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; } - bm_buffer = bitmap_get_buffer(plugin->bitmap); + bm_buffer = amiga_bitmap_get_buffer(plugin->bitmap); adt_frame.MethodID = ADTM_LOADFRAME; adt_frame.alf_TimeStamp = 0; @@ -229,7 +231,7 @@ bool amiga_dt_anim_convert(struct content *c) content__set_title(c, title); */ - bitmap_modified(plugin->bitmap); + amiga_bitmap_modified(plugin->bitmap); content_set_ready(c); content_set_done(c); @@ -245,7 +247,7 @@ void amiga_dt_anim_destroy(struct content *c) LOG(("amiga_dt_anim_destroy")); if (plugin->bitmap != NULL) - bitmap_destroy(plugin->bitmap); + amiga_bitmap_destroy(plugin->bitmap); DisposeDTObject(plugin->dto); diff --git a/amiga/dt_picture.c b/amiga/dt_picture.c index 15fc30e6a..b5c3ba5d0 100644 --- a/amiga/dt_picture.c +++ b/amiga/dt_picture.c @@ -23,22 +23,25 @@ #ifdef WITH_AMIGA_DATATYPES #include "amiga/os3support.h" -#include "amiga/bitmap.h" -#include "amiga/filetype.h" -#include "amiga/datatypes.h" -#include "content/content_protected.h" -#include "desktop/plotters.h" -#include "image/bitmap.h" -#include "image/image_cache.h" -#include "utils/log.h" -#include "utils/messages.h" - +#include #include #include #include #include #include +#include "utils/log.h" +#include "utils/messages.h" +#include "content/content_protected.h" +#include "desktop/plotters.h" +#include "image/bitmap.h" +#include "image/image_cache.h" + +#include "amiga/bitmap.h" +#include "amiga/filetype.h" +#include "amiga/datatypes.h" + + static nserror amiga_dt_picture_create(const content_handler *handler, lwc_string *imime_type, const http_parameter *params, llcache_handle *llcache, const char *fallback_charset, @@ -179,20 +182,21 @@ static struct bitmap *amiga_dt_picture_cache_convert(struct content *c) if((dto = amiga_dt_picture_newdtobject(adt))) { - bitmap = bitmap_create(c->width, c->height, BITMAP_NEW); + bitmap = amiga_bitmap_create(c->width, c->height, BITMAP_NEW); if (!bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return NULL; } - bm_buffer = bitmap_get_buffer(bitmap); + bm_buffer = amiga_bitmap_get_buffer(bitmap); IDoMethod(dto, PDTM_READPIXELARRAY, - bm_buffer, PBPAFMT_RGBA, bitmap_get_rowstride(bitmap), + bm_buffer, PBPAFMT_RGBA, + amiga_bitmap_get_rowstride(bitmap), 0, 0, c->width, c->height); - bitmap_set_opaque(bitmap, bitmap_test_opaque(bitmap)); + amiga_bitmap_set_opaque(bitmap, amiga_bitmap_test_opaque(bitmap)); DisposeDTObject(dto); adt->dto = NULL; diff --git a/amiga/file.c b/amiga/file.c index e7f1fd356..307fbfcec 100644 --- a/amiga/file.c +++ b/amiga/file.c @@ -188,7 +188,7 @@ void ami_file_save(int type, char *fname, struct Window *win, if((bm = content_get_bitmap(object))) { bm->url = (char *)nsurl_access(hlcache_handle_get_url(object)); bm->title = (char *)content_get_title(object); - bitmap_save(bm, fname, 0); + amiga_bitmap_save(bm, fname, 0); } #ifdef WITH_NS_SVG else if(ami_mime_compare(object, "svg") == true) { diff --git a/amiga/gui.c b/amiga/gui.c index dd067710a..3df4d5459 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -828,8 +828,8 @@ static void ami_gui_commandline(int *argc, char **argv) p++; } while(*p != NULL); - char *new_argv = malloc(sizeof(char *) * new_argc); - char **new_argvp = &new_argv; + const char *new_argv = malloc(sizeof(char *) * new_argc); + const char **new_argvp = &new_argv; *new_argvp = messages_get("NetSurf"); p = (char **)rarray[A_NSOPTS]; @@ -3082,7 +3082,7 @@ static void ami_gui_cache_favicon(nsurl *url, struct bitmap *favicon) STRPTR filename = NULL; if ((filename = ami_gui_get_cache_favicon_name(url, false))) { - if(favicon) bitmap_save(favicon, filename, AMI_BITMAP_FORCE_OVERWRITE); + if(favicon) amiga_bitmap_save(favicon, filename, AMI_BITMAP_FORCE_OVERWRITE); FreeVec(filename); } } @@ -5410,6 +5410,7 @@ int main(int argc, char** argv) .search = amiga_search_table, .search_web = &amiga_search_web_table, .llcache = filesystem_llcache_table, + .bitmap = amiga_bitmap_table, }; #ifdef __amigaos4__ diff --git a/amiga/icon.c b/amiga/icon.c index dfbf84c09..042e1a826 100644 --- a/amiga/icon.c +++ b/amiga/icon.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -36,10 +37,6 @@ #endif #include -#include "amiga/os3support.h" -#include "amiga/bitmap.h" -#include "amiga/icon.h" -#include "amiga/misc.h" #include "desktop/plotters.h" #include "image/bitmap.h" #include "content/content_protected.h" @@ -48,6 +45,11 @@ #include "utils/utils.h" #include "utils/file.h" +#include "amiga/os3support.h" +#include "amiga/bitmap.h" +#include "amiga/icon.h" +#include "amiga/misc.h" + #define THUMBNAIL_WIDTH 100 /* Icon sizes for thumbnails, usually the same as */ #define THUMBNAIL_HEIGHT 86 /* WIDTH/HEIGHT in desktop/thumbnail.c */ @@ -182,14 +184,14 @@ bool amiga_icon_convert(struct content *c) return false; } - icon_c->bitmap = bitmap_create(width, height, BITMAP_NEW); + icon_c->bitmap = amiga_bitmap_create(width, height, BITMAP_NEW); if (!icon_c->bitmap) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); if(dobj) FreeDiskObject(dobj); return false; } - imagebuf = (ULONG *) bitmap_get_buffer(icon_c->bitmap); + imagebuf = (ULONG *) amiga_bitmap_get_buffer(icon_c->bitmap); if (!imagebuf) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -229,7 +231,7 @@ bool amiga_icon_convert(struct content *c) c->width = width; c->height = height; - bitmap_modified(icon_c->bitmap); + amiga_bitmap_modified(icon_c->bitmap); content_set_ready(c); content_set_done(c); content_set_status(c, ""); @@ -252,7 +254,7 @@ void amiga_icon_destroy(struct content *c) amiga_icon_content *icon_c = (amiga_icon_content *)c; if (icon_c->bitmap != NULL) - bitmap_destroy(icon_c->bitmap); + amiga_bitmap_destroy(icon_c->bitmap); } diff --git a/amiga/plotters.c b/amiga/plotters.c index 899ec4930..4c86f3160 100644 --- a/amiga/plotters.c +++ b/amiga/plotters.c @@ -510,7 +510,7 @@ static bool ami_bitmap(int x, int y, int width, int height, struct bitmap *bitma (nsoption_bool(direct_render) == false), 1)) { uint32 comptype = COMPOSITE_Src_Over_Dest; uint32 compflags = COMPFLAG_IgnoreDestAlpha; - if(bitmap_get_opaque(bitmap)) { + if(amiga_bitmap_get_opaque(bitmap)) { compflags |= COMPFLAG_SrcAlphaOverride; comptype = COMPOSITE_Src; } diff --git a/amiga/theme.c b/amiga/theme.c index b75f6ed5c..4d6107ab4 100644 --- a/amiga/theme.c +++ b/amiga/theme.c @@ -176,7 +176,7 @@ void ami_theme_throbber_setup(void) void ami_theme_throbber_free(void) { - bitmap_destroy(throbber_nsbm); + amiga_bitmap_destroy(throbber_nsbm); throbber = NULL; } -- cgit v1.2.3