[PATCH] Little cleanup in image loader internal functions

Rodolfo Ribeiro Gomes (via Code Review) gerrit at gerrit.libreoffice.org
Fri May 17 16:38:30 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3950

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/50/3950/1

Little cleanup in image loader internal functions

Change-Id: I6def704dc22d7a536849a9e4b51a08bf68778329
Signed-off-by: Rodolfo Ribeiro Gomes <rodolforg at gmail.com>
---
M vcl/source/gdi/impimagetree.cxx
1 file changed, 22 insertions(+), 43 deletions(-)



diff --git a/vcl/source/gdi/impimagetree.cxx b/vcl/source/gdi/impimagetree.cxx
index bcdfd01..97fa471 100644
--- a/vcl/source/gdi/impimagetree.cxx
+++ b/vcl/source/gdi/impimagetree.cxx
@@ -63,13 +63,13 @@
 
 namespace {
 
-OUString createPath(
+static OUString createPath(
     OUString const & name, sal_Int32 pos, OUString const & locale)
 {
     return name.copy(0, pos + 1) + locale + name.copy(pos);
 }
 
-boost::shared_ptr< SvStream > wrapFile(osl::File & file)
+static boost::shared_ptr< SvStream > wrapFile(osl::File & file)
 {
     // This could use SvInputStream instead if that did not have a broken
     // SeekPos implementation for an XInputStream that is not also XSeekable
@@ -89,22 +89,7 @@
     return s;
 }
 
-void loadFromFile(
-    osl::File & file,
-    OUString const & path, BitmapEx & bitmap)
-{
-    boost::shared_ptr< SvStream > s(wrapFile(file));
-    if (path.endsWith(".png"))
-    {
-        vcl::PNGReader aPNGReader( *s );
-        aPNGReader.SetIgnoreGammaChunk( sal_True );
-        bitmap = aPNGReader.Read();
-    } else {
-        *s >> bitmap;
-    }
-}
-
-boost::shared_ptr< SvStream > wrapStream(
+static boost::shared_ptr< SvStream > wrapStream(
     css::uno::Reference< css::io::XInputStream > const & stream)
 {
     // This could use SvInputStream instead if that did not have a broken
@@ -126,18 +111,17 @@
     return s;
 }
 
-void loadFromStream(
-    css::uno::Reference< css::io::XInputStream > const & stream,
-    OUString const & path, BitmapEx & bitmap)
+static void loadImageFromStream(
+    boost::shared_ptr< SvStream > pStream,
+    OUString const & rPath, BitmapEx & rBitmap)
 {
-    boost::shared_ptr< SvStream > s(wrapStream(stream));
-    if (path.endsWith(".png"))
+    if (rPath.endsWith(".png"))
     {
-        vcl::PNGReader aPNGReader( *s );
+        vcl::PNGReader aPNGReader( *pStream );
         aPNGReader.SetIgnoreGammaChunk( sal_True );
-        bitmap = aPNGReader.Read();
+        rBitmap = aPNGReader.Read();
     } else {
-        *s >> bitmap;
+        *pStream >> rBitmap;
     }
 }
 
@@ -270,27 +254,22 @@
 
 void ImplImageTree::resetPaths() {
     m_paths.clear();
+
+    OUString url( "$BRAND_BASE_DIR/share/config/" );
+    rtl::Bootstrap::expandMacros(url);
+    if ( m_style != "default" )
     {
-        OUString url(
-            "$BRAND_BASE_DIR/share/config");
-        rtl::Bootstrap::expandMacros(url);
         INetURLObject u(url);
         OSL_ASSERT(!u.HasError());
         bool ok = u.Append("images_" + m_style, INetURLObject::ENCODE_ALL);
         OSL_ASSERT(ok); (void) ok;
-        m_paths.push_back(
-            std::make_pair(
-                u.GetMainURL(INetURLObject::NO_DECODE),
-                css::uno::Reference< css::container::XNameAccess >()));
+        url = u.GetMainURL(INetURLObject::NO_DECODE);
     }
-    if ( m_style == "default" )
-    {
-        OUString url( "$BRAND_BASE_DIR/share/config/images");
-        rtl::Bootstrap::expandMacros(url);
-        m_paths.push_back(
-            std::make_pair(
-                url, css::uno::Reference< css::container::XNameAccess >()));
-    }
+    else
+        url += "images";
+    m_paths.push_back(
+        std::make_pair(
+            url, css::uno::Reference< css::container::XNameAccess >()));
 }
 
 bool ImplImageTree::checkStyleCacheLookup(
@@ -328,7 +307,7 @@
             {
                 osl::File file(i->first + "/" + *j);
                 if (file.open(osl_File_OpenFlag_Read) == ::osl::FileBase::E_None) {
-                    loadFromFile(file, *j, bitmap);
+                    loadImageFromStream( wrapFile(file), *j, bitmap );
                     file.close();
                     return true;
                 }
@@ -362,7 +341,7 @@
                 css::uno::Reference< css::io::XInputStream > s;
                 bool ok = i->second->getByName(*j) >>= s;
                 OSL_ASSERT(ok); (void) ok;
-                loadFromStream(s, *j, bitmap);
+                loadImageFromStream( wrapStream(s), *j, bitmap );
                 return true;
             }
         }

-- 
To view, visit https://gerrit.libreoffice.org/3950
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6def704dc22d7a536849a9e4b51a08bf68778329
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Rodolfo Ribeiro Gomes <libo at rodolfo.eng.br>



More information about the LibreOffice mailing list