mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-17 00:10:31 +02:00
- Fixes #15145 A replacement listed in a new [indexed] section of textures.ini holds palette indices instead of colors: a palette PNG (the file's palette index) or an 8-bit grayscale PNG (the gray value), at any resolution. When the texture is built, the indices go through the game's current CLUT, including the CLUT index shift, mask and start position, and the result is uploaded as an ordinary RGBA texture. A game that swaps or customizes a palette keeps working with a high-resolution replacement. [indexed] keys use the [hashes] format and are matched with the same wildcards, so a key with a zero CLUT hash covers every palette of the texture. The contents hash only covers the indices, so one image is shared by all palettes (the loaded data is shared, each palette still has its own texture cache entry). Saving does not dump indexed textures yet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
45 lines
1.8 KiB
C++
45 lines
1.8 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);
|