aboutsummaryrefslogtreecommitdiff
path: root/src/ppm.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-09 23:07:37 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-09 23:07:37 +0300
commitec57f80b20e2309774b7e3a215640637e1c8e0f7 (patch)
treec68058ab9e2c8294eea5dfe36a18672644d3c67a /src/ppm.c
parent00c3363ca258f160b875ec254e701017be0314db (diff)
better
Diffstat (limited to 'src/ppm.c')
-rw-r--r--src/ppm.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/ppm.c b/src/ppm.c
index caeff9b..22bfaa5 100644
--- a/src/ppm.c
+++ b/src/ppm.c
@@ -3,7 +3,7 @@
#include <string.h>
#include "ppm.h"
-void save_as_ppm(char* file_path, int *t, size_t width, size_t height, size_t scaler)
+void save_as_ppm(char* file_path, small_t *t, size_t width, size_t height, size_t scaler)
{
FILE *fp = fopen(file_path, "wb");
if(!fp) {
@@ -12,14 +12,14 @@ void save_as_ppm(char* file_path, int *t, size_t width, size_t height, size_t sc
}
if(scaler == 0) {
- fprintf(stderr, "ERROR: Invalid value for scaler %d\n", scaler);
+ fprintf(stderr, "ERROR: Invalid value for scaler %ld\n", scaler);
exit(EXIT_FAILURE);
}
- fprintf(fp, "P6\n%d %d 255\n", width*scaler, height*scaler);
+ fprintf(fp, "P6\n%ld %ld 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 * 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++)
@@ -30,7 +30,7 @@ void save_as_ppm(char* file_path, int *t, size_t width, size_t height, size_t sc
fclose(fp);
}
-int *load_from_ppm(char *file_path, size_t *width, size_t *height)
+small_t *load_from_ppm(char *file_path, size_t *width, size_t *height)
{
FILE *fp = fopen(file_path, "rb");
if(!fp) {
@@ -55,7 +55,7 @@ int *load_from_ppm(char *file_path, size_t *width, size_t *height)
fread(pixels, *width*3, *height, fp);
- int *t = malloc((*width) * (*height ) * sizeof(int));
+ small_t *t = malloc((*width) * (*height));
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;
@@ -67,7 +67,7 @@ int *load_from_ppm(char *file_path, size_t *width, size_t *height)
return t;
}
-void free_ppm(int *t)
+void free_ppm(small_t *t)
{
free(t);
}