aboutsummaryrefslogtreecommitdiff
path: root/src/ppm.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-09 00:35:47 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-09 00:35:47 +0300
commita68cc52b5c5d1c104de8d675b90816aaa39f4ace (patch)
treed4d7d095b812349c1d8c90e20e91d18d25a88374 /src/ppm.c
parentc6862f7f703bcff364573e95f180f05ce8e45040 (diff)
nearly works
Diffstat (limited to 'src/ppm.c')
-rw-r--r--src/ppm.c40
1 files changed, 20 insertions, 20 deletions
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 <string.h>
#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);