vcl/unx/gtk3/gtk3gtkinst.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
New commits: commit 53e4e87d4bccdc12f6b87166b9123de627b844f9 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Wed Oct 14 15:04:43 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Oct 14 18:26:09 2020 +0200 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 <caol...@redhat.com> 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) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits