about summary refs log tree commit diff
path: root/other/pamx
diff options
context:
space:
mode:
Diffstat (limited to 'other/pamx')
-rw-r--r--other/pamx/Makefile10
-rw-r--r--other/pamx/pamx.c1
-rw-r--r--other/pamx/send.c119
-rw-r--r--other/pamx/window.c1
4 files changed, 84 insertions, 47 deletions
diff --git a/other/pamx/Makefile b/other/pamx/Makefile
index 4e06e0fd..e4892540 100644
--- a/other/pamx/Makefile
+++ b/other/pamx/Makefile
@@ -9,7 +9,7 @@ include $(BUILDDIR)/config.mk
 
 EXTERN_INCLUDE =
 
-ifeq ($(shell pkg-config x11 --modversion --silence-errors),)
+ifeq ($(shell $(PKG_CONFIG) x11 --modversion --silence-errors),)
   # Pkg-config has never heard of X11, or doesn't even exist
 
   ifneq ($(X11LIB),NONE)
@@ -20,8 +20,8 @@ ifeq ($(shell pkg-config x11 --modversion --silence-errors),)
   endif
 else
   HAVE_X11LIB = Y
-  X11LIB = $(shell pkg-config x11 --libs)
-  EXTERN_INCLUDES += $(shell pkg-config x11 --cflags)
+  X11LIB = $(shell $(PKG_CONFIG) x11 --libs)
+  EXTERN_INCLUDES += $(shell $(PKG_CONFIG) x11 --cflags)
 endif
 
 ifeq ($(HAVE_X11LIB),Y)
@@ -46,10 +46,10 @@ all: $(BINARIES)
 
 include $(SRCDIR)/common.mk
 
-ifeq ($(shell pkg-config x11 --libs),)
+ifeq ($(shell $(PKG_CONFIG) x11 --libs),)
   X11_LIBOPTS = $(shell $(LIBOPT) $(LIBOPTR) $(X11LIB))
 else
-  X11_LIBOPTS = $(shell pkg-config x11 --libs)
+  X11_LIBOPTS = $(shell $(PKG_CONFIG) x11 --libs)
 endif
 
 pamx: image.o send.o window.o
diff --git a/other/pamx/pamx.c b/other/pamx/pamx.c
index e22693ea..35900f82 100644
--- a/other/pamx/pamx.c
+++ b/other/pamx/pamx.c
@@ -3,6 +3,7 @@
    Copyright information is in the file COPYRIGHT
 */
 
+#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */
 #define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 #define _BSD_SOURCE  /* Make sure strdup() is in <string.h> */
 #include <signal.h>
diff --git a/other/pamx/send.c b/other/pamx/send.c
index fd50d5e9..3c3852e2 100644
--- a/other/pamx/send.c
+++ b/other/pamx/send.c
@@ -22,9 +22,10 @@
 #include "send.h"
 
 #define TRUE_TO_15BIT(PIXEL)     \
+    ((unsigned short) \
     ((((PIXEL) & 0xf80000) >> 9) | \
     (((PIXEL) & 0x00f800) >> 6) | \
-    (((PIXEL) & 0x0000f8) >> 3))
+     (((PIXEL) & 0x0000f8) >> 3)))
 
 #define RED_INTENSITY(P)   (((P) & 0x7c00) >> 10)
 #define GREEN_INTENSITY(P) (((P) & 0x03e0) >> 5)
@@ -116,63 +117,97 @@ bitsPerPixelAtDepth(Display *    const disp,
      
 
 
-static Image *
-itrueToRGB(Image *      const imageP,
-           unsigned int const ddepth) {
-
-    int y, x, num_pixels, colors;
-    unsigned long pixel_counts[32786];
-    unsigned long pixel_array[32786];
-    Pixel pixval;
+static void
+findColors(const Image *   const imageP,
+           unsigned int *  const pixelCt) {
+/*----------------------------------------------------------------------------
+   Find the colors in the Itrue raster 'raster'; return the histogram of
+   those colors as 'pixelCt'.
+-----------------------------------------------------------------------------*/
+    unsigned short color;
     unsigned char * pixel;
-    unsigned char * dpixel;
-    Image * newImageP;
-    
-    newImageP = newRGBImage(imageP->width, imageP->height, ddepth);
+    unsigned int y;
 
-    colors = 1 << ddepth;
-  
-    memset(pixel_counts, 0, 32768 * sizeof(unsigned long));
+    for (color = 0; color < 32768; ++color)
+        pixelCt[color] = 0;  /* initial value */
   
-    pixel= imageP->data;
-    for (y= 0; y < imageP->height; y++) {
+    for (y = 0, pixel = imageP->data; y < imageP->height; ++y) {
         unsigned int x;
-        for (x= 0; x < imageP->width; x++) {
-            unsigned int const z = TRUE_TO_15BIT(memToVal(pixel, 3));
-            pixel_counts[z]++;
+        for (x = 0; x < imageP->width; ++x) {
+            unsigned int const color = TRUE_TO_15BIT(memToVal(pixel, 3));
+            ++pixelCt[color];
             pixel += 3;
         }
     }
-    num_pixels = 0;
-    for (x = 0; x < 32768; ++x) {
-        if (pixel_counts[x] > 0) {
-            unsigned long const red = RED_INTENSITY(x);
-            unsigned long const grn = GREEN_INTENSITY(x);
-            unsigned long const blu = BLUE_INTENSITY(x);
-            pixel_counts[x] = num_pixels;
-            *(newImageP->rgb.red + num_pixels) = red<<11;
-            *(newImageP->rgb.grn + num_pixels) = grn<<11; 
-            *(newImageP->rgb.blu + num_pixels) =  blu<<11;
-            pixel_array[num_pixels++] = (short)x;
-            if (num_pixels > colors)
-                break;
+}
+
+
+
+static Image *
+pseudoColorImageFromItrue(Image *      const imageP,
+                          unsigned int const ddepth) {
+/*----------------------------------------------------------------------------
+  A pseudoColor image from the RGB image *imageP.
+
+  We compute the index -- i.e. assign each color in *imageP a number.
+-----------------------------------------------------------------------------*/
+    unsigned int const maxColorCt = (1 << ddepth);
+
+    unsigned int y;
+    unsigned int colorCt;
+        /* Number of colors we've indexed so far */
+    unsigned int pixelCt[32768];
+        /* colorCt[x] is the number of pixels of color 'x' in the image,
+           where 'x' is the 15 bit RGB representation of the color.
+        */
+    unsigned int colorIndex[32768];
+        /* colorIndex[x] is the color index we assigned to the color 'x',
+           where 'x' is the 15 bit RGB representation of the color.
+        */
+    Pixel pixval;
+    unsigned char * dpixel;
+    Image * newImageP;
+    unsigned short color;  /* A color, in 15 bit RGB */
+    unsigned char * pixel;
+
+    newImageP = newRGBImage(imageP->width, imageP->height, ddepth);
+
+    findColors(imageP, pixelCt);
+
+    for (color = 0, colorCt = 0;
+         color < 32768 && colorCt <= maxColorCt;
+         ++color) {
+        if (pixelCt[color] > 0) {
+            unsigned long const red = RED_INTENSITY(color);
+            unsigned long const grn = GREEN_INTENSITY(color);
+            unsigned long const blu = BLUE_INTENSITY(color);
+
+            /* Put the color in the color map */
+            newImageP->rgb.red[colorCt] = red<<11;
+            newImageP->rgb.grn[colorCt] = grn<<11; 
+            newImageP->rgb.blu[colorCt] = blu<<11;
+
+            /* Reverse-index it */
+            colorIndex[color] = colorCt;
+
+            ++colorCt;
         }
     }    
-
-    pixel = imageP->data;
-    dpixel = newImageP->data;
+    newImageP->rgb.used = colorCt;
     
-    for (y = 0; y < imageP->height; ++y) {
+    for (y = 0, pixel  = imageP->data, dpixel = newImageP->data;
+         y < imageP->height;
+         ++y) {
+
         unsigned int x;
         for (x = 0; x < imageP->width; ++x) {
-            unsigned int const z = TRUE_TO_15BIT(memToVal(pixel, 3));
-            pixval = pixel_counts[z];
+            unsigned short const color = TRUE_TO_15BIT(memToVal(pixel, 3));
+            pixval = colorIndex[color];
             valToMem(pixval, dpixel, newImageP->pixlen);
             pixel += 3;
             dpixel += newImageP->pixlen;
         }
     }
-    newImageP->rgb.used = num_pixels;
     newImageP->rgb.compressed = 1;
 
     return newImageP;
@@ -197,7 +232,7 @@ makeUsableVisual(Image *      const origImageP,
             *newImagePP = origImageP;
             break;
         case PseudoColor:
-            *newImagePP = itrueToRGB(origImageP, ddepth);
+            *newImagePP = pseudoColorImageFromItrue(origImageP, ddepth);
             if (*newImagePP == NULL)
                 pm_error("Unable to convert for Pseudocolor.");
             break;
diff --git a/other/pamx/window.c b/other/pamx/window.c
index e2de1577..d907163b 100644
--- a/other/pamx/window.c
+++ b/other/pamx/window.c
@@ -6,6 +6,7 @@
    See COPYRIGHT file for copyright information.
 */
 
+#define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */
 #define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 #define _BSD_SOURCE    /* Make sure strcaseeq() is in nstring.h */