Files
ppsspp/Common/Data/Format/PNGLoad.h
T
Claude 1692aad51e Texture replacement: Optionally dump paletted textures as 8-bit palette PNGs
saveIndexed = true in [options] saves the CLUT4/CLUT8 textures listed in
[indexed] as palette PNGs, saveIndexed = all saves every one of them.
The file is named <hash>_indexed.png, with the CLUT hash zeroed so one
file serves every palette of the texture. The other textures are dumped
as before.

The indices are decoded from PSP memory and the palette comes from the
current CLUT, so the dump looks like the game's texture. Add the file to
[hashes] and [indexed] to use it as a replacement.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 16:15:11 +02:00

49 lines
2.1 KiB
C++

#pragma once
#include <cstdint>
#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);
// Loads a palette or grayscale PNG (up to 8 bits) as one byte per pixel, tightly packed:
// the palette index for palette images, the gray value for grayscale ones. Returns 0 for any
// other kind of PNG. *image_data_ptr should be deleted with free().
int pngLoadIndexed(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); }
};
bool pngSave(const Path &filename, const void *buffer, int w, int h, int bytesPerPixel);
// Saves an 8-bit palette PNG: one byte per pixel, tightly packed, with numColors (1 to 256) palette entries
// in RGBA byte order. The alpha of the entries goes in a tRNS chunk.
bool pngSaveIndexed(const Path &filename, const uint8_t *indices, int w, int h, const uint32_t *palette, int numColors);