#include #include #include "EasyBMP.h" #define B(a) ( a > 125 ? 1 : 0 ) using namespace std; char hex(int a, int b, int c, int d) { if ( a == 0 && b == 0 && c == 0 && d == 0 ) { return '0'; } else if ( a == 0 && b == 0 && c == 0 && d == 1 ) { return '1'; } else if ( a == 0 && b == 0 && c == 1 && d == 0 ) { return '2'; } else if ( a == 0 && b == 0 && c == 1 && d == 1 ) { return '3'; } else if ( a == 0 && b == 1 && c == 0 && d == 0 ) { return '4'; } else if ( a == 0 && b == 1 && c == 0 && d == 1 ) { return '5'; } else if ( a == 0 && b == 1 && c == 1 && d == 0 ) { return '6'; } else if ( a == 0 && b == 1 && c == 1 && d == 1 ) { return '7'; } else if ( a == 1 && b == 0 && c == 0 && d == 0 ) { return '8'; } else if ( a == 1 && b == 0 && c == 0 && d == 1 ) { return '9'; } else if ( a == 1 && b == 0 && c == 1 && d == 0 ) { return 'A'; } else if ( a == 1 && b == 0 && c == 1 && d == 1 ) { return 'B'; } else if ( a == 1 && b == 1 && c == 0 && d == 0 ) { return 'C'; } else if ( a == 1 && b == 1 && c == 0 && d == 1 ) { return 'D'; } else if ( a == 1 && b == 1 && c == 1 && d == 0 ) { return 'E'; } else if ( a == 1 && b == 1 && c == 1 && d == 1 ) { return 'F'; } else return'0'; } char binary(int a) { if(a == 1) {return '1';} else {return '0';} } int main( int argc, char* argv[] ) { cout << "Begining to parce the BMP file" << endl; //Open the bmp image - My need to change BMP Image; Image.ReadFromFile( "color_640by480.bmp" ); //Output hex compresses file ofstream rgbfile; rgbfile.open ("RGB_Values.rgb"); //Output the bits separately ofstream rfile; rfile.open ("R_Values.r"); ofstream gfile; gfile.open ("G_Values.g"); ofstream bfile; bfile.open ("B_Values.b"); //For the entire image for( int j = 0 ; j < Image.TellHeight() ; j++ ) { for( int i = 0; i < Image.TellWidth() ; i+=1 ) { //RGB text file compresses the RGB values to HEX rgbfile << hex ( 0, B( (int) Image(i,j)->Blue), B( (int) Image(i,j)->Green), B( (int) Image(i,j)->Red) ); //Create individual RGB values rfile << binary( B( (int) Image(i,j)->Red)); gfile << binary( B( (int) Image(i,j)->Green)); bfile << binary( B( (int) Image(i,j)->Blue)); } } rgbfile << endl << Image.TellHeight() << endl; rfile << endl << Image.TellHeight() << endl; gfile << endl << Image.TellHeight() << endl; bfile << endl << Image.TellHeight() << endl; cout << Image.TellHeight() << endl; //Close all files rgbfile.close(); rfile.close(); gfile.close(); bfile.close(); cout << "Parced BMP file done. Check: RGB_Values.rgb R_Values.r G_Values.g B_Values.b" << endl; return 0; }