diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-04-12 11:11:13 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-04-12 13:56:53 +0200 |
commit | 812f0a83d223cddf00b121db40ca7ff91c22ccfa (patch) | |
tree | 8137fdfbac1f3c50bcd5b55ef66cd036aef0e455 /vcl | |
parent | ed437865a0db175e45ff421d50f429dff421d0cf (diff) |
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: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/image.h | 24 | ||||
-rw-r--r-- | vcl/source/image/Image.cxx | 6 | ||||
-rw-r--r-- | vcl/source/image/ImplImage.cxx | 13 |
3 files changed, 31 insertions, 12 deletions
diff --git a/vcl/inc/image.h b/vcl/inc/image.h index c9fb5393191a..c5acc06f782a 100644 --- a/vcl/inc/image.h +++ b/vcl/inc/image.h @@ -25,22 +25,31 @@ #include <unordered_map> #include <vector> -struct ImplImage +class ImplImage { +private: BitmapChecksum maBitmapChecksum; /// 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* OUString maStockName; + /// Original bitmap - or cache of a potentially scaled bitmap BitmapEx maBitmapEx; BitmapEx maDisabledBitmapEx; + bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx); + +public: 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 Size getSizePixel(); @@ -48,9 +57,12 @@ struct ImplImage BitmapEx getBitmapEx(bool bDisabled = false); /// Taking account of HiDPI scaling BitmapEx getBitmapExForHiDPI(bool bDisabled = false); + bool isEqual(const ImplImage &ref) const; - bool isSizeEmpty() const { return maSizePixel == Size(0, 0); } - bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx); + bool isSizeEmpty() const + { + return maSizePixel == Size(); + } }; #endif // INCLUDED_VCL_INC_IMAGE_H diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index e52583b99bd9..4316f9145a16 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -60,7 +60,7 @@ Image::Image(const OUString & rFileUrl) OUString sImageName; if (rFileUrl.startsWith("private:graphicrepository/", &sImageName)) { - mpImplData = std::make_shared<ImplImage>(sImageName); + mpImplData = std::make_shared<ImplImage>(sImageName, Size()); } else { @@ -72,8 +72,8 @@ Image::Image(const OUString & rFileUrl) } } -Image::Image(StockImage, const OUString & rFileUrl) - : mpImplData(std::make_shared<ImplImage>(rFileUrl)) +Image::Image(StockImage, const OUString & rFileUrl, Size aSpecificSize) + : mpImplData(std::make_shared<ImplImage>(rFileUrl, aSpecificSize)) { } diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx index 95d605e47173..7605f88d9767 100644 --- a/vcl/source/image/ImplImage.cxx +++ b/vcl/source/image/ImplImage.cxx @@ -39,14 +39,16 @@ ImplImage::ImplImage(const BitmapEx &rBitmapEx) : maBitmapChecksum(0) , maSizePixel(rBitmapEx.GetSizePixel()) + , maPreferedSizePixel() , maBitmapEx(rBitmapEx) { } -ImplImage::ImplImage(const OUString &aStockName) +ImplImage::ImplImage(const OUString &aStockName, Size const & rPreferedSize) : maBitmapChecksum(0) - , maSizePixel(0,0) // defer size lookup - , maStockName( aStockName ) + , maSizePixel() // defer size lookup + , maPreferedSizePixel(rPreferedSize) + , maStockName(aStockName) { } @@ -61,6 +63,11 @@ bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx) SAL_WARN("vcl", "Failed to load scaled image from " << maStockName << " at " << fScale); return false; } + if (maPreferedSizePixel != Size()) + { + Size aScaleSize(maPreferedSizePixel.Width() * fScale, maPreferedSizePixel.Height() * fScale); + aBitmapEx.Scale(aScaleSize); + } rBitmapEx = aBitmapEx; return true; } |