summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-10-14 15:04:43 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-10-14 18:26:09 +0200
commit53e4e87d4bccdc12f6b87166b9123de627b844f9 (patch)
treeb9010df663f1cfb21b4bd4de90c6584be358cd3c /vcl
parent9eaaf97ab32068a619b5c36772619b7e66268800 (diff)
ImageTree::getImageStream may sub a req for a .png with svg data
so we can't rely on the input path name as to its data format. its going to be either png or data, so select which based on the first byte, so presumably keeping the startup optimization of commit 9e5cbcf90f15f46f84900a58bcaee437b98587f6 Date: Wed Dec 18 15:35:19 2019 +0200 load images by explicit type Change-Id: I0b2b743c138075f651d376767984be88745327a5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104287 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/unx/gtk3/gtk3gtkinst.cxx20
1 files changed, 11 insertions, 9 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index edd2d6bf63c5..acd917d27cf6 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -3224,13 +3224,16 @@ namespace
namespace
{
- GdkPixbuf* load_icon_from_stream(SvMemoryStream& rStream, const OString& image_type)
+ GdkPixbuf* load_icon_from_stream(SvMemoryStream& rStream)
{
- // if we know the image type, it's a little faster to hand the type over and skip the type
- // detection.
- GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new_with_type(image_type.getStr(), nullptr);
- gdk_pixbuf_loader_write(pixbuf_loader, static_cast<const guchar*>(rStream.GetData()),
- rStream.TellEnd(), nullptr);
+ auto nLength = rStream.TellEnd();
+ if (!nLength)
+ return nullptr;
+ const guchar* pData = static_cast<const guchar*>(rStream.GetData());
+ assert((*pData == 137 || *pData == '<') && "if we want to support more than png or svg this function must change");
+ // if we know the image type, it's a little faster to hand the type over and skip the type detection.
+ GdkPixbufLoader *pixbuf_loader = gdk_pixbuf_loader_new_with_type(*pData == 137 ? "png" : "svg", nullptr);
+ gdk_pixbuf_loader_write(pixbuf_loader, pData, nLength, nullptr);
gdk_pixbuf_loader_close(pixbuf_loader, nullptr);
GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(pixbuf_loader);
if (pixbuf)
@@ -3244,8 +3247,7 @@ namespace
auto xMemStm = ImageTree::get().getImageStream(rIconName, rIconTheme, rUILang);
if (!xMemStm)
return nullptr;
- OUString sImageType = rIconName.copy(rIconName.lastIndexOf('.')+1).toAsciiLowerCase();
- return load_icon_from_stream(*xMemStm, sImageType.toUtf8());
+ return load_icon_from_stream(*xMemStm);
}
}
@@ -3276,7 +3278,7 @@ namespace
vcl::PNGWriter aWriter(aImage.GetBitmapEx(), &aFilterData);
aWriter.Write(*xMemStm);
- return load_icon_from_stream(*xMemStm, "png");
+ return load_icon_from_stream(*xMemStm);
}
GdkPixbuf* getPixbuf(const VirtualDevice& rDevice)