Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <string.h>
  6. #include <direct.h>
  7. #include <stdlib.h>
  8. #pragma pack(push, 1)
  9.  
  10. struct BITMAPFILEHEADER
  11. {
  12. unsigned char b1,b2;
  13. unsigned long bfSize;
  14. unsigned short bfReserved1;
  15. unsigned short bfReserved2;
  16. unsigned long bfOffBits;
  17. unsigned long headerLength; // Длинна этого заголовка (4 байта)
  18. unsigned long width; // Ширина изображения (4 байта)
  19. unsigned long height; // Высота изображения (4 байта)
  20. unsigned short colorPlaneNumber; // Число цветовых плоскостей (2 байта)
  21. unsigned short bitPixel; // Бит/пиксель (2 байта)
  22. unsigned long compressMethod; // Метод сжатия (4 байта)
  23. unsigned long massLength; // Длинна массива с мусоро (4 байта)
  24. unsigned long massWidth; // Ширина массива с мусором (4 байта)
  25. unsigned long massHeight; // Высота массива с мусором (4 байта)
  26. unsigned long colorNumber; // Число цветов изображения (4 байта)
  27. unsigned long generalColorNumber; // Число основных цветов (4 байта)
  28. };
  29.  
  30. #pragma pack(pop)
  31.  
  32. int counter, i, j, ch, x, df;
  33. int** img, cpy;
  34. FILE* f, fout;
  35. int main(int argc, char* argv[])
  36. {
  37. char* dir;
  38. for (i = 1; i < argc; i++)
  39. {
  40. if (strcmp(argv[i],"--input")==0)
  41. f = fopen(argv[i+1],"rb");
  42. if (strcmp(argv[i],"--output")==0)
  43. {
  44. dir = argv[i+1];
  45. mkdir(dir);
  46. }
  47. if (strcmp(argv[i],"--max_iter")==0)
  48. counter = strtol(argv[i+1],0,10);
  49. if (strcmp(argv[i],"--dump_freq")==0)
  50. df = strtol(argv[i+1], 0, 10);
  51. }
  52. if (f == NULL)
  53. {
  54. printf("I really just wonna die");
  55. return 1;
  56. }
  57. char* filename;
  58. struct BITMAPFILEHEADER aa;
  59. FILE* cartonka = fopen("sheet.bmp", "wb");
  60. fread(&aa, sizeof(aa), 1, f);
  61. fwrite(&aa, sizeof(aa), 1, cartonka);
  62. printf("%i %u %d \n", sizeof(aa), aa.width, aa.height);
  63. img = (int**)malloc(aa.height * sizeof(int*));
  64. for(i = 0; i < aa.height; i++)
  65. img[i] = (unsigned char*)malloc(aa.width * sizeof(int*));
  66. printf("aa.width=%d aa.height=%d\n", aa.width, aa.height);
  67. for (i = 0; i < aa.height; i++)
  68. for (j = 0; j < aa.width; j++)
  69. fread(&img[i][j], sizeof(int), 1, f);
  70. fclose(f);
  71. printf("111\n");
  72. while (ch != counter)
  73. {
  74. cpy = img;
  75. for (i = 0; i < aa.height; i++)
  76. {
  77. for (j = 0; j < aa.width; j++)
  78. {
  79. fwrite(&img[i][j], sizeof(img[i][j]), 1, cartonka);
  80. printf("%d ", img[i][j]);
  81. }
  82. printf("\n");
  83. }
  84. fclose(cartonka);
  85. printf("ASASASAS");
  86. /* for(i = 0; i < aa.width; i++)
  87. for (j = 0; j < aa.height; j++)
  88. cpy = img[i][j]; */
  89. /* for (i = 0; i < aa.width; i++)
  90. for (j = 0; j < aa.height; j++)
  91. {
  92. int sc = 0;
  93. if ((i > 0) && (cpy[i-1][j] == 255))
  94. sc++;
  95. if ((i > 0) && (j > 0) && (cpy[i-1][j-1] == 255))
  96. sc++;
  97. if ((i < aa.width - 1) && (cpy[i+1][j] == 255))
  98. sc++;
  99. if ((j < aa.height - 1) && (cpy[i][j+1] == 255))
  100. sc++;
  101. if ((j < aa.height - 1) && (i < aa.width - 1) && (cpy[i+1][j+1] == 255))
  102. sc++;
  103. if ((i > 0) && (j < aa.height - 1) && (cpy[i-1][j+1] == 255))
  104. sc++;
  105. if ((j > 0) && (i < aa.width - 1) && (cpy[i+1][j-1] == 255))
  106. sc++;
  107. x = sc;
  108. if (x == 3)
  109. img[i][j] = 255;
  110. if ((x < 2) || (x > 3))
  111. img[i][j] = 0;
  112. } */
  113. printf("ch=%d counter=%d df=%d\n", ch, counter, df);
  114. ch++;
  115. if ((ch % df == 0) && (ch != 0))
  116. {
  117. char* way = dir;
  118. strcat(dir, "\\");
  119. printf("%s\n", dir);
  120. // printf("ch=%d counter=%d df=%d\n", ch, counter, df);
  121. filename = itoa(ch, filename, 10);
  122. printf("HUY\n");
  123. strcat(way, filename);
  124. printf("AGDSGF");
  125. strcat(way, ".bmp");
  126. printf("SOOOOS\n");
  127. printf("%s", way);
  128. FILE* OU = fopen(way, "wb");
  129. printf(way, "\n");
  130. fwrite(&aa, sizeof(aa), 1, OU);
  131. for (i = 0; i < aa.width; i++)
  132. for (j = 0; j < aa.height; j++)
  133. fwrite(&img[i][j], sizeof(img[i][j]), 1, OU);
  134. fclose(OU);
  135. }
  136.  
  137. }
  138. free(img);
  139. free(cpy);
  140. return 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement