diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-04-16 15:56:48 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-04-16 15:56:48 +0100 |
commit | 3c61db33ffc94ee194dd0111a332762199334d37 (patch) | |
tree | dc321eb5f1e94974a62009abb36cd3111256ed70 /atari/bitmap.c | |
parent | ad18ef5db99eb38075e6e49246b097a8ba727ab8 (diff) | |
download | netsurf-3c61db33ffc94ee194dd0111a332762199334d37.tar.gz netsurf-3c61db33ffc94ee194dd0111a332762199334d37.tar.bz2 |
Convert atari frontend to use bitmap operation table
Diffstat (limited to 'atari/bitmap.c')
-rwxr-xr-x | atari/bitmap.c | 211 |
1 files changed, 87 insertions, 124 deletions
diff --git a/atari/bitmap.c b/atari/bitmap.c index 3bca82e46..52e515faf 100755 --- a/atari/bitmap.c +++ b/atari/bitmap.c @@ -68,20 +68,6 @@ int init_mfdb(int bpp, int w, int h, uint32_t flags, MFDB * out ) /** * Create a bitmap. * - * \param w width of image in pixels - * \param h 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 w, int h, unsigned int state) -{ - return bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, state, NULL ); -} - -/** - * Create a bitmap. - * * \param w width of image in pixels * \param h height of image in pixels * \param bpp number of BYTES per pixel @@ -90,7 +76,7 @@ void *bitmap_create(int w, int h, unsigned int state) * \param pixdata NULL or an memory address to use as the bitmap pixdata * \return an opaque struct bitmap, or NULL on memory exhaustion */ -void * 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, unsigned int state, void * pixdata ) { struct bitmap * bitmap; @@ -128,7 +114,37 @@ void * bitmap_create_ex( int w, int h, short bpp, int rowstride, unsigned int st return bitmap; } -void * bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int state, void * bmp ) + +/* exported interface documented in atari/bitmap.h */ +void *atari_bitmap_create(int w, int h, unsigned int state) +{ + return atari_bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, state, NULL ); +} + +/** + * The bitmap image has changed, so flush any persistant cache. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +static void bitmap_modified(void *bitmap) +{ + struct bitmap *bm = bitmap; + if( bm->resized != NULL ) { + atari_bitmap_destroy( bm->resized ); + bm->resized = NULL; + } + if( bm->converted ){ + if( bm->pixdata != bm->native.fd_addr ){ + free( bm->native.fd_addr ); + } + bm->native.fd_addr = NULL; + bm->converted = false; + } +} + + +/* exported interface documented in atari/bitmap.h */ +void *atari_bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int state, void * bmp ) { struct bitmap * bitmap = bmp; int newsize = rowstride * h; @@ -163,46 +179,6 @@ void * bitmap_realloc( int w, int h, short bpp, int rowstride, unsigned int stat return( bitmap ); } -void bitmap_to_mfdb(void * bitmap, MFDB * out) -{ - struct bitmap * bm; - uint8_t * tmp; - size_t dststride, oldstride; - - bm = bitmap; - assert( out != NULL ); - assert( bm->pixdata != NULL ); - - oldstride = bitmap_get_rowstride( bm ); - dststride = MFDB_STRIDE( bm->width ); - - if( oldstride != dststride * bm->bpp ) - { - assert( oldstride <= dststride ); - /* we need to convert the img to new rowstride */ - tmp = bm->pixdata; - bm->pixdata = calloc(1, dststride * bm->bpp * bm->height ); - if( tmp == NULL ){ - bm->pixdata = tmp; - out->fd_addr = NULL; - return; - } - bm->rowstride = dststride * bm->bpp; - int i=0; - for( i=0; i<bm->height; i++) { - memcpy( (bm->pixdata+i*bm->rowstride), (tmp + i*oldstride), oldstride); - } - free( tmp ); - } - out->fd_w = dststride; - out->fd_h = bm->height; - out->fd_wdwidth = dststride >> 4; - out->fd_addr = bm->pixdata; - out->fd_stand = 0; - out->fd_nplanes = (short)bm->bpp; - out->fd_r1 = out->fd_r2 = out->fd_r3 = 0; -} - /** * Return a pointer to the pixel data in a bitmap. @@ -213,8 +189,7 @@ void bitmap_to_mfdb(void * bitmap, MFDB * out) * 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) +static unsigned char *bitmap_get_buffer(void *bitmap) { struct bitmap *bm = bitmap; @@ -226,7 +201,9 @@ unsigned char * bitmap_get_buffer(void *bitmap) return bm->pixdata; } -size_t bitmap_buffer_size( void * bitmap ) + +/* exported interface documented in atari/bitmap.h */ +size_t atari_bitmap_buffer_size(void *bitmap) { struct bitmap * bm = bitmap; if( bm == NULL ) @@ -235,14 +212,8 @@ size_t bitmap_buffer_size( 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 bitmap_get_rowstride(void *bitmap) +/* exported interface documented in atari/bitmap.h */ +size_t atari_bitmap_get_rowstride(void *bitmap) { struct bitmap *bm = bitmap; @@ -254,13 +225,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 interface documented in atari/bitmap.h */ +void atari_bitmap_destroy(void *bitmap) { struct bitmap *bm = bitmap; @@ -270,10 +236,11 @@ void bitmap_destroy(void *bitmap) } if( bm->resized != NULL ) { - bitmap_destroy(bm->resized); + atari_bitmap_destroy(bm->resized); } - if( bm->converted && ( bm->native.fd_addr != bm->pixdata ) ) + if( bm->converted && ( bm->native.fd_addr != bm->pixdata ) ) { free( bm->native.fd_addr ); + } free(bm->pixdata); free(bm); } @@ -288,32 +255,11 @@ void bitmap_destroy(void *bitmap) * \return true on success, false on error and error reported */ -bool bitmap_save(void *bitmap, const char *path, unsigned flags) +static bool bitmap_save(void *bitmap, const char *path, unsigned flags) { return true; } -/** - * The bitmap image has changed, so flush any persistant cache. - * - * \param bitmap a bitmap, as returned by bitmap_create() - */ -void bitmap_modified(void *bitmap) -{ - struct bitmap *bm = bitmap; - if( bm->resized != NULL ) { - bitmap_destroy( bm->resized ); - bm->resized = NULL; - } - if( bm->converted ){ - if( bm->pixdata != bm->native.fd_addr ){ - free( bm->native.fd_addr ); - } - bm->native.fd_addr = NULL; - bm->converted = false; - } - -} /** * Sets whether a bitmap should be plotted opaque @@ -321,7 +267,7 @@ void bitmap_modified(void *bitmap) * \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) +static void bitmap_set_opaque(void *bitmap, bool opaque) { struct bitmap *bm = bitmap; @@ -341,7 +287,7 @@ void bitmap_set_opaque(void *bitmap, bool opaque) * \param bitmap a bitmap, as returned by bitmap_create() * \return whether the bitmap is opaque */ -bool bitmap_test_opaque(void *bitmap) +static bool bitmap_test_opaque(void *bitmap) { int tst; struct bitmap *bm = bitmap; @@ -368,12 +314,8 @@ 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 interface documented in atari/bitmap.h */ +bool atari_bitmap_get_opaque(void *bitmap) { struct bitmap *bm = bitmap; @@ -385,7 +327,9 @@ bool bitmap_get_opaque(void *bitmap) return bm->opaque; } -int bitmap_get_width(void *bitmap) + +/* exported interface documented in atari/bitmap.h */ +int atari_bitmap_get_width(void *bitmap) { struct bitmap *bm = bitmap; @@ -397,7 +341,9 @@ int bitmap_get_width(void *bitmap) return(bm->width); } -int bitmap_get_height(void *bitmap) + +/* exported interface documented in atari/bitmap.h */ +int atari_bitmap_get_height(void *bitmap) { struct bitmap *bm = bitmap; @@ -410,27 +356,26 @@ int bitmap_get_height(void *bitmap) /** -* -* Gets the number of BYTES per pixel. -* -*/ -size_t bitmap_get_bpp(void *bitmap) + * Gets the number of BYTES per pixel. + */ +static size_t bitmap_get_bpp(void *bitmap) { struct bitmap *bm = bitmap; return bm->bpp; } -bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, +/* exported interface documented in atari/bitmap.h */ +bool atari_bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh) { unsigned int state = 0; short bpp = bitmap_get_bpp( img ); - int stride = bitmap_get_rowstride( img ); + int stride = atari_bitmap_get_rowstride( img ); int err; if( img->resized != NULL ) { if( img->resized->width != nw || img->resized->height != nh ) { - bitmap_destroy( img->resized ); + atari_bitmap_destroy( img->resized ); img->resized = NULL; } else { /* the bitmap is already resized */ @@ -442,7 +387,7 @@ bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, if (img->opaque == true) { state |= BITMAP_OPAQUE; } - img->resized = bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); + img->resized = atari_bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); if( img->resized == NULL ) { printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp); assert(img->resized); @@ -460,18 +405,19 @@ bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, err = Hermes_ConverterCopy( hermes_h, img->pixdata, - 0, /* x src coord of top left in pixel coords */ - 0, /* y src coord of top left in pixel coords */ - bitmap_get_width( img ), bitmap_get_height( img ), + 0, /* x src coord of top left in pixel coords */ + 0, /* y src coord of top left in pixel coords */ + atari_bitmap_get_width( img ), + atari_bitmap_get_height( img ), stride, /* stride as bytes */ img->resized->pixdata, - 0, /* x dst coord of top left in pixel coords */ - 0, /* y dst coord of top left in pixel coords */ + 0, /* x dst coord of top left in pixel coords */ + 0, /* y dst coord of top left in pixel coords */ nw, nh, - bitmap_get_rowstride(img->resized) /* stride as bytes */ + atari_bitmap_get_rowstride(img->resized) /* stride as bytes */ ); if( err == 0 ) { - bitmap_destroy( img->resized ); + atari_bitmap_destroy( img->resized ); img->resized = NULL; return(false); } @@ -479,6 +425,23 @@ bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, return(true); } +static struct gui_bitmap_table bitmap_table = { + .create = atari_bitmap_create, + .destroy = atari_bitmap_destroy, + .set_opaque = bitmap_set_opaque, + .get_opaque = atari_bitmap_get_opaque, + .test_opaque = bitmap_test_opaque, + .get_buffer = bitmap_get_buffer, + .get_rowstride = atari_bitmap_get_rowstride, + .get_width = atari_bitmap_get_width, + .get_height = atari_bitmap_get_height, + .get_bpp = bitmap_get_bpp, + .save = bitmap_save, + .modified = bitmap_modified, +}; + +struct gui_bitmap_table *atari_bitmap_table = &bitmap_table; + /* * Local Variables: * c-basic-offset:8 |