From 593f1795985139aabc730dc74ec3e16131d725b2 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 9 Feb 2014 18:11:04 +0000 Subject: Release 10.65.04 git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2123 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/specialty/ppmrelief.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'editor/specialty/ppmrelief.c') 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 +#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 ); -- cgit 1.4.1