about summary refs log tree commit diff
path: root/other
diff options
context:
space:
mode:
Diffstat (limited to 'other')
-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.c50
-rw-r--r--other/ppmsvgalib.c2
5 files changed, 27 insertions, 173 deletions
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 9c9689ac..32a48c5a 100644
--- a/other/pamx/image.h
+++ b/other/pamx/image.h
@@ -82,9 +82,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 17980643..c6503d5e 100644
--- a/other/pamx/pamx.c
+++ b/other/pamx/pamx.c
@@ -175,35 +175,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);
+        }
     }
 }
 
@@ -218,7 +215,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));
 
@@ -238,12 +235,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;
         }
     }
diff --git a/other/ppmsvgalib.c b/other/ppmsvgalib.c
index 67cc2b1a..f607d047 100644
--- a/other/ppmsvgalib.c
+++ b/other/ppmsvgalib.c
@@ -249,7 +249,7 @@ main(int argc, char *argv[]) {
     int format;
     int rc;
 
-    ppm_init( &argc, argv );
+    ppm_init(&argc, argv);
 
     rc = vga_init();         /* Initialize. */
     if (rc < 0)