7 /* this table is useful for quick conversions between depth and ncolors
10 unsigned long DepthToColorsTable[] =
39 void newRGBMapData(RGBMap *rgb, unsigned int size)
43 rgb->compressed = FALSE;
44 rgb->red = (Intensity *)checked_malloc(sizeof(Intensity) * size);
45 rgb->green = (Intensity *)checked_malloc(sizeof(Intensity) * size);
46 rgb->blue = (Intensity *)checked_malloc(sizeof(Intensity) * size);
49 void freeRGBMapData(RGBMap *rgb)
51 free((byte *)rgb->red);
52 free((byte *)rgb->green);
53 free((byte *)rgb->blue);
56 Image *newBitImage(unsigned int width, unsigned int height)
61 image = (Image *)checked_malloc(sizeof(Image));
62 image->type = IBITMAP;
63 newRGBMapData(&(image->rgb), (unsigned int)2);
64 *(image->rgb.red)= *(image->rgb.green) = *(image->rgb.blue)= 65535;
65 *(image->rgb.red + 1)= *(image->rgb.green + 1) = *(image->rgb.blue + 1)= 0;
68 image->height = height;
70 linelen = ((width + 7) / 8);
71 image->data = (unsigned char *)checked_calloc(linelen * height);
75 Image *newRGBImage(unsigned int width, unsigned int height, unsigned int depth)
78 unsigned int pixlen, numcolors;
80 if (depth == 0) /* special case for `zero' depth image, which is */
81 depth = 1; /* sometimes interpreted as `one color' */
82 pixlen = ((depth+7) / 8);
83 numcolors = depthToColors(depth);
84 image = (Image *)checked_malloc(sizeof(Image));
86 newRGBMapData(&(image->rgb), numcolors);
88 image->height = height;
90 image->pixlen = pixlen;
91 image->data = (unsigned char *)checked_malloc(width * height * pixlen);
95 void freeImageData(Image *image)
97 freeRGBMapData(&(image->rgb));
101 void freeImage(Image *image)
103 freeImageData(image);