Fix ImageMetadataDatabase::calculateImageSize calling Image::readPngMetadata on non-PNG images.
This commit is contained in:
parent
8457c2e954
commit
1f5e8a4629
@ -17,6 +17,12 @@ void readPngData(png_structp pngPtr, png_bytep data, png_size_t length) {
|
|||||||
((IODevice*)png_get_io_ptr(pngPtr))->readFull((char*)data, length);
|
((IODevice*)png_get_io_ptr(pngPtr))->readFull((char*)data, length);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool Image::isPng(IODevicePtr device) {
|
||||||
|
png_byte header[8];
|
||||||
|
device->readAbsolute(0, (char*)header, sizeof(header));
|
||||||
|
return !png_sig_cmp(header, 0, sizeof(header));
|
||||||
|
}
|
||||||
|
|
||||||
Image Image::readPng(IODevicePtr device) {
|
Image Image::readPng(IODevicePtr device) {
|
||||||
png_byte header[8];
|
png_byte header[8];
|
||||||
device->readFull((char*)header, sizeof(header));
|
device->readFull((char*)header, sizeof(header));
|
||||||
|
@ -27,6 +27,7 @@ STAR_CLASS(Image);
|
|||||||
class Image {
|
class Image {
|
||||||
public:
|
public:
|
||||||
static Image readPng(IODevicePtr device);
|
static Image readPng(IODevicePtr device);
|
||||||
|
static bool isPng(IODevicePtr device);
|
||||||
// Returns the size and pixel format that would be constructed from the given
|
// Returns the size and pixel format that would be constructed from the given
|
||||||
// png file, without actually loading it.
|
// png file, without actually loading it.
|
||||||
static tuple<Vec2U, PixelFormat> readPngMetadata(IODevicePtr device);
|
static tuple<Vec2U, PixelFormat> readPngMetadata(IODevicePtr device);
|
||||||
|
@ -174,7 +174,11 @@ Vec2U ImageMetadataDatabase::calculateImageSize(AssetPath const& path) const {
|
|||||||
imageSize = *size;
|
imageSize = *size;
|
||||||
} else {
|
} else {
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
imageSize = get<0>(Image::readPngMetadata(assets->openFile(path.basePath)));
|
auto file = assets->openFile(path.basePath);
|
||||||
|
if (Image::isPng(file))
|
||||||
|
imageSize = get<0>(Image::readPngMetadata(file));
|
||||||
|
else
|
||||||
|
imageSize = fallback();
|
||||||
locker.lock();
|
locker.lock();
|
||||||
m_sizeCache[path.basePath] = imageSize;
|
m_sizeCache[path.basePath] = imageSize;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user