aboutsummaryrefslogtreecommitdiff
path: root/lib/png.c
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-04-01 17:38:32 -0700
committerChristian C <cc@localhost>2025-04-01 17:38:32 -0700
commita18cea2fef7aa1545c9a984b60919541b26a6f84 (patch)
treed1ab991e28b701bdfdc9035704389ad6c57391c9 /lib/png.c
parent2bc54ac42b831a7dfcba26c2d12ba002f80a5e40 (diff)
Clang Format
Diffstat (limited to 'lib/png.c')
-rw-r--r--lib/png.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/lib/png.c b/lib/png.c
index 5da0b95..1264a5a 100644
--- a/lib/png.c
+++ b/lib/png.c
@@ -1,17 +1,16 @@
#include <lib/png.h>
-#include <stdio.h>
#include <png.h>
+#include <stdio.h>
// Save bitmap to file
-void save_png(Bitmap* bitmap, char* fname)
-{
+void save_png(Bitmap *bitmap, char *fname) {
FILE *fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
PixelSize_t pixel_size = 3;
PixelDepth_t pixel_depth = 8;
- png_byte ** row_pointers = NULL;
+ png_byte **row_pointers = NULL;
size_t x, y;
fp = fopen(fname, "wb");
if (fp == NULL) {
@@ -35,20 +34,19 @@ void save_png(Bitmap* bitmap, char* fname)
fclose(fp);
return;
}
- png_set_IHDR(png_ptr, info_ptr,
- bitmap->width, bitmap->height,
- pixel_depth,
- PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(png_ptr, info_ptr, bitmap->width, bitmap->height, pixel_depth,
+ PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- row_pointers = png_malloc(png_ptr, bitmap->height*sizeof(png_byte*));
+ row_pointers = png_malloc(png_ptr, bitmap->height * sizeof(png_byte *));
for (y = 0; y < bitmap->height; y++) {
- png_byte *row = png_malloc(png_ptr, sizeof(PixelChannel_t)*bitmap->width*pixel_size);
+ png_byte *row = png_malloc(png_ptr, sizeof(PixelChannel_t) * bitmap->width *
+ pixel_size);
row_pointers[y] = row;
for (x = 0; x < bitmap->width; x++) {
- *row++ = bitmap->image_buffer[x + y*bitmap->width].red;
- *row++ = bitmap->image_buffer[x + y*bitmap->width].green;
- *row++ = bitmap->image_buffer[x + y*bitmap->width].blue;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].red;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].green;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].blue;
}
}
png_init_io(png_ptr, fp);
@@ -61,4 +59,3 @@ void save_png(Bitmap* bitmap, char* fname)
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
}
-