Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-09-11 15:11:01 +1000
committerGitHub <noreply@github.com>2024-09-11 15:11:01 +1000
commit7852ad9cf2efdf359132c986f46b0e34acbd28ba (patch)
tree8b16b62548e221d5a0357680ea2d3d237fed17ad
parent8457c2e9542230ce6c71d7fc696d4f79e4a5456c (diff)
parent1f5e8a462908a7c6e7eac5b53c70749837d29c64 (diff)
Merge pull request #112 from floydinator-git/image-fix
Fix images added by assets.add not working in-game.
-rw-r--r--source/core/StarImage.cpp6
-rw-r--r--source/core/StarImage.hpp1
-rw-r--r--source/game/StarImageMetadataDatabase.cpp6
3 files changed, 12 insertions, 1 deletions
diff --git a/source/core/StarImage.cpp b/source/core/StarImage.cpp
index 82e3b05..52c2370 100644
--- a/source/core/StarImage.cpp
+++ b/source/core/StarImage.cpp
@@ -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);
};
+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) {
png_byte header[8];
device->readFull((char*)header, sizeof(header));
diff --git a/source/core/StarImage.hpp b/source/core/StarImage.hpp
index 478d074..aac0105 100644
--- a/source/core/StarImage.hpp
+++ b/source/core/StarImage.hpp
@@ -27,6 +27,7 @@ STAR_CLASS(Image);
class Image {
public:
static Image readPng(IODevicePtr device);
+ static bool isPng(IODevicePtr device);
// Returns the size and pixel format that would be constructed from the given
// png file, without actually loading it.
static tuple<Vec2U, PixelFormat> readPngMetadata(IODevicePtr device);
diff --git a/source/game/StarImageMetadataDatabase.cpp b/source/game/StarImageMetadataDatabase.cpp
index bf84e51..d04e984 100644
--- a/source/game/StarImageMetadataDatabase.cpp
+++ b/source/game/StarImageMetadataDatabase.cpp
@@ -174,7 +174,11 @@ Vec2U ImageMetadataDatabase::calculateImageSize(AssetPath const& path) const {
imageSize = *size;
} else {
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();
m_sizeCache[path.basePath] = imageSize;
}