From 57315da56fa3b036f8e3e2d32a5f90a11ae7c3de Mon Sep 17 00:00:00 2001 From: kartofen Date: Thu, 11 Aug 2022 16:41:00 +0300 Subject: works with images --- src/ppm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/ppm.c') diff --git a/src/ppm.c b/src/ppm.c index 7bc8bb7..7952305 100644 --- a/src/ppm.c +++ b/src/ppm.c @@ -17,7 +17,7 @@ void save_as_ppm(char* file_path, small_t *t, size_t width, size_t height, size_ exit(EXIT_FAILURE); } - fprintf(fp, "P6\n%ld %ld 255\n", width*scaler, height*scaler); + fprintf(fp, "P6\n%ld %ld\n255\n", width*scaler, height*scaler); for(size_t i = 0; i < height * scaler; i++) for(size_t j = 0; j < width * scaler; j++) @@ -48,7 +48,12 @@ small_t *load_from_ppm(char *file_path, size_t *width, size_t *height) fgets(line, sizeof(line), fp); *width = atoi(strtok(line, " ")); *height = atoi(strtok(NULL, " ")); - (void)strtok(NULL, " "); + + fgets(line, sizeof(line), fp); + if(atoi(line) != 255) { + printf("Maximum color value must be 255"); + exit(1); + } small_t *t = malloc((*width) * (*height ) * 3); -- cgit v1.2.3