4 * functions to allocate and deallocate structures and structure data
8 * Copyright 1989, 1991 Jim Frost.
9 * See included file "copyright.h" for complete copyright information.
14 /* this table is useful for quick conversions between depth and ncolors
17 unsigned long DepthToColorsTable[] =
46 char *dupString(char *s)
53 d = (char *)lmalloc(strlen(s) + 1);
58 void newRGBMapData(RGBMap *rgb, unsigned int size)
62 rgb->compressed = FALSE;
63 rgb->red = (Intensity *)lmalloc(sizeof(Intensity) * size);
64 rgb->green = (Intensity *)lmalloc(sizeof(Intensity) * size);
65 rgb->blue = (Intensity *)lmalloc(sizeof(Intensity) * size);
68 void freeRGBMapData(RGBMap *rgb)
70 lfree((byte *)rgb->red);
71 lfree((byte *)rgb->green);
72 lfree((byte *)rgb->blue);
75 Image *newBitImage(unsigned int width, unsigned int height)
80 image = (Image *)lmalloc(sizeof(Image));
81 image->type = IBITMAP;
83 newRGBMapData(&(image->rgb), (unsigned int)2);
84 *(image->rgb.red)= *(image->rgb.green) = *(image->rgb.blue)= 65535;
85 *(image->rgb.red + 1)= *(image->rgb.green + 1) = *(image->rgb.blue + 1)= 0;
88 image->height = height;
90 linelen = ((width + 7) / 8);
91 image->data = (unsigned char *)lcalloc(linelen * height);
95 Image *newRGBImage(unsigned int width, unsigned int height, unsigned int depth)
98 unsigned int pixlen, numcolors;
100 if (depth == 0) /* special case for `zero' depth image, which is */
101 depth = 1; /* sometimes interpreted as `one color' */
102 pixlen = ((depth+7) / 8);
103 numcolors = depthToColors(depth);
104 image = (Image *)lmalloc(sizeof(Image));
107 newRGBMapData(&(image->rgb), numcolors);
108 image->width = width;
109 image->height = height;
110 image->depth = depth;
111 image->pixlen = pixlen;
112 image->data = (unsigned char *)lmalloc(width * height * pixlen);
116 void freeImageData(Image *image)
120 lfree((byte *)image->title);
123 freeRGBMapData(&(image->rgb));
127 void freeImage(Image *image)
129 freeImageData(image);
130 lfree((byte *)image);
133 byte *lmalloc(unsigned int size)
141 if (!(area = (byte *)malloc(size)))
143 fprintf(stderr, "Out of memory!\n");
150 byte *lcalloc(unsigned int size)
158 if (!(area = (byte *)calloc(1, size)))
160 fprintf(stderr, "Out of memory!\n");
167 void lfree(byte *area)