/* * BMP -> PNG ファイル変換ユーティリティ * bmp2png.c 2000.02 J.Baba * * libpng および zlib ライブラリを使用 * */ #include #include #include "png.h" #include "bmplib.h" #define MAX_PATH 270 int main( int argc, char *argv[] ) { char * w_ptr; FILE * fp; char inpfile[ MAX_PATH ]; char outfile[ MAX_PATH ]; DIB dib; if( argc < 2 ) { printf( "\n\t>bmp2png input_file[.bmp] [output_file[.png]]\n\n"); printf("%s",png_get_copyright(NULL)); exit(0); } // ファイル名の操作 strcpy( inpfile, argv[1] ); if( ( w_ptr = strchr( inpfile, '.' ) ) == 0 ) strcat( inpfile, ".bmp" ); if( argc < 3 ) { strcpy( outfile, inpfile ); if( w_ptr = strchr( outfile, '.' ) ) *w_ptr = 0; } else strcpy( inpfile, argv[2] ); if( ( w_ptr = strchr( outfile, '.' ) ) == 0 ) strcat( outfile, ".png" ); if( ( fp = fopen( inpfile, "rb" ) ) == NULL ) { printf( "input file (%s) not open!\n", inpfile ); exit(1); } // BMP ファイルを読み、DIB を作成 if( ( dib = bmp_read_dib_file( fp ) ) == NULL ) { printf( "BMP file read error!\n" ); exit(1); } fclose( fp ); if( ( fp = fopen( outfile, "wb" ) ) == 0 ) { printf( "Write file(%s) open error!\n", outfile ); exit(1); } // PNG ファイルの書き出し if( png_save_dib_file( fp, dib ) == FALSE ) { fclose( fp ); printf( "Write file(%s) open error!\n", outfile ); exit(1); } free( dib ); fclose( fp ); }