From 620ecbee2ed1cb478e0289722d86dd72717f1cb8 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 28 Jun 2015 15:34:21 +0000 Subject: Release 10.71.00 git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@2588 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/pbm/pbmtoatk.c | 69 ++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'converter/pbm/pbmtoatk.c') diff --git a/converter/pbm/pbmtoatk.c b/converter/pbm/pbmtoatk.c index 9399f602..ea5b7abe 100644 --- a/converter/pbm/pbmtoatk.c +++ b/converter/pbm/pbmtoatk.c @@ -118,63 +118,52 @@ process_atk_byte(int * const pcurcount, int -main(int argc, char *argv[]) { +main(int argc, const char ** argv) { - FILE *ifd; - bit *bitrow; - register bit *bP; - int rows, cols, format, row; - int col; - unsigned char curbyte, newbyte; - int curcount, gather; + FILE * ifP; + bit * bitrow; + int rows, cols, format; + unsigned int row; + unsigned char curbyte; + int curcount; - pbm_init ( &argc, argv ); + pm_proginit(&argc, argv); if (argc-1 > 1) pm_error("Too many arguments. Only argument is file name"); else if (argc-1 == 1) { - ifd = pm_openr( argv[1] ); + ifP = pm_openr(argv[1]); } else { - ifd = stdin; + ifP = stdin; } - pbm_readpbminit(ifd, &cols, &rows, &format); - bitrow = pbm_allocrow(cols); + pbm_readpbminit(ifP, &cols, &rows, &format); + bitrow = pbm_allocrow_packed(cols); - printf ("\\begindata{raster,%d}\n", 1); - printf ("%d %d %d %d ", RASTERVERSION, 0, DEFAULTSCALE, DEFAULTSCALE); - printf ("%d %d %d %d\n", 0, 0, cols, rows); /* subraster */ - printf ("bits %d %d %d\n", 1, cols, rows); + printf("\\begindata{raster,%d}\n", 1); + printf("%d %d %d %d ", RASTERVERSION, 0, DEFAULTSCALE, DEFAULTSCALE); + printf("%d %d %d %d\n", 0, 0, cols, rows); /* subraster */ + printf("bits %d %d %d\n", 1, cols, rows); for (row = 0; row < rows; ++row) { - pbm_readpbmrow(ifd, bitrow, cols, format); - bP = bitrow; - gather = 0; - newbyte = 0; - curbyte = 0; - curcount = 0; - col = 0; - while (col < cols) { - if (gather > 7) { - process_atk_byte (&curcount, &curbyte, stdout, newbyte, FALSE); - gather = 0; - newbyte = 0; - } - newbyte = (newbyte << 1) | (*bP++); - gather += 1; - col += 1; - } - - if (gather > 0) { - newbyte = (newbyte << (8 - gather)); - process_atk_byte (&curcount, &curbyte, stdout, newbyte, TRUE); + unsigned int const byteCt = pbm_packed_bytes(cols); + unsigned int i; + + pbm_readpbmrow_packed(ifP, bitrow, cols, format); + pbm_cleanrowend_packed(bitrow, cols); + + for (i = 0, curbyte = 0, curcount = 0; i < byteCt; ++i) { + process_atk_byte(&curcount, &curbyte, stdout, + bitrow[i], + i + 1 < byteCt ? FALSE : TRUE ); } } - pm_close( ifd ); + pbm_freerow_packed(bitrow); + pm_close(ifP); - printf ("\\enddata{raster, %d}\n", 1); + printf("\\enddata{raster, %d}\n", 1); return 0; } -- cgit 1.4.1