summaryrefslogtreecommitdiff
path: root/src/png.c
diff options
context:
space:
mode:
authorToad King2012-06-14 03:21:06 -0400
committerToad King2012-06-14 03:21:06 -0400
commit6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119 (patch)
tree885cf7f507139b795ba7b2a6fb829dc044da39dd /src/png.c
downloadsnes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.tar.gz
snes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.tar.bz2
snes9x2002-6fb0c7a7a53e1eba7a0f5dc5b1ade312a0d76119.zip
initial pocketsnes commit
Diffstat (limited to 'src/png.c')
-rw-r--r--src/png.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/png.c b/src/png.c
new file mode 100644
index 0000000..2d24c47
--- /dev/null
+++ b/src/png.c
@@ -0,0 +1,38 @@
+/*
+ Simple PNG handling library
+ Under GPL v2 License
+ 2011 by bitrider
+*/
+
+#include <stdlib.h>
+#include "lodepng.h"
+#include "png.h"
+
+#define ERROR(err) {if (error) (*error) = PNG_ERROR_OPENING; return NULL;}
+gBITMAP *load_png(char *filename, int *error) /* We need to open the file */
+{
+ gBITMAP *img = NULL;
+ unsigned int e;
+
+ // allocate memory
+ img = malloc(sizeof(gBITMAP));
+ if (!img) ERROR(PNG_ERROR_MEMORY);
+
+ img->data = NULL;
+
+ e = LodePNG_decode32_file(&img->data, &img->w, &img->h, filename);
+ if (e) {
+ gDestroyBitmap(img);
+ ERROR(e);
+ }
+
+ img->bpp = 32;
+ if (error) (*error) = PNG_OK;
+ return img;
+}
+
+int save_png(gBITMAP *img, char *filename) {
+ if ((!img) || (!img->data) || (img->bpp != 32)) return PNG_ERROR_INVALID_INPUT;
+
+ return LodePNG_encode32_file(filename, img->data, img->w, img->h);
+}