+
+
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+
+static int
+PutPixel1(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ register char *src;
+ register char *dst;
+ register int i;
+ register char *data;
+ Pixel px;
+ int nbytes;
+
+ for (i=0, px=pixel; i<sizeof(unsigned long); i++, px>>=8)
+ ((unsigned char *)&pixel)[i] = px;
+ src = &ximage->data[XYINDEX(x, y, ximage)];
+ dst = (char *)&px;
+ px = 0;
+ nbytes = ximage->bitmap_unit >> 3;
+ for (i = nbytes; --i >= 0; ) *dst++ = *src++;
+ XYNORMALIZE(&px, ximage);
+ i = ((x + ximage->xoffset) % ximage->bitmap_unit);
+ _putbits ((char *)&pixel, i, 1, (char *)&px);
+ XYNORMALIZE(&px, ximage);
+ src = (char *) &px;
+ dst = &ximage->data[XYINDEX(x, y, ximage)];
+ for (i = nbytes; --i >= 0; )
+ *dst++ = *src++;
+
+ return 1;
+}
+
+static int
+PutPixel(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ register char *src;
+ register char *dst;
+ register int i;
+ register char *data;
+ Pixel px;
+ int nbytes, ibpp;
+
+ ibpp = ximage->bits_per_pixel;
+ if (ximage->depth == 4)
+ pixel &= 0xf;
+ for (i = 0, px = pixel; i < sizeof(unsigned long); i++, px >>= 8)
+ ((unsigned char *) &pixel)[i] = px;
+ src = &ximage->data[ZINDEX(x, y, ximage)];
+ dst = (char *) &px;
+ px = 0;
+ nbytes = (ibpp + 7) >> 3;
+ for (i = nbytes; --i >= 0;)
+ *dst++ = *src++;
+ ZNORMALIZE(&px, ximage);
+ _putbits((char *) &pixel, (x * ibpp) & 7, ibpp, (char *) &px);
+ ZNORMALIZE(&px, ximage);
+ src = (char *) &px;
+ dst = &ximage->data[ZINDEX(x, y, ximage)];
+ for (i = nbytes; --i >= 0;)
+ *dst++ = *src++;
+
+ return 1;
+}
+
+static int
+PutPixel32(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ *((unsigned long *)addr) = pixel;
+ return 1;
+}
+
+static int
+PutPixel32MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ addr[0] = pixel >> 24;
+ addr[1] = pixel >> 16;
+ addr[2] = pixel >> 8;
+ addr[3] = pixel;
+ return 1;
+}
+
+static int
+PutPixel32LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX32(x, y, ximage)];
+ addr[3] = pixel >> 24;
+ addr[2] = pixel >> 16;
+ addr[1] = pixel >> 8;
+ addr[0] = pixel;
+ return 1;
+}
+
+static int
+PutPixel16MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
+ addr[0] = pixel >> 8;
+ addr[1] = pixel;
+ return 1;
+}
+
+static int
+PutPixel16LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ unsigned char *addr;
+
+ addr = &((unsigned char *)ximage->data) [ZINDEX16(x, y, ximage)];
+ addr[1] = pixel >> 8;
+ addr[0] = pixel;
+ return 1;
+}
+
+static int
+PutPixel8(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ ximage->data[ZINDEX8(x, y, ximage)] = pixel;
+ return 1;
+}
+
+static int
+PutPixel1MSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ if (pixel & 1)
+ ximage->data[ZINDEX1(x, y, ximage)] |= 0x80 >> (x & 7);
+ else
+ ximage->data[ZINDEX1(x, y, ximage)] &= ~(0x80 >> (x & 7));
+ return 1;
+}
+
+static int
+PutPixel1LSB(ximage, x, y, pixel)
+ register XImage *ximage;
+ int x;
+ int y;
+ unsigned long pixel;
+{
+ if (pixel & 1)
+ ximage->data[ZINDEX1(x, y, ximage)] |= 1 << (x & 7);
+ else
+ ximage->data[ZINDEX1(x, y, ximage)] &= ~(1 << (x & 7));
+ return 1;
+}
+
+#endif /* not FOR_MSW && not AMIGA */
+
+/*
+ * This function parses an Xpm file or data and directly create an XImage
+ */
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+int xpmParseDataAndCreate(
+ Display* display
+, xpmData* data
+, XImage** image_return
+, XImage** shapeimage_return
+, XpmImage* image
+, XpmInfo* info
+, XpmAttributes* attributes
+)
+#else
+int
+xpmParseDataAndCreate(display, data, image_return, shapeimage_return,
+ image, info, attributes)
+ Display *display;
+ xpmData *data;
+ XImage **image_return;
+ XImage **shapeimage_return;
+ XpmImage *image;
+ XpmInfo *info;
+ XpmAttributes *attributes;
+#endif
+{
+ /* variables stored in the XpmAttributes structure */
+ Visual *visual;
+ Colormap colormap;
+ unsigned int depth;
+ int bitmap_format;
+ XpmFreeColorsFunc freeColors;
+ void *closure;
+
+ /* variables to return */
+ XImage *ximage = NULL;
+ XImage *shapeimage = NULL;
+ unsigned int mask_pixel_index = XpmUndefPixel;
+
+ /* calculation variables */
+ Pixel *image_pixels = NULL;
+ Pixel *mask_pixels = NULL;
+ Pixel *alloc_pixels = NULL;
+ Pixel *used_pixels = NULL;
+ unsigned int nalloc_pixels = 0;
+ unsigned int nused_pixels = 0;
+ unsigned int width, height, ncolors, cpp;
+ unsigned int x_hotspot, y_hotspot, hotspot = 0, extensions = 0;
+ XpmColor *colorTable = NULL;
+ char *hints_cmt = NULL;
+ char *colors_cmt = NULL;
+ char *pixels_cmt = NULL;
+
+ unsigned int cmts;
+ int ErrorStatus;
+ xpmHashTable hashtable;
+
+
+ /* initialize return values */
+ if (image_return)
+ *image_return = NULL;
+ if (shapeimage_return)
+ *shapeimage_return = NULL;
+
+
+ /* retrieve information from the XpmAttributes */
+ if (attributes && (attributes->valuemask & XpmVisual))
+ visual = attributes->visual;
+ else
+ visual = XDefaultVisual(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmColormap))
+ colormap = attributes->colormap;
+ else
+ colormap = XDefaultColormap(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmDepth))
+ depth = attributes->depth;
+ else
+ depth = XDefaultDepth(display, XDefaultScreen(display));
+
+ if (attributes && (attributes->valuemask & XpmBitmapFormat))
+ bitmap_format = attributes->bitmap_format;
+ else
+ bitmap_format = ZPixmap;
+
+ if (attributes && (attributes->valuemask & XpmFreeColors))
+ freeColors = attributes->free_colors;
+ else
+ freeColors = FreeColors;
+ if (attributes && (attributes->valuemask & XpmColorClosure))
+ closure = attributes->color_closure;
+ else
+ closure = NULL;
+
+ cmts = info && (info->valuemask & XpmReturnComments);
+
+ /*
+ * parse the header
+ */
+ ErrorStatus = xpmParseHeader(data);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * read values
+ */
+ ErrorStatus = xpmParseValues(data, &width, &height, &ncolors, &cpp,
+ &x_hotspot, &y_hotspot, &hotspot,
+ &extensions);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+
+ /*
+ * store the hints comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &hints_cmt);
+
+ /*
+ * init the hastable
+ */
+ if (USE_HASHTABLE) {
+ ErrorStatus = xpmHashTableInit(&hashtable);
+ if (ErrorStatus != XpmSuccess)
+ return (ErrorStatus);
+ }
+
+ /*
+ * read colors
+ */
+ ErrorStatus = xpmParseColors(data, ncolors, cpp, &colorTable, &hashtable);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+ /*
+ * store the colors comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &colors_cmt);
+
+ /* malloc pixels index tables */
+ image_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!image_pixels)
+ RETURN(XpmNoMemory);
+
+ mask_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!mask_pixels)
+ RETURN(XpmNoMemory);
+
+ /* maximum of allocated pixels will be the number of colors */
+ alloc_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!alloc_pixels)
+ RETURN(XpmNoMemory);
+
+ /* maximum of allocated pixels will be the number of colors */
+ used_pixels = (Pixel *) XpmMalloc(sizeof(Pixel) * ncolors);
+ if (!used_pixels)
+ RETURN(XpmNoMemory);
+
+ /* get pixel colors, store them in index tables */
+ ErrorStatus = CreateColors(display, attributes, colorTable, ncolors,
+ image_pixels, mask_pixels, &mask_pixel_index,
+ alloc_pixels, &nalloc_pixels, used_pixels,
+ &nused_pixels);
+
+ if (ErrorStatus != XpmSuccess
+ && (ErrorStatus < 0 || (attributes
+ && (attributes->valuemask & XpmExactColors)
+ && attributes->exactColors)))
+ RETURN(ErrorStatus);
+
+ /* now create the ximage */
+ if (image_return) {
+ ErrorStatus = CreateXImage(display, visual, depth,
+ (depth == 1 ? bitmap_format : ZPixmap),
+ width, height, &ximage);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+
+ /*
+ * set the XImage pointer function, to be used with XPutPixel,
+ * to an internal optimized function
+ */
+
+ if (ximage->bits_per_pixel == 8)
+ ximage->f.put_pixel = PutPixel8;
+ else if (((ximage->bits_per_pixel | ximage->depth) == 1) &&
+ (ximage->byte_order == ximage->bitmap_bit_order))
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel1MSB;
+ else
+ ximage->f.put_pixel = PutPixel1LSB;
+ else if (ximage->bits_per_pixel == 16)
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel16MSB;
+ else
+ ximage->f.put_pixel = PutPixel16LSB;
+ else if (ximage->bits_per_pixel == 32)
+#if !defined(WORD64) && !defined(LONG64)
+ if (*((char *)&byteorderpixel) == ximage->byte_order)
+ ximage->f.put_pixel = PutPixel32;
+ else
+#endif
+ if (ximage->bitmap_bit_order == MSBFirst)
+ ximage->f.put_pixel = PutPixel32MSB;
+ else
+ ximage->f.put_pixel = PutPixel32LSB;
+ else if ((ximage->bits_per_pixel | ximage->depth) == 1)
+ ximage->f.put_pixel = PutPixel1;
+ else
+ ximage->f.put_pixel = PutPixel;
+#endif /* not FOR_MSW && not AMIGA */
+ }
+
+ /* create the shape mask image */
+ if (mask_pixel_index != XpmUndefPixel && shapeimage_return) {
+ ErrorStatus = CreateXImage(display, visual, 1, bitmap_format,
+ width, height, &shapeimage);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+
+#if !defined(FOR_MSW) && !defined(AMIGA)
+ if (shapeimage->bitmap_bit_order == MSBFirst)
+ shapeimage->f.put_pixel = PutPixel1MSB;
+ else
+ shapeimage->f.put_pixel = PutPixel1LSB;
+#endif
+ }
+
+ /*
+ * read pixels and put them in the XImage
+ */
+ ErrorStatus = ParseAndPutPixels(
+#ifdef FOR_MSW
+ display,
+#endif
+ data, width, height, ncolors, cpp,
+ colorTable, &hashtable,
+ ximage, image_pixels,
+ shapeimage, mask_pixels);
+ XpmFree(image_pixels);
+ image_pixels = NULL;
+ XpmFree(mask_pixels);
+ mask_pixels = NULL;
+
+ /*
+ * free the hastable
+ */
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus)
+ else if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+
+ /*
+ * store the pixels comment line
+ */
+ if (cmts)
+ xpmGetCmt(data, &pixels_cmt);
+
+ /*
+ * parse extensions
+ */
+ if (info && (info->valuemask & XpmReturnExtensions))
+ if (extensions) {
+ ErrorStatus = xpmParseExtensions(data, &info->extensions,
+ &info->nextensions);
+ if (ErrorStatus != XpmSuccess)
+ RETURN(ErrorStatus);
+ } else {
+ info->extensions = NULL;
+ info->nextensions = 0;
+ }
+
+ /*
+ * store found informations in the XpmImage structure
+ */
+ image->width = width;
+ image->height = height;
+ image->cpp = cpp;
+ image->ncolors = ncolors;
+ image->colorTable = colorTable;
+ image->data = NULL;
+
+ if (info) {
+ if (cmts) {
+ info->hints_cmt = hints_cmt;
+ info->colors_cmt = colors_cmt;
+ info->pixels_cmt = pixels_cmt;
+ }
+ if (hotspot) {
+ info->x_hotspot = x_hotspot;
+ info->y_hotspot = y_hotspot;
+ info->valuemask |= XpmHotspot;
+ }
+ }
+ /* if requested return used pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnPixels ||
+/* 3.2 backward compatibility code */
+ attributes->valuemask & XpmReturnInfos)) {
+/* end 3.2 bc */
+ attributes->pixels = used_pixels;
+ attributes->npixels = nused_pixels;
+ attributes->mask_pixel = mask_pixel_index;
+ } else
+ XpmFree(used_pixels);
+
+ /* if requested return alloc'ed pixels in the XpmAttributes structure */
+ if (attributes && (attributes->valuemask & XpmReturnAllocPixels)) {
+ attributes->alloc_pixels = alloc_pixels;
+ attributes->nalloc_pixels = nalloc_pixels;
+ } else
+ XpmFree(alloc_pixels);
+
+ /* return created images */
+ if (image_return)
+ *image_return = ximage;
+ if (shapeimage_return)
+ *shapeimage_return = shapeimage;
+
+ return (XpmSuccess);
+
+/* exit point in case of error, free only locally allocated variables */
+error:
+ if (USE_HASHTABLE)
+ xpmHashTableFree(&hashtable);
+ if (colorTable)
+ xpmFreeColorTable(colorTable, ncolors);
+ if (hints_cmt)
+ XpmFree(hints_cmt);
+ if (colors_cmt)
+ XpmFree(colors_cmt);
+ if (pixels_cmt)
+ XpmFree(pixels_cmt);
+ if (ximage)
+ XDestroyImage(ximage);
+ if (shapeimage)
+ XDestroyImage(shapeimage);
+ if (image_pixels)
+ XpmFree(image_pixels);
+ if (mask_pixels)
+ XpmFree(mask_pixels);
+ if (nalloc_pixels)
+ (*freeColors)(display, colormap, alloc_pixels, nalloc_pixels, NULL);
+ if (alloc_pixels)
+ XpmFree(alloc_pixels);
+ if (used_pixels)
+ XpmFree(used_pixels);
+
+ return (ErrorStatus);
+}
+
+#ifdef __OS2__
+/* Visual Age cannot deal with old, non-ansi, code */
+static int ParseAndPutPixels(
+ Display* dc
+, xpmData* data
+, unsigned int width
+, unsigned int height
+, unsigned int ncolors
+, unsigned int cpp
+, XpmColor* colorTable
+, xpmHashTable* hashtable
+, XImage* image
+, Pixel* image_pixels
+, XImage* shapeimage
+, Pixel* shape_pixels
+)
+#else
+static int
+ParseAndPutPixels(
+#ifdef FOR_MSW
+ dc,
+#endif
+ data, width, height, ncolors, cpp, colorTable, hashtable,
+ image, image_pixels, shapeimage, shape_pixels)
+#ifdef FOR_MSW
+ Display *dc;
+#endif
+ xpmData *data;
+ unsigned int width;
+ unsigned int height;
+ unsigned int ncolors;
+ unsigned int cpp;
+ XpmColor *colorTable;
+ xpmHashTable *hashtable;
+ XImage *image;
+ Pixel *image_pixels;
+ XImage *shapeimage;
+ Pixel *shape_pixels;
+#endif
+{
+ unsigned int a, x, y;
+#ifdef __OS2__
+ HAB hab;
+ HPS hps;
+ DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL, NULL};
+ SIZEL sizl = {0, 0};
+ POINTL point;
+#endif
+
+ switch (cpp) {
+
+ case (1): /* Optimize for single character
+ * colors */
+ {
+ unsigned short colidx[256];
+#ifdef FOR_MSW
+ HDC shapedc;
+ HBITMAP obm, sobm;
+
+ if ( shapeimage ) {
+#ifdef __OS2__
+ shapedc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+ hps = GpiCreatePS(hab, *dc, &sizl, GPIA_ASSOC | PU_PELS);
+ sobm = GpiSetBitmap(hps, shapeimage->bitmap);
+#else
+ shapedc = CreateCompatibleDC(*dc);
+ sobm = SelectObject(shapedc, shapeimage->bitmap);
+#endif
+ } else {
+ shapedc = NULL;
+ }
+#ifdef __OS2__
+ obm = GpiSetBitmap(hps, image->bitmap);
+#else
+ obm = SelectObject(*dc, image->bitmap);
+#endif
+
+#endif
+
+
+ bzero((char *)colidx, 256 * sizeof(short));
+ for (a = 0; a < ncolors; a++)
+ colidx[(unsigned char)colorTable[a].string[0]] = a + 1;
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ int c = xpmGetC(data);
+
+ if (c > 0 && c < 256 && colidx[c] != 0) {
+#ifndef FOR_MSW
+ XPutPixel(image, x, y, image_pixels[colidx[c] - 1]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[colidx[c] - 1]);
+#else
+#ifdef __OS2__
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)image_pixels[colidx[c] - 1]);
+ GpiSetPel(hps, &point);
+#else
+ SetPixel(*dc, x, y, image_pixels[colidx[c] - 1]);
+#endif
+ if (shapedc) {
+#ifdef __OS2__
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)shape_pixels[colidx[c] - 1]);
+ GpiSetPel(hps, &point);
+#else
+ SetPixel(shapedc, x, y, shape_pixels[colidx[c] - 1]);
+#endif
+ }
+#endif
+ } else
+ return (XpmFileInvalid);
+ }
+ }
+#ifdef FOR_MSW
+ if ( shapedc ) {
+#ifdef __OS2__
+ GpiSetBitmap(hps, sobm);
+ DevCloseDC(shapedc);
+#else
+ SelectObject(shapedc, sobm);
+ DeleteDC(shapedc);
+#endif
+ }
+#ifdef __OS2__
+ GpiSetBitmap(hps, obm);
+#else
+ SelectObject(*dc, obm);
+#endif
+#endif
+ }
+ break;
+
+ case (2): /* Optimize for double character
+ * colors */
+ {
+/* free all allocated pointers at all exits */
+#define FREE_CIDX {int f; for (f = 0; f < 256; f++) \
+if (cidx[f]) XpmFree(cidx[f]);}
+
+ /* array of pointers malloced by need */
+ unsigned short *cidx[256];
+ int char1;
+
+ bzero((char *)cidx, 256 * sizeof(unsigned short *)); /* init */
+ for (a = 0; a < ncolors; a++) {
+ char1 = colorTable[a].string[0];
+ if (cidx[char1] == NULL) { /* get new memory */
+ cidx[char1] = (unsigned short *)
+ XpmCalloc(256, sizeof(unsigned short));
+ if (cidx[char1] == NULL) { /* new block failed */
+ FREE_CIDX;
+ return (XpmNoMemory);
+ }
+ }
+ cidx[char1][(unsigned char)colorTable[a].string[1]] = a + 1;
+ }
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ int cc1 = xpmGetC(data);
+ if (cc1 > 0 && cc1 < 256) {
+ int cc2 = xpmGetC(data);
+ if (cc2 > 0 && cc2 < 256 &&
+ cidx[cc1] && cidx[cc1][cc2] != 0) {
+#ifndef FOR_MSW
+ XPutPixel(image, x, y,
+ image_pixels[cidx[cc1][cc2] - 1]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[cidx[cc1][cc2] - 1]);
+#else
+#ifdef __OS2__
+ *dc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+ hps = GpiCreatePS(hab, *dc, &sizl, GPIA_ASSOC | PU_PELS);
+
+ GpiSetBitmap(hps, image->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)image_pixels[cidx[cc1][cc2] - 1]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y, image_pixels[cidx[cc1][cc2] - 1]);
+#endif
+ if (shapeimage) {
+#ifdef __OS2__
+ GpiSetBitmap(hps, shapeimage->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)shape_pixels[cidx[cc1][cc2] - 1]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y,
+ shape_pixels[cidx[cc1][cc2] - 1]);
+#endif
+ }
+#endif
+ } else {
+ FREE_CIDX;
+ return (XpmFileInvalid);
+ }
+ } else {
+ FREE_CIDX;
+ return (XpmFileInvalid);
+ }
+ }
+ }
+ FREE_CIDX;
+ }
+ break;
+
+ default: /* Non-optimized case of long color
+ * names */
+ {
+ char *s;
+ char buf[BUFSIZ];
+
+ buf[cpp] = '\0';
+ if (USE_HASHTABLE) {
+ xpmHashAtom *slot;
+
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ for (a = 0, s = buf; a < cpp; a++, s++)
+ *s = xpmGetC(data);
+ slot = xpmHashSlot(hashtable, buf);
+ if (!*slot) /* no color matches */
+ return (XpmFileInvalid);
+#ifndef FOR_MSW
+ XPutPixel(image, x, y,
+ image_pixels[HashColorIndex(slot)]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y,
+ shape_pixels[HashColorIndex(slot)]);
+#else
+#ifdef __OS2__
+ *dc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+ hps = GpiCreatePS(hab, *dc, &sizl, GPIA_ASSOC | PU_PELS);
+
+ GpiSetBitmap(hps, image->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)image_pixels[HashColorIndex(slot)]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y,
+ image_pixels[HashColorIndex(slot)]);
+#endif
+ if (shapeimage) {
+#ifdef __OS2__
+ GpiSetBitmap(hps, shapeimage->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)shape_pixels[HashColorIndex(slot)]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y,
+ shape_pixels[HashColorIndex(slot)]);
+#endif
+ }
+#endif
+ }
+ }
+ } else {
+ for (y = 0; y < height; y++) {
+ xpmNextString(data);
+ for (x = 0; x < width; x++) {
+ for (a = 0, s = buf; a < cpp; a++, s++)
+ *s = xpmGetC(data);
+ for (a = 0; a < ncolors; a++)
+ if (!strcmp(colorTable[a].string, buf))
+ break;
+ if (a == ncolors) /* no color matches */
+ return (XpmFileInvalid);
+#ifndef FOR_MSW
+ XPutPixel(image, x, y, image_pixels[a]);
+ if (shapeimage)
+ XPutPixel(shapeimage, x, y, shape_pixels[a]);
+#else
+#ifdef __OS2__
+ *dc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+ hps = GpiCreatePS(hab, *dc, &sizl, GPIA_ASSOC | PU_PELS);
+
+ GpiSetBitmap(hps, image->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)image_pixels[a]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, image->bitmap);
+ SetPixel(*dc, x, y, image_pixels[a]);
+#endif
+ if (shapeimage) {
+#ifdef __OS2__
+ GpiSetBitmap(hps, image->bitmap);
+ point.x = x;
+ point.y = y;
+ GpiSetColor(hps, (LONG)shape_pixels[a]);
+ GpiSetPel(hps, &point);
+#else
+ SelectObject(*dc, shapeimage->bitmap);
+ SetPixel(*dc, x, y, shape_pixels[a]);
+#endif
+ }
+#endif
+ }
+ }
+ }
+ }
+ break;
+ }
+ return (XpmSuccess);
+}