Add decoding png function for Save Dialog

This commit is contained in:
Xele02 committed 2012-12-14 23:35:09 +01:00
1 parent 839b393745
commit 09ad65d3dd
3 files changed
+30

No files matched your search

+2
View File
@@ -17,6 +17,7 @@ LOCAL_SRC_FILES :=\
base/error_context.cpp \
base/stringutil.cpp \
ext/sha1/sha1.cpp \
ext/stb_image/stb_image.c \
ext/stb_vorbis/stb_vorbis.c.arm \
ext/vjson/json.cpp \
ext/vjson/block_allocator.cpp \
@@ -48,6 +49,7 @@ LOCAL_SRC_FILES :=\
gfx/texture_atlas.cpp \
gfx/texture_gen.cpp \
image/zim_load.cpp \
image/png_load.cpp \
ui/ui.cpp \
ui/ui_context.cpp \
ui/screen.cpp \
+25
View File
@@ -36,6 +36,31 @@ int pngLoad(const char *file, int *pwidth, int *pheight, unsigned char **image_d
return 1;
}
int pngLoadPtr(const unsigned char *input_ptr, const int input_len, int *pwidth, int *pheight, unsigned char **image_data_ptr,
bool flip) {
if (flip)
{
ELOG("pngLoad: flip flag not supported, image will be loaded upside down");
}
int x,y,n;
unsigned char *data = stbi_load_from_memory(input_ptr,input_len, &x, &y, &n, 4); // 4 = force RGBA
if (!data)
return 0;
*pwidth = x;
*pheight = y;
// ... process data if not NULL ...
// ... x = width, y = height, n = # 8-bit components per pixel ...
// ... replace '0' with '1'..'4' to force that many components per pixel
// ... but 'n' will always be the number that it would have been if you said 0
// TODO: Get rid of this silly copy which is only to make the buffer free-able with free()
*image_data_ptr = (unsigned char *)malloc(x * y * 4);
memcpy(*image_data_ptr, data, x * y * 4);
stbi_image_free(data);
return 1;
}
#else
+3
View File
@@ -6,6 +6,9 @@
int pngLoad(const char *file, int *pwidth,
int *pheight, unsigned char **image_data_ptr, bool flip);
int pngLoadPtr(const unsigned char *input_ptr, const int input_len, int *pwidth,
int *pheight, unsigned char **image_data_ptr, bool flip);
#endif // _PNG_LOAD_H