about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-12-24 18:19:22 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-12-24 18:19:22 +0000
commit958d2b758ce55a01af8f926c5a6c450ba2620805 (patch)
tree294e5be056d4ba9a0e9f6e55bcee84583fd213c3
parent1dcdceadbc56a51c209628498d0edcf62c7fdce8 (diff)
downloadnetpbm-mirror-958d2b758ce55a01af8f926c5a6c450ba2620805.tar.gz
netpbm-mirror-958d2b758ce55a01af8f926c5a6c450ba2620805.tar.xz
netpbm-mirror-958d2b758ce55a01af8f926c5a6c450ba2620805.zip
Add pnm_colorname()
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@175 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--lib/libpamcolor.c32
-rw-r--r--lib/libppmcolor.c13
-rw-r--r--lib/pam.h5
3 files changed, 43 insertions, 7 deletions
diff --git a/lib/libpamcolor.c b/lib/libpamcolor.c
index e11415ca..ef8546b3 100644
--- a/lib/libpamcolor.c
+++ b/lib/libpamcolor.c
@@ -11,6 +11,10 @@
 #define _FILE_OFFSET_BITS 64
 #define _LARGE_FILES  
 
+#define _BSD_SOURCE 1      /* Make sure strdup() is in string.h */
+#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
+
+#include <string.h>
 #include <limits.h>
 
 #include "pm_c_util.h"
@@ -44,6 +48,34 @@ pnm_parsecolor(const char * const colorname,
 
 
 
+const char *
+pnm_colorname(struct pam * const pamP,
+              tuple        const color,
+              int          const hexok) {
+
+    const char * retval;
+    pixel colorp;
+    char * colorname;
+
+    if (pamP->depth < 3)
+        PPM_ASSIGN(colorp, color[0], color[0], color[0]);
+    else 
+        PPM_ASSIGN(colorp,
+                   color[PAM_RED_PLANE],
+                   color[PAM_GRN_PLANE],
+                   color[PAM_BLU_PLANE]);
+
+    colorname = ppm_colorname(&colorp, pamP->maxval, hexok);
+
+    retval = strdup(colorname);
+    if (retval == NULL)
+        pm_error("Couldn't get memory for color name string");
+
+    return retval;
+}
+
+
+
 double pnm_lumin_factor[3] = {PPM_LUMINR, PPM_LUMING, PPM_LUMINB};
 
 void
diff --git a/lib/libppmcolor.c b/lib/libppmcolor.c
index 87f14a5e..7e324185 100644
--- a/lib/libppmcolor.c
+++ b/lib/libppmcolor.c
@@ -399,13 +399,13 @@ ppm_parsecolor(const char * const colorname,
 
 
 
-char*
-ppm_colorname(const pixel* const colorP, 
-              pixval       const maxval, 
-              int          const hexok)   {
+char *
+ppm_colorname(const pixel * const colorP, 
+              pixval        const maxval, 
+              int           const hexok)   {
 
     int r, g, b;
-    FILE* f;
+    FILE * f;
     static char colorname[200];
 
     if (maxval == 255) {
@@ -445,8 +445,7 @@ ppm_colorname(const pixel* const colorP,
        hex specifier, so return that.
     */
     sprintf(colorname, "#%02x%02x%02x", r, g, b);
-    return colorname;
-}
+    return colorname;}
 
 
 
diff --git a/lib/pam.h b/lib/pam.h
index b5befda4..e66b831d 100644
--- a/lib/pam.h
+++ b/lib/pam.h
@@ -454,6 +454,11 @@ tuple
 pnm_parsecolor(const char * const colorname,
                sample       const maxval);
 
+const char *
+pnm_colorname(struct pam * const pamP,
+              tuple        const color,
+              int          const hexok);
+
 extern double 
 pnm_lumin_factor[3];