aboutsummaryrefslogtreecommitdiff
path: root/src/ppm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ppm.c')
-rw-r--r--src/ppm.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/ppm.c b/src/ppm.c
index 24216f5..7bc8bb7 100644
--- a/src/ppm.c
+++ b/src/ppm.c
@@ -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);