/* ppmtomptool.c - generates a MPEGTool format RGB file from a PPM file ( Hacked by minor modifications to ppmtorgb3.c. Not the most efficient way to do things but it works. New append mode added to make it easier to generate sequences of images - Pramod ) ** ** 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" #include "pgm.h" FILE *pm_opena(); FILE* pm_opena( name ) char* name; { FILE* f; #ifdef MSDOS f = fopen( name, "wb" ); #else /*MSDOS*/ f = fopen( name, "a+" ); #endif /*MSDOS*/ if ( f == NULL ) { pm_perror( name ); exit( 1 ); } return f; } void main( argc, argv ) int argc; char* argv[]; { FILE* ifp; FILE* file; int i; char* basename; char filename[100]; char* cp; pixel* pixelrow; register pixel* pP; gray** grayrow; register gray* gP; int rows, cols, format, row; register int col; pixval maxval; ppm_init( &argc, argv ); if ( argc == 2 || argc > 3 ) pm_usage( "[ppmfile mptoolfile]" ); if ( argc == 3 ) { ifp = pm_openr( argv[1] ); basename = argv[2]; } else { ifp = stdin; basename = "noname"; } ppm_readppminit( ifp, &cols, &rows, &maxval, &format ); pixelrow = ppm_allocrow( cols ); (void) strcpy( filename, basename ); (void) strcat( filename, ".mpt"); file = pm_opena( filename ); grayrow = (gray **)malloc(rows*3*sizeof(struct gray *)); for (i=0; i < rows*3; i++) grayrow[i] = pgm_allocrow( cols ); for ( row = 0; row < rows; ++row ) { ppm_readppmrow( ifp, pixelrow, cols, maxval, format ); for ( col = 0, pP = pixelrow, gP = grayrow[row]; col < cols; ++col, ++pP, ++gP ) *gP = (gray) PPM_GETR( *pP ); for ( col = 0, pP = pixelrow, gP = grayrow[row + rows]; col < cols; ++col, ++pP, ++gP ) *gP = (gray) PPM_GETG( *pP ); for ( col = 0, pP = pixelrow, gP = grayrow[row + 2*rows]; col < cols; ++col, ++pP, ++gP ) *gP = (gray) PPM_GETB( *pP ); } for ( i = 0; i < rows*3; i++) pgm_writepgmrow( file, grayrow[i], cols, maxval, 0 ); pm_close( ifp ); pm_close( file ); exit( 0 ); }