[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - vcl/inc vcl/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Dec 19 21:39:45 UTC 2016


 vcl/inc/implimagetree.hxx          |   25 +++++++--
 vcl/source/image/ImplImageTree.cxx |  100 +++++++++++++++++++------------------
 2 files changed, 74 insertions(+), 51 deletions(-)

New commits:
commit 5b97553b9340e5d23fc1288a3be0ffb998d2e779
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Dec 18 15:02:59 2016 +0100

    ImplImageTree extract parameters to own struct
    
    Change-Id: I56e68ab19e63637d21dea7929f093bb1aceb982a
    Reviewed-on: https://gerrit.libreoffice.org/32135
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 6fd7c0c7714a90a6b99003b67a47b28b800cfdff)
    Reviewed-on: https://gerrit.libreoffice.org/32166

diff --git a/vcl/inc/implimagetree.hxx b/vcl/inc/implimagetree.hxx
index a229177..108dc97 100644
--- a/vcl/inc/implimagetree.hxx
+++ b/vcl/inc/implimagetree.hxx
@@ -38,6 +38,23 @@ namespace com { namespace sun { namespace star { namespace container {
     class XNameAccess;
 }}}}
 
+struct ImageRequestParameters
+{
+    OUString msName;
+    OUString msStyle;
+    BitmapEx& mrBitmap;
+    bool mbLocalized;
+    ImageLoadFlags meFlags;
+
+    ImageRequestParameters(const OUString & rName, const OUString & rStyle, BitmapEx& rBitmap, bool bLocalized, ImageLoadFlags eFlags)
+        : msName(rName)
+        , msStyle(rStyle)
+        , mrBitmap(rBitmap)
+        , mbLocalized(bLocalized)
+        , meFlags(eFlags)
+    {}
+};
+
 class ImplImageTree
 {
 public:
@@ -100,9 +117,7 @@ private:
         return maIconSets[maCurrentStyle];
     }
 
-    bool doLoadImage(
-        OUString const & name, OUString const & style,
-        BitmapEx & bitmap, bool localized, const ImageLoadFlags eFlags);
+    bool doLoadImage(ImageRequestParameters& rParameters);
 
     std::vector<OUString> getPaths(OUString const & name, LanguageTag& rLanguageTag);
 
@@ -112,9 +127,9 @@ private:
 
     void createStyle();
 
-    bool iconCacheLookup(OUString const & rName, bool bLocalized, const ImageLoadFlags eFlags, BitmapEx & rBitmap);
+    bool iconCacheLookup(ImageRequestParameters& rParameters);
 
-    bool findImage(std::vector<OUString> const & rPaths, BitmapEx & rBitmap, const ImageLoadFlags eFlags);
+    bool findImage(std::vector<OUString> const & rPaths, ImageRequestParameters& rParameters);
 
     void loadImageLinks();
 
diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx
index 744d487..114f084 100644
--- a/vcl/source/image/ImplImageTree.cxx
+++ b/vcl/source/image/ImplImageTree.cxx
@@ -132,44 +132,44 @@ std::shared_ptr<SvStream> wrapStream(css::uno::Reference< css::io::XInputStream
     return s;
 }
 
-void loadImageFromStream(std::shared_ptr<SvStream> const & xStream, OUString const & rPath, BitmapEx & rBitmap, const ImageLoadFlags eFlags)
+void loadImageFromStream(std::shared_ptr<SvStream> const & xStream, OUString const & rPath, ImageRequestParameters& rParameters)
 {
     static bool bIconsForDarkTheme = !!getenv("VCL_ICONS_FOR_DARK_THEME");
 
     bool bConvertToDarkTheme = bIconsForDarkTheme;
-    if (eFlags & ImageLoadFlags::IgnoreDarkTheme)
+    if (rParameters.meFlags & ImageLoadFlags::IgnoreDarkTheme)
         bConvertToDarkTheme = false;
 
     float aScaleFactor = Application::GetDefaultDevice()->GetDPIScaleFactor();
-    if (eFlags & ImageLoadFlags::IgnoreScalingFactor)
+    if (rParameters.meFlags & ImageLoadFlags::IgnoreScalingFactor)
         aScaleFactor = 1.0f;
 
     if (rPath.endsWith(".png"))
     {
         vcl::PNGReader aPNGReader(*xStream);
-        aPNGReader.SetIgnoreGammaChunk( true );
-        rBitmap = aPNGReader.Read();
+        aPNGReader.SetIgnoreGammaChunk(true);
+        rParameters.mrBitmap = aPNGReader.Read();
     }
     else if (rPath.endsWith(".svg"))
     {
-        vcl::bitmap::loadFromSvg(*xStream.get(), rPath, rBitmap, double(aScaleFactor));
+        vcl::bitmap::loadFromSvg(*xStream.get(), rPath, rParameters.mrBitmap, double(aScaleFactor));
         if (bConvertToDarkTheme)
-            rBitmap = BitmapProcessor::createLightImage(rBitmap);
+            rParameters.mrBitmap = BitmapProcessor::createLightImage(rParameters.mrBitmap);
         return;
     }
     else
     {
-        ReadDIBBitmapEx(rBitmap, *xStream);
+        ReadDIBBitmapEx(rParameters.mrBitmap, *xStream);
     }
 
     if (bConvertToDarkTheme)
-        rBitmap = BitmapProcessor::createLightImage(rBitmap);
+        rParameters.mrBitmap = BitmapProcessor::createLightImage(rParameters.mrBitmap);
 
     if (aScaleFactor > 1.0f)
-        rBitmap.Scale(double(aScaleFactor), double(aScaleFactor), BmpScaleFlag::Fast);
+        rParameters.mrBitmap.Scale(double(aScaleFactor), double(aScaleFactor), BmpScaleFlag::Fast);
 }
 
-}
+} // end anonymous namespace
 
 ImplImageTree::ImplImageTree()
 {
@@ -263,7 +263,8 @@ bool ImplImageTree::loadImage(OUString const & name, OUString const & style, Bit
     {
         try
         {
-            if (doLoadImage(name, aStyle, rBitmap, localized, eFlags))
+            ImageRequestParameters aParameters(name, aStyle, rBitmap, localized, eFlags);
+            if (doLoadImage(aParameters))
                 return true;
         }
         catch (css::uno::RuntimeException &)
@@ -276,19 +277,20 @@ bool ImplImageTree::loadImage(OUString const & name, OUString const & style, Bit
 
 bool ImplImageTree::loadDefaultImage(OUString const & style, BitmapEx& bitmap, const ImageLoadFlags eFlags)
 {
-    return doLoadImage("res/grafikde.png", style, bitmap, false, eFlags);
+    ImageRequestParameters aParameters("res/grafikde.png", style, bitmap, false, eFlags);
+    return doLoadImage(aParameters);
 }
 
-OUString createVariant(const ImageLoadFlags eFlags)
+OUString createVariant(ImageRequestParameters& rParameters)
 {
     static bool bIconsForDarkTheme = !!getenv("VCL_ICONS_FOR_DARK_THEME");
 
     bool bConvertToDarkTheme = bIconsForDarkTheme;
-    if (eFlags & ImageLoadFlags::IgnoreDarkTheme)
+    if (rParameters.meFlags & ImageLoadFlags::IgnoreDarkTheme)
         bConvertToDarkTheme = false;
 
     sal_Int32 aScalePercentage = Application::GetDefaultDevice()->GetDPIScalePercentage();
-    if (eFlags & ImageLoadFlags::IgnoreScalingFactor)
+    if (rParameters.meFlags & ImageLoadFlags::IgnoreScalingFactor)
         aScalePercentage = 100;
 
     OUString aVariant;
@@ -303,22 +305,22 @@ OUString createVariant(const ImageLoadFlags eFlags)
     return aVariant;
 }
 
-bool loadDiskCachedVersion(OUString const & sStyle, OUString const & sVariant, OUString const & sName, BitmapEx & rBitmapEx)
+bool loadDiskCachedVersion(OUString const & sVariant, ImageRequestParameters& rParameters)
 {
-    OUString sUrl(getIconCacheUrl(sStyle, sVariant, sName));
+    OUString sUrl(getIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName));
     if (!urlExists(sUrl))
         return false;
     SvFileStream aFileStream(sUrl, StreamMode::READ);
     vcl::PNGReader aPNGReader(aFileStream);
     aPNGReader.SetIgnoreGammaChunk( true );
-    rBitmapEx = aPNGReader.Read();
+    rParameters.mrBitmap = aPNGReader.Read();
     return true;
 }
 
-void cacheBitmapToDisk(OUString const & sStyle, OUString const & sVariant, OUString const & sName, BitmapEx & rBitmapEx)
+void cacheBitmapToDisk(OUString const & sVariant, ImageRequestParameters& rParameters)
 {
-    OUString sUrl(createIconCacheUrl(sStyle, sVariant, sName));
-    vcl::PNGWriter aWriter(rBitmapEx);
+    OUString sUrl(createIconCacheUrl(rParameters.msStyle, sVariant, rParameters.msName));
+    vcl::PNGWriter aWriter(rParameters.mrBitmap);
     try
     {
         SvFileStream aStream(sUrl, StreamMode::WRITE);
@@ -329,38 +331,44 @@ void cacheBitmapToDisk(OUString const & sStyle, OUString const & sVariant, OUStr
     {}
 }
 
-bool ImplImageTree::doLoadImage(OUString const & name, OUString const & style, BitmapEx & bitmap, bool localized, const ImageLoadFlags eFlags)
+bool ImplImageTree::doLoadImage(ImageRequestParameters& rParameters)
 {
-    setStyle(style);
+    setStyle(rParameters.msStyle);
 
-    if (iconCacheLookup(name, localized, eFlags, bitmap))
+    if (iconCacheLookup(rParameters))
         return true;
 
-    if (!bitmap.IsEmpty())
-        bitmap.SetEmpty();
+    if (!rParameters.mrBitmap.IsEmpty())
+        rParameters.mrBitmap.SetEmpty();
 
     LanguageTag aLanguageTag = Application::GetSettings().GetUILanguageTag();
 
-    std::vector<OUString> paths = getPaths(name, aLanguageTag);
+    std::vector<OUString> paths = getPaths(rParameters.msName, aLanguageTag);
+
+    bool bFound = false;
 
-    bool found = false;
-    try {
-        found = findImage(paths, bitmap, eFlags);
-    } catch (css::uno::RuntimeException &) {
+    try
+    {
+        bFound = findImage(paths, rParameters);
+    }
+    catch (css::uno::RuntimeException&)
+    {
         throw;
-    } catch (const css::uno::Exception & e) {
+    }
+    catch (const css::uno::Exception& e)
+    {
         SAL_INFO("vcl", "ImplImageTree::doLoadImage exception " << e.Message);
     }
 
-    if (found)
+    if (bFound)
     {
-        OUString aVariant = createVariant(eFlags);
+        OUString aVariant = createVariant(rParameters);
         if (!aVariant.isEmpty())
-            cacheBitmapToDisk(style, aVariant, name, bitmap);
-        getCurrentIconSet().maIconCache[name] = std::make_pair(localized, bitmap);
+            cacheBitmapToDisk(aVariant, rParameters);
+        getCurrentIconSet().maIconCache[rParameters.msName] = std::make_pair(rParameters.mbLocalized, rParameters.mrBitmap);
     }
 
-    return found;
+    return bFound;
 }
 
 void ImplImageTree::shutdown()
@@ -407,25 +415,25 @@ void ImplImageTree::createStyle()
     loadImageLinks();
 }
 
-bool ImplImageTree::iconCacheLookup(OUString const & name, bool localized, const ImageLoadFlags eFlags, BitmapEx & bitmap)
+bool ImplImageTree::iconCacheLookup(ImageRequestParameters& rParameters)
 {
     IconCache& rIconCache = getCurrentIconSet().maIconCache;
 
-    IconCache::iterator i(rIconCache.find(getRealImageName(name)));
-    if (i != rIconCache.end() && i->second.first == localized)
+    IconCache::iterator i(rIconCache.find(getRealImageName(rParameters.msName)));
+    if (i != rIconCache.end() && i->second.first == rParameters.mbLocalized)
     {
-        bitmap = i->second.second;
+        rParameters.mrBitmap = i->second.second;
         return true;
     }
 
-    OUString aVariant = createVariant(eFlags);
-    if (!aVariant.isEmpty() && loadDiskCachedVersion(maCurrentStyle, aVariant, name, bitmap))
+    OUString aVariant = createVariant(rParameters);
+    if (!aVariant.isEmpty() && loadDiskCachedVersion(aVariant, rParameters))
         return true;
 
     return false;
 }
 
-bool ImplImageTree::findImage(std::vector<OUString> const & paths, BitmapEx & bitmap, const ImageLoadFlags eFlags)
+bool ImplImageTree::findImage(std::vector<OUString> const & paths, ImageRequestParameters& rParameters)
 {
     if (!checkPathAccess())
         return false;
@@ -441,7 +449,7 @@ bool ImplImageTree::findImage(std::vector<OUString> const & paths, BitmapEx & bi
             assert(ok);
             (void)ok; // prevent unused warning in release build
 
-            loadImageFromStream(wrapStream(aStream), rPath, bitmap, eFlags);
+            loadImageFromStream(wrapStream(aStream), rPath, rParameters);
             return true;
         }
     }


More information about the Libreoffice-commits mailing list