Боринский Игорь P3214
4 unresolved threads
- Last updated by Боринский Игорь
109 for (uint32_t i = 0; i < image->height; ++i) { 110 for (uint32_t j = 0; j < image->width; ++j) { 111 uint8_t* pixel_pointer = image_buffer + i * (sizeof(struct pixel) * header.biWidth + padding) + j * sizeof(struct pixel); 112 *pixel_pointer = image->data[image->width * i + j].b; 113 *(pixel_pointer + 1) = image->data[image->width * i + j].g; 114 *(pixel_pointer + 2) = image->data[image->width * i + j].r; 115 } 116 for (uint64_t j = 0; j < padding; ++j) { 117 image_buffer[(image->width * 3 + padding) * i + image->width * 3 + j] = 0; 118 } 119 } 120 121 if (image->data == NULL) { 122 free(image_buffer); 123 return false; 124 } - Last updated by Боринский Игорь
105 return false; 106 } 107 108 const uint8_t padding = size_of_padding(image->width); 109 for (uint32_t i = 0; i < image->height; ++i) { 110 for (uint32_t j = 0; j < image->width; ++j) { 111 uint8_t* pixel_pointer = image_buffer + i * (sizeof(struct pixel) * header.biWidth + padding) + j * sizeof(struct pixel); 112 *pixel_pointer = image->data[image->width * i + j].b; 113 *(pixel_pointer + 1) = image->data[image->width * i + j].g; 114 *(pixel_pointer + 2) = image->data[image->width * i + j].r; 115 } 116 for (uint64_t j = 0; j < padding; ++j) { 117 image_buffer[(image->width * 3 + padding) * i + image->width * 3 + j] = 0; 118 } 119 } 120 - Last updated by Боринский Игорь
74 } 75 76 fseek(in, header.bOffBits, SEEK_SET); 77 uint8_t* image_buffer = malloc(header.biSizeImage); 78 if(fread(image_buffer, header.biSizeImage, 1, in) < 1) { 79 free(image_buffer); 80 return false; 81 } 82 *image = image_create(header.biWidth, header.biHeight); 83 84 uint32_t padding = size_of_padding(header.biWidth); 85 86 for (uint32_t i = 0; i < header.biHeight; ++i) { 87 for (uint32_t j = 0; j < header.biWidth; ++j) { 88 uint8_t* pixel_pointer = image_buffer + i * (sizeof(struct pixel) * header.biWidth + padding) + j * sizeof(struct pixel); 89 image->data[i * header.biWidth + j] = pixel_create(*(pixel_pointer + 2), *(pixel_pointer + 1), *pixel_pointer); changed this line in version 3 of the diff
- Last updated by Боринский Игорь
1 #include "90rotate.h" 2 #include "image.h" 3 #include <malloc.h> 4 #include <stdbool.h> 5 #include <stdint.h> 6 7 static bool rotate_90_degrees(struct image* image) { 8 struct image some_image = image_create(image->height, image->width); 9 if (some_image.data == NULL) { 10 return false; 11 } 12 for (uint64_t x = 0; x < image->height; ++x) { 13 for (uint64_t y = 0; y < image->width; ++y) { 14 some_image.data[x * some_image.width + y] = image->data[y * image->width + (some_image.height - 1 - x)]; 15 } 16 } Тут перепутаны все индексы. Должно быть
for (uint64_t y = 0; y < some_image.height; ++y) { for (uint64_t x = 0; x < some_image.width; ++x) { some_image.data[y * some_image.width + x] = image->data[x * image->width + (image->width - 1 - y)]; } }
В повороте на 270 аналогично всё перепутано. В результате обращение вне выделенной памяти происзодит
added 1 commit
- c370bb7a - Update solution/src/bmp_io.c, solution/src/90rotate.c files
added 1 commit
- 1368aa70 - Update solution/src/g24_io.c, solution/include/g24_io.h, solution/src/main.c files