diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-12-31 08:08:29 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-12-31 08:08:29 +0000 |
commit | 31fc573df625b06a5f7b8b8e769e9f35cbfdaf91 (patch) | |
tree | caf153af4ea24150e1f54e77c35b9ee51e727055 /lib/libpnm3.c | |
parent | 2cc04cae07f40a7c58616e4614e88cf0ae8e63c7 (diff) | |
download | netpbm-mirror-31fc573df625b06a5f7b8b8e769e9f35cbfdaf91.tar.gz netpbm-mirror-31fc573df625b06a5f7b8b8e769e9f35cbfdaf91.tar.xz netpbm-mirror-31fc573df625b06a5f7b8b8e769e9f35cbfdaf91.zip |
Release 10.37.0
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@187 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpnm3.c')
-rw-r--r-- | lib/libpnm3.c | 148 |
1 files changed, 72 insertions, 76 deletions
diff --git a/lib/libpnm3.c b/lib/libpnm3.c index f10a7fca..4df8041c 100644 --- a/lib/libpnm3.c +++ b/lib/libpnm3.c @@ -21,16 +21,8 @@ #include "pbm.h" #include "libpbm.h" -#if __STDC__ xel pnm_backgroundxel( xel** xels, int cols, int rows, xelval maxval, int format ) -#else /*__STDC__*/ -xel -pnm_backgroundxel( xels, cols, rows, maxval, format ) - xel** xels; - int cols, rows, format; - xelval maxval; -#endif /*__STDC__*/ { xel bgxel, ul, ur, ll, lr; @@ -93,16 +85,8 @@ pnm_backgroundxel( xels, cols, rows, maxval, format ) return bgxel; } -#if __STDC__ xel pnm_backgroundxelrow( xel* xelrow, int cols, xelval maxval, int format ) -#else /*__STDC__*/ -xel -pnm_backgroundxelrow( xelrow, cols, maxval, format ) - xel* xelrow; - int cols, format; - xelval maxval; -#endif /*__STDC__*/ { xel bgxel, l, r; @@ -158,71 +142,57 @@ pnm_backgroundxelrow( xelrow, cols, maxval, format ) return bgxel; } -#if __STDC__ -xel -pnm_whitexel( xelval maxval, int format ) -#else /*__STDC__*/ + + xel -pnm_whitexel( maxval, format ) - xelval maxval; - int format; -#endif /*__STDC__*/ - { - xel x; +pnm_whitexel(xelval const maxval, + int const format) { - switch ( PNM_FORMAT_TYPE(format) ) - { + xel retval; + + switch (PNM_FORMAT_TYPE(format)) { case PPM_TYPE: - PPM_ASSIGN( x, maxval, maxval, maxval ); - break; + PPM_ASSIGN(retval, maxval, maxval, maxval); + break; case PGM_TYPE: - PNM_ASSIGN1( x, maxval ); - break; - case PBM_TYPE: - PNM_ASSIGN1( x, maxval ); - break; + PNM_ASSIGN1(retval, maxval); + break; default: - pm_error( "Invalid format passed to pnm_whitexel()"); + pm_error("Invalid format %d passed to pnm_whitexel()", format); } - return x; - } + return retval; +} + + -#if __STDC__ -xel -pnm_blackxel( xelval maxval, int format ) -#else /*__STDC__*/ xel -pnm_blackxel( maxval, format ) - xelval maxval; - int format; -#endif /*__STDC__*/ - { - xel x; +pnm_blackxel(xelval const maxval, + int const format) { - switch ( PNM_FORMAT_TYPE(format) ) - { + xel retval; + + switch (PNM_FORMAT_TYPE(format)) { case PPM_TYPE: - PPM_ASSIGN( x, 0, 0, 0 ); - break; + PPM_ASSIGN(retval, 0, 0, 0); + break; case PGM_TYPE: - PNM_ASSIGN1( x, (xelval) 0 ); - break; - case PBM_TYPE: - PNM_ASSIGN1( x, (xelval) 0 ); - break; + PNM_ASSIGN1(retval, 0); + break; default: - pm_error( "Invalid format passed to pnm_blackxel(): %d", format); + pm_error("Invalid format %d passed to pnm_blackxel()", format); } + + return retval; +} + - return x; - } void pnm_invertxel(xel* const xP, @@ -252,16 +222,8 @@ pnm_invertxel(xel* const xP, -#if __STDC__ void pnm_promoteformat( xel** xels, int cols, int rows, xelval maxval, int format, xelval newmaxval, int newformat ) -#else /*__STDC__*/ -void -pnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat ) - xel** xels; - xelval maxval, newmaxval; - int cols, rows, format, newformat; -#endif /*__STDC__*/ { int row; @@ -270,16 +232,8 @@ pnm_promoteformat( xels, cols, rows, maxval, format, newmaxval, newformat ) xels[row], cols, maxval, format, newmaxval, newformat ); } -#if __STDC__ void pnm_promoteformatrow( xel* xelrow, int cols, xelval maxval, int format, xelval newmaxval, int newformat ) -#else /*__STDC__*/ -void -pnm_promoteformatrow( xelrow, cols, maxval, format, newmaxval, newformat ) - xel* xelrow; - xelval maxval, newmaxval; - int cols, format, newformat; -#endif /*__STDC__*/ { register int col; register xel* xP; @@ -409,3 +363,45 @@ pnm_xeltopixel(xel const 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_parsecolorxel()", + format); + } + + return retval; +} |