diff options
Diffstat (limited to 'converter/ppm/mtvtoppm.c')
-rw-r--r-- | converter/ppm/mtvtoppm.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/converter/ppm/mtvtoppm.c b/converter/ppm/mtvtoppm.c index e8558632..42f99428 100644 --- a/converter/ppm/mtvtoppm.c +++ b/converter/ppm/mtvtoppm.c @@ -30,39 +30,42 @@ main( argc, argv ) ppm_init( &argc, argv ); if ( argc > 2 ) - pm_usage( "[mtvfile]" ); + pm_usage( "[mtvfile]" ); if ( argc == 2 ) - ifp = pm_openr( argv[1] ); + ifp = pm_openr( argv[1] ); else - ifp = stdin; + ifp = stdin; /* Read in the MTV file. First the header. */ if ( fgets( line, MAXLINE, ifp ) == NULL ) - pm_error( "unable to read MTV file header" ); + pm_error( "unable to read MTV file header" ); if ( sscanf( line, "%d%d", &cols, &rows ) != 2 ) - pm_error( "unable to parse MTV file header" ); + pm_error( "unable to parse MTV file header" ); if ( cols <= 0 || rows <= 0 ) - pm_error( "invalid size: %d %d", cols, rows ); + pm_error( "invalid size: %d %d", cols, rows ); maxval = 255; ppm_writeppminit( stdout, cols, rows, maxval, 0 ); pixelrow = ppm_allocrow( cols ); for ( row = 0; row < rows; row++ ) - { - for ( col = 0, pP = pixelrow; col < cols; col++, pP++ ) - { - if ( fread( buf, sizeof(buf), 1, ifp ) != 1 ) - pm_error( "EOF / read error" ); - PPM_ASSIGN( *pP, buf[0], buf[1], buf[2] ); - } - ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 ); - } + { + for ( col = 0, pP = pixelrow; col < cols; col++, pP++ ) + { + if ( fread( buf, sizeof(buf), 1, ifp ) != 1 ) + pm_error( "EOF / read error" ); + PPM_ASSIGN( *pP, buf[0], buf[1], buf[2] ); + } + ppm_writeppmrow( stdout, pixelrow, cols, maxval, 0 ); + } pm_close( ifp ); pm_close( stdout ); exit( 0 ); } + + + |