diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2018-11-26 11:06:20 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-11-27 13:09:33 +0100 |
commit | a71ea5cefffc4169237310d72f2d6e96c8bbf63d (patch) | |
tree | 581d84c1f4c393263fd8a695061cf53242de10ad /vcl/source/image | |
parent | 3f2ac501e6593ef5095b308b887c48349e00c0a3 (diff) |
Preserve stock images until render time.
This allows us to choose to render HiDPI images at the right time,
when we have the DPI of the device to render to.
The first step in a better, and more industry standard way of
improving our UI for HiDPI via rendering level scaling that should
retain a consistent look across the app with many fewer changes.
Change-Id: I36681f3242cb650de4f0b2d0fcdffbe5618e30fc
Reviewed-on: https://gerrit.libreoffice.org/64040
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'vcl/source/image')
-rw-r--r-- | vcl/source/image/Image.cxx | 106 | ||||
-rw-r--r-- | vcl/source/image/ImplImage.cxx | 68 |
2 files changed, 105 insertions, 69 deletions
diff --git a/vcl/source/image/Image.cxx b/vcl/source/image/Image.cxx index 049e3bef5d0d..8bce4839a1ea 100644 --- a/vcl/source/image/Image.cxx +++ b/vcl/source/image/Image.cxx @@ -58,17 +58,11 @@ Image::Image(const OUString & rFileUrl) sal_Int32 nIndex = 0; if (rFileUrl.getToken( 0, '/', nIndex ) == "private:graphicrepository") { - OUString sPathName(rFileUrl.copy(nIndex)); - BitmapEx aBitmapEx; - if (vcl::ImageRepository::loadImage(sPathName, aBitmapEx)) - { - ImplInit(aBitmapEx); - } + mpImplData.reset(new ImplImage(rFileUrl.copy(nIndex))); } else { Graphic aGraphic; - if (ERRCODE_NONE == GraphicFilter::LoadGraphic(rFileUrl, IMP_PNG, aGraphic)) { ImplInit(aGraphic.GetBitmapEx()); @@ -79,33 +73,23 @@ Image::Image(const OUString & rFileUrl) void Image::ImplInit(const BitmapEx& rBitmapEx) { if (!rBitmapEx.IsEmpty()) - { mpImplData.reset(new ImplImage(rBitmapEx)); - } } Size Image::GetSizePixel() const { - Size aRet; - if (mpImplData) - { - aRet = mpImplData->maBitmapEx.GetSizePixel(); - } - - return aRet; + return mpImplData->getSizePixel(); + else + return Size(); } BitmapEx Image::GetBitmapEx() const { - BitmapEx aRet; - if (mpImplData) - { - aRet = mpImplData->maBitmapEx; - } - - return aRet; + return mpImplData->getBitmapEx(); + else + return BitmapEx(); } bool Image::operator==(const Image& rImage) const @@ -117,7 +101,7 @@ bool Image::operator==(const Image& rImage) const else if (!rImage.mpImplData || !mpImplData) bRet = false; else - bRet = rImage.mpImplData->maBitmapEx == mpImplData->maBitmapEx; + bRet = rImage.mpImplData->isEqual(*mpImplData); return bRet; } @@ -128,63 +112,49 @@ void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle return; const Point aSrcPos(0, 0); - Size aBitmapSizePixel = mpImplData->maBitmapEx.GetSizePixel(); + Size aBitmapSizePixel = mpImplData->getSizePixel(); Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(aBitmapSizePixel); - if (nStyle & DrawImageFlags::Disable) - { - BitmapChecksum aChecksum = mpImplData->maBitmapEx.GetChecksum(); - if (mpImplData->maBitmapChecksum != aChecksum) - { - BitmapEx aDisabledBmpEx(mpImplData->maBitmapEx); - BitmapFilter::Filter(aDisabledBmpEx, BitmapDisabledImageFilter()); + // FIXME: do the HiDPI scaling fun here [!] =) + BitmapEx aRenderBmp = mpImplData->getBitmapEx(!!(nStyle & DrawImageFlags::Disable)); - mpImplData->maBitmapChecksum = aChecksum; - mpImplData->maDisabledBitmapEx = aDisabledBmpEx; - } - pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aBitmapSizePixel, mpImplData->maDisabledBitmapEx); - } - else + if (!(nStyle & DrawImageFlags::Disable) && + (nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight | + DrawImageFlags::Deactive | DrawImageFlags::SemiTransparent))) { - if (nStyle & (DrawImageFlags::ColorTransform | DrawImageFlags::Highlight | - DrawImageFlags::Deactive | DrawImageFlags::SemiTransparent)) + BitmapEx aTempBitmapEx(aRenderBmp); + + if (nStyle & (DrawImageFlags::Highlight | DrawImageFlags::Deactive)) { - BitmapEx aTempBitmapEx(mpImplData->maBitmapEx); + const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings(); + Color aColor; + if (nStyle & DrawImageFlags::Highlight) + aColor = rSettings.GetHighlightColor(); + else + aColor = rSettings.GetDeactiveColor(); + + BitmapFilter::Filter(aTempBitmapEx, BitmapColorizeFilter(aColor)); + } - if (nStyle & (DrawImageFlags::Highlight | DrawImageFlags::Deactive)) + if (nStyle & DrawImageFlags::SemiTransparent) + { + if (aTempBitmapEx.IsTransparent()) { - const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings(); - Color aColor; - if (nStyle & DrawImageFlags::Highlight) - aColor = rSettings.GetHighlightColor(); - else - aColor = rSettings.GetDeactiveColor(); - - BitmapFilter::Filter(aTempBitmapEx, BitmapColorizeFilter(aColor)); + Bitmap aAlphaBmp(aTempBitmapEx.GetAlpha().GetBitmap()); + aAlphaBmp.Adjust(50); + aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aAlphaBmp)); } - - if (nStyle & DrawImageFlags::SemiTransparent) + else { - if (aTempBitmapEx.IsTransparent()) - { - Bitmap aAlphaBmp(aTempBitmapEx.GetAlpha().GetBitmap()); - aAlphaBmp.Adjust(50); - aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aAlphaBmp)); - } - else - { - sal_uInt8 cErase = 128; - aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aTempBitmapEx.GetSizePixel(), &cErase)); - } + sal_uInt8 cErase = 128; + aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aTempBitmapEx.GetSizePixel(), &cErase)); } - pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aTempBitmapEx.GetSizePixel(), aTempBitmapEx); - } - else - { - pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, mpImplData->maBitmapEx.GetSizePixel(), mpImplData->maBitmapEx); } + aRenderBmp = aTempBitmapEx; } + + pOutDev->DrawBitmapEx(rPos, aOutSize, aSrcPos, aBitmapSizePixel, aRenderBmp); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/image/ImplImage.cxx b/vcl/source/image/ImplImage.cxx index 82a2099e8813..471dcb091e3d 100644 --- a/vcl/source/image/ImplImage.cxx +++ b/vcl/source/image/ImplImage.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/log.hxx> #include <vcl/outdev.hxx> #include <vcl/bitmapex.hxx> #include <vcl/alpha.hxx> @@ -25,15 +26,80 @@ #include <vcl/virdev.hxx> #include <vcl/image.hxx> #include <vcl/settings.hxx> +#include <vcl/BitmapFilter.hxx> +#include <vcl/ImageTree.hxx> +#include <vcl/imagerepository.hxx> +#include <BitmapDisabledImageFilter.hxx> +#include <comphelper/lok.hxx> #include <image.h> #include <memory> ImplImage::ImplImage(const BitmapEx &rBitmapEx) : maBitmapChecksum(0) + , maSizePixel(rBitmapEx.GetSizePixel()) , maBitmapEx(rBitmapEx) - , maDisabledBitmapEx() { } +ImplImage::ImplImage(const OUString &aStockName) + : maBitmapChecksum(0) + , maSizePixel(0,0) // defer size lookup + , maStockName( aStockName ) +{ +} + +Size ImplImage::getSizePixel() +{ + Size aRet; + if (!isSizeEmpty()) + aRet = maSizePixel; + else if (isStock()) + { + BitmapEx aBitmapEx; + if (vcl::ImageRepository::loadImage(maStockName, aBitmapEx)) + { + assert(!maDisabledBitmapEx); + assert(maBitmapChecksum == 0); + maBitmapEx = aBitmapEx; + maSizePixel = aBitmapEx.GetSizePixel(); + aRet = maSizePixel; + } + else + SAL_WARN("vcl", "Failed to load stock icon " << maStockName); + } + return aRet; +} + +/// non-HiDPI compatibility method. +BitmapEx ImplImage::getBitmapEx(bool bDisabled) +{ + getSizePixel(); // force load, and at unity scale. + if (bDisabled) + { + // Changed since we last generated this. + BitmapChecksum aChecksum = maBitmapEx.GetChecksum(); + if (maBitmapChecksum != aChecksum || + maDisabledBitmapEx.GetSizePixel() != maBitmapEx.GetSizePixel()) + { + maDisabledBitmapEx = maBitmapEx; + BitmapFilter::Filter(maDisabledBitmapEx, BitmapDisabledImageFilter()); + maBitmapChecksum = aChecksum; + } + return maDisabledBitmapEx; + } + + return maBitmapEx; +} + +bool ImplImage::isEqual(const ImplImage &ref) const +{ + if (isStock() != ref.isStock()) + return false; + if (isStock()) + return maStockName == ref.maStockName; + else + return maBitmapEx == ref.maBitmapEx; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |