diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-11-28 06:14:47 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-11-28 06:14:47 +0000 |
commit | 42981754a445355aac8d62efdd276ba96fcdac03 (patch) | |
tree | 195742bf12807c159b5f35f0cd2bbc31c16d44d7 /lib/libpnm3.c | |
parent | 352e360cc05a80c3338a73a355d34be3b181ea4b (diff) | |
download | netpbm-mirror-42981754a445355aac8d62efdd276ba96fcdac03.tar.gz netpbm-mirror-42981754a445355aac8d62efdd276ba96fcdac03.tar.xz netpbm-mirror-42981754a445355aac8d62efdd276ba96fcdac03.zip |
Fix -background with PGM/PBM input - pnmrotate, pnmshear
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@156 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpnm3.c')
-rw-r--r-- | lib/libpnm3.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/libpnm3.c b/lib/libpnm3.c index 80ccadfa..c7951546 100644 --- a/lib/libpnm3.c +++ b/lib/libpnm3.c @@ -345,3 +345,45 @@ xeltopixel(xel const inputxel) { PNM_GET1(inputxel), PNM_GET1(inputxel), PNM_GET1(inputxel)); return outputpixel; } + + + +xel +pnm_parsecolorxel(const char * const colorName, + xelval const maxval, + int const format) { + + pixel const bgColor = ppm_parsecolor(colorName, maxval); + + xel retval; + + switch(PNM_FORMAT_TYPE(format)) { + case PPM_TYPE: + PNM_ASSIGN(retval, + PPM_GETR(bgColor), PPM_GETG(bgColor), PPM_GETB(bgColor)); + break; + case PGM_TYPE: + if (PPM_ISGRAY(bgColor)) + PNM_ASSIGN1(retval, PPM_GETB(bgColor)); + else + pm_error("Non-gray color '%s' specified for a " + "grayscale (PGM) image", + colorName); + break; + case PBM_TYPE: + if (PPM_EQUAL(bgColor, ppm_whitepixel(maxval))) + PNM_ASSIGN1(retval, maxval); + else if (PPM_EQUAL(bgColor, ppm_blackpixel())) + PNM_ASSIGN1(retval, 0); + else + pm_error ("Color '%s', which is neither black nor white, " + "specified for a black and white (PBM) image", + colorName); + break; + default: + pm_error("Invalid format code %d passed to pnm_parsecolor()", + format); + } + + return retval; +} |