P32102 Chaykin Vadim Konstantinovich's third assignment
15 unresolved threads
had to change
void usage()
tovoid usage(void)
in tester/src/main.cprobably shouldn't have done that, but my tester was outdated
Edited by Чайкин Вадим Константинович, P32241 // 2 // Created by vad1mchk on 11/16/22. 3 // 4 5 #include "../include/bmp_header.h" 6 #include "../include/file_read_write.h" 7 #include "../include/util.h" 21 22 static uint32_t get_padding(const uint32_t width); 23 24 enum read_status from_bmp(FILE *in, struct image *img) { 25 struct bmp_header header; 26 if (fread(&header, sizeof(struct bmp_header), 1, in) != 1) { 27 return READ_INVALID_HEADER; 28 } 29 if (validate_header(header)) return READ_INVALID_HEADER; 30 println("Header read successfully:"); 31 print_header(header); 32 33 uint32_t width = header.biWidth; 34 uint32_t height = header.biHeight; 35 uint32_t padding = get_padding(width); 36 struct pixel *pixels = malloc(sizeof(struct pixel) * width * height); 58 header.biSizeImage = (width * sizeof(struct pixel) + get_padding(width)) * height; 59 header.bfileSize = header.bOffBits + header.biSizeImage; 60 println("Header generated:"); 61 print_header(header); 62 if (fwrite(&header, sizeof(struct bmp_header), 1, out) != 1) { 63 return WRITE_HEADER_ERROR; 64 } 65 println("Header written successfully."); 66 67 struct pixel *pixels = img->data; 68 for (int32_t i = 0; i < height; i++) { 69 size_t pixels_count = fwrite(pixels + width * i, sizeof(struct pixel), width, out); 70 printf("line %" PRId32 ": %zu pixels written\n", i, pixels_count); 71 if (pixels_count != width) return WRITE_DATA_ERROR; 72 if (padding != 0) { 73 if (fwrite(&pixels, sizeof(uint8_t), padding, out) != padding) return WRITE_DATA_ERROR; 2 #include "../include/file_read_write.h" 3 #include "../include/rotate.h" 4 #include "../include/util.h" 1 5 #include <stdio.h> 2 6 3 int main( int argc, char** argv ) { 4 (void) argc; (void) argv; // supress 'unused parameters' warning 7 int main(int argc, char **argv) { 8 FILE *input_file; 9 FILE *output_file; 10 enum open_status o_status; 11 enum read_status r_status; 12 enum write_status w_status; 13 enum close_status c_status; 5 14 15 if (argc != 3) { 13 enum close_status c_status; 5 14 15 if (argc != 3) { 16 println_err(open_error_messages[OPEN_WRONG_ARGUMENTS_COUNT]); 17 return OPEN_WRONG_ARGUMENTS_COUNT; 18 } 19 20 o_status = open_input_file(argv[1], &input_file); 21 if (o_status) { 22 println_err(open_error_messages[o_status]); 23 return 1; 24 } 25 26 struct image img; 27 r_status = from_bmp(input_file, &img); 28 if (r_status) { 22 println_err(open_error_messages[o_status]); 23 return 1; 24 } 25 26 struct image img; 27 r_status = from_bmp(input_file, &img); 28 if (r_status) { 29 println_err(read_error_messages[r_status]); 30 return 2; 31 } 32 33 c_status = close_input_file(input_file); 34 if (c_status) { 35 println_err(close_error_messages[c_status]); 36 return 3; 37 } 27 r_status = from_bmp(input_file, &img); 28 if (r_status) { 29 println_err(read_error_messages[r_status]); 30 return 2; 31 } 32 33 c_status = close_input_file(input_file); 34 if (c_status) { 35 println_err(close_error_messages[c_status]); 36 return 3; 37 } 38 39 struct image result = rotate(img); 40 destroy_image(&img); 41 42 o_status = open_output_file(argv[2], &output_file); 33 c_status = close_input_file(input_file); 34 if (c_status) { 35 println_err(close_error_messages[c_status]); 36 return 3; 37 } 38 39 struct image result = rotate(img); 40 destroy_image(&img); 41 42 o_status = open_output_file(argv[2], &output_file); 43 if (o_status) { 44 println_err(open_error_messages[o_status]); 45 return 4; 46 } 47 48 w_status = to_bmp(output_file, &result); 1 // 2 // Created by vad1mchk on 11/16/22. 3 // 4 #include "../include/rotate.h" 5 #include <malloc.h> 6 7 struct image rotate(const struct image source) { 8 uint32_t width = source.width; 9 uint32_t height = source.height; 10 struct pixel *old_pixels = source.data; 11 struct pixel *new_pixels = malloc(sizeof(struct pixel) * width * height); assigned to @andrew
@Vad1mChK_ с вас фиксы
4 5 #include "../include/util.h" 6 #include <stdio.h> 7 8 void println(const char *message) { 9 printf("%s\n", message); 10 } 11 12 void println_err(const char *message) { 13 fprintf(stderr, "\033[1mimage-transformer:\033[31m error\033[0m: %s\n", message); 14 } 15 16 void print_newline(void) { 17 printf("\n"); 18 } 19 36 return 3; 37 } 38 39 struct image result = rotate(img); 40 destroy_image(&img); 41 42 o_status = open_output_file(argv[2], &output_file); 43 if (o_status) { 44 println_err(open_error_messages[o_status]); 45 return 4; 46 } 47 48 w_status = to_bmp(output_file, &result); 49 if (w_status) { 50 println_err(write_error_messages[w_status]); 51 return 5; 30 return 2; 31 } 32 33 c_status = close_input_file(input_file); 34 if (c_status) { 35 println_err(close_error_messages[c_status]); 36 return 3; 37 } 38 39 struct image result = rotate(img); 40 destroy_image(&img); 41 42 o_status = open_output_file(argv[2], &output_file); 43 if (o_status) { 44 println_err(open_error_messages[o_status]); 45 return 4; 11 OPEN_WRONG_ARGUMENTS_COUNT, 12 OPEN_INPUT_FILE_NOT_FOUND, 13 OPEN_INPUT_FILE_INSUFFICIENT_PRIVILEGES, 14 OPEN_OUTPUT_FILE_INSUFFICIENT_PRIVILEGES, 15 OPEN_INPUT_FILE_WTF, 16 OPEN_OUTPUT_FILE_WTF 17 }; 18 19 enum close_status { 20 CLOSE_OK = 0, 21 CLOSE_INPUT_FILE_BAD_DESCRIPTOR, 22 CLOSE_OUTPUT_FILE_BAD_DESCRIPTOR, 23 CLOSE_INPUT_FILE_WTF, 24 CLOSE_OUTPUT_FILE_WTF 25 }; 26