Валеева Карина P3232
13 unresolved threads
- Last updated by Ilya Chermantiev
4 5 #include "../../include/image.h" 6 #include "../../include/bmp.h" 7 8 #define BMP_SIGNATURE 0x4D42 9 #define BMP_HEADER_SIZE 40 10 #define BMP_BIT_COUNT 24 11 #define BMP_PLANES 1 12 #define PADDING 4 13 14 15 uint8_t get_padding(uint64_t image_width) { 16 return (PADDING - ((image_width * sizeof(struct pixel)) % PADDING)) % PADDING; 17 } 18 19 enum read_status from_bmp(FILE *in, struct image *img) { - Last updated by Ilya Chermantiev
38 39 uint8_t padding = get_padding(img->width); 40 41 42 for (uint64_t i = 0; i < img->height; ++i) { 43 size_t bytes = fread(img->data + i * img->width, sizeof(struct pixel), img->width, in); 44 if (bytes != img->width || fseek(in, padding, SEEK_CUR)) { 45 free_image(img); 46 return READ_INVALID_BITS; 47 } 48 } 49 50 return READ_OK; 51 } 52 53 enum write_status to_bmp(FILE *out, struct image *img) { 44 if (bytes != img->width || fseek(in, padding, SEEK_CUR)) { 45 free_image(img); 46 return READ_INVALID_BITS; 47 } 48 } 49 50 return READ_OK; 51 } 52 53 enum write_status to_bmp(FILE *out, struct image *img) { 54 uint8_t padding = get_padding(img->width); 55 56 struct bmp_header header = { 57 .bfType = BMP_SIGNATURE, 58 .bfileSize = sizeof(struct bmp_header) + sizeof(struct pixel) * img->width * img->height, 59 .bfReserved = 0, 51 } 52 53 enum write_status to_bmp(FILE *out, struct image *img) { 54 uint8_t padding = get_padding(img->width); 55 56 struct bmp_header header = { 57 .bfType = BMP_SIGNATURE, 58 .bfileSize = sizeof(struct bmp_header) + sizeof(struct pixel) * img->width * img->height, 59 .bfReserved = 0, 60 .bfOffBits = sizeof(struct bmp_header), 61 .biSize = BMP_HEADER_SIZE, 62 .biWidth = img->width, 63 .biHeight = img->height, 64 .biPlanes = BMP_PLANES, 65 .biBitCount = BMP_BIT_COUNT, 66 .biCompression = 0, 1 #include "../include/image.h" 2 3 #include <stdlib.h> 4 5 struct image allocate_image(uint64_t width, uint64_t height) { 6 struct image new_image = {.width = width, .height = height, .data = malloc(width * height * sizeof(struct pixel))}; 1 #include "../include/image.h" 2 3 4 struct image none(struct image image) { 5 struct image new_image = allocate_image(image.width, image.height); 6 for (uint64_t row = 0; row < image.height; row++) { 7 for (uint64_t column = 0; column < image.width; column++) { 8 new_image.data[row * image.width + column] = image.data[row * image.width + column]; @kartusx ждём фиксы
@kartusx я так понимаю что это исправление плагиата?
assigned to @RayRelax
1 #include "../include/image.h" 2 3 #include <stdlib.h> 4 5 struct image allocate_image(uint64_t width, uint64_t height) { 6 struct image new_image = {.width = width, .height = height, .data = malloc(width * height * sizeof(struct pixel))}; 7 if (new_image.data == NULL) free(new_image.data); 1 #include "../include/image.h" 2 3 4 struct image none(struct image image) { 5 struct image new_image = allocate_image(image.width, image.height); 6 for (uint64_t row = 0; row < image.height; row++) { 7 for (uint64_t column = 0; column < image.width; column++) { 3 4 struct image none(struct image image) { 5 struct image new_image = allocate_image(image.width, image.height); 6 for (uint64_t row = 0; row < image.height; row++) { 7 for (uint64_t column = 0; column < image.width; column++) { 8 new_image.data[row * image.width + column] = image.data[row * image.width + column]; 9 } 10 } 11 return new_image; 12 } 13 14 struct image cw90(struct image image) { 15 struct image new_image = allocate_image(image.height, image.width); 16 for (uint32_t row = 0; row < image.height; ++row) { 17 for (uint32_t column = 0; column < image.width; ++column) { 18 new_image.data[row + (image.width - column - 1) * image.height] = image.data[row * image.width + column]; 30 31 int main(int argc, char **argv) { 32 if (argc != 4) { 33 fprintf(stderr, "Incorrect input args."); 34 return EXIT_ERROR; 35 } 36 37 char *input_image = argv[1]; 38 char *output_image = argv[2]; 39 char *transformation = argv[3]; 40 41 FILE *in = fopen(input_image, "rb"); 42 if (!in) { 43 fprintf(stderr, "Error while opening input file\n"); 44 return OPEN_FILE_ERROR; 45 } 3 #include <stdlib.h> 4 5 struct image allocate_image(uint64_t width, uint64_t height) { 6 struct image new_image = {.width = width, .height = height, .data = malloc(width * height * sizeof(struct pixel))}; 7 if (new_image.data == NULL) free(new_image.data); 8 return new_image; 9 } 10 11 void free_image(struct image *image) { 12 if (image != NULL) { 13 if (image->data != NULL) { 14 free(image->data); 15 image->data = NULL; 16 } 17 } 18 } @kartusx нужно внести правки по ревью или ответить на комментарии ревьюеров