6 /* this table is useful for quick conversions between depth and ncolors
9 unsigned long DepthToColorsTable[] =
38 char *dupString(char *s)
45 d = (char *)lmalloc(strlen(s) + 1);
50 void newRGBMapData(RGBMap *rgb, unsigned int size)
54 rgb->compressed = FALSE;
55 rgb->red = (Intensity *)lmalloc(sizeof(Intensity) * size);
56 rgb->green = (Intensity *)lmalloc(sizeof(Intensity) * size);
57 rgb->blue = (Intensity *)lmalloc(sizeof(Intensity) * size);
60 void freeRGBMapData(RGBMap *rgb)
62 lfree((byte *)rgb->red);
63 lfree((byte *)rgb->green);
64 lfree((byte *)rgb->blue);
67 Image *newBitImage(unsigned int width, unsigned int height)
72 image = (Image *)lmalloc(sizeof(Image));
73 image->type = IBITMAP;
75 newRGBMapData(&(image->rgb), (unsigned int)2);
76 *(image->rgb.red)= *(image->rgb.green) = *(image->rgb.blue)= 65535;
77 *(image->rgb.red + 1)= *(image->rgb.green + 1) = *(image->rgb.blue + 1)= 0;
80 image->height = height;
82 linelen = ((width + 7) / 8);
83 image->data = (unsigned char *)lcalloc(linelen * height);
87 Image *newRGBImage(unsigned int width, unsigned int height, unsigned int depth)
90 unsigned int pixlen, numcolors;
92 if (depth == 0) /* special case for `zero' depth image, which is */
93 depth = 1; /* sometimes interpreted as `one color' */
94 pixlen = ((depth+7) / 8);
95 numcolors = depthToColors(depth);
96 image = (Image *)lmalloc(sizeof(Image));
99 newRGBMapData(&(image->rgb), numcolors);
100 image->width = width;
101 image->height = height;
102 image->depth = depth;
103 image->pixlen = pixlen;
104 image->data = (unsigned char *)lmalloc(width * height * pixlen);
108 void freeImageData(Image *image)
112 lfree((byte *)image->title);
115 freeRGBMapData(&(image->rgb));
119 void freeImage(Image *image)
121 freeImageData(image);
122 lfree((byte *)image);
125 byte *lmalloc(unsigned int size)
133 if (!(area = (byte *)malloc(size)))
135 fprintf(stderr, "Out of memory!\n");
142 byte *lcalloc(unsigned int size)
150 if (!(area = (byte *)calloc(1, size)))
152 fprintf(stderr, "Out of memory!\n");
159 void lfree(byte *area)