about summary refs log tree commit diff
path: root/editor/ppm3d.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-02-18 00:45:06 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-02-18 00:45:06 +0000
commit73109d82230bf5768d6aa7b27cd565914dbe2a1e (patch)
tree543ccb0afff26e9cc48ff2222bb2c103a23c97dd /editor/ppm3d.c
parent24fc4c22a6f8748ea9b573229389cc81a5385802 (diff)
downloadnetpbm-mirror-73109d82230bf5768d6aa7b27cd565914dbe2a1e.tar.gz
netpbm-mirror-73109d82230bf5768d6aa7b27cd565914dbe2a1e.tar.xz
netpbm-mirror-73109d82230bf5768d6aa7b27cd565914dbe2a1e.zip
Add -color to ppm3d
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@225 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/ppm3d.c')
-rw-r--r--editor/ppm3d.c89
1 files changed, 62 insertions, 27 deletions
diff --git a/editor/ppm3d.c b/editor/ppm3d.c
index fd9a10dd..79ece022 100644
--- a/editor/ppm3d.c
+++ b/editor/ppm3d.c
@@ -109,17 +109,15 @@ computeGrayscaleRow(const pixel * const inputRow,
 
 
 static void
-compute3dRow(pixel *      const lPixelrow,
-             gray *       const lGrayrow,
-             pixel *      const rPixelrow,
-             gray *       const rGrayrow,
-             pixel *      const pixelrow,
-             unsigned int const cols,
-             unsigned int const offset) {
+compute3dRowMono(gray *       const lGrayrow,
+                 gray *       const rGrayrow,
+                 pixel *      const pixelrow,
+                 unsigned int const cols,
+                 unsigned int const offset) {
     
     unsigned int col;
-    gray * lgP;
-    gray * rgP;
+    gray *  lgP;
+    gray *  rgP;
     pixel * pP;
 
     assert(offset <= cols);
@@ -131,22 +129,16 @@ compute3dRow(pixel *      const lPixelrow,
         if (col < offset/2)
             ++lgP;
         else if (col >= offset/2 && col < offset) {
-            pixval const blu = (float) *lgP;
-            pixval const red = 0;
-            PPM_ASSIGN(*pP, red, blu, blu);
+            PPM_ASSIGN(*pP, 0, *lgP, *lgP);
             ++lgP;
             ++pP;
         } else if (col >= offset && col < cols) {
-            pixval const red = (float) *rgP;
-            pixval const blu = (float) *lgP;
-            PPM_ASSIGN(*pP, red, blu, blu);
+            PPM_ASSIGN(*pP, *rgP, *lgP, *lgP);
             ++lgP;
             ++rgP;
             ++pP;
         } else if (col >= cols && col < cols + offset/2) {
-            pixval const blu = 0;
-            pixval const red = (float) *rgP;
-            PPM_ASSIGN(*pP, red, blu, blu);
+            PPM_ASSIGN(*pP, *rgP, 0, 0);
             ++rgP;
             ++pP;
         } else
@@ -157,6 +149,46 @@ compute3dRow(pixel *      const lPixelrow,
 
 
 static void
+compute3dRowColor(pixel *      const lPixelrow,
+                  pixel *      const rPixelrow,
+                  pixel *      const pixelrow,
+                  unsigned int const cols,
+                  unsigned int const offset) {
+    
+    unsigned int col;
+    pixel * lP;
+    pixel * rP;
+    pixel * pP;
+
+    assert(offset <= cols);
+
+    for (col = 0, pP = pixelrow, lP = lPixelrow, rP = rPixelrow;
+         col < cols + offset;
+         ++col) {
+            
+        if (col < offset/2)
+            ++lP;
+        else if (col >= offset/2 && col < offset) {
+            PPM_ASSIGN(*pP, 0, PPM_GETG(*lP), PPM_GETB(*lP));
+            ++lP;
+            ++pP;
+        } else if (col >= offset && col < cols) {
+            PPM_ASSIGN(*pP, PPM_GETR(*rP), PPM_GETG(*lP), PPM_GETB(*lP));
+            ++lP;
+            ++rP;
+            ++pP;
+        } else if (col >= cols && col < cols + offset/2) {
+            PPM_ASSIGN(*pP, PPM_GETR(*rP), 0, 0);
+            ++rP;
+            ++pP;
+        } else
+            ++rP;
+    }
+}    
+
+
+
+static void
 write3dRaster(FILE *       const ofP,
               FILE *       const lIfP,
               FILE *       const rIfP,
@@ -165,21 +197,22 @@ write3dRaster(FILE *       const ofP,
               pixval       const maxval,
               int          const lFormat,
               int          const rFormat,
-              unsigned int const offset) {
+              unsigned int const offset,
+              bool         const color) {
 
     pixel * lPixelrow;
-    gray * lGrayrow;
+    gray *  lGrayrow;
     pixel * rPixelrow;
-    gray * rGrayrow;
+    gray *  rGrayrow;
     pixel * pixelrow;
 
     unsigned int row;
 
     lPixelrow = ppm_allocrow (cols);
-    lGrayrow = pgm_allocrow (cols);
+    lGrayrow  = pgm_allocrow (cols);
     rPixelrow = ppm_allocrow (cols);
-    rGrayrow = pgm_allocrow (cols);
-    pixelrow = ppm_allocrow (cols);
+    rGrayrow  = pgm_allocrow (cols);
+    pixelrow  = ppm_allocrow (cols);
 
     for (row = 0; row < rows; ++row) {
         ppm_readppmrow(lIfP, lPixelrow, cols, maxval, lFormat);
@@ -188,8 +221,10 @@ write3dRaster(FILE *       const ofP,
         computeGrayscaleRow(lPixelrow, lGrayrow, maxval, cols);
         computeGrayscaleRow(rPixelrow, rGrayrow, maxval, cols);
 
-        compute3dRow(lPixelrow, lGrayrow, rPixelrow, rGrayrow,
-                     pixelrow, cols, offset);
+        if (color)
+            compute3dRowColor(lPixelrow, rPixelrow, pixelrow, cols, offset);
+        else
+            compute3dRowMono(lGrayrow, rGrayrow, pixelrow, cols, offset);
 
         ppm_writeppmrow(ofP, pixelrow, cols, maxval, 0);
     }
@@ -247,7 +282,7 @@ main(int argc, char *argv[]) {
     ppm_writeppminit(stdout, cols, rows, maxval, 0);
 
     write3dRaster(stdout, lIfP, rIfP, cols, rows, maxval,
-                  lFormat, rFormat, cmdline.offset);
+                  lFormat, rFormat, cmdline.offset, cmdline.color);
 
     pm_close(lIfP);
     pm_close(rIfP);