Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4.  
  5. void store32(int value, char *buf)
  6. {
  7. buf[0] = (char) (value & 0x000000FF);
  8. value = value >> 8;
  9. buf[1] = (char) (value & 0x000000FF);
  10. value = value >> 8;
  11. buf[2] = (char) (value & 0x000000FF);
  12. value = value >> 8;
  13. buf[3] = (char) (value & 0x000000FF);
  14. }
  15.  
  16. int main(int argc, char **argv)
  17. {
  18. char infilename[128];
  19. char outfilename[128];
  20. FILE *infile;
  21. FILE *outfile;
  22. char buf[128];
  23. short x_size, y_size;
  24. int x_size2, y_size2;
  25. int cells;
  26. char incell;
  27. int outcell;
  28. int x;
  29.  
  30. infile = fopen(argv[1], "rb");
  31. outfile = fopen(argv[2], "wb");
  32.  
  33. if (infile && outfile) {
  34. if (fread(&x_size, 1, 2, infile) == 2) {
  35. if (fread(&y_size, 1, 2, infile) == 2) {
  36. x_size2 = x_size;
  37. y_size2 = y_size;
  38. memset(buf, 0, 6);
  39. store32(x_size2, buf + 6);
  40. store32(y_size2, buf + 10);
  41. fwrite(buf, 1, 14, outfile);
  42. cells = x_size * y_size;
  43. for (x = 0; x < cells; x++) {
  44. memset(buf, 0, 16);
  45. fwrite(buf, 1, 16, outfile);
  46. fread(&incell, 1, 1, infile);
  47. outcell = incell;
  48. store32(outcell, buf);
  49. fwrite(buf, 1, 4, outfile);
  50. }
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement