Kaydet (Commit) 812f0a83 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

internally resize image instead of scaling bitmaps outside

When we want a different size Image, we can now set that as a
parameter at construction of the Image. Previously we needed to
create an Image, forcefully take the bitmap out, resize the bitmap
and create a new Image out of that.
Doing it internally gives us the benefit to have a more control
over the scaling process, especially when dealing with HiDPI
images.

Change-Id: I104118f4d863d519cc7aad1a17ca0289c01ed9ff
Reviewed-on: https://gerrit.libreoffice.org/70617
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst ed437865
...@@ -785,25 +785,17 @@ void NewToolbarController::setItemImage( const OUString &rCommand ) ...@@ -785,25 +785,17 @@ void NewToolbarController::setItemImage( const OUString &rCommand )
bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge(); bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
INetURLObject aURLObj( aURL ); INetURLObject aURLObj( aURL );
Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig ); Size aPreferredSize(bBig ? pToolBox->GetDefaultImageSize() : Size());
if ( !aImage ) Image aImage = SvFileInformationManager::GetImageNoDefault(aURLObj, bBig, aPreferredSize);
aImage = !!aMenuImage ? if (!aImage)
aMenuImage : {
SvFileInformationManager::GetImage( aURLObj, bBig ); aImage = !!aMenuImage ? aMenuImage : SvFileInformationManager::GetImage(aURLObj, bBig, aPreferredSize);
}
// if everything failed, just use the image associated with the toolbar item command // if everything failed, just use the image associated with the toolbar item command
if ( !aImage ) if ( !aImage )
return; return;
Size aBigSize( pToolBox->GetDefaultImageSize() ); pToolBox->SetItemImage( m_nToolBoxId, aImage );
if ( bBig && aImage.GetSizePixel() != aBigSize )
{
BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
aScaleBmpEx.Scale( aBigSize, BmpScaleFlag::Interpolate );
pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
}
else
pToolBox->SetItemImage( m_nToolBoxId, aImage );
m_aLastURL = aURL; m_aLastURL = aURL;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <svtools/svtdllapi.h> #include <svtools/svtdllapi.h>
#include <tools/gen.hxx>
enum class SvImageId { enum class SvImageId {
NONE = 0, NONE = 0,
...@@ -119,10 +120,10 @@ private: ...@@ -119,10 +120,10 @@ private:
public: public:
SVT_DLLPUBLIC static OUString GetImageId( const INetURLObject& rURL, bool bBig = false ); SVT_DLLPUBLIC static OUString GetImageId( const INetURLObject& rURL, bool bBig = false );
SVT_DLLPUBLIC static Image GetImage( const INetURLObject& rURL, bool bBig = false ); SVT_DLLPUBLIC static Image GetImage( const INetURLObject& rURL, bool bBig = false, Size const & rPreferredSize = Size());
SVT_DLLPUBLIC static OUString GetFileImageId( const INetURLObject& rURL ); SVT_DLLPUBLIC static OUString GetFileImageId( const INetURLObject& rURL );
SVT_DLLPUBLIC static Image GetFileImage( const INetURLObject& rURL ); SVT_DLLPUBLIC static Image GetFileImage( const INetURLObject& rURL );
SVT_DLLPUBLIC static Image GetImageNoDefault( const INetURLObject& rURL, bool bBig = false ); SVT_DLLPUBLIC static Image GetImageNoDefault(const INetURLObject& rURL, bool bBig = false, Size const & rPreferredSize = Size());
SVT_DLLPUBLIC static Image GetFolderImage( const svtools::VolumeInfo& rInfo ); SVT_DLLPUBLIC static Image GetFolderImage( const svtools::VolumeInfo& rInfo );
SVT_DLLPUBLIC static OUString GetDescription( const INetURLObject& rObject ); SVT_DLLPUBLIC static OUString GetDescription( const INetURLObject& rObject );
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <memory> #include <memory>
struct ImplImage; class ImplImage;
namespace com::sun::star::graphic { class XGraphic; } namespace com::sun::star::graphic { class XGraphic; }
namespace com::sun::star::uno { template <class interface_type> class Reference; } namespace com::sun::star::uno { template <class interface_type> class Reference; }
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
explicit Image(BitmapEx const & rBitmapEx); explicit Image(BitmapEx const & rBitmapEx);
explicit Image(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); explicit Image(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic);
explicit Image(OUString const & rPNGFileUrl); explicit Image(OUString const & rPNGFileUrl);
explicit Image(StockImage , OUString const & rPNGFilePath); explicit Image(StockImage, OUString const & rPNGFilePath, Size aSpecificSize = Size());
Size GetSizePixel() const; Size GetSizePixel() const;
BitmapEx GetBitmapEx() const; BitmapEx GetBitmapEx() const;
......
...@@ -686,11 +686,11 @@ static OUString GetImageNameFromList_Impl( SvImageId nImageId, bool bBig ) ...@@ -686,11 +686,11 @@ static OUString GetImageNameFromList_Impl( SvImageId nImageId, bool bBig )
return OUString(); return OUString();
} }
static Image GetImageFromList_Impl( SvImageId nImageId, bool bBig ) static Image GetImageFromList_Impl( SvImageId nImageId, bool bBig, Size aSize = Size())
{ {
OUString sImageName(GetImageNameFromList_Impl(nImageId, bBig)); OUString sImageName(GetImageNameFromList_Impl(nImageId, bBig));
if (!sImageName.isEmpty()) if (!sImageName.isEmpty())
return Image(StockImage::Yes, sImageName); return Image(StockImage::Yes, sImageName, aSize);
return Image(); return Image();
} }
...@@ -766,11 +766,11 @@ OUString SvFileInformationManager::GetImageId(const INetURLObject& rObject, bool ...@@ -766,11 +766,11 @@ OUString SvFileInformationManager::GetImageId(const INetURLObject& rObject, bool
return GetImageNameFromList_Impl(nImage, bBig); return GetImageNameFromList_Impl(nImage, bBig);
} }
Image SvFileInformationManager::GetImage( const INetURLObject& rObject, bool bBig ) Image SvFileInformationManager::GetImage(const INetURLObject& rObject, bool bBig, Size const & rPreferredSize)
{ {
SvImageId nImage = GetImageId_Impl( rObject, true ); SvImageId nImage = GetImageId_Impl( rObject, true );
DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
return GetImageFromList_Impl( nImage, bBig ); return GetImageFromList_Impl(nImage, bBig, rPreferredSize);
} }
OUString SvFileInformationManager::GetFileImageId(const INetURLObject& rObject) OUString SvFileInformationManager::GetFileImageId(const INetURLObject& rObject)
...@@ -787,15 +787,15 @@ Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject ) ...@@ -787,15 +787,15 @@ Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject )
return GetImageFromList_Impl( nImage, false/*bBig*/ ); return GetImageFromList_Impl( nImage, false/*bBig*/ );
} }
Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, bool bBig ) Image SvFileInformationManager::GetImageNoDefault(const INetURLObject& rObject, bool bBig, Size const & rPreferredSize)
{ {
SvImageId nImage = GetImageId_Impl( rObject, true ); SvImageId nImage = GetImageId_Impl(rObject, true);
DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" ); DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
if ( nImage == SvImageId::File ) if ( nImage == SvImageId::File )
return Image(); return Image();
return GetImageFromList_Impl( nImage, bBig ); return GetImageFromList_Impl(nImage, bBig, rPreferredSize);
} }
Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo ) Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo )
......
...@@ -25,22 +25,31 @@ ...@@ -25,22 +25,31 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
struct ImplImage class ImplImage
{ {
private:
BitmapChecksum maBitmapChecksum; BitmapChecksum maBitmapChecksum;
/// if non-empty: cached original size of maStockName else Size of maBitmap /// if non-empty: cached original size of maStockName else Size of maBitmap
Size maSizePixel; Size maSizePixel;
Size maPreferedSizePixel;
/// If set - defines the bitmap via images.zip* /// If set - defines the bitmap via images.zip*
OUString maStockName; OUString maStockName;
/// Original bitmap - or cache of a potentially scaled bitmap /// Original bitmap - or cache of a potentially scaled bitmap
BitmapEx maBitmapEx; BitmapEx maBitmapEx;
BitmapEx maDisabledBitmapEx; BitmapEx maDisabledBitmapEx;
bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx);
public:
ImplImage(const BitmapEx& rBitmapEx); ImplImage(const BitmapEx& rBitmapEx);
ImplImage(const OUString &aStockName); ImplImage(const OUString &aStockName, Size const & rPreferedSize);
bool isStock() const { return maStockName.getLength() > 0; } bool isStock() const
{
return maStockName.getLength() > 0;
}
/// get size in co-ordinates not scaled for HiDPI /// get size in co-ordinates not scaled for HiDPI
Size getSizePixel(); Size getSizePixel();
...@@ -48,9 +57,12 @@ struct ImplImage ...@@ -48,9 +57,12 @@ struct ImplImage
BitmapEx getBitmapEx(bool bDisabled = false); BitmapEx getBitmapEx(bool bDisabled = false);
/// Taking account of HiDPI scaling /// Taking account of HiDPI scaling
BitmapEx getBitmapExForHiDPI(bool bDisabled = false); BitmapEx getBitmapExForHiDPI(bool bDisabled = false);
bool isEqual(const ImplImage &ref) const; bool isEqual(const ImplImage &ref) const;
bool isSizeEmpty() const { return maSizePixel == Size(0, 0); } bool isSizeEmpty() const
bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx); {
return maSizePixel == Size();
}
}; };
#endif // INCLUDED_VCL_INC_IMAGE_H #endif // INCLUDED_VCL_INC_IMAGE_H
......
...@@ -60,7 +60,7 @@ Image::Image(const OUString & rFileUrl) ...@@ -60,7 +60,7 @@ Image::Image(const OUString & rFileUrl)
OUString sImageName; OUString sImageName;
if (rFileUrl.startsWith("private:graphicrepository/", &sImageName)) if (rFileUrl.startsWith("private:graphicrepository/", &sImageName))
{ {
mpImplData = std::make_shared<ImplImage>(sImageName); mpImplData = std::make_shared<ImplImage>(sImageName, Size());
} }
else else
{ {
...@@ -72,8 +72,8 @@ Image::Image(const OUString & rFileUrl) ...@@ -72,8 +72,8 @@ Image::Image(const OUString & rFileUrl)
} }
} }
Image::Image(StockImage, const OUString & rFileUrl) Image::Image(StockImage, const OUString & rFileUrl, Size aSpecificSize)
: mpImplData(std::make_shared<ImplImage>(rFileUrl)) : mpImplData(std::make_shared<ImplImage>(rFileUrl, aSpecificSize))
{ {
} }
......
...@@ -39,14 +39,16 @@ ...@@ -39,14 +39,16 @@
ImplImage::ImplImage(const BitmapEx &rBitmapEx) ImplImage::ImplImage(const BitmapEx &rBitmapEx)
: maBitmapChecksum(0) : maBitmapChecksum(0)
, maSizePixel(rBitmapEx.GetSizePixel()) , maSizePixel(rBitmapEx.GetSizePixel())
, maPreferedSizePixel()
, maBitmapEx(rBitmapEx) , maBitmapEx(rBitmapEx)
{ {
} }
ImplImage::ImplImage(const OUString &aStockName) ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize)
: maBitmapChecksum(0) : maBitmapChecksum(0)
, maSizePixel(0,0) // defer size lookup , maSizePixel() // defer size lookup
, maStockName( aStockName ) , maPreferedSizePixel(rPreferedSize)
, maStockName(aStockName)
{ {
} }
...@@ -61,6 +63,11 @@ bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx) ...@@ -61,6 +63,11 @@ bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale); SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale);
return false; return false;
} }
if (maPreferedSizePixel != Size())
{
Size aScaleSize(maPreferedSizePixel.Width() * fScale, maPreferedSizePixel.Height() * fScale);
aBitmapEx.Scale(aScaleSize);
}
rBitmapEx = aBitmapEx; rBitmapEx = aBitmapEx;
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment