diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-09-09 17:59:48 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-09-09 17:59:48 +0000 |
commit | bb90be5f15cee8dcf80962ab482b7f07707332cd (patch) | |
tree | 73a81a85bf885353b5be48d2289963a2b13f26ba | |
parent | cc4dde06897248afb92f5c037d40a5f239554ffb (diff) | |
download | netpbm-mirror-bb90be5f15cee8dcf80962ab482b7f07707332cd.tar.gz netpbm-mirror-bb90be5f15cee8dcf80962ab482b7f07707332cd.tar.xz netpbm-mirror-bb90be5f15cee8dcf80962ab482b7f07707332cd.zip |
Make pbm_readpbminit() and pgm_readpgminit() recognize other Netpbm formats and issue special error message
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@410 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | doc/HISTORY | 6 | ||||
-rw-r--r-- | lib/libpbm2.c | 50 | ||||
-rw-r--r-- | lib/libpgm1.c | 16 |
3 files changed, 49 insertions, 23 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index d8b62dcf..1b16f17e 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -29,7 +29,7 @@ not yet BJH Release 10.40.00 sample Postscript. It doesn't really know how to do that, so now it just writes 8 unless you do -psfilter. - pnmmargin: recognize invalid options better. Thanks + pnmmargin: recognize invalid options better. Thanks Prophet of the Way <afu@wta.att.ne.jp>. pnmtopng: Sort palette properly when alpha maxval != 255. @@ -42,6 +42,10 @@ not yet BJH Release 10.40.00 libnetpbm: Add pm_system_lp(), pm_system_vp(). + libnetpbm: Make pbm_readpbminit() and pgm_readpgminit() + recognize incompatible Netpbm formats and issue a + helpful error message. + libnetpbm: pbm_readppminit: read PBM as maxval of 255, not 1. libnetpbm: Fix pm_drain() to use the specified limit. diff --git a/lib/libpbm2.c b/lib/libpbm2.c index d04328ef..19ca93b3 100644 --- a/lib/libpbm2.c +++ b/lib/libpbm2.c @@ -13,6 +13,7 @@ #include "pbm.h" #include "libpbm.h" #include "fileio.h" +#include "pam.h" static bit getbit (FILE * const file) { @@ -54,25 +55,42 @@ pbm_readpbminitrest( file, colsP, rowsP ) pm_error("Number of columns in header is too large."); } -void -pbm_readpbminit( file, colsP, rowsP, formatP ) - FILE* file; - int* colsP; - int* rowsP; - int* formatP; - { - /* Check magic number. */ - *formatP = pm_readmagicnumber( file ); - switch ( PBM_FORMAT_TYPE(*formatP) ) - { - case PBM_TYPE: - pbm_readpbminitrest( file, colsP, rowsP ); - break; + +void +pbm_readpbminit(FILE * const ifP, + int * const colsP, + int * const rowsP, + int * const formatP) { + + *formatP = pm_readmagicnumber(ifP); + + switch (PAM_FORMAT_TYPE(*formatP)) { + case PBM_TYPE: + pbm_readpbminitrest(ifP, colsP, rowsP); + break; + + case PGM_TYPE: + pm_error("The input file is a PGM, not a PBM. You may want to " + "convert it to PBM with 'pamditherbw | pamtopnm' or " + "'pamthreshold | pamtopnm'"); + + case PPM_TYPE: + pm_error("The input file is a PPM, not a PBM. You may want to " + "convert it to PBM with 'ppmtopgm', 'pamditherbw', and " + "'pamtopnm'"); + + case PAM_TYPE: + pm_error("The input file is a PAM, not a PBM. " + "If it is a black and white image, you can convert it " + "to PBM with 'pamtopnm'"); + break; default: - pm_error( "bad magic number - not a pbm file" ); - } + pm_error("bad magic number - not a Netpbm file"); } +} + + void pbm_readpbmrow( file, bitrow, cols, format ) diff --git a/lib/libpgm1.c b/lib/libpgm1.c index f615069d..34cc6392 100644 --- a/lib/libpgm1.c +++ b/lib/libpgm1.c @@ -122,11 +122,6 @@ pgm_readpgminit(FILE * const fileP, /* Check magic number. */ realFormat = pm_readmagicnumber(fileP); switch (PAM_FORMAT_TYPE(realFormat)) { - case PGM_TYPE: - *formatP = realFormat; - pgm_readpgminitrest(fileP, colsP, rowsP, maxvalP); - break; - case PBM_TYPE: *formatP = realFormat; pbm_readpbminitrest(fileP, colsP, rowsP); @@ -150,6 +145,15 @@ pgm_readpgminit(FILE * const fileP, *maxvalP = PGM_MAXMAXVAL; break; + case PGM_TYPE: + *formatP = realFormat; + pgm_readpgminitrest(fileP, colsP, rowsP, maxvalP); + break; + + case PPM_TYPE: + pm_error("Input file is a PPM, which this program cannot process. " + "You may want to convert it to PGM with 'ppmtopgm'"); + case PAM_TYPE: pnm_readpaminitrestaspnm(fileP, colsP, rowsP, maxvalP, formatP); @@ -159,7 +163,7 @@ pgm_readpgminit(FILE * const fileP, break; default: - pm_error("bad magic number - not a pgm or pbm file"); + pm_error("bad magic number - not a Netpbm file"); } validateComputableSize(*colsP, *rowsP); } |