about summary refs log tree commit diff
path: root/editor
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-07-27 20:36:04 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-07-27 20:36:04 +0000
commit1f0f4a30e3b27653821ffa4347694619320dce6a (patch)
tree87de9e1a8ccf7eb190a2b4f641dada571eb9867b /editor
parent39a3b6d0fd7821eef8ec9392bdbfdb83bb356d1e (diff)
downloadnetpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.tar.gz
netpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.tar.xz
netpbm-mirror-1f0f4a30e3b27653821ffa4347694619320dce6a.zip
Release 10.35.48
git-svn-id: http://svn.code.sf.net/p/netpbm/code/stable@690 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r--editor/pamperspective.c112
1 files changed, 74 insertions, 38 deletions
diff --git a/editor/pamperspective.c b/editor/pamperspective.c
index d460ffcf..a655443e 100644
--- a/editor/pamperspective.c
+++ b/editor/pamperspective.c
@@ -1083,46 +1083,82 @@ static int clean_y (int const y,  const struct pam *const outpam)
   return MIN(MAX(0, y), outpam->height-1);
 }
 
-static void init_buffer (buffer *const b, const world_data *const world,
-                         const option *const options,
-                         const struct pam *const inpam,
-                         const struct pam *const outpam)
-{
-  int yul, yur, yll, ylr, y_min;
-  int i, num_rows;
-
-  yul = outpixel_to_iny (0,0,world);
-  yur = outpixel_to_iny (outpam->width-1,0,world);
-  yll = outpixel_to_iny (0,outpam->height-1,world);
-  ylr = outpixel_to_iny (outpam->width-1,outpam->height-1,world);
-
-  y_min = MIN (MIN (yul,yur), MIN (yll,ylr));
-  num_rows = MAX (MAX (diff (yul, yur),
-                       diff (yll, ylr)),
-                  MAX (diff (clean_y(yul,outpam), clean_y(y_min,outpam)),
-                       diff (clean_y(yur,outpam), clean_y(y_min,outpam))))
-    + 2;
-  switch (options->enums[3]) {  /* --interpolation */
-  case interp_nearest:
-    break;
-  case interp_linear:
-    num_rows += 1;
-    break;
-  };
-  if (num_rows > inpam->height)
-    num_rows = inpam->height;
-
-  b->num_rows = num_rows;
-  MALLOCARRAY_SAFE (b->rows, num_rows);
-  for (i=0; i<num_rows; i++) {
-    b->rows[i] = pnm_allocpamrow (inpam);
-    pnm_readpamrow (inpam, b->rows[i]);
-  };
-  b->last_physical = num_rows-1;
-  b->last_logical = num_rows-1;
-  b->inpam = inpam;
+static unsigned int
+distance(unsigned int const a,
+         unsigned int const b) {
+
+    return a > b ? a - b : b - a;
+}
+
+
+
+static int
+boundedRow(int                const unboundedRow,
+           const struct pam * const outpamP) {
+
+    return MIN(MAX(0, unboundedRow), outpamP->height-1);
+}
+
+
+
+static unsigned int
+windowHeight(const world_data * const worldP,
+             const struct pam * const inpamP,
+             const struct pam * const outpamP,
+             const option *     const optionsP) {
+
+    unsigned int outRow;
+    unsigned int maxRowWindowHeight;
+    
+    maxRowWindowHeight = 1;  /* initial value */
+
+    for (outRow = 0; outRow < outpamP->height; ++outRow) {
+        unsigned int const leftCol = 0;
+        unsigned int const rghtCol = outpamP->width - 1;
+        unsigned int const leftInRow =
+            boundedRow(outpixel_to_iny(leftCol, outRow, worldP), outpamP);
+        unsigned int const rghtInRow =
+            boundedRow(outpixel_to_iny(rghtCol, outRow, worldP), outpamP);
+        
+        unsigned int const rowWindowHeight = distance(leftInRow, rghtInRow);
+
+        maxRowWindowHeight = MAX(maxRowWindowHeight, rowWindowHeight);
+    }
+    
+    /* We add 2 for rounding */
+
+    return maxRowWindowHeight + 2;
+}
+
+
+
+static void
+init_buffer(buffer *           const bufferP,
+            const world_data * const worldP,
+            const option *     const optionsP,
+            const struct pam * const inpamP,
+            const struct pam * const outpamP) {
+
+    unsigned int const num_rows =
+        windowHeight(worldP, inpamP, outpamP, optionsP);
+
+    MALLOCARRAY_SAFE(bufferP->rows, num_rows);
+    bufferP->num_rows = num_rows;
+    {
+        unsigned int row;
+        for (row = 0; row < num_rows; ++row) {
+            bufferP->rows[row] = pnm_allocpamrow(inpamP);
+            pnm_readpamrow(inpamP, bufferP->rows[row]);
+        }
+    }
+    bufferP->last_logical = num_rows-1;
+    bufferP->last_physical = num_rows-1;
+    bufferP->inpam = inpamP;
 }
 
+
+
+
 static tuple* read_buffer (buffer *const b, int const logical_y)
 {
   int y;