about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-09-15 19:18:08 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-09-15 19:18:08 +0000
commit89ee8a92e9c79a09799fc69ec8646aa50603d859 (patch)
tree1910a1dbd36d2246cb0e8515037e2a32a73f301d /lib
parented82d489966de49329ffed22acdd6a4f502e6e3a (diff)
downloadnetpbm-mirror-89ee8a92e9c79a09799fc69ec8646aa50603d859.tar.gz
netpbm-mirror-89ee8a92e9c79a09799fc69ec8646aa50603d859.tar.xz
netpbm-mirror-89ee8a92e9c79a09799fc69ec8646aa50603d859.zip
Add pnm_maketuplergbn, pnm_makerowrgbn, and pnm_makearrayrgbn
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3324 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpamn.c60
-rw-r--r--lib/pam.h12
2 files changed, 71 insertions, 1 deletions
diff --git a/lib/libpamn.c b/lib/libpamn.c
index 65c8979f..8ae57037 100644
--- a/lib/libpamn.c
+++ b/lib/libpamn.c
@@ -69,7 +69,8 @@ allocpamrown(const struct pam * const pamP,
    overflow will not occur in our calculations.  NOTE: pnm_readpaminit()
    ensures this assumption is valid.
 -----------------------------------------------------------------------------*/
-    int const bytes_per_tuple = allocationDepth(pamP) * sizeof(samplen);
+    unsigned int const bytes_per_tuple =
+        allocationDepth(pamP) * sizeof(samplen);
 
     tuplen * tuplerown;
     const char * error;
@@ -643,6 +644,63 @@ pnm_unapplyopacityrown(struct pam * const pamP,
 
 
 
+void
+pnm_maketuplergbn(const struct pam * const pamP,
+                  tuplen             const tuple) {
+
+    if (allocationDepth(pamP) < 3)
+        pm_error("allocation depth %u passed to pnm_maketuplergb().  "
+                 "Must be at least 3.", allocationDepth(pamP));
+
+    if (pamP->depth < 3)
+        tuple[2] = tuple[1] = tuple[0];
+}
+
+
+
+void
+pnm_makerowrgbn(const struct pam * const pamP,
+                tuplen *           const tuplerow) {
+
+    if (pamP->depth < 3) {
+        unsigned int col;
+
+        if (allocationDepth(pamP) < 3)
+            pm_error("allocation depth %u passed to pnm_makerowrgb().  "
+                     "Must be at least 3.", allocationDepth(pamP));
+
+        for (col = 0; col < pamP->width; ++col) {
+            tuplen const thisTuple = tuplerow[col];
+            thisTuple[2] = thisTuple[1] = thisTuple[0];
+        }
+    }
+}
+
+
+
+void
+pnm_makearrayrgbn(const struct pam * const pamP,
+                  tuplen **          const tuples) {
+
+    if (pamP->depth < 3) {
+        unsigned int row;
+        if (allocationDepth(pamP) < 3)
+            pm_error("allocation depth %u passed to pnm_makearrayrgb().  "
+                     "Must be at least 3.", allocationDepth(pamP));
+
+        for (row = 0; row < pamP->height; ++row) {
+            tuplen * const tuplerow = tuples[row];
+            unsigned int col;
+            for (col = 0; col < pamP->width; ++col) {
+                tuplen const thisTuple = tuplerow[col];
+                thisTuple[2] = thisTuple[1] = thisTuple[0];
+            }
+        }
+    }
+}
+
+
+
 static void
 fillInMap(pnm_transformMap const ungammaTransformMap,
           sample           const maxval,
diff --git a/lib/pam.h b/lib/pam.h
index c2cfb4c7..74b20f46 100644
--- a/lib/pam.h
+++ b/lib/pam.h
@@ -482,6 +482,18 @@ void
 pnm_unapplyopacityrown(struct pam * const pamP,
                        tuplen *     const tuplenrow);
 
+void
+pnm_maketuplergbn(const struct pam * const pamP,
+                  tuplen             const tuple);
+
+void
+pnm_makerowrgbn(const struct pam * const pamP,
+                tuplen *           const tuplerow);
+
+void
+pnm_makearrayrgbn(const struct pam * const pamP,
+                  tuplen **          const tuples);
+
 pnm_transformMap *
 pnm_creategammatransform(const struct pam * const pamP);