about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-12-26 18:09:17 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-12-26 18:09:17 +0000
commit02a71abde62302150972eda0be074c2a21f6579a (patch)
treee5041fd4c9597efaec4e22724f79601170c04fd5 /generator
parent0a75e38834b1a121fd723185bdfad0d6850475a2 (diff)
downloadnetpbm-mirror-02a71abde62302150972eda0be074c2a21f6579a.tar.gz
netpbm-mirror-02a71abde62302150972eda0be074c2a21f6579a.tar.xz
netpbm-mirror-02a71abde62302150972eda0be074c2a21f6579a.zip
Make -smoothing effective even without -texfile
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1818 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pamstereogram.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/generator/pamstereogram.c b/generator/pamstereogram.c
index ae98bdae..c119ff5a 100644
--- a/generator/pamstereogram.c
+++ b/generator/pamstereogram.c
@@ -13,7 +13,7 @@
  *
  * ----------------------------------------------------------------------
  *
- * Copyright (C) 2006, 2010 Scott Pakin <scott+pbm@pakin.org>
+ * Copyright (C) 2006-2012 Scott Pakin <scott+pbm@pakin.org>
  *
  * All rights reserved.
  *
@@ -252,10 +252,6 @@ parseCommandLine(int                  argc,
         pm_message("warning: -bgcolor has no effect "
                    "except in conjunction with -texfile");
 
-    if (smoothingSpec && !texfileSpec)
-        pm_message("warning: -smoothing has no effect "
-                   "except in conjunction with -texfile");
-
     if (!guidesizeSpec)
         cmdlineP->guidesize = 0;
 
@@ -774,19 +770,21 @@ drawguides(int                const guidesize,
 
 
 
-/* Do the bulk of the work.  See the paper cited above for code
- * comments.  All I (Scott) did was transcribe the code and make
- * minimal changes for Netpbm.  And some style changes by Bryan to
- * match Netpbm style.
- */
 static void
 makeStereoRow(const struct pam * const inPamP,
               tuple *            const inRow,
               int *              const same,
               double             const depthOfField,
               double             const eyesep,
-              unsigned int       const dpi) {
+              unsigned int       const dpi,
+              unsigned int       const optWidth,
+              unsigned int       const smoothing) {
 
+/* Do the bulk of the work.  See the paper cited above for code
+ * comments.  All I (Scott) did was transcribe the code and make
+ * minimal changes for Netpbm.  And some style changes by Bryan to
+ * match Netpbm style.
+ */ 
 #define Z(X) (inRow[X][0]/(double)inPamP->maxval)
 
     int const width       = inPamP->width;
@@ -837,6 +835,21 @@ makeStereoRow(const struct pam * const inPamP,
             }
         }
     }
+
+    /* If smoothing is enabled, replace each non-duplicate pixel with
+       the pixel adjacent to its right neighbor. */
+    if (smoothing > 0) {
+        int const baseCol = width - optWidth - 1;
+
+        int col;
+
+        for (col = width - 1; col >= 0; --col)
+            same[col] = same[same[col]];
+        for (col = baseCol; col >= 0; --col) {
+            if (same[col] == col)
+                same[col] = same[col+1] - 1;
+        }
+    }
 }
 
 
@@ -1117,7 +1130,9 @@ makeImageRows(const struct pam * const inPamP,
               double             const eyesep,
               unsigned int       const dpi,
               bool               const crossEyed,
-              bool               const makeMask) {
+              bool               const makeMask,
+              unsigned int       const magnifypat,
+              unsigned int       const smoothing) {
 
     tuple * inRow;     /* One row of pixels read from the height-map file */
     tuple * outRow;    /* One row of pixels to write to the height-map file */
@@ -1145,10 +1160,6 @@ makeImageRows(const struct pam * const inPamP,
         pm_error("Unable to allocate space for \"tuplesPerCol\" array.");
     rowBuffer = pnm_allocpamrow(&outputGeneratorP->pam);
 
-    /* See the paper cited above for code comments.  All I (Scott) did was
-     * transcribe the code and make minimal changes for Netpbm.  And some
-     * style changes by Bryan to match Netpbm style.
-     */
     for (row = 0; row < inPamP->height; ++row) {
         pnm_readpamrow(inPamP, inRow);
         if (crossEyed)
@@ -1158,7 +1169,9 @@ makeImageRows(const struct pam * const inPamP,
             invertHeightRow(inPamP, inRow);
 
         /* Determine color constraints. */
-        makeStereoRow(inPamP, inRow, same, depthOfField, eyesep, dpi);
+        makeStereoRow(inPamP, inRow, same, depthOfField, eyesep, dpi,
+                      round2int(eyesep * dpi)/(magnifypat * 2),
+                      smoothing);
 
         if (makeMask)
             makeMaskRow(&outputGeneratorP->pam, same, outRow);
@@ -1213,7 +1226,8 @@ produceStereogram(FILE *             const ifP,
 
     makeImageRows(&inPam, outputGeneratorP,
                   cmdline.depth, cmdline.eyesep, cmdline.dpi,
-                  cmdline.crosseyed, cmdline.makemask);
+                  cmdline.crosseyed, cmdline.makemask, cmdline.magnifypat,
+                  cmdline.smoothing);
 
     /* Draw guide boxes at the bottom, if desired. */
     if (cmdline.guidesize > 0)
@@ -1282,3 +1296,6 @@ main(int argc, const char *argv[]) {
 
     return 0;
 }
+
+
+