mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-22 22:33:46 +00:00
Implement read callback for libpng
This commit is contained in:
parent
cc7e8c1b1f
commit
d13190990e
1 changed files with 16 additions and 5 deletions
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
|
|
||||||
|
static void ReportError(const char *msg) {
|
||||||
|
fprintf(stderr, "ERROR: ImageLoaderPNG -- %s\n", msg);
|
||||||
|
}
|
||||||
|
|
||||||
class PNGStreamReader {
|
class PNGStreamReader {
|
||||||
public:
|
public:
|
||||||
static void ReadDataFromStream(
|
static void ReadDataFromStream(
|
||||||
|
@ -12,23 +16,30 @@ public:
|
||||||
png_bytep outBytes,
|
png_bytep outBytes,
|
||||||
png_size_t byteCountToRead
|
png_size_t byteCountToRead
|
||||||
) {
|
) {
|
||||||
|
png_voidp io_ptr = png_get_io_ptr( png_ptr );
|
||||||
|
if( io_ptr == NULL ) {
|
||||||
|
ReportError("Read callback had invalid io pointer.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageLoaderPNG &loader = *(ImageLoaderPNG *)(io_ptr);
|
||||||
|
|
||||||
|
const unsigned char *stream = &(loader.m_RawData[loader.m_StreamPosition]);
|
||||||
|
memcpy(outBytes, stream, byteCountToRead);
|
||||||
|
|
||||||
|
loader.m_StreamPosition += byteCountToRead;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageLoaderPNG::ImageLoaderPNG(const unsigned char *rawData)
|
ImageLoaderPNG::ImageLoaderPNG(const unsigned char *rawData)
|
||||||
: ImageLoader(rawData)
|
: ImageLoader(rawData)
|
||||||
|
, m_StreamPosition(8) // We start at position 8 because of PNG header.
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageLoaderPNG::~ImageLoaderPNG() {
|
ImageLoaderPNG::~ImageLoaderPNG() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ReportError(const char *msg) {
|
|
||||||
fprintf(stderr, "ERROR: ImageLoaderPNG -- %s\n", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ImageLoaderPNG::ReadData() {
|
bool ImageLoaderPNG::ReadData() {
|
||||||
|
|
||||||
const int kNumSigBytesToRead = 8;
|
const int kNumSigBytesToRead = 8;
|
||||||
|
|
Loading…
Reference in a new issue