mirror of https://github.com/OpenRCT2/OpenRCT2.git
Add expand option to PngRead
This commit is contained in:
parent
7089ec80fc
commit
25015fb15d
|
@ -32,7 +32,7 @@ namespace Imaging
|
||||||
static void PngWarning(png_structp png_ptr, const char * b);
|
static void PngWarning(png_structp png_ptr, const char * b);
|
||||||
static void PngError(png_structp png_ptr, const char * b);
|
static void PngError(png_structp png_ptr, const char * b);
|
||||||
|
|
||||||
bool PngRead(uint8 * * pixels, uint32 * width, uint32 * height, const utf8 * path)
|
bool PngRead(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path)
|
||||||
{
|
{
|
||||||
png_structp png_ptr;
|
png_structp png_ptr;
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
|
@ -68,8 +68,13 @@ namespace Imaging
|
||||||
png_set_read_fn(png_ptr, &fs, PngReadData);
|
png_set_read_fn(png_ptr, &fs, PngReadData);
|
||||||
png_set_sig_bytes(png_ptr, sig_read);
|
png_set_sig_bytes(png_ptr, sig_read);
|
||||||
|
|
||||||
// To simplify the reading process, convert 4-16 bit data to 24-32 bit data
|
uint32 readFlags = PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING;
|
||||||
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_GRAY_TO_RGB, nullptr);
|
if (expand)
|
||||||
|
{
|
||||||
|
// If we expand the resulting image always be full RGBA
|
||||||
|
readFlags |= PNG_TRANSFORM_GRAY_TO_RGB | PNG_TRANSFORM_EXPAND;
|
||||||
|
}
|
||||||
|
png_read_png(png_ptr, info_ptr, readFlags, nullptr);
|
||||||
|
|
||||||
// Read header
|
// Read header
|
||||||
png_uint_32 pngWidth, pngHeight;
|
png_uint_32 pngWidth, pngHeight;
|
||||||
|
@ -97,6 +102,16 @@ namespace Imaging
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (bitDepth == 8 && !expand)
|
||||||
|
{
|
||||||
|
// 8-bit paletted
|
||||||
|
Guard::Assert(rowBytes == pngWidth, GUARD_LINE);
|
||||||
|
for (png_uint_32 i = 0; i < pngHeight; i++)
|
||||||
|
{
|
||||||
|
Memory::Copy(dst, rowPointers[i], rowBytes);
|
||||||
|
dst += rowBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 32-bit PNG (with alpha)
|
// 32-bit PNG (with alpha)
|
||||||
|
@ -287,9 +302,9 @@ namespace Imaging
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, const utf8 * path)
|
bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path)
|
||||||
{
|
{
|
||||||
return Imaging::PngRead(pixels, width, height, path);
|
return Imaging::PngRead(pixels, width, height, expand, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path)
|
bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
namespace Imaging
|
namespace Imaging
|
||||||
{
|
{
|
||||||
bool PngRead(uint8 * * pixels, uint32 * width, uint32 * height, const utf8 * path);
|
bool PngRead(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path);
|
||||||
bool PngWrite(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path);
|
bool PngWrite(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path);
|
||||||
bool PngWrite32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path);
|
bool PngWrite32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace Imaging
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, const utf8 * path);
|
bool image_io_png_read(uint8 * * pixels, uint32 * width, uint32 * height, bool expand, const utf8 * path);
|
||||||
bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path);
|
bool image_io_png_write(const rct_drawpixelinfo * dpi, const rct_palette * palette, const utf8 * path);
|
||||||
bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path);
|
bool image_io_png_write_32bpp(sint32 width, sint32 height, const void * pixels, const utf8 * path);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue