about summary refs log tree commit diff
path: root/other
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-20 23:57:15 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-20 23:57:15 +0000
commit5ee8bda85276139b6d97ce082c37bba329bef353 (patch)
tree004c96e3c9f773ba9b2e8d9466064d6cbbdf844d /other
parent637c9a13c92245741684d11f2d8c2258e04925ab (diff)
downloadnetpbm-mirror-5ee8bda85276139b6d97ce082c37bba329bef353.tar.gz
netpbm-mirror-5ee8bda85276139b6d97ce082c37bba329bef353.tar.xz
netpbm-mirror-5ee8bda85276139b6d97ce082c37bba329bef353.zip
Add some more code for more that two operands; not functional yet
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1223 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other')
-rw-r--r--other/pamarith.c89
1 files changed, 63 insertions, 26 deletions
diff --git a/other/pamarith.c b/other/pamarith.c
index d8ea19fa..dcca0a6e 100644
--- a/other/pamarith.c
+++ b/other/pamarith.c
@@ -400,48 +400,66 @@ doNormalizedArith(struct pam *  const inpam1P,
                   struct pam *  const outpamP,
                   enum function const function) {
 
+    /* Some of the logic in this subroutine is designed for future
+       expansion into non-dyadic computations.  But for now, all
+       computations have exactly two operands.
+    */
     unsigned int const operandCt = 2;
 
-    tuplen * tuplerown1;
-    tuplen * tuplerown2;
+    tuplen ** tuplerown;
+        /* tuplerown[0] is the current row in the first operand image */
+
     tuplen * tuplerownOut;
     unsigned int row;
     samplen * operands;
+        /* operand[0] is the first operand in the current one-sample
+           computation
+        */
+    unsigned int * plane;
+        /* plane[0] is the plane number in the first operand image for 
+           the current one-sample computation.  plane[1] is the plane number
+           in the second operand image, etc.
+         */
 
     MALLOCARRAY_NOFAIL(operands, operandCt);
+    MALLOCARRAY_NOFAIL(plane, operandCt);
+    MALLOCARRAY_NOFAIL(tuplerown, operandCt);
 
-    tuplerown1   = pnm_allocpamrown(inpam1P);
-    tuplerown2   = pnm_allocpamrown(inpam2P);
+    tuplerown[0] = pnm_allocpamrown(inpam1P);
+    tuplerown[1] = pnm_allocpamrown(inpam2P);
     tuplerownOut = pnm_allocpamrown(outpamP);
 
     for (row = 0; row < outpamP->height; ++row) {
         unsigned int col;
-        pnm_readpamrown(inpam1P, tuplerown1);
-        pnm_readpamrown(inpam2P, tuplerown2);
+        pnm_readpamrown(inpam1P, tuplerown[0]);
+        pnm_readpamrown(inpam2P, tuplerown[1]);
         
         for (col = 0; col < outpamP->width; ++col) {
             unsigned int outplane;
             
             for (outplane = 0; outplane < outpamP->depth; ++outplane) {
-                unsigned int const plane1 = MIN(outplane, inpam1P->depth-1);
-                unsigned int const plane2 = MIN(outplane, inpam2P->depth-1);
+                unsigned int op;
 
-                operands[0] = tuplerown1[col][plane1];
-                operands[1] = tuplerown2[col][plane2];
+                plane[0] = MIN(outplane, inpam1P->depth-1);
+                plane[1] = MIN(outplane, inpam2P->depth-1);
+
+                for (op = 0; op < operandCt; ++op)
+                    operands[op] = tuplerown[op][col][plane[op]];
 
                 tuplerownOut[col][outplane] = 
                     applyNormalizedFunction(function, operands, operandCt); 
                 assert(tuplerownOut[col][outplane] >= 0.);
                 assert(tuplerownOut[col][outplane] <= 1.);
-
             }
         }
         pnm_writepamrown(outpamP, tuplerownOut);
     }
 
-    pnm_freepamrown(tuplerown1);
-    pnm_freepamrown(tuplerown2);
+    pnm_freepamrown(tuplerown[0]);
+    pnm_freepamrown(tuplerown[1]);
+    free(tuplerown);
     pnm_freepamrown(tuplerownOut);
+    free(plane);
     free(operands);
 }
 
@@ -701,14 +719,28 @@ doUnNormalizedArith(struct pam *  const inpam1P,
    maxval to do the computation without time-consuming normalization of
    sample values.
 -----------------------------------------------------------------------------*/
+    /* Some of the logic in this subroutine is designed for future
+       expansion into non-dyadic computations.  But for now, all
+       computations have exactly two operands.
+    */
     unsigned int const operandCt = 2;
+
     sample const maxval = outpamP->maxval;
 
-    tuple * tuplerow1;
-    tuple * tuplerow2;
+    tuple ** tuplerow;
+        /* tuplerow[0] is the current row in the first operand image */
+
     tuple * tuplerowOut;
     unsigned int row;
     sample * operands;
+        /* operand[0] is the first operand in the current one-sample
+           computation
+        */
+    unsigned int * plane;
+        /* plane[0] is the plane number in the first operand image for 
+           the current one-sample computation.  plane[1] is the plane number
+           in the second operand image, etc.
+         */
 
     /* Input conditions: */
     assert(inpam1P->maxval == maxval);
@@ -716,25 +748,29 @@ doUnNormalizedArith(struct pam *  const inpam1P,
     assert(outpamP->maxval == maxval);
 
     MALLOCARRAY_NOFAIL(operands, operandCt);
+    MALLOCARRAY_NOFAIL(plane, operandCt);
+    MALLOCARRAY_NOFAIL(tuplerow, operandCt);
 
-    tuplerow1   = pnm_allocpamrow(inpam1P);
-    tuplerow2   = pnm_allocpamrow(inpam2P);
+    tuplerow[0]   = pnm_allocpamrow(inpam1P);
+    tuplerow[1]   = pnm_allocpamrow(inpam2P);
     tuplerowOut = pnm_allocpamrow(outpamP);
 
     for (row = 0; row < outpamP->height; ++row) {
         unsigned int col;
-        pnm_readpamrow(inpam1P, tuplerow1);
-        pnm_readpamrow(inpam2P, tuplerow2);
+        pnm_readpamrow(inpam1P, tuplerow[0]);
+        pnm_readpamrow(inpam2P, tuplerow[1]);
         
         for (col = 0; col < outpamP->width; ++col) {
             unsigned int outplane;
             
             for (outplane = 0; outplane < outpamP->depth; ++outplane) {
-                unsigned int const plane1 = MIN(outplane, inpam1P->depth-1);
-                unsigned int const plane2 = MIN(outplane, inpam2P->depth-1);
+                unsigned int op;
+
+                plane[0] = MIN(outplane, inpam1P->depth-1);
+                plane[1] = MIN(outplane, inpam2P->depth-1);
 
-                operands[0] = tuplerow1[col][plane1];
-                operands[1] = tuplerow2[col][plane2];
+                for (op = 0; op < operandCt; ++op)
+                    operands[op] = tuplerow[op][col][plane[op]];
 
                 tuplerowOut[col][outplane] = 
                     applyUnNormalizedFunction(function, operands, operandCt,
@@ -747,10 +783,11 @@ doUnNormalizedArith(struct pam *  const inpam1P,
         pnm_writepamrow(outpamP, tuplerowOut);
     }
 
-    pnm_freepamrow(tuplerow1);
-    pnm_freepamrow(tuplerow2);
+    pnm_freepamrow(tuplerow[0]);
+    pnm_freepamrow(tuplerow[1]);
+    free(tuplerow);
     pnm_freepamrow(tuplerowOut);
-
+    free(plane);
     free(operands);
 }