Add support for base64 images in image entity URLs

This commit is contained in:
Karol Suprynowicz 2024-12-20 23:49:37 +01:00
parent 8f1c08a02e
commit b85935c0c4

View file

@ -254,6 +254,18 @@ NetworkTexturePointer TextureCache::getTexture(const QUrl& url, image::TextureUs
if (url.scheme() == RESOURCE_SCHEME) {
return getResourceTexture(url);
}
QString urlString = url.toString();
if (content.isEmpty() && (urlString.contains("data:image/jpeg;base64,")
|| urlString.contains("data:image/png;base64,")
|| urlString.contains("data:image/webp;base64,"))) {
QString binaryUrl = urlString.split(",")[1];
auto decodedContent = binaryUrl.isEmpty() ? QByteArray() : QByteArray::fromBase64(binaryUrl.toUtf8());
if (!decodedContent.isEmpty()) {
return getTexture(url, type, decodedContent, maxNumPixels, sourceChannel);
}
}
QString decodedURL = QUrl::fromPercentEncoding(url.toEncoded());
if (decodedURL.startsWith("{")) {
return getTextureByUUID(decodedURL);