/* ** bmt2bmp.c - BMT to BMP format conversion program ** ** File created: 6/26/2000 ** Last revision: 8/10/2000 ** ** Copyright (C) 2000 Sean R. Wells ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ** */ #include #include #define MAKE_BMP #define X_AXIS 96 #define Y_AXIS 48 #define BMT_SIZE ( ( X_AXIS * Y_AXIS ) / 8 ) int WriteBMPHeader ( FILE *outfile ) { int i; int bmp_header[70] = { 0x42, 0x4d, /* BM - Indicates bmp */ 0x7a, 0x02, 0x00, 0x00, /* Size of file (in bytes) */ 0x00, 0x00, 0x00, 0x00, /* Reserved */ 0x3e, 0x00, 0x00, 0x00, /* Offset to bmp data */ 0x28, 0x00, 0x00, 0x00, /* Length of header */ 0x60, 0x00, 0x00, 0x00, /* Width (in pixels) */ 0x30, 0x00, 0x00, 0x00, /* Height (in pixels) */ 0x01, 0x00, /* Planes */ 0x01, 0x00, /* Bits per pixel */ 0x00, 0x00, 0x00, 0x00, /* Compression */ 0x40, 0x02, 0x00, 0x00, /* Side of data (in bytes) */ 0x00, 0x00, 0x00, 0x00, /* Horizontal resolution */ 0x00, 0x00, 0x00, 0x00, /* Vertical resolution */ 0x00, 0x00, 0x00, 0x00, /* Colors */ 0x00, 0x00, 0x00, 0x00, /* Important colors */ 0xff, 0xff, 0xff, 0xff, /* Palette (white) */ 0x00, 0x00, 0x00, 0x00 /* Palette (black) */ }; int bmp_header_len = 62; for ( i = 0; i < bmp_header_len; i++ ) { fprintf ( outfile, "%c", ( char ) bmp_header[i] ); } return ( 0 ); } int ReadBMTData ( FILE *infile, char bitmap[] ) { int i; for ( i = 0; i < BMT_SIZE; i++ ) { bitmap[i] = getc ( infile ); } return ( 0 ); } int BitmapFlip ( char bitmap[] ) { int line_count; int byte_count; int in_position; int out_position; char out_bitmap[BMT_SIZE]; for ( line_count = 0; line_count < Y_AXIS; line_count++ ) { for ( byte_count = 0; byte_count < X_AXIS / 8; byte_count++ ) { in_position = BMT_SIZE - ( line_count * X_AXIS / 8 ) + byte_count - X_AXIS / 8; out_position = ( line_count * X_AXIS / 8 ) + byte_count; out_bitmap[out_position] = bitmap[in_position]; } } for ( byte_count = 0; byte_count < BMT_SIZE; byte_count++ ) { bitmap[byte_count] = out_bitmap[byte_count]; } return ( 0 ); } int WriteBMPData ( FILE *outfile, char bitmap[] ) { int i; for ( i = 0; i < BMT_SIZE; i++ ) { fprintf ( outfile, "%c", ( char ) bitmap[i] ); } return ( 0 ); } int ConvertBMTData ( char in_bitmap[] ) { int byte_count; int bit_count; int in_position; int out_position; int line_count; char out_bitmap[BMT_SIZE]; for ( byte_count = 0; byte_count < BMT_SIZE; byte_count++ ) { out_bitmap[byte_count] = 0; } for ( line_count = 0; line_count < Y_AXIS / 8; line_count++ ) { for ( byte_count = 0; byte_count < X_AXIS; byte_count++ ) { for ( bit_count = 0; bit_count < 8; bit_count++ ) { in_position = byte_count + ( line_count * X_AXIS ); out_position = ( X_AXIS / 8 * bit_count ) + ( byte_count / 8 ) + ( line_count * X_AXIS ); if ( ( ( in_bitmap[in_position] >> bit_count ) & 0x01 ) == 0 ) { out_bitmap[out_position] = ( out_bitmap[out_position] & ( int ) ( 0xff - pow ( 2 , ( 7 - byte_count % 8 ) ) ) ); } else { out_bitmap[out_position] = ( out_bitmap[out_position] | ( int ) pow ( 2, ( 7 - byte_count % 8 ) ) ); } } } } #ifdef MAKE_BMP BitmapFlip ( out_bitmap ); #endif for ( byte_count = 0; byte_count < BMT_SIZE; byte_count++ ) { in_bitmap[byte_count] = out_bitmap[byte_count]; } return ( 0 ); } int main ( argc, argv ) int argc; char **argv; { FILE *infile; FILE *outfile; char bitmap [BMT_SIZE]; if ( argc < 3 ) { fprintf ( stderr, "bmt2bmp version 1.0b Copyright (C) 2000 Sean R. Wells\n" ); fprintf ( stderr, "Usage: bmt2bmp \n" ); return ( 0 ); } infile = fopen ( argv[1], "rb" ); if ( !infile ) { fprintf ( stderr, "ERROR - Could not open input file\n" ); return ( 0 ); } ReadBMTData ( infile, bitmap ); fclose ( infile ); outfile = fopen ( argv[2], "wb" ); if ( !outfile ) { fprintf ( stderr, "ERROR - Could not open output file\n" ); return ( 0 ); } #ifdef MAKE_BMP WriteBMPHeader ( outfile ); #endif ConvertBMTData ( bitmap ); WriteBMPData ( outfile, bitmap ); fclose ( outfile ); return ( 0 ); }