vcl/unx/gtk3/gtk3gtkinst.cxx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
New commits: commit 2a8cd72be8045ff90bad87acb884c5c96ca96ed2 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Wed Oct 14 15:04:43 2020 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Oct 15 22:06:19 2020 +0200 tdf#136799 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/+/104300 Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 792b9381d7d5..d2d0ca46c7e5 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3183,13 +3183,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) @@ -3203,8 +3206,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); } } @@ -3235,7 +3237,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