diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-04-06 19:33:44 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2019-04-06 19:33:44 +0000 |
commit | 9ad490d118b9c9b38415ddbc5155c9d4f62109bd (patch) | |
tree | f7ae6ecd6514efa41e9eb37157978274a286f877 /editor | |
parent | aad47e743f21763ac13b73eb927ad7d001254572 (diff) | |
download | netpbm-mirror-9ad490d118b9c9b38415ddbc5155c9d4f62109bd.tar.gz netpbm-mirror-9ad490d118b9c9b38415ddbc5155c9d4f62109bd.tar.xz netpbm-mirror-9ad490d118b9c9b38415ddbc5155c9d4f62109bd.zip |
Release 10.86.01
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3592 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor')
-rw-r--r-- | editor/pnmcrop.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/editor/pnmcrop.c b/editor/pnmcrop.c index bea7a1bf..3f414e1b 100644 --- a/editor/pnmcrop.c +++ b/editor/pnmcrop.c @@ -387,17 +387,15 @@ backgroundColorFmName(const char * const colorName, /*---------------------------------------------------------------------------- The color indicated by 'colorName'. - If the image is PGM we allow only shades of gray. If it is PBM, we allow - only pure black and pure white. + The return value is based on maxval 'maxval' and format 'format'. + + Abort the program if 'colorName' names a color that cannot be represented + in format 'format'. Development note: It would be logical to relax the above restriction when -closeness is specified. Implementation is harder than it seems because of the -margin option. It is unlikely that there is demand for this feature. If really necessary, the user can convert the input image to PPM. - - Adjust xel for maxval and image type (PPM, PGM, PBM) of the image to - examine. For PGM and PBM, only the blue plane is given a value. So set - the other two to zero. (This is necessary for making comparisons). -----------------------------------------------------------------------------*/ pixel const backgroundColor = ppm_parsecolor(colorName, maxval); @@ -416,18 +414,22 @@ backgroundColorFmName(const char * const colorName, xel backgroundXel; - backgroundXel = pnm_pixeltoxel(backgroundColor); /* initial value */ - - /* Adjust backgroundXel to match input image format, if necessary */ - - if (PBM_FORMAT_TYPE(format) == PBM_TYPE && hasGray) - pm_error("Invalid color specified: '%s'. " - "Image has no intermediate levels of gray.", - colorName); - - if (PPM_FORMAT_TYPE(format) != PPM_TYPE && hasColor) - pm_error("Invalid color specified: '%s'. " - "Image does not have color.", colorName); + if (PPM_FORMAT_TYPE(format)) { + backgroundXel = pnm_pixeltoxel(backgroundColor); + } else { + /* Derive PBM or PGM xel from pixel 'backgroundColor' */ + if (hasColor) + pm_error("Invalid color specified: '%s'. " + "Image does not have color.", colorName); + else { + if (PBM_FORMAT_TYPE(format) == PBM_TYPE && hasGray) + pm_error("Invalid color specified: '%s'. " + "Image has no intermediate levels of gray.", + colorName); + else + PNM_ASSIGN1(backgroundXel, backgroundColor.r); + } + } return backgroundXel; } |