diff options
Diffstat (limited to 'src/ppm.c')
-rw-r--r-- | src/ppm.c | 19 |
1 files changed, 5 insertions, 14 deletions
@@ -21,12 +21,10 @@ void save_as_ppm(char* file_path, small_t *t, size_t width, size_t height, size_ for(size_t i = 0; i < height * scaler; i++) for(size_t j = 0; j < width * scaler; j++) - { - char c = (t[(i/scaler) * width + (j/scaler)] == 0) ? 255 : 0; - for(int j = 0; j < 3; j++) + for(int k = 0; k < 3; k++) { + char c = t[((i/scaler) * width + (j/scaler))*3 + k]; fwrite(&c, 1, 1, fp); - } - + } fclose(fp); } @@ -52,16 +50,9 @@ small_t *load_from_ppm(char *file_path, size_t *width, size_t *height) *height = atoi(strtok(NULL, " ")); (void)strtok(NULL, " "); - char *pixels = malloc((*width) * (*height ) * 3); - - fread(pixels, *width*3, *height, fp); - - small_t *t = malloc((*width) * (*height) * sizeof(small_t)); - 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; + small_t *t = malloc((*width) * (*height ) * 3); - free(pixels); + fread(t, *width*3, *height, fp); fclose(fp); |