diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-03-26 02:53:02 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-03-26 02:53:02 +0000 |
commit | b117a415aaf58c435805243a930e833f8cf62421 (patch) | |
tree | ca6cda4c24d37737a3942e534b95006bcd566c5a /generator/pgmnoise.c | |
parent | 34bb24c566c9d9fe3c4ae71fc4c6b53323fb1dd9 (diff) | |
download | netpbm-mirror-b117a415aaf58c435805243a930e833f8cf62421.tar.gz netpbm-mirror-b117a415aaf58c435805243a930e833f8cf62421.tar.xz netpbm-mirror-b117a415aaf58c435805243a930e833f8cf62421.zip |
Promote trunk (10.90.00) to advanced
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3784 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator/pgmnoise.c')
-rw-r--r-- | generator/pgmnoise.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/generator/pgmnoise.c b/generator/pgmnoise.c index 40d0e189..e3e4eca6 100644 --- a/generator/pgmnoise.c +++ b/generator/pgmnoise.c @@ -3,11 +3,12 @@ Frank Neumann, October 1993 *********************************************************************/ +#include <assert.h> #include "pm_c_util.h" #include "mallocvar.h" +#include "nstring.h" #include "shhopt.h" #include "pgm.h" -#include <assert.h> @@ -68,16 +69,24 @@ parseCommandLine(int argc, const char ** const argv, "Arguments are width and height of image, in pixels", argc-1); else { - int const width = atoi(argv[1]); - int const height = atoi(argv[2]); - - if (width <= 0) - pm_error("Width must be positive, not %d", width); + const char * error; /* error message of pm_string_to_uint */ + unsigned int width, height; + + pm_string_to_uint(argv[1], &width, &error); + if (error) + pm_error("Width argument is not an unsigned integer. %s", + error); + else if (width == 0) + pm_error("Width argument is zero; must be positive"); else cmdlineP->width = width; - if (height <= 0) - pm_error("Height must be positive, not %d", width); + pm_string_to_uint(argv[2], &height, &error); + if (error) + pm_error("Height argument is not an unsigned integer. %s ", + error); + else if (height == 0) + pm_error("Height argument is zero; must be positive"); else cmdlineP->height = height; } @@ -139,7 +148,7 @@ pgmnoise(FILE * const ofP, /* If maxval is 2^n-1, we draw exactly n bits from the pool. Otherwise call rand() and determine gray value by modulo. - In the latter case, there is a miniscule skew toward 0 (=black) + In the latter case, there is a minuscule skew toward 0 (=black) because smaller numbers are produced more frequently by modulo. Thus we employ the pool method only when it is certain that no skew will ensue. |