From a68cc52b5c5d1c104de8d675b90816aaa39f4ace Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 9 Aug 2022 00:35:47 +0300 Subject: nearly works --- src/ppm.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/ppm.c') diff --git a/src/ppm.c b/src/ppm.c index 7ac29f3..a39b9cb 100644 --- a/src/ppm.c +++ b/src/ppm.c @@ -3,7 +3,7 @@ #include #include "ppm.h" -void save_as_ppm(char* file_path, int *t, int width, int height) +void save_as_ppm(char* file_path, int *t, size_t width, size_t height) { FILE *fp = fopen(file_path, "wb"); if(!fp) { @@ -11,34 +11,34 @@ void save_as_ppm(char* file_path, int *t, int width, int height) exit(EXIT_FAILURE); } - fprintf(fp, "P6\n%d %d 255\n", width, height); + // fprintf(fp, "P6\n%ld %ld 255\n", width, height); - for(int i = 0; i < height; i++) - for(int j = 0; j < width; j++) - { - char c = (t[i * width + j] == 0) ? 255 : 0; - for(int j = 0; j < 3; j++) - fwrite(&c, 1, 1, fp); - } - - // int scaler = 10; - - // fprintf(fp, "P6\n%d %d 255\n", width*scaler, height*scaler); - - // for(int i = 0; i < height * scaler; i++) - // for(int j = 0; j < width * scaler; j++) + // for(size_t i = 0; i < height; i++) + // for(size_t j = 0; j < width; j++) // { - // char c = (t[(i/scaler) * width + (j/scaler)] == 0) ? 255 : 0; + // char c = (t[i * width + j] == 0) ? 255 : 0; // for(int j = 0; j < 3; j++) // fwrite(&c, 1, 1, fp); // } + int scaler = 5; + + fprintf(fp, "P6\n%d %d 255\n", width*scaler, height*scaler); + + for(int i = 0; i < height * scaler; i++) + for(int j = 0; j < width * scaler; j++) + { + char c = (t[(i/scaler) * width + (j/scaler)] == 0) ? 255 : 0; + for(int j = 0; j < 3; j++) + fwrite(&c, 1, 1, fp); + } + fclose(fp); } -int *load_from_ppm(char *file_path, int *width, int *height) +int *load_from_ppm(char *file_path, size_t *width, size_t *height) { FILE *fp = fopen(file_path, "rb"); if(!fp) { @@ -64,8 +64,8 @@ int *load_from_ppm(char *file_path, int *width, int *height) fread(pixels, *width*3, *height, fp); int *t = malloc((*width) * (*height ) * sizeof(int)); - for(int i = 0; i < *height; i++) - for(int j = 0; j < *width; j++) + for(size_t i = 0; i < *height; i++) + for(size_t j = 0; j < *width; j++) t[i * *width + j] = (pixels[(i * *width + j) * 3] == 0) ? 1 : 0; free(pixels); -- cgit v1.2.3