diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2006-08-19 03:12:28 +0000 |
commit | 1fd361a1ea06e44286c213ca1f814f49306fdc43 (patch) | |
tree | 64c8c96cf54d8718847339a403e5e67b922e8c3f /converter/ppm/rgb3toppm.c | |
download | netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.gz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.tar.xz netpbm-mirror-1fd361a1ea06e44286c213ca1f814f49306fdc43.zip |
Create Subversion repository
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm/rgb3toppm.c')
-rw-r--r-- | converter/ppm/rgb3toppm.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/converter/ppm/rgb3toppm.c b/converter/ppm/rgb3toppm.c new file mode 100644 index 00000000..a666553c --- /dev/null +++ b/converter/ppm/rgb3toppm.c @@ -0,0 +1,88 @@ +/* rgb3toppm - combine three portable graymaps into one portable pixmap +** +** Copyright (C) 1991 by Jef Poskanzer. +** +** Permission to use, copy, modify, and distribute this software and its +** documentation for any purpose and without fee is hereby granted, provided +** that the above copyright notice appear in all copies and that both that +** copyright notice and this permission notice appear in supporting +** documentation. This software is provided "as is" without express or +** implied warranty. +*/ + +#include "ppm.h" + +int +main( argc, argv ) + int argc; + char* argv[]; + { + FILE* rfd; + FILE* gfd; + FILE* bfd; + gray* rrow; + gray* rP; + gray* grow; + gray* gP; + gray* brow; + gray* bP; + pixel* pixelrow; + register pixel* pP; + int rows, cols, trows, tcols, row, col; + gray rmaxval, gmaxval, bmaxval; + int rformat, gformat, bformat; + pixval pmaxval; + + + ppm_init( &argc, argv ); + + if ( argc != 4 ) + pm_usage( "<red pgmfile> <green pgmfile> <blue pgmfile> " ); + + rfd = pm_openr( argv[1] ); + gfd = pm_openr( argv[2] ); + bfd = pm_openr( argv[3] ); + + pgm_readpgminit( rfd, &cols, &rows, &rmaxval, &rformat ); + pgm_readpgminit( gfd, &tcols, &trows, &gmaxval, &gformat ); + if ( tcols != cols || trows != rows ) + pm_error( "all three graymaps must be the same size" ); + pgm_readpgminit( bfd, &tcols, &trows, &bmaxval, &bformat ); + if ( tcols != cols || trows != rows ) + pm_error( "all three graymaps must be the same size" ); + + pmaxval = rmaxval; + if ( gmaxval > pmaxval ) pmaxval = gmaxval; + if ( bmaxval > pmaxval ) pmaxval = bmaxval; + rrow = pgm_allocrow( cols ); + grow = pgm_allocrow( cols ); + brow = pgm_allocrow( cols ); + + ppm_writeppminit( stdout, cols, rows, pmaxval, 0 ); + pixelrow = ppm_allocrow( cols ); + + for ( row = 0; row < rows; row++ ) + { + pgm_readpgmrow( rfd, rrow, cols, rmaxval, rformat ); + pgm_readpgmrow( gfd, grow, cols, gmaxval, gformat ); + pgm_readpgmrow( bfd, brow, cols, bmaxval, bformat ); + + for ( col = 0, rP = rrow, gP = grow, bP = brow, pP = pixelrow; + col < cols; + ++col, ++rP, ++gP, ++bP, ++pP ) + { + if ( rmaxval != pmaxval ) *rP = (int) *rP * pmaxval / rmaxval; + if ( gmaxval != pmaxval ) *gP = (int) *gP * pmaxval / gmaxval; + if ( bmaxval != pmaxval ) *bP = (int) *bP * pmaxval / bmaxval; + PPM_ASSIGN( *pP, *rP, *gP, *bP ); + } + ppm_writeppmrow( stdout, pixelrow, cols, pmaxval, 0 ); + } + + pm_close( rfd ); + pm_close( gfd ); + pm_close( bfd ); + pm_close( stdout ); + + exit( 0 ); + } |