dc9e7527ce8516efbb098a4f0f8702d49986677b
kate
  Thu Jul 16 09:44:16 2015 -0700
Removing obsolete 8-bit color support. refs #15722

diff --git src/lib/memgfx.c src/lib/memgfx.c
index 058abcc..aa23c41 100644
--- src/lib/memgfx.c
+++ src/lib/memgfx.c
@@ -1,88 +1,69 @@
 /* memgfx - routines for drawing on bitmaps in memory.
  * Currently limited to 256 color bitmaps. 
  *
  * This file is copyright 2002 Jim Kent, but license is hereby
  * granted for all use - public, private or commercial. */
 
 #include "common.h"
 #include "memgfx.h"
 #include "gemfont.h"
 #include "localmem.h"
 #include "vGfx.h"
 #include "vGfxPrivate.h"
 #include "colHash.h"
 
 
-
 Color multiply(Color src, Color new)
 {
-#ifdef COLOR32
 unsigned char rs = (src >> 0) & 0xff;
 unsigned char gs = (src >> 8) & 0xff;
 unsigned char bs = (src >> 16) & 0xff;
 unsigned char rn = (new >> 0) & 0xff;
 unsigned char gn = (new >> 8) & 0xff;
 unsigned char bn = (new >> 16) & 0xff;
 
 unsigned char ro = ((unsigned) rn * rs) / 255;
 unsigned char go = ((unsigned) gn * gs) / 255;
 unsigned char bo = ((unsigned) bn * bs) / 255;
 return MAKECOLOR_32(ro, go, bo);
-#else
-/* no multiply write mode in 8 bit */
-return new;
-#endif /* COLOR32 */
 }
 
-
 #ifndef min3
 #define min3(x,y,z) (min(x,min(y,z)))
 /* Return min of x,y, and z. */
 #endif
 
 #ifndef max3
 #define max3(x,y,z) (max(x,max(y,z)))
 /* Return max of x,y, and z. */
 #endif
 
 void _mgPutDotMultiply(struct memGfx *mg, int x, int y,Color color)
 {
 Color *pt = _mgPixAdr(mg,x,y);
 *pt = multiply(*pt, color);
 }
 
 
 static void mgSetDefaultColorMap(struct memGfx *mg)
 /* Set up default color map for a memGfx. */
 {
-#ifdef COLOR32
     return;
-#else
-
-/* Note dependency in order here and in MG_WHITE, MG_BLACK, etc. */
-int i;
-for (i=0; i<ArraySize(mgFixedColors); ++i)
-    {
-    struct rgbColor *c = &mgFixedColors[i];
-    mgAddColor(mg, c->r, c->g, c->b);
-    }
-#endif
 }
 
 
-
 void mgSetWriteMode(struct memGfx *mg, unsigned int writeMode)
 /* Set write mode */
 {
 mg->writeMode = writeMode;
 }
 
 void mgSetClip(struct memGfx *mg, int x, int y, int width, int height)
 /* Set clipping rectangle. */
 {
 int x2, y2;
 if (x < 0)
     x = 0;
 if (y < 0)
     y = 0;
 x2 = x + width;
@@ -100,164 +81,96 @@
 void mgUnclip(struct memGfx *mg)
 /* Set clipping rect cover full thing. */
 {
 mgSetClip(mg, 0,0,mg->width, mg->height);
 }
 
 struct memGfx *mgNew(int width, int height)
 /* Return new memGfx. Note new pixel memory is uninitialized */
 {
 struct memGfx *mg;
 
 mg = needMem(sizeof(*mg));
 mg->width = width;
 mg->height = height;
 mg->pixels = needLargeMem(width*height*sizeof(Color));
-#ifndef COLOR32
-mg->colorHash = colHashNew();
-#endif
 mgSetDefaultColorMap(mg);
 mgUnclip(mg);
 return mg;
 }
 
 void mgClearPixels(struct memGfx *mg)
 /* Set all pixels to background. */
 {
-#ifdef COLOR32
 memset((unsigned char *)mg->pixels, 0xff, mg->width*mg->height*sizeof(unsigned int));
-#else
-zeroBytes(mg->pixels, mg->width*mg->height);
-#endif
 }
 
 void mgClearPixelsTrans(struct memGfx *mg)
 /* Set all pixels to transparent. */
 {
-#ifdef COLOR32
 unsigned int *ptr = mg->pixels;
 unsigned int *lastPtr = &mg->pixels[mg->width * mg->height];
 for(; ptr < lastPtr; ptr++)
 #ifdef MEMGFX_BIGENDIAN
     *ptr = 0xffffff00;
 #else
     *ptr = 0x00ffffff;  // transparent white
 #endif
-
-#else
-zeroBytes(mg->pixels, mg->width*mg->height);
-#endif
 }
 
 Color mgFindColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b)
 /* Returns closest color in color map to rgb values.  If it doesn't
  * already exist in color map and there's room, it will create
  * exact color in map. */
 {
-#ifdef COLOR32
 return MAKECOLOR_32(r,g,b);
-#else
-struct colHashEl *che;
-if ((che = colHashLookup(mg->colorHash, r, g, b)) != NULL)
-    return che->ix;
-if (mgColorsFree(mg))
-    return mgAddColor(mg, r, g, b);
-return mgClosestColor(mg, r, g, b);
-#endif
 }
 
 
 struct rgbColor mgColorIxToRgb(struct memGfx *mg, int colorIx)
 /* Return rgb value at color index. */
 {
-#ifdef COLOR32
 static struct rgbColor rgb;
 #ifdef MEMGFX_BIGENDIAN
 rgb.r = (colorIx >> 24) & 0xff;
 rgb.g = (colorIx >> 16) & 0xff;
 rgb.b = (colorIx >> 8) & 0xff;
 #else
 rgb.r = (colorIx >> 0) & 0xff;
 rgb.g = (colorIx >> 8) & 0xff;
 rgb.b = (colorIx >> 16) & 0xff;
 #endif
-
 return rgb;
-#else
-return mg->colorMap[colorIx];
-#endif
 }
 
 Color mgClosestColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b)
 /* Returns closest color in color map to r,g,b */
 {
-#ifdef COLOR32
 return MAKECOLOR_32(r,g,b);
-#else
-struct rgbColor *c = mg->colorMap;
-int closestDist = 0x7fffffff;
-int closestIx = -1;
-int dist, dif;
-int i;
-for (i=0; i<mg->colorsUsed; ++i)
-    {
-    dif = c->r - r;
-    dist = dif*dif;
-    dif = c->g - g;
-    dist += dif*dif;
-    dif = c->b - b;
-    dist += dif*dif;
-    if (dist < closestDist)
-        {
-        closestDist = dist;
-        closestIx = i;
-        }
-    ++c;
-    }
-return closestIx;
-#endif
 }
 
 
 Color mgAddColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b)
 /* Adds color to end of color map if there's room. */
 {
-#ifdef COLOR32
 return MAKECOLOR_32(r,g,b);
-#else
-int colIx = mg->colorsUsed;
-if (colIx < 256)
-    {
-    struct rgbColor *c = mg->colorMap + mg->colorsUsed;
-    c->r = r;
-    c->g = g;
-    c->b = b;
-    mg->colorsUsed += 1;
-    colHashAdd(mg->colorHash, r, g, b, colIx);
-    }
-return (Color)colIx;
-#endif
 }
 
 int mgColorsFree(struct memGfx *mg)
 /* Returns # of unused colors in color map. */
 {
-#ifdef COLOR32
 return 1 << 23;
-#else
-return 256-mg->colorsUsed;
-#endif
 }
 
 void mgFree(struct memGfx **pmg)
 {
 struct memGfx *mg = *pmg;
 if (mg != NULL)
     {
     if (mg->pixels != NULL)
 	freeMem(mg->pixels);
     if (mg->colorHash)
         colHashFree(&mg->colorHash);
     zeroBytes(mg, sizeof(*mg));
     freeMem(mg);
     }
 *pmg = NULL;