Log file path in libpng errors & warnings properly
This commit is contained in:
parent
678a461904
commit
b4b2219aed
@ -95,8 +95,8 @@ StringList PackedAssetSource::assetPaths() const {
|
||||
|
||||
IODevicePtr PackedAssetSource::open(String const& path) {
|
||||
struct AssetReader : public IODevice {
|
||||
AssetReader(FilePtr file, StreamOffset offset, StreamOffset size)
|
||||
: file(file), fileOffset(offset), assetSize(size), assetPos(0) {
|
||||
AssetReader(FilePtr file, String path, StreamOffset offset, StreamOffset size)
|
||||
: file(file), path(path), fileOffset(offset), assetSize(size), assetPos(0) {
|
||||
setMode(IOMode::Read);
|
||||
}
|
||||
|
||||
@ -119,6 +119,10 @@ IODevicePtr PackedAssetSource::open(String const& path) {
|
||||
return assetPos;
|
||||
}
|
||||
|
||||
String deviceName() const override {
|
||||
return strf("{}:{}", file->deviceName(), path);
|
||||
}
|
||||
|
||||
bool atEnd() override {
|
||||
return assetPos >= assetSize;
|
||||
}
|
||||
@ -133,6 +137,7 @@ IODevicePtr PackedAssetSource::open(String const& path) {
|
||||
}
|
||||
|
||||
FilePtr file;
|
||||
String path;
|
||||
StreamOffset fileOffset;
|
||||
StreamOffset assetSize;
|
||||
StreamOffset assetPos;
|
||||
@ -142,7 +147,7 @@ IODevicePtr PackedAssetSource::open(String const& path) {
|
||||
if (!p)
|
||||
throw AssetSourceException::format("Requested file '{}' does not exist in the packed assets file", path);
|
||||
|
||||
return make_shared<AssetReader>(m_packedFile, p->first, p->second);
|
||||
return make_shared<AssetReader>(m_packedFile, path, p->first, p->second);
|
||||
}
|
||||
|
||||
ByteArray PackedAssetSource::read(String const& path) {
|
||||
|
@ -5,16 +5,19 @@
|
||||
|
||||
namespace Star {
|
||||
|
||||
void logPngError(png_structp png_ptr, png_const_charp c) {
|
||||
Logger::debug("PNG error in file: '{}', {}", ((IODevice*)png_get_error_ptr(png_ptr))->deviceName(), c);
|
||||
};
|
||||
|
||||
void logPngWarning(png_structp png_ptr, png_const_charp c) {
|
||||
Logger::debug("PNG warning in file: '{}', {}", ((IODevice*)png_get_error_ptr(png_ptr))->deviceName(), c);
|
||||
};
|
||||
|
||||
void readPngData(png_structp pngPtr, png_bytep data, png_size_t length) {
|
||||
((IODevice*)png_get_io_ptr(pngPtr))->readFull((char*)data, length);
|
||||
};
|
||||
|
||||
Image Image::readPng(IODevicePtr device) {
|
||||
auto logPngError = [](png_structp png_ptr, png_const_charp c) {
|
||||
Logger::debug("PNG error in file: '{}', {}", (char*)png_get_error_ptr(png_ptr), c);
|
||||
};
|
||||
|
||||
auto readPngData = [](png_structp pngPtr, png_bytep data, png_size_t length) {
|
||||
IODevice* device = (IODevice*)png_get_io_ptr(pngPtr);
|
||||
device->readFull((char*)data, length);
|
||||
};
|
||||
|
||||
png_byte header[8];
|
||||
device->readFull((char*)header, sizeof(header));
|
||||
|
||||
@ -26,7 +29,7 @@ Image Image::readPng(IODevicePtr device) {
|
||||
throw ImageException("Internal libPNG error");
|
||||
|
||||
// Use custom warning function to suppress cerr warnings
|
||||
png_set_error_fn(png_ptr, (png_voidp)device->deviceName().utf8Ptr(), logPngError, logPngError);
|
||||
png_set_error_fn(png_ptr, (png_voidp)device.get(), logPngError, logPngWarning);
|
||||
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
@ -111,15 +114,6 @@ Image Image::readPng(IODevicePtr device) {
|
||||
}
|
||||
|
||||
tuple<Vec2U, PixelFormat> Image::readPngMetadata(IODevicePtr device) {
|
||||
auto logPngError = [](png_structp png_ptr, png_const_charp c) {
|
||||
Logger::debug("PNG error in file: '{}', {}", (char*)png_get_error_ptr(png_ptr), c);
|
||||
};
|
||||
|
||||
auto readPngData = [](png_structp pngPtr, png_bytep data, png_size_t length) {
|
||||
IODevice* device = (IODevice*)png_get_io_ptr(pngPtr);
|
||||
device->readFull((char*)data, length);
|
||||
};
|
||||
|
||||
png_byte header[8];
|
||||
device->readFull((char*)header, sizeof(header));
|
||||
|
||||
@ -131,7 +125,7 @@ tuple<Vec2U, PixelFormat> Image::readPngMetadata(IODevicePtr device) {
|
||||
throw ImageException("Internal libPNG error");
|
||||
|
||||
// Use custom warning function to suppress cerr warnings
|
||||
png_set_error_fn(png_ptr, (png_voidp)device->deviceName().utf8Ptr(), logPngError, logPngError);
|
||||
png_set_error_fn(png_ptr, (png_voidp)device.get(), logPngError, logPngWarning);
|
||||
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
|
Loading…
Reference in New Issue
Block a user