16#include <ext/libpng/png.h>
31void PNGTextureWriter::writePNGDataToMemory(png_structp png_ptr, png_bytep inBytes, png_size_t inBytesToWrite) {
32 png_voidp io_ptr = png_get_io_ptr(png_ptr);
33 if (io_ptr ==
nullptr)
return;
36 pngOutputStream->
writeBytes((int8_t*)inBytes, inBytesToWrite);
45 if (
write(texture, data, removeAlphaChannel, flipY) ==
false)
return false;
47 FileSystem::getInstance()->setContent(pathName, fileName, data);
54 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
59 png_infop info = png_create_info_struct(png);
64 if (setjmp(png_jmpbuf(png))) {
75 auto bytesPerPixel = texture->
getDepth() / 8;
87 removeAlphaChannel ==
false && bytesPerPixel == 4?PNG_COLOR_TYPE_RGBA:PNG_COLOR_TYPE_RGB,
89 PNG_COMPRESSION_TYPE_DEFAULT,
90 PNG_FILTER_TYPE_DEFAULT
92 png_write_info(png, info);
95 if (removeAlphaChannel ==
true) {
96 png_set_filler(png, 0, PNG_FILLER_AFTER);
100 png_bytep* row_pointers =
new png_bytep[height];
102 for (
auto y = 0; y < height; y++) row_pointers[y] = pixels->getBuffer() + width * bytesPerPixel * (height - 1 - y);
104 for (
auto y = 0; y < height; y++) row_pointers[y] = pixels->getBuffer() + width * bytesPerPixel * y;
107 png_write_image(png, row_pointers);
108 png_write_end(png, NULL);
112 png_destroy_write_struct(&png, &info);
void writeBytes(int8_t *inBytes, int32_t inBytesToRead)
Read byte.
PNG texture writer class.
static bool write(Texture *texture, const string &pathName, const string &fileName, bool removeAlphaChannel=true, bool flipY=true)
Writes a texture to PNG file.
static void writePNGDataToMemory(png_structp png_ptr, png_bytep inBytes, png_size_t inBytesToWrite)
Write PNG data to memory.
static void flushPNGDataToMemory(png_structp png_ptr)
Flush PNG data.
ByteBuffer * getTextureData()
int32_t getTextureHeight() const
int32_t getTextureWidth() const
File system singleton class.