diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 5 | ||||
-rw-r--r-- | lib/libpbm2.c | 85 | ||||
-rw-r--r-- | lib/libpnm1.c | 9 | ||||
-rw-r--r-- | lib/libppm1.c | 9 | ||||
-rw-r--r-- | lib/pbm.h | 22 | ||||
-rw-r--r-- | lib/pnm.h | 2 | ||||
-rw-r--r-- | lib/ppm.h | 2 | ||||
-rw-r--r-- | lib/util/Makefile | 1 | ||||
-rw-r--r-- | lib/util/bitio.c (renamed from lib/bitio.c) | 0 | ||||
-rw-r--r-- | lib/util/bitio.h (renamed from lib/bitio.h) | 0 | ||||
-rw-r--r-- | lib/util/nstring.c | 62 |
11 files changed, 118 insertions, 79 deletions
diff --git a/lib/Makefile b/lib/Makefile index 19557909..fa73d194 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,7 +25,7 @@ else LIBSYSTEM = libsystem.o endif -LIBOBJECTS = libpm.o pmfileio.o fileio.o bitio.o colorname.o \ +LIBOBJECTS = libpm.o pmfileio.o fileio.o colorname.o \ libpamd.o \ libpbm1.o libpbm2.o libpbm3.o libpbmfont.o \ libpgm1.o libpgm2.o \ @@ -39,6 +39,7 @@ LIBOBJECTS = libpm.o pmfileio.o fileio.o bitio.o colorname.o \ # Library objects to be linked but not built by common.mk: LIBOBJECTS_X = \ + util/bitio.o \ util/filename.o \ util/io.o \ util/mallocvar.o \ @@ -52,7 +53,7 @@ LIBOBJECTS_X = \ MANUALS3 = libnetpbm MANUALS5 = pbm pgm ppm pnm pam -INTERFACE_HEADERS = bitio.h colorname.h \ +INTERFACE_HEADERS = colorname.h \ pam.h pamdraw.h pammap.h pbm.h pbmfont.h \ pgm.h pm.h pm_gamma.h pm_system.h pnm.h \ ppm.h ppmcmap.h ppmdfont.h ppmdraw.h ppmfloyd.h \ diff --git a/lib/libpbm2.c b/lib/libpbm2.c index a77fa0ae..f199c51a 100644 --- a/lib/libpbm2.c +++ b/lib/libpbm2.c @@ -10,6 +10,7 @@ ** implied warranty. */ +#include <assert.h> #include <limits.h> #include "pbm.h" @@ -34,11 +35,9 @@ getbit (FILE * const file) { void -pbm_readpbminitrest( file, colsP, rowsP ) - FILE* file; - int* colsP; - int* rowsP; - { +pbm_readpbminitrest( FILE * const file, + int * const colsP, + int * const rowsP ) { /* Read size. */ *colsP = (int)pm_getuint( file ); *rowsP = (int)pm_getuint( file ); @@ -55,7 +54,7 @@ pbm_readpbminitrest( file, colsP, rowsP ) pm_error("Number of columns in header is too large."); if (*rowsP < 0) pm_error("Number of columns in header is too large."); - } +} @@ -122,32 +121,29 @@ pbm_readpbminit(FILE * const ifP, void -pbm_readpbmrow( file, bitrow, cols, format ) - FILE* file; - bit* bitrow; - int cols, format; - { - register int col, bitshift; - register bit* bP; +pbm_readpbmrow( FILE * const file, + bit * const bitrow, + int const cols, + int const format) { + + int col, bitshift; switch ( format ) { case PBM_FORMAT: - for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) - *bP = getbit( file ); + for ( col = 0; col < cols; ++col ) + bitrow[col] = getbit( file ); break; case RPBM_FORMAT: { - register unsigned char item; + unsigned char item; bitshift = -1; item = 0; /* item's value is meaningless here */ - for ( col = 0, bP = bitrow; col < cols; ++col, ++bP ) - { - if ( bitshift == -1 ) - { + for ( col = 0; col < cols; ++col ) { + if ( bitshift == -1 ) { item = pm_getrawbyte( file ); bitshift = 7; } - *bP = ( item >> bitshift ) & 1; + bitrow[col] = ( item >> bitshift ) & 1; --bitshift; } } @@ -156,7 +152,7 @@ pbm_readpbmrow( file, bitrow, cols, format ) default: pm_error( "can't happen" ); } - } +} @@ -184,12 +180,12 @@ pbm_readpbmrow_packed(FILE * const fileP, break; case RPBM_FORMAT: { - int bytes_read; - bytes_read = fread(packedBits, 1, pbm_packed_bytes(cols), fileP); + unsigned int bytesReadCt; + bytesReadCt = fread(packedBits, 1, pbm_packed_bytes(cols), fileP); - if (bytes_read < pbm_packed_bytes(cols)) { + if (bytesReadCt < pbm_packed_bytes(cols)) { if (feof(fileP)) - if (bytes_read == 0) + if (bytesReadCt == 0) pm_error("Attempt to read a raw PBM image row, but " "no more rows left in file."); else @@ -201,7 +197,7 @@ pbm_readpbmrow_packed(FILE * const fileP, break; default: - pm_error( "Internal error in pbm_readpbmrow_packed." ); + pm_error("Internal error in pbm_readpbmrow_packed."); } } @@ -262,17 +258,36 @@ pbm_readpbmrow_bitoffset(FILE * const ifP, window[last] = leftBits | rightBits; } -} +} + + + +void +pbm_cleanrowend_packed(unsigned char * const packedBits, + unsigned int const cols) { +/*---------------------------------------------------------------------------- + Set fractional "don't care" bits at end of row to zero. +----------------------------------------------------------------------------*/ + unsigned int const bitsPerChar = 8; + + if (cols % bitsPerChar > 0) { + unsigned int const last = pbm_packed_bytes(cols) - 1; + + assert(pbm_packed_bytes(cols) > 0); + + packedBits[last] >>= bitsPerChar - cols % bitsPerChar; + packedBits[last] <<= bitsPerChar - cols % bitsPerChar; + } +} bit** -pbm_readpbm( file, colsP, rowsP ) - FILE* file; - int* colsP; - int* rowsP; - { - register bit** bits; +pbm_readpbm( FILE * const file, + int * const colsP, + int * const rowsP) { + + bit ** bits; int format, row; pbm_readpbminit( file, colsP, rowsP, &format ); @@ -283,4 +298,4 @@ pbm_readpbm( file, colsP, rowsP ) pbm_readpbmrow( file, bits[row], *colsP, format ); return bits; - } +} diff --git a/lib/libpnm1.c b/lib/libpnm1.c index adfacd03..db21b078 100644 --- a/lib/libpnm1.c +++ b/lib/libpnm1.c @@ -47,15 +47,12 @@ pnm_allocrow(unsigned int const cols) { void -pnm_init( argcP, argv ) - int* argcP; - char* argv[]; - { +pnm_init(int * const argcP, char ** const argv) { ppm_init( argcP, argv ); - } +} void -pnm_nextimage(FILE *file, int * const eofP) { +pnm_nextimage(FILE * const file, int * const eofP) { pm_nextimage(file, eofP); } diff --git a/lib/libppm1.c b/lib/libppm1.c index a3be5d3b..c1eb152c 100644 --- a/lib/libppm1.c +++ b/lib/libppm1.c @@ -49,12 +49,11 @@ ppm_allocrow(unsigned int const cols) { void -ppm_init( argcP, argv ) - int* argcP; - char* argv[]; - { +ppm_init(int * const argcP, char ** const argv) { pgm_init( argcP, argv ); - } +} + + void ppm_nextimage(FILE * const fileP, diff --git a/lib/pbm.h b/lib/pbm.h index 24574d07..a29adb48 100644 --- a/lib/pbm.h +++ b/lib/pbm.h @@ -58,9 +58,21 @@ pbm_allocrow(unsigned int const cols); #define pbm_freearray_packed(packed_bits, rows) \ pm_freearray((char **) packed_bits, rows) -bit** pbm_readpbm(FILE* file, int* colsP, int* rowsP); -void pbm_readpbminit(FILE* file, int* colsP, int* rowsP, int* formatP); -void pbm_readpbmrow(FILE* file, bit* bitrow, int cols, int format); +bit** +pbm_readpbm(FILE * const file, + int * const colsP, + int * const rowsP); + +void +pbm_readpbminit(FILE * const file, + int * const colsP, + int * const rowsP, int * const formatP); + +void +pbm_readpbmrow(FILE * const file, + bit * const bitrow, + int const cols, + int const format); void pbm_readpbmrow_packed(FILE * const file, @@ -76,6 +88,10 @@ pbm_readpbmrow_bitoffset(FILE * const fileP, unsigned int const offset); void +pbm_cleanrowend_packed(unsigned char * const packedBits, + unsigned int const cols); + +void pbm_writepbminit(FILE * const fileP, int const cols, int const rows, diff --git a/lib/pnm.h b/lib/pnm.h index de5f1d91..3b490552 100644 --- a/lib/pnm.h +++ b/lib/pnm.h @@ -37,7 +37,7 @@ pnm_init(int * const argcP, char ** const argv); void -pnm_nextimage(FILE *file, int * const eofP); +pnm_nextimage(FILE * const file, int * const eofP); xel * pnm_allocrow(unsigned int const cols); diff --git a/lib/ppm.h b/lib/ppm.h index 7a24f926..82241b70 100644 --- a/lib/ppm.h +++ b/lib/ppm.h @@ -77,7 +77,7 @@ ppm_blackpixel(void) { return retval; } -void ppm_init(int * argcP, char* argv[]); +void ppm_init(int * const argcP, char ** const argv); #define ppm_allocarray(cols, rows) \ ((pixel**) pm_allocarray(cols, rows, sizeof(pixel))) diff --git a/lib/util/Makefile b/lib/util/Makefile index 28dfddfe..c8522a04 100644 --- a/lib/util/Makefile +++ b/lib/util/Makefile @@ -12,6 +12,7 @@ include $(BUILDDIR)/config.mk # nstring is required for asprintf(), etc. Also some systems don't have # snprintf(), e.g. Solaris 2.5.1. 2002.03.29. UTILOBJECTS = \ + bitio.o \ filename.o \ io.o \ mallocvar.o \ diff --git a/lib/bitio.c b/lib/util/bitio.c index ca1b55f9..ca1b55f9 100644 --- a/lib/bitio.c +++ b/lib/util/bitio.c diff --git a/lib/bitio.h b/lib/util/bitio.h index dfc5a153..dfc5a153 100644 --- a/lib/bitio.h +++ b/lib/util/bitio.h diff --git a/lib/util/nstring.c b/lib/util/nstring.c index 039c2b3b..711cfca9 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -897,49 +897,59 @@ pm_stripeq(const char * const comparand, Return 1 (true) if the strings are identical; 0 (false) otherwise. -----------------------------------------------------------------------------*/ - char *p, *q, *px, *qx; - char equal; + const char * p; + const char * q; + const char * px; + const char * qx; + bool equal; /* Make p and q point to the first non-blank character in each string. - If there are no non-blank characters, make them point to the terminating - NULL. - */ + If there are no non-blank characters, make them point to the terminating + NUL. + */ - p = (char *) comparand; - while (ISSPACE(*p)) p++; - q = (char *) comparator; - while (ISSPACE(*q)) q++; + p = &comparand[0]; + while (ISSPACE(*p)) + p++; + q = &comparator[0]; + while (ISSPACE(*q)) + q++; /* Make px and qx point to the last non-blank character in each string. If there are no nonblank characters (which implies the string is - null), make them point to the terminating NULL. + null), make them point to the terminating NUL. */ - if (*p == '\0') px = p; + if (*p == '\0') + px = p; else { px = p + strlen(p) - 1; - while (ISSPACE(*px)) px--; + while (ISSPACE(*px)) + --px; } - if (*q == '\0') qx = q; + if (*q == '\0') + qx = q; else { qx = q + strlen(q) - 1; - while (ISSPACE(*qx)) qx--; + while (ISSPACE(*qx)) + --qx; } - equal = 1; /* initial assumption */ - - /* If the stripped strings aren't the same length, - we know they aren't equal - */ - if (px - p != qx - q) equal = 0; - - else - while (p <= px) { - if (*p != *q) equal = 0; - p++; q++; + if (px - p != qx - q) { + /* The stripped strings aren't the same length, so we know they aren't + equal. + */ + equal = false; + } else { + /* Move p and q through the nonblank characters, comparing. */ + for (equal = true; p <= px; ++p, ++q) { + assert(q <= qx); /* Because stripped strings are same length */ + if (*p != *q) + equal = false; + } } - return equal; + return equal ? 1 : 0; } |