From bb90be5f15cee8dcf80962ab482b7f07707332cd Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 9 Sep 2007 17:59:48 +0000 Subject: 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 --- lib/libpbm2.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'lib/libpbm2.c') 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 ) -- cgit 1.4.1