diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2014-02-09 18:11:04 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2014-02-09 18:11:04 +0000 |
commit | 593f1795985139aabc730dc74ec3e16131d725b2 (patch) | |
tree | d70b4493cf98761300565c92b4748505c5890fd0 /editor/specialty/ppmrelief.c | |
parent | 69f6a4b0348f6ed02da0da9a3ae1adb758f24e3e (diff) | |
download | netpbm-mirror-593f1795985139aabc730dc74ec3e16131d725b2.tar.gz netpbm-mirror-593f1795985139aabc730dc74ec3e16131d725b2.tar.xz netpbm-mirror-593f1795985139aabc730dc74ec3e16131d725b2.zip |
Release 10.65.04
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2123 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/specialty/ppmrelief.c')
-rw-r--r-- | editor/specialty/ppmrelief.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/editor/specialty/ppmrelief.c b/editor/specialty/ppmrelief.c index 5e0669c3..1c408aec 100644 --- a/editor/specialty/ppmrelief.c +++ b/editor/specialty/ppmrelief.c @@ -11,6 +11,7 @@ */ #include <stdio.h> +#include "pm_c_util.h" #include "ppm.h" int @@ -38,6 +39,11 @@ main(int argc, char * argv[]) { pm_usage( usage ); ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); + + if (cols < 3 || rows < 3 ) + pm_error("Input image too small: %u x %u. Must be at least 3x3", + cols, rows); + mv2 = maxval / 2; /* Allocate space for 3 input rows, plus an output row. */ @@ -67,12 +73,12 @@ main(int argc, char * argv[]) { ppm_readppmrow( ifp, inputbuf[rowa], cols, maxval, format ); for ( col = 0; col < cols - 2; ++col ) { - r = PPM_GETR( inputbuf[rowa][col] ) + - ( mv2 - PPM_GETR( inputbuf[rowb][col + 2] ) ); - g = PPM_GETG( inputbuf[rowa][col] ) + - ( mv2 - PPM_GETG( inputbuf[rowb][col + 2] ) ); - b = PPM_GETB( inputbuf[rowa][col] ) + - ( mv2 - PPM_GETB( inputbuf[rowb][col + 2] ) ); + r = MAX(0, MIN(maxval, PPM_GETR( inputbuf[rowa][col] ) + + ( mv2 - PPM_GETR( inputbuf[rowb][col + 2] ) ))); + g = MAX(0, MIN(maxval, PPM_GETG( inputbuf[rowa][col] ) + + ( mv2 - PPM_GETG( inputbuf[rowb][col + 2] ) ))); + b = MAX(0, MIN(maxval, PPM_GETB( inputbuf[rowa][col] ) + + ( mv2 - PPM_GETB( inputbuf[rowb][col + 2] ) ))); PPM_ASSIGN( outputrow[col + 1], r, g, b ); } ppm_writeppmrow( stdout, outputrow, cols, maxval, 0 ); |