X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fimage.c;fp=src%2Fimage.c;h=d75de85516a59de7dd74c26286c30d30fb9a192c;hb=9e0e44d9596ef874ec5d1e1bd749748c3a9e93f0;hp=f72ea2305a97e7ed77ce1438f67c192b353fb065;hpb=d46a473059b29c03d44430dfc75f170e3eb7cf63;p=rocksndiamonds.git diff --git a/src/image.c b/src/image.c index f72ea230..d75de855 100644 --- a/src/image.c +++ b/src/image.c @@ -862,3 +862,105 @@ void freeXImage(Image *image, XImageInfo *ximageinfo) free((byte *)ximageinfo); /* should we free private color map to ??? */ } + + + +/* this table is useful for quick conversions between depth and ncolors + */ + +unsigned long DepthToColorsTable[] = +{ + /* 0 */ 1, + /* 1 */ 2, + /* 2 */ 4, + /* 3 */ 8, + /* 4 */ 16, + /* 5 */ 32, + /* 6 */ 64, + /* 7 */ 128, + /* 8 */ 256, + /* 9 */ 512, + /* 10 */ 1024, + /* 11 */ 2048, + /* 12 */ 4096, + /* 13 */ 8192, + /* 14 */ 16384, + /* 15 */ 32768, + /* 16 */ 65536, + /* 17 */ 131072, + /* 18 */ 262144, + /* 19 */ 524288, + /* 20 */ 1048576, + /* 21 */ 2097152, + /* 22 */ 4194304, + /* 23 */ 8388608, + /* 24 */ 16777216 +}; + +void newRGBMapData(RGBMap *rgb, unsigned int size) +{ + rgb->used = 0; + rgb->size = size; + rgb->compressed = FALSE; + rgb->red = (Intensity *)checked_malloc(sizeof(Intensity) * size); + rgb->green = (Intensity *)checked_malloc(sizeof(Intensity) * size); + rgb->blue = (Intensity *)checked_malloc(sizeof(Intensity) * size); +} + +void freeRGBMapData(RGBMap *rgb) +{ + free((byte *)rgb->red); + free((byte *)rgb->green); + free((byte *)rgb->blue); +} + +Image *newBitImage(unsigned int width, unsigned int height) +{ + Image *image; + unsigned int linelen; + + image = (Image *)checked_malloc(sizeof(Image)); + image->type = IBITMAP; + newRGBMapData(&(image->rgb), (unsigned int)2); + *(image->rgb.red)= *(image->rgb.green) = *(image->rgb.blue)= 65535; + *(image->rgb.red + 1)= *(image->rgb.green + 1) = *(image->rgb.blue + 1)= 0; + image->rgb.used = 2; + image->width = width; + image->height = height; + image->depth = 1; + linelen = ((width + 7) / 8); + image->data = (unsigned char *)checked_calloc(linelen * height); + return(image); +} + +Image *newRGBImage(unsigned int width, unsigned int height, unsigned int depth) +{ + Image *image; + unsigned int pixlen, numcolors; + + if (depth == 0) /* special case for `zero' depth image, which is */ + depth = 1; /* sometimes interpreted as `one color' */ + pixlen = ((depth+7) / 8); + numcolors = depthToColors(depth); + image = (Image *)checked_malloc(sizeof(Image)); + image->type = IRGB; + newRGBMapData(&(image->rgb), numcolors); + image->width = width; + image->height = height; + image->depth = depth; + image->pixlen = pixlen; + image->data = (unsigned char *)checked_malloc(width * height * pixlen); + return(image); +} + +void freeImageData(Image *image) +{ + freeRGBMapData(&(image->rgb)); + free(image->data); +} + +void freeImage(Image *image) +{ + freeImageData(image); + free((byte *)image); +}