Alex Pletnev P32111
11 unresolved threads
1 #include <stdio.h> 1 #include "./../include/bmp.h" 2 #include "./../include/rotate.h" 3 #include "./../include/write_output_util.h" 4 int main(int argc, char** argv ) { 5 /** 6 * checking the number of arguments 7 */ 8 if (argc != 3) { 9 return 1; - Last updated by Alexsandr Pletnev
7 */ 8 if (argc != 3) { 9 return 1; 10 } 11 /** 12 * set paths 13 */ 14 char *inputPath = argv[1]; 15 char *outputPath = argv[2]; 16 /** 17 * try open file and fill <code>*input</code> 18 */ 19 FILE *input = NULL; 20 //открываем 21 enum open_status openInputStatus = open_file(&input, inputPath, "rb"); 22 if (openInputStatus) { changed this line in version 3 of the diff
- Last updated by Alexsandr Pletnev
9 return 1; 10 } 11 /** 12 * set paths 13 */ 14 char *inputPath = argv[1]; 15 char *outputPath = argv[2]; 16 /** 17 * try open file and fill <code>*input</code> 18 */ 19 FILE *input = NULL; 20 //открываем 21 enum open_status openInputStatus = open_file(&input, inputPath, "rb"); 22 if (openInputStatus) { 23 print_err("can't open input file, check your input, pls"); 24 return openInputStatus; changed this line in version 3 of the diff
- Last updated by Alexsandr Pletnev
6 * checking the number of arguments 7 */ 8 if (argc != 3) { 9 return 1; 10 } 11 /** 12 * set paths 13 */ 14 char *inputPath = argv[1]; 15 char *outputPath = argv[2]; 16 /** 17 * try open file and fill <code>*input</code> 18 */ 19 FILE *input = NULL; 20 //открываем 21 enum open_status openInputStatus = open_file(&input, inputPath, "rb"); Это конечно круто, что файл открывается, но хотелось бы чтобы еще кто-то этот файл за собой закрыл. А у него ведь могли быть дети. подумайте о них... (то есть имеется в виду закрыть файл не только в том случае, если все прошло успешно, а закрыть его также в случае ошибки)
(то же самое касается выделенной картинки и файла для записи туда результата)
- Last updated by Alexsandr Pletnev
1 // 2 // Created by Александр Плетнёв on 20.11.2022. 3 // 4 #ifndef IMAGE_TRANSFORMER_BMP_H 5 #define IMAGE_TRANSFORMER_BMP_H 6 7 #include "image.h" 8 9 10 #include <stdint.h> 11 #include <stdio.h> 12 13 #include <stdlib.h> 14 15 16 /* deserializer */ changed this line in version 3 of the diff
1 // 2 // Created by Александр Плетнёв on 20.11.2022. 3 // 4 5 #ifndef IMAGE_TRANSFORMER_IMAGE_H 6 #define IMAGE_TRANSFORMER_IMAGE_H 7 8 9 #include <stdint.h> 10 #include <stdio.h> 11 12 13 /**just a <b>pixel</b>*/ 14 struct pixel { uint8_t b, g, r; }; - Last updated by Alexsandr Pletnev
10 #include <stdio.h> 11 12 13 /**just a <b>pixel</b>*/ 14 struct pixel { uint8_t b, g, r; }; 15 16 /**just a <b>image</b>*/ 17 #pragma pack(push, 1) 18 struct image { 19 uint64_t width, height; 20 struct pixel* data; 21 }; 22 #pragma pack(pop) 23 24 enum open_status { 25 OPEN_OK, changed this line in version 3 of the diff
- Last updated by Alexsandr Pletnev
- Last updated by Alexsandr Pletnev
45 * @return size of padding 46 */ 47 static uint32_t get_padding(struct image const* img) { 48 if (img->width * sizeof(struct pixel) % 4 == 0) return 0; 49 return 4 - img->width * sizeof(struct pixel) % 4; 50 } 51 /** 52 * create bmp header for img 53 * @param img - struct image* 54 * @return bmp header (struct bmp_header) 55 */ 56 static struct bmp_header make_bmp_header(struct image const* img) { 57 struct bmp_header bmpHeader = { 58 .bfType = LITTLE_ENDIAN_BMP, 59 .bfileSize = img->width * img->height * sizeof(struct pixel) 60 + img->width * get_padding(img) * sizeof(struct pixel) changed this line in version 3 of the diff
77 return bmpHeader; 78 } 79 static struct image allocate_image(struct bmp_header bmpHeader) { 80 return (struct image) {bmpHeader.biWidth, 81 bmpHeader.biHeight, 82 malloc(bmpHeader.biSizeImage)}; 83 } 84 void free_image(struct image const* img) { 85 free(img->data); 86 } 87 88 enum read_status from_bmp( FILE *in, struct image *img ) { 89 struct bmp_header bmpHeader = {0}; 90 //size_t headerSize = 91 fread(&bmpHeader, 1, sizeof(struct bmp_header), in); 92 //TODO: validate header @andrew, @Andryss и @OlegSuper готово!!!