From 847cfc7c5d1fa7f4c3a8715da220b4cac06f2621 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 4 Mar 2010 03:37:13 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1141 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/pbm/ybmtopbm.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/converter/pbm/ybmtopbm.c b/converter/pbm/ybmtopbm.c index 5ef29501..98e520f3 100644 --- a/converter/pbm/ybmtopbm.c +++ b/converter/pbm/ybmtopbm.c @@ -19,7 +19,7 @@ static short const ybmMagic = ( ( '!' << 8 ) | '!' ); static int item; -static int bitsperitem, bitshift; +static int bitsInBuffer, bitshift; @@ -50,7 +50,6 @@ getinit(FILE * const ifP, *depthP = 1; *padrightP = ((*colsP + 15) / 16) * 16 - *colsP; - bitsperitem = 0; } @@ -60,16 +59,18 @@ getbit(FILE * const ifP) { bit b; - if (bitsperitem == 0) { + if (bitsInBuffer == 0) { item = getc(ifP) | getc(ifP) << 8; + if (item == EOF) pm_error("EOF / read error"); - bitsperitem = 16; + + bitsInBuffer = 16; bitshift = 0; } b = ((item >> bitshift) & 1 ) ? PBM_BLACK : PBM_WHITE; - --bitsperitem; + --bitsInBuffer; ++bitshift; return b; } @@ -100,6 +101,8 @@ main(int argc, const char * argv[]) { ifP = pm_openr(inputFile); + bitsInBuffer = 0; + getinit(ifP, &cols, &rows, &depth, &padright); if (depth != 1) pm_error("YBM file has depth of %u, must be 1", (unsigned)depth); @@ -109,10 +112,12 @@ main(int argc, const char * argv[]) { bitrow = pbm_allocrow(cols); for (row = 0; row < rows; ++row) { - /* Get data. */ + /* Get raster. */ unsigned int col; + for (col = 0; col < cols; ++col) bitrow[col] = getbit(ifP); + /* Discard line padding */ for (col = 0; col < padright; ++col) getbit(ifP); -- cgit 1.4.1