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/Makefile7
-rw-r--r--other/pamx/Makefile251
-rw-r--r--other/pamx/image.c92
-rw-r--r--other/pamx/image.h5
-rw-r--r--other/pamx/pamx.c53
-rw-r--r--other/pamx/window.c4
6 files changed, 35 insertions, 177 deletions
diff --git a/other/pamx/Makefile b/other/pamx/Makefile
index baff506d..a40ea3a6 100644
--- a/other/pamx/Makefile
+++ b/other/pamx/Makefile
@@ -5,11 +5,12 @@ endif
 SUBDIR = other/pamx
 VPATH=.:$(SRCDIR)/$(SUBDIR)
 
-include $(BUILDDIR)/Makefile.config
+include $(BUILDDIR)/config.mk
 
+EXTERN_INCLUDE =
 ifneq ($(X11LIB),NONE)
   ifneq ($(X11HDR_DIR),)
-    INCLUDES += -I$(X11HDR_DIR)
+    EXTERN_INCLUDES += -I$(X11HDR_DIR)
   endif
 endif
 
@@ -36,7 +37,7 @@ MERGEBINARIES = $(BINARIES)
 
 all: $(BINARIES)
 
-include $(SRCDIR)/Makefile.common
+include $(SRCDIR)/common.mk
 
 pamx: $(PAMX_OBJECTS) $(NETPBMLIB) $(LIBOPT)
 	$(LD) -o $@ $(PAMX_OBJECTS) \
diff --git a/other/pamx/Makefile2 b/other/pamx/Makefile2
deleted file mode 100644
index f69e103f..00000000
--- a/other/pamx/Makefile2
+++ /dev/null
@@ -1,51 +0,0 @@
-# C compiler to use, including special flags.
-CC=gcc
-
-WARNINGS = -Wall -Wmissing-declarations -Wundef -Wimplicit -Wwrite-strings \
-	-Winline \
-	-Wstrict-prototypes -Wmissing-prototypes \
-	-Werror
-
-CFLAGS = $(WARNINGS) -fno-common -g
-INCLUDES = -I /home/bryanh/netpbm/other/importinc
-
-# X11 include and library information.
-X11_LIB_DIR=-L/subsysx/X11R6/lib
-X11_LIB_NAME=-lX11
-NETPBMLIB = /home/bryanh/netpbm/lib/libnetpbm.so
-
-LIBS=$(X11_LIB_DIR) $(X11_LIB_NAME) -lm
-
-default: pamx
-
-# files for the image library
-IMAGE_SRCS= image.c
-IMAGE_OBJS= ${IMAGE_SRCS:.c=.o}
-
-# files for the image processing library
-PROCESS_HDRS=
-# no image processing.
-PROCESS_SRCS= fill.c
-PROCESS_OBJS= ${PROCESS_SRCS:.c=.o}
-
-X_SRCS= send.c window.c pamx.c
-X_OBJS= ${X_SRCS:.c=.o}
-
-OBJS= $(IMAGE_OBJS) $(PROCESS_OBJS) $(X_OBJS) $(NETPBMLIB)
-
-.c.o: $*.c
-	$(CC) -c $(CFLAGS) $(INCLUDES) $*.c $(CADD)
-
-pamx: $(OBJS) $(OPTIONAL_LIBS)
-	$(CC) -o $@ $(OBJS) $(OPTIONAL_LIBS) $(LIBS)
-
-clean::
-	rm -f *.o pamx
-
-dep:
-	$(CC) -MM -MG $(INCLUDES) *.c >Makefile.depend
-
-include Makefile.depend
-
-Makefile.depend:
-	>$@
diff --git a/other/pamx/image.c b/other/pamx/image.c
index 892a9768..0e719438 100644
--- a/other/pamx/image.c
+++ b/other/pamx/image.c
@@ -237,95 +237,3 @@ freeImage(Image * const imageP) {
 
     free(imageP);
 }
-
-
-
-
-static void
-fillRow1(struct pam *     const pamP,
-         tuple *          const tuplerow,
-         unsigned char ** const pP) {
-
-    unsigned int col;
-    
-    for (col = 0; col < pamP->width; ++col) {
-        unsigned int plane;
-        for (plane = 0; plane < pamP->depth; ++plane)
-            *(*pP)++ =
-                pnm_scalesample(tuplerow[col][0], pamP->maxval, 255);
-    }
-}
-
-
-
-static void
-fillRow3(struct pam *     const pamP,
-         tuple *          const tuplerow,
-         unsigned char ** const pP) {
-
-    unsigned int col;
-    
-    for (col = 0; col < pamP->width; ++col) {
-        unsigned int plane;
-        for (plane = 0; plane < pamP->depth; ++plane)
-            *(*pP)++ =
-                pnm_scalesample(tuplerow[col][plane], pamP->maxval, 255);
-    }
-}
-
-
-
-Image *
-pbmLoad(const char * const fullname,
-        const char * const name,
-        bool         const verbose) {
-
-    FILE * ifP;
-    struct pam pam;
-    Image * imageP;
-    unsigned int row;
-    const char * filename;
-    tuple * tuplerow;
-    unsigned char * p;
-    enum {DEPTH_1, DEPTH_3} depth;
-
-    if (STREQ(fullname, "stdin"))
-        filename = "-";
-    else
-        filename = fullname;
-
-    ifP = pm_openr(filename);
-
-    pnm_readpaminit(ifP, &pam, PAM_STRUCT_SIZE(tuple_type));
-
-    if (strncmp(pam.tuple_type, "RGB", 3) == 0) {
-        depth = DEPTH_3;
-        if (pam.depth < 3)
-            pm_error("Invalid depth %u for RGB tuple type.", pam.depth);
-    } else
-        depth = DEPTH_1;
-
-    imageP = newTrueImage(pam.width, pam.height);
-
-    p = &imageP->data[0];  /* initial value */
-
-    tuplerow = pnm_allocpamrow(&pam);
-
-    for (row = 0; row < pam.height; ++row) {
-        pnm_readpamrow(&pam, tuplerow);
-        
-        switch (depth) {
-        case DEPTH_3:
-            fillRow3(&pam, tuplerow, &p);
-            break;
-        case DEPTH_1:
-            fillRow1(&pam, tuplerow, &p);
-            break;
-        }
-    }
-    pnm_freepamrow(tuplerow);
-    
-    pm_close(ifP);
-
-    return imageP;
-}
diff --git a/other/pamx/image.h b/other/pamx/image.h
index ea597b2e..5b352a28 100644
--- a/other/pamx/image.h
+++ b/other/pamx/image.h
@@ -81,9 +81,4 @@ colorIntensity(unsigned int const red,
             BlueIntensity[blu / 256]);
 }
 
-Image *
-pbmLoad(const char * const fullname,
-        const char * const name,
-        bool         const verbose);
-
 #endif
diff --git a/other/pamx/pamx.c b/other/pamx/pamx.c
index 5fd525b7..130cc64c 100644
--- a/other/pamx/pamx.c
+++ b/other/pamx/pamx.c
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include "pm_c_util.h"
 #include "pam.h"
 #include "shhopt.h"
 #include "mallocvar.h"
@@ -176,35 +177,32 @@ errorHandler(Display *     const disp,
 
 
 
-static void
-fillRow1(struct pam *     const pamP,
-         tuple *          const tuplerow,
-         unsigned char ** const pP) {
-
-    unsigned int col;
-    
-    for (col = 0; col < pamP->width; ++col) {
-        unsigned int plane;
-        for (plane = 0; plane < 3; ++plane)
-            *(*pP)++ =
-                pnm_scalesample(tuplerow[col][0], pamP->maxval, 255);
-    }
-}
-
-
+enum usableDepth {DEPTH_1, DEPTH_3};
 
 static void
-fillRow3(struct pam *     const pamP,
-         tuple *          const tuplerow,
-         unsigned char ** const pP) {
+fillRow(struct pam *     const pamP,
+        tuple *          const tuplerow,
+        enum usableDepth const depth,
+        unsigned char ** const pP) {
+/*----------------------------------------------------------------------------
+   Add one row to the 24-bit truecolor image data at *pP, and advance
+   *pP just past that row.
 
+   Use either the first plane or the first 3 planes of tuplerow[]
+   for its contents, according to 'depth'.
+-----------------------------------------------------------------------------*/
     unsigned int col;
     
     for (col = 0; col < pamP->width; ++col) {
+        /* Truecolor image data has 3 bytes per pixel, one each for
+           red, green, and blue.
+        */
         unsigned int plane;
-        for (plane = 0; plane < pamP->depth; ++plane)
+        for (plane = 0; plane < 3; ++plane) {
+            unsigned int const tuplePlane = depth == DEPTH_3 ? plane : 0;
             *(*pP)++ =
-                pnm_scalesample(tuplerow[col][plane], pamP->maxval, 255);
+                pnm_scalesample(tuplerow[col][tuplePlane], pamP->maxval, 255);
+        }
     }
 }
 
@@ -219,7 +217,7 @@ loadPamImage(FILE *   const ifP,
     unsigned int row;
     tuple * tuplerow;
     unsigned char * p;
-    enum {DEPTH_1, DEPTH_3} depth;
+    enum usableDepth depth;
 
     pnm_readpaminit(ifP, &pam, PAM_STRUCT_SIZE(tuple_type));
 
@@ -239,12 +237,17 @@ loadPamImage(FILE *   const ifP,
     for (row = 0; row < pam.height; ++row) {
         pnm_readpamrow(&pam, tuplerow);
         
+        /* This semantically wasteful code allows a dumb compiler
+           optimizer to recognize that the depth is constant and
+           therefore not generate code that checks the depth every
+           time it processes a sample.
+        */
         switch (depth) {
         case DEPTH_3:
-            fillRow3(&pam, tuplerow, &p);
+            fillRow(&pam, tuplerow, DEPTH_3, &p);
             break;
         case DEPTH_1:
-            fillRow1(&pam, tuplerow, &p);
+            fillRow(&pam, tuplerow, DEPTH_1, &p);
             break;
         }
     }
@@ -297,7 +300,7 @@ determineTitle(struct cmdlineInfo const cmdline,
     if (cmdline.title)
         title = strdup(cmdline.title);
     else {
-        if (STREQ(cmdline.inputFileName, "-"))
+        if (streq(cmdline.inputFileName, "-"))
             title = NULL;
         else {
             title = pm_basename(cmdline.inputFileName);
diff --git a/other/pamx/window.c b/other/pamx/window.c
index 1a6e510b..2eb48241 100644
--- a/other/pamx/window.c
+++ b/other/pamx/window.c
@@ -6,6 +6,8 @@
    See COPYRIGHT file for copyright information.
 */
 
+#define _BSD_SOURCE    /* Make sure strcaseeq() is in nstring.h */
+
 #include <assert.h>
 #include <ctype.h>
 #include <signal.h>
@@ -555,7 +557,7 @@ visualClassFromName(const char * const name) {
     bool found;
     
     for (a = 0, found = FALSE; VisualClassName[a].name; ++a) {
-        if (STRCASEEQ(VisualClassName[a].name, name)) {
+        if (strcaseeq(VisualClassName[a].name, name)) {
             /* Check for uniqueness.  We special-case StaticGray
                because we have two spellings but they are unique if
                we find either.