Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct _color_table {
- unsigned char R;
- unsigned char G;
- unsigned char B;
- } _color_table;
- int search_pattern(FILE *INput) {
- char pattern[11] = { 0x06, 'c', 'o', 'l', 'o', 'r', 's', 0x00, 0x00, 0x40, 0x00 };
- char get_pattern[11] = { 0 };
- while (fread(&get_pattern,sizeof(char),11,INput)) {
- if (feof(INput)) {
- break;
- }
- if (!strcmp(get_pattern,pattern)) {
- return 1;
- }
- fseek(INput, -10, SEEK_CUR);
- }
- return 0;
- }
- int main(int argc, char **argv) {
- unsigned char BMP_HEADER[54] = { 0x42, 0x4D, 0x36, 0xC0, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
- 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0xC4, 0x0E,
- 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- _color_table color_table[] = {
- { 0, 0, 0}, // 0 NONE
- { 127, 178, 56 }, // 1 GRASS
- { 247, 233, 163 }, // 2 SAND
- { 199, 199, 199 }, // 3 WOOL
- { 255, 0, 0 }, // 4 FIRE
- { 160, 160, 255 }, // 5 ICE
- { 167, 167, 167 }, // 6 METAL
- { 0, 124, 0 }, // 7 PLANT
- { 255, 255, 255 }, // 8 SNOW
- { 164, 168, 184 }, // 9 CLAY
- { 151, 109, 77 }, // 10 DIRT
- { 112, 112, 112 }, // 11 STONE
- { 64, 64, 255 }, // 12 WATER
- { 143, 119, 72 }, // 13 WOOD
- { 255, 252, 245 }, // 14 QUARTZ
- { 216, 127, 51 }, // 15 COLOR_ORANGE
- { 178, 76, 216 }, // 16 COLOR_MAGENTA
- { 102, 153, 216 }, // 17 COLOR_LIGHT_BLUE
- { 229, 229, 51 }, // 18 COLOR_YELLOW
- { 127, 204, 25 }, // 19 COLOR_LIGHT_GREEN
- { 242, 127, 165 }, // 20 COLOR_PING
- { 76, 76, 76 }, // 21 COLOR_GRAY
- { 153, 153, 153 }, // 22 COLOR_LIGHT_GRAY
- { 76, 127, 153 }, // 23 COLOR_CYAN
- { 127, 63, 178 }, // 24 COLOR_PURPLE
- { 51, 76, 178 }, // 25 COLOR_BLUE
- { 102, 76, 51 }, // 26 COLOR_BROWN
- { 102, 127, 51 }, // 27 COLOR_GREEN
- { 153, 51, 51 }, // 28 COLOR_RED
- { 25, 25, 25 }, // 29 COLOR_BLACK
- { 250, 238, 77 }, // 30 GOLD
- { 92, 219, 213 }, // 31 DIAMOND
- { 74, 128, 255 }, // 32 LAPIS
- { 0, 217, 58 }, // 33 EMERALD
- { 129, 86, 49 }, // 34 PODZOL
- { 112, 2, 0 }, // 35 NETHER
- { 209, 177, 161 }, // 36 TERRACOTTA_WHIE
- { 159, 82, 36 }, // 37 TERRACOTTA_ORANGE
- { 149, 87, 108 }, // 38 TERRACOTTA_MAGENTA
- { 112, 108, 138 }, // 39 TERRACOTTA_LIGHT_BLUE
- { 186, 133, 36 }, // 40 TERRACOTTA_YELLOW
- { 103, 117, 53 }, // 41 TERRACOTTA_LIGHT_GREEN
- { 160, 77, 78 }, // 42 TERRACOTTA_PINK
- { 57, 41, 35 }, // 43 TERRACOTTA_GRAY
- { 135, 107, 98 }, // 44 TERRACOTTA_LIGHT_GRAY
- { 87, 92, 92 }, // 45 TERRACOTTA_CYAN
- { 122, 73, 88 }, // 46 TERRACOTTA_PURPLE
- { 76, 62, 92 }, // 47 TERRACOTTA_BLUE
- { 76, 50, 35 }, // 48 TERRACOTTA_BROWN
- { 76, 82, 42 }, // 49 TERRACOTTA_GREEN
- { 142, 60, 46 }, // 50 TERRACOTTA_RED
- { 37, 22, 16 } // 51 TERRACOTTA_BLACK
- };
- unsigned char colors[16384] = { 0 };
- FILE *INput = NULL;
- FILE *OUTput = NULL;
- unsigned int shade_ID = 0;
- unsigned int base_color_ID = 0;
- int i = 0;
- int j = 0;
- char output[256] = { 0 };
- strcpy(output, argv[1]);
- strcat(output, ".bmp");
- INput = fopen(argv[1],"rb");
- if (INput == NULL) {
- printf("Could not open: %s\n",argv[1]);
- return -1;
- }
- if (search_pattern(INput)) {
- printf("Pattern found\n");
- }
- else {
- printf("Pattern not found\n");
- fclose(INput);
- return -1;
- }
- fread(&colors,sizeof(char),16384,INput);
- fclose(INput);
- OUTput = fopen(output,"wb");
- if (OUTput == NULL) {
- printf("Could not open: %s\n",output);
- return -1;
- }
- fwrite(BMP_HEADER, sizeof(char),54,OUTput);
- j = 127;
- while (j >= 0) {
- i = 128*j;
- while (i < 128*(j+1)){
- base_color_ID = colors[i]/4;
- shade_ID = colors[i]%4;
- switch (shade_ID) {
- case 0 :
- fputc((color_table[base_color_ID].B*180)/255, OUTput);
- fputc((color_table[base_color_ID].G*180)/255, OUTput);
- fputc((color_table[base_color_ID].R*180)/255, OUTput);
- break;
- case 1 :
- fputc((color_table[base_color_ID].B*220)/255, OUTput);
- fputc((color_table[base_color_ID].G*220)/255, OUTput);
- fputc((color_table[base_color_ID].R*220)/255, OUTput);
- break;
- case 2 :
- fputc((color_table[base_color_ID].B*255)/255, OUTput);
- fputc((color_table[base_color_ID].G*255)/255, OUTput);
- fputc((color_table[base_color_ID].R*255)/255, OUTput);
- break;
- case 3 :
- fputc((color_table[base_color_ID].B*135)/255, OUTput);
- fputc((color_table[base_color_ID].G*135)/255, OUTput);
- fputc((color_table[base_color_ID].R*135)/255, OUTput);
- break;
- }
- i++;
- }
- j--;
- }
- fclose(OUTput);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement