|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdint.h> |
| 3 | +#include <stdlib.h> |
| 4 | +#include <string.h> |
| 5 | +typedef struct _BMPHeader { |
| 6 | + char BM[2]; |
| 7 | + uint32_t size; |
| 8 | + uint32_t reserve; |
| 9 | + uint32_t offset; |
| 10 | + uint32_t header_size; |
| 11 | + uint32_t width; |
| 12 | + uint32_t height; |
| 13 | + uint16_t planes; |
| 14 | + uint16_t bpp; |
| 15 | + uint32_t compression; |
| 16 | + uint32_t bitmap_size; |
| 17 | + uint32_t h_res; |
| 18 | + uint32_t v_res; |
| 19 | + uint32_t palette; |
| 20 | + uint32_t important; |
| 21 | +}__attribute__((__packed__)) Header; |
| 22 | +int main(int argc, char **argv) { |
| 23 | + FILE *pF[9]; |
| 24 | + char *filename = argv[1]; |
| 25 | + for ( int i=0; i<9; ++i ) { |
| 26 | + pF[i] = fopen(filename, "rb"); |
| 27 | + if ( pF[i] == NULL ) { |
| 28 | + printf("error! file %s doesn't exist.\n", filename); |
| 29 | + return 0; |
| 30 | + } |
| 31 | + } |
| 32 | + char output[11] = {'o', 'u', 't', 'p', 'u', 't', '.', 'b', 'm', 'p', '\0'}; |
| 33 | + FILE *pR = fopen(output, "wb"); |
| 34 | + Header H[9], res; |
| 35 | + printf("size of Herder %d\n", sizeof(Header)); |
| 36 | + for ( int i=0; i<9; ++i ) fread(H+i, sizeof(Header), 1, pF[i]); |
| 37 | + res = H[0]; |
| 38 | + res.height = H[0].height + H[3].height + H[6].height; |
| 39 | + res.width = H[0].width + H[1].width + H[2].width; |
| 40 | + res.bitmap_size = res.height*res.width*3+(res.width%4*res.height); |
| 41 | + res.size = res.bitmap_size + res.offset; |
| 42 | + fwrite(&res, sizeof(Header), 1, pR); |
| 43 | + for ( int i=2; i<9; i+=3 ) { |
| 44 | + for ( int j=0; j<H[i].height; ++j ) { |
| 45 | + for ( int k=0; k<3; ++k ) { |
| 46 | + uint8_t data[H[i-k].width*3]; |
| 47 | + fread(data, sizeof(uint8_t), H[i-k].width*3, pF[i-k]); |
| 48 | + fwrite(data, sizeof(uint8_t), H[i-k].width*3, pR); |
| 49 | + fseek(pF[i-k], H[i-k].width%4, SEEK_CUR); |
| 50 | + } |
| 51 | + uint8_t padding; |
| 52 | + for ( int k=0; k<res.width%4; ++k ) fwrite(&padding, sizeof(uint8_t), 1, pR); |
| 53 | + } |
| 54 | + } |
| 55 | + for ( int i=0; i<9; ++i ) fclose(pF[i]); |
| 56 | + fclose(pR); |
| 57 | + puts("done!"); |
| 58 | + return 0; |
| 59 | +} |
0 commit comments