Files
ppsspp/Common/Data/Format/PNGLoad.h
T
libretroadmin d56b453891 Replace zlib, zstd, libchdr, libzip and libpng with libretro-common
Deflate, zlib and gzip streams go through rinflate and rdeflate, zstd
through rzstd, CHD images through rchd, zip archives through
rzip_archive and PNG through rpng. The bundled libraries, their build
glue and the system-library options are gone; adler32 and uncompress
keep zlib's ABI for the prebuilt FFmpeg archives that still call them.
libretro-common is one CMake library that the core, the headless tool
and the unit tests all link.

The reads take shorter paths on the way. CHD decodes straight from the
loader's reads and a range of blocks at a time, and a file read at any
alignment decodes into place; CSO keeps one inflate stream instead of
one per block; a plain ISO serves a file read with one read of its exact
bytes; a stored zip member is read in place and a deflated one through
restart points rather than a copy of the whole image in memory; zip
members decode into the caller's buffer; sequential reads through the
frontend's VFS skip the seek, which also keeps its buffering.

libretro/test reads one image as ISO, CSO, CHD and zip through the block
devices, boots each, and checks the codecs against Python-made vectors;
a CI job runs it.
2026-10-08 14:14:38 +02:00

48 lines
1.7 KiB
C++

#pragma once
#include <cstdint>
#include <vector>
#include "Common/BitSet.h"
#include "Common/File/Path.h"
// *image_data_ptr should be deleted with free()
// return value of 1 == success.
int pngLoad(const char *file, int *pwidth,
int *pheight, unsigned char **image_data_ptr);
int pngLoadPtr(const unsigned char *input_ptr, size_t input_len, int *pwidth,
int *pheight, unsigned char **image_data_ptr,
int maxWidth = 8192, int maxHeight = 8192);
// PNG peeker - just read the start of a PNG straight into this struct, in order to
// look at basic parameters like width and height. Note that while PNG is a chunk-based
// format, the IHDR chunk is REQUIRED to be the first one, so this will work.
// Does not handle Apple's weirdo extension CgBI. http://iphonedevwiki.net/index.php/CgBI_file_format
// That should not be an issue.
struct PNGHeaderPeek {
uint32_t magic;
uint32_t ignore0;
uint32_t ignore1;
uint32_t ihdrTag;
uint32_t be_width; // big endian
uint32_t be_height;
uint8_t bitDepth; // bits per channel, can be 1, 2, 4, 8, 16
uint8_t colorType; // really, pixel format. 0 = grayscale, 2 = rgb, 3 = palette index, 4 = gray+alpha, 6 = rgba
bool IsValidPNGHeader() const;
int Width() const { return swap32(be_width); }
int Height() const { return swap32(be_height); }
};
// bytesPerPixel 4 is RGBA8888, 3 is RGB888.
bool pngSave(const Path &filename, const void *buffer, int w, int h, int bytesPerPixel);
enum class PNGFormat {
RGBA8888,
BGRA8888,
RGB888,
};
// Tightly packed pixels in, a complete PNG file out.
bool pngEncode(std::vector<uint8_t> *out, const void *buffer, int w, int h, PNGFormat format = PNGFormat::RGBA8888);