From 1fd361a1ea06e44286c213ca1f814f49306fdc43 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 19 Aug 2006 03:12:28 +0000 Subject: Create Subversion repository git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/pamtosvg/bitmap.c | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 converter/other/pamtosvg/bitmap.c (limited to 'converter/other/pamtosvg/bitmap.c') diff --git a/converter/other/pamtosvg/bitmap.c b/converter/other/pamtosvg/bitmap.c new file mode 100644 index 00000000..1a00e748 --- /dev/null +++ b/converter/other/pamtosvg/bitmap.c @@ -0,0 +1,116 @@ +/* bitmap.c: operations on bitmaps. */ + +#include + +#include "mallocvar.h" + +#include "bitmap.h" + +at_bitmap_type * +at_bitmap_new(unsigned short width, + unsigned short height, + unsigned int planes) { + + at_bitmap_type * bitmap; + + MALLOCVAR_NOFAIL(bitmap); + + *bitmap = at_bitmap_init(NULL, width, height, planes); + + return bitmap; +} + + + +at_bitmap_type * +at_bitmap_copy(at_bitmap_type * src) +{ + at_bitmap_type * dist; + unsigned short width, height, planes; + + width = at_bitmap_get_width(src); + height = at_bitmap_get_height(src); + planes = at_bitmap_get_planes(src); + + dist = at_bitmap_new(width, height, planes); + memcpy(dist->bitmap, + src->bitmap, + width * height * planes * sizeof(unsigned char)); + return dist; +} + + + +at_bitmap_type +at_bitmap_init(unsigned char * area, + unsigned short width, + unsigned short height, + unsigned int planes) { + + at_bitmap_type bitmap; + + if (area) + bitmap.bitmap = area; + else { + if (width * height == 0) + bitmap.bitmap = NULL; + else { + MALLOCARRAY(bitmap.bitmap, width * height * planes); + if (bitmap.bitmap == NULL) + pm_error("Unable to allocate %u x %u x %u bitmap array", + width, height, planes); + bzero(bitmap.bitmap, + width * height * planes * sizeof(unsigned char)); + } + } + + bitmap.width = width; + bitmap.height = height; + bitmap.np = planes; + + return bitmap; +} + +void +at_bitmap_free (at_bitmap_type * bitmap) +{ + free_bitmap (bitmap); + free(bitmap); +} + +unsigned short +at_bitmap_get_width (at_bitmap_type * bitmap) +{ + return bitmap->width; +} + +unsigned short +at_bitmap_get_height (at_bitmap_type * bitmap) +{ + return bitmap->height; +} + +unsigned short +at_bitmap_get_planes (at_bitmap_type * bitmap) +{ + return bitmap->np; +} + + + +bitmap_type +new_bitmap (unsigned short width, unsigned short height) +{ + return at_bitmap_init(NULL,width,height,1); +} + +/* Free the storage that is allocated for a bitmap. On the other hand, + the bitmap might not have any storage allocated for it if it is zero + in either dimension; in that case, don't free it. */ + +void +free_bitmap (bitmap_type *b) +{ + if (b->bitmap != NULL) + free (b->bitmap); +} -- cgit 1.4.1