#include #include #include #include #include "bitmap.h" using namespace std; int main (int argc, char **argv) { srand(451234); if (argc != 2) { printf ("Usage: %s [bmp file]\n", argv[0]); exit (1); } else { Image *InImage = (Image *) malloc(sizeof(Image)); ImageLoad(argv[1], InImage); ifstream fin(argv[1]); string sout(argv[1]); string rout = "r"; rout.append(sout); string gout = "g"; gout.append(sout); string bout = "b"; bout.append(sout); FILE *image; FILE *r_out; FILE *g_out; FILE *b_out; if ((image = fopen(argv[1], "rb"))==NULL) { printf("File Not Found : %s\n",argv[1]); return 0; } if ((r_out = fopen("outr.bmp", "w"))==NULL) { printf("File Creation error\n"); return 0; } if ((g_out = fopen("outg.bmp", "w"))==NULL) { printf("File Creation error\n"); return 0; } if ((b_out = fopen("outb.bmp", "w"))==NULL) { printf("File Creation error\n"); return 0; } char header; // grab the header and insert it into the other images for(int i = 0; i < 54; i++) { header = getc(image); fputc((char)header, r_out); fputc((char)header, g_out); fputc((char)header, b_out); } for(i = 0; i < (InImage->sizeX * InImage->sizeY); i++) { if((unsigned int)InImage->data[3 * i] >= 127) { char mike[9]; for(int c = 0; c < 9; c++) { mike[c] = rand() % 256; if((mike[c] == 13) || (mike[c] == 10)) mike[c]++; } fputc(mike[0], r_out); fputc(mike[1], r_out); fputc(mike[2], r_out); fputc(mike[3], g_out); fputc(mike[4], g_out); fputc(mike[5], g_out); fputc(mike[6], b_out); fputc(mike[7], b_out); fputc(mike[8], b_out); } else { int j, val1, val2, val3; int k; int choice = rand() % 3; switch(choice) { case 0: for(j = 0; j < 3; j++) { val1 = rand() % 256; if((val1 == 13) || (val1 == 10)) val1 = 14; val2 = rand() % (256 - val1); if((val2 == 13) || (val2 == 10)) val2 = 14; val3 = 255 - (val1 + val2); if((val3 == 13) || (val3 == 10)) val3 = 14; k = fputc( val1, r_out); k = fputc( val2, g_out); k = fputc( val3, b_out); } break; case 1: for(j = 0; j < 3; j++) { val1 = rand() % 256; if((val1 == 13) || (val1 == 10)) val1 = 14; val2 = rand() % (256 - val1); if((val2 == 13) || (val2 == 10)) val2 = 14; val3 = 255 - (val1 + val2); if((val3 == 13) || (val3 == 10)) val3 = 14; k = fputc( val1, g_out); k = fputc( val2, b_out); k = fputc( val3, r_out); } break; case 2: for(j = 0; j < 3; j++) { val1 = rand() % 256; if((val1 == 13) || (val1 == 10)) val1 = 14; val2 = rand() % (256 - val1); if((val2 == 13) || (val2 == 10)) val2 = 14; val3 = 255 - (val1 + val2); if((val3 == 13) || (val3 == 10)) val3 = 14; k = fputc( val1, b_out); k = fputc( val2, r_out); k = fputc( val3, g_out); } break; } } } } return 1; }