diff options
Diffstat (limited to 'converter/pgm/pgmtofs.c')
-rw-r--r-- | converter/pgm/pgmtofs.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/converter/pgm/pgmtofs.c b/converter/pgm/pgmtofs.c index 53a2e7b3..8780b35a 100644 --- a/converter/pgm/pgmtofs.c +++ b/converter/pgm/pgmtofs.c @@ -35,14 +35,14 @@ main( argc, argv ) argn = 1; if ( argn < argc ) - { + { ifp = pm_openr( argv[argn] ); ++argn; - } + } else - { + { ifp = stdin; - } + } if ( argn != argc ) pm_usage( usage ); @@ -60,19 +60,19 @@ main( argc, argv ) pm_error( "maxval of %d is too large for FaceSaver(tm)", maxval ); nmaxval = pm_bitstomaxval( bps ); - + /* Compute padding to round cols * bps up to the nearest multiple of 8. */ padright = ( ( cols * bps + 7 ) / 8 ) * 8 - cols * bps; putinit( cols, rows, bps ); for ( row = rows - 1; row >= 0; --row ) - { + { for ( col = 0, gP = grays[row]; col < cols; ++col, ++gP ) - { + { if ( maxval != nmaxval ) *gP = (int) *gP * nmaxval / maxval; putgray( *gP ); - } + } for ( col = 0; col < padright; ++col ) putgray( 0 ); } @@ -83,6 +83,7 @@ main( argc, argv ) } + static int bitspersample, item, bitsperitem, bitshift, itemsperline, items; static void @@ -109,16 +110,18 @@ putinit( cols, rows, bps ) bitshift = 8 - bitspersample; } + + static void putitem( ) { const char* const hexits = "0123456789abcdef"; if ( itemsperline == 30 ) - { + { putchar( '\n' ); itemsperline = 0; - } + } putchar( hexits[item >> 4] ); putchar( hexits[item & 15] ); ++itemsperline; @@ -128,6 +131,8 @@ putitem( ) bitshift = 8 - bitspersample; } + + static void putgray( gray g ) { @@ -138,6 +143,8 @@ putgray( gray g ) bitshift -= bitspersample; } + + static void putrest( ) { @@ -145,3 +152,6 @@ putrest( ) putitem( ); printf( "\n" ); } + + + |