Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- #include <direct.h>
- #include <stdlib.h>
- #pragma pack(push, 1)
- struct BITMAPFILEHEADER
- {
- unsigned char b1,b2;
- unsigned long bfSize;
- unsigned short bfReserved1;
- unsigned short bfReserved2;
- unsigned long bfOffBits;
- unsigned long headerLength; // Длинна этого заголовка (4 байта)
- unsigned long width; // Ширина изображения (4 байта)
- unsigned long height; // Высота изображения (4 байта)
- unsigned short colorPlaneNumber; // Число цветовых плоскостей (2 байта)
- unsigned short bitPixel; // Бит/пиксель (2 байта)
- unsigned long compressMethod; // Метод сжатия (4 байта)
- unsigned long massLength; // Длинна массива с мусоро (4 байта)
- unsigned long massWidth; // Ширина массива с мусором (4 байта)
- unsigned long massHeight; // Высота массива с мусором (4 байта)
- unsigned long colorNumber; // Число цветов изображения (4 байта)
- unsigned long generalColorNumber; // Число основных цветов (4 байта)
- };
- #pragma pack(pop)
- int counter, i, j, ch, x, df;
- int** img, cpy;
- FILE* f, fout;
- int main(int argc, char* argv[])
- {
- char* dir;
- for (i = 1; i < argc; i++)
- {
- if (strcmp(argv[i],"--input")==0)
- f = fopen(argv[i+1],"rb");
- if (strcmp(argv[i],"--output")==0)
- {
- dir = argv[i+1];
- mkdir(dir);
- }
- if (strcmp(argv[i],"--max_iter")==0)
- counter = strtol(argv[i+1],0,10);
- if (strcmp(argv[i],"--dump_freq")==0)
- df = strtol(argv[i+1], 0, 10);
- }
- if (f == NULL)
- {
- printf("I really just wonna die");
- return 1;
- }
- char* filename;
- struct BITMAPFILEHEADER aa;
- FILE* cartonka = fopen("sheet.bmp", "wb");
- fread(&aa, sizeof(aa), 1, f);
- fwrite(&aa, sizeof(aa), 1, cartonka);
- printf("%i %u %d \n", sizeof(aa), aa.width, aa.height);
- img = (int**)malloc(aa.height * sizeof(int*));
- for(i = 0; i < aa.height; i++)
- img[i] = (unsigned char*)malloc(aa.width * sizeof(int*));
- printf("aa.width=%d aa.height=%d\n", aa.width, aa.height);
- for (i = 0; i < aa.height; i++)
- for (j = 0; j < aa.width; j++)
- fread(&img[i][j], sizeof(int), 1, f);
- fclose(f);
- printf("111\n");
- while (ch != counter)
- {
- cpy = img;
- for (i = 0; i < aa.height; i++)
- {
- for (j = 0; j < aa.width; j++)
- {
- fwrite(&img[i][j], sizeof(img[i][j]), 1, cartonka);
- printf("%d ", img[i][j]);
- }
- printf("\n");
- }
- fclose(cartonka);
- printf("ASASASAS");
- /* for(i = 0; i < aa.width; i++)
- for (j = 0; j < aa.height; j++)
- cpy = img[i][j]; */
- /* for (i = 0; i < aa.width; i++)
- for (j = 0; j < aa.height; j++)
- {
- int sc = 0;
- if ((i > 0) && (cpy[i-1][j] == 255))
- sc++;
- if ((i > 0) && (j > 0) && (cpy[i-1][j-1] == 255))
- sc++;
- if ((i < aa.width - 1) && (cpy[i+1][j] == 255))
- sc++;
- if ((j < aa.height - 1) && (cpy[i][j+1] == 255))
- sc++;
- if ((j < aa.height - 1) && (i < aa.width - 1) && (cpy[i+1][j+1] == 255))
- sc++;
- if ((i > 0) && (j < aa.height - 1) && (cpy[i-1][j+1] == 255))
- sc++;
- if ((j > 0) && (i < aa.width - 1) && (cpy[i+1][j-1] == 255))
- sc++;
- x = sc;
- if (x == 3)
- img[i][j] = 255;
- if ((x < 2) || (x > 3))
- img[i][j] = 0;
- } */
- printf("ch=%d counter=%d df=%d\n", ch, counter, df);
- ch++;
- if ((ch % df == 0) && (ch != 0))
- {
- char* way = dir;
- strcat(dir, "\\");
- printf("%s\n", dir);
- // printf("ch=%d counter=%d df=%d\n", ch, counter, df);
- filename = itoa(ch, filename, 10);
- printf("HUY\n");
- strcat(way, filename);
- printf("AGDSGF");
- strcat(way, ".bmp");
- printf("SOOOOS\n");
- printf("%s", way);
- FILE* OU = fopen(way, "wb");
- printf(way, "\n");
- fwrite(&aa, sizeof(aa), 1, OU);
- for (i = 0; i < aa.width; i++)
- for (j = 0; j < aa.height; j++)
- fwrite(&img[i][j], sizeof(img[i][j]), 1, OU);
- fclose(OU);
- }
- }
- free(img);
- free(cpy);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement