Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void store32(int value, char *buf)
- {
- buf[0] = (char) (value & 0x000000FF);
- value = value >> 8;
- buf[1] = (char) (value & 0x000000FF);
- value = value >> 8;
- buf[2] = (char) (value & 0x000000FF);
- value = value >> 8;
- buf[3] = (char) (value & 0x000000FF);
- }
- int main(int argc, char **argv)
- {
- char infilename[128];
- char outfilename[128];
- FILE *infile;
- FILE *outfile;
- char buf[128];
- short x_size, y_size;
- int x_size2, y_size2;
- int cells;
- char incell;
- int outcell;
- int x;
- infile = fopen(argv[1], "rb");
- outfile = fopen(argv[2], "wb");
- if (infile && outfile) {
- if (fread(&x_size, 1, 2, infile) == 2) {
- if (fread(&y_size, 1, 2, infile) == 2) {
- x_size2 = x_size;
- y_size2 = y_size;
- memset(buf, 0, 6);
- store32(x_size2, buf + 6);
- store32(y_size2, buf + 10);
- fwrite(buf, 1, 14, outfile);
- cells = x_size * y_size;
- for (x = 0; x < cells; x++) {
- memset(buf, 0, 16);
- fwrite(buf, 1, 16, outfile);
- fread(&incell, 1, 1, infile);
- outcell = incell;
- store32(outcell, buf);
- fwrite(buf, 1, 4, outfile);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement