canvas/source/vcl/canvasbitmaphelper.cxx | 18 ++---------------- include/vcl/bitmapex.hxx | 12 ++++++++++++ include/vcl/errcode.hxx | 24 +++++++++++++++++------- svtools/source/misc/ehdl.cxx | 2 +- sw/inc/error.hrc | 4 ++-- uui/source/iahndl.cxx | 2 +- vcl/source/gdi/bitmapex.cxx | 21 +++++++++++++++++++++ vcl/source/helper/errcode.cxx | 2 +- 8 files changed, 57 insertions(+), 28 deletions(-)
New commits: commit 62275a93e3b13a20aa1de7945a32a0d25582c1ca Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Fri Mar 16 15:30:43 2018 +0200 move pixel color extracting from canvas to BitmapEx part of making GetAlpha/GetMask an internal detail of vcl Change-Id: I874a68f340cd3074cfbeb6303f52adeeb13e56a5 Reviewed-on: https://gerrit.libreoffice.org/51435 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx index c2003f6a67cf..eef6258dded3 100644 --- a/canvas/source/vcl/canvasbitmaphelper.cxx +++ b/canvas/source/vcl/canvasbitmaphelper.cxx @@ -194,28 +194,14 @@ namespace vclcanvas ENSURE_ARG_OR_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(), "Y coordinate out of bounds" ); - Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); - Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); - - Bitmap::ScopedReadAccess pReadAccess( aBitmap ); - Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? - nullptr : aAlpha.AcquireReadAccess(), - aAlpha ); - ENSURE_OR_THROW( pReadAccess.get() != nullptr, - "Could not acquire read access to bitmap" ); + ::Color aColor = mpBackBuffer->getBitmapReference().GetPixelColor(pos.X, pos.Y); uno::Sequence< sal_Int8 > aRes( 4 ); sal_Int8* pRes = aRes.getArray(); - - const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) ); pRes[ 0 ] = aColor.GetRed(); pRes[ 1 ] = aColor.GetGreen(); pRes[ 2 ] = aColor.GetBlue(); - - if( pAlphaReadAccess.get() != nullptr ) - pRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex(); - else - pRes[ 3 ] = sal_uInt8(255); + pRes[ 3 ] = aColor.GetTransparency(); return aRes; } diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx index d78f273b21ad..c61969869b33 100644 --- a/include/vcl/bitmapex.hxx +++ b/include/vcl/bitmapex.hxx @@ -378,6 +378,18 @@ public: sal_Int32 nX, sal_Int32 nY) const; + /** Get pixel color (including alpha) at given position + + @param nX + integer X-Position in Bitmap + + @param nY + integer Y-Position in Bitmap + */ + ::Color GetPixelColor( + sal_Int32 nX, + sal_Int32 nY) const; + /** Create transformed Bitmap @param fWidth diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx index 14b3fa17efd6..dba603347679 100644 --- a/vcl/source/gdi/bitmapex.cxx +++ b/vcl/source/gdi/bitmapex.cxx @@ -769,6 +769,27 @@ sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const return nTransparency; } + +Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const +{ + Bitmap aAlpha( GetAlpha().GetBitmap() ); + + Bitmap aTestBitmap(maBitmap); + Bitmap::ScopedReadAccess pReadAccess( aTestBitmap ); + assert( pReadAccess ); + + Color aColor = pReadAccess->GetColor( nY, nX ).GetColor(); + + if (!aAlpha.IsEmpty()) + { + Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.AcquireReadAccess(), aAlpha ); + aColor.SetTransparency( pAlphaReadAccess->GetPixel( nY, nX ).GetIndex() ); + } + else + aColor.SetTransparency(255); + return aColor; +} + // Shift alpha transparent pixels between cppcanvas/ implementations // and vcl in a generally grotesque and under-performing fashion bool BitmapEx::Create( const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas, commit e9c74a075c3c0809b993c017c11d1505bd244dc8 Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Fri Mar 16 16:35:00 2018 +0200 drop ErrCode::GetRest it was always a broken API because it includes the code, the class, and only part of the subsystemarea. Change-Id: I6f88b54aed2feab02a6aeaa783d7c642054b8075 Reviewed-on: https://gerrit.libreoffice.org/51430 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/vcl/errcode.hxx b/include/vcl/errcode.hxx index 8f1ba5ffc912..174c424f2871 100644 --- a/include/vcl/errcode.hxx +++ b/include/vcl/errcode.hxx @@ -64,11 +64,17 @@ enum class WarningFlag { Yes }; class SAL_WARN_UNUSED ErrCode final { public: - explicit constexpr ErrCode(WarningFlag, ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode) - : m_value(ERRCODE_WARNING_MASK | (sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode) {} - explicit constexpr ErrCode(ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode) - : m_value((sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode) {} - explicit constexpr ErrCode(ErrCodeArea nArea, sal_uInt32 nClassAndCode) + explicit ErrCode(WarningFlag, ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode) + : m_value(ERRCODE_WARNING_MASK | (sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode) + { + assert(nCode <= 0xff && "code out of range"); + } + explicit ErrCode(ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode) + : m_value((sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode) + { + assert(nCode <= 0xff && "code out of range"); + } + explicit constexpr ErrCode(ErrCodeArea nArea, sal_uInt16 nClassAndCode) : m_value((sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | nClassAndCode) {} explicit constexpr ErrCode(sal_uInt32 nValue) : m_value(nValue) {} @@ -116,6 +122,10 @@ public: return ErrCode(m_value & ~ERRCODE_DYNAMIC_MASK); } + constexpr ErrCode StripWarningAndDynamic() const { + return ErrCode(m_value & ~(ERRCODE_DYNAMIC_MASK | ERRCODE_WARNING_MASK)); + } + constexpr ErrCodeArea GetArea() const { return static_cast<ErrCodeArea>((m_value >> ERRCODE_AREA_SHIFT) & 0x01fff); } @@ -124,8 +134,8 @@ public: return static_cast<ErrCodeClass>((m_value >> ERRCODE_CLASS_SHIFT) & 0x1f); } - constexpr sal_uInt16 GetRest() const { - return m_value & 0x7fff; + constexpr sal_uInt8 GetCode() const { + return static_cast<sal_uInt8>(m_value & 0xff); } OUString toHexString() const { diff --git a/svtools/source/misc/ehdl.cxx b/svtools/source/misc/ehdl.cxx index 3ab4c7cedb9c..246b55ae4a24 100644 --- a/svtools/source/misc/ehdl.cxx +++ b/svtools/source/misc/ehdl.cxx @@ -221,7 +221,7 @@ bool SfxErrorHandler::GetErrorString(ErrCode lErrId, OUString &rStr) const for (const ErrMsgCode* pItem = pIds; pItem->second; ++pItem) { - if (pItem->second.GetRest() == lErrId.GetRest()) + if (pItem->second == lErrId.StripWarningAndDynamic()) { rStr = rStr.replaceAll("$(ERROR)", Translate::get(pItem->first, aResLocale)); bRet = true; diff --git a/sw/inc/error.hrc b/sw/inc/error.hrc index 7f6b8d3f61c7..1e61b007cf98 100644 --- a/sw/inc/error.hrc +++ b/sw/inc/error.hrc @@ -24,8 +24,8 @@ #define NC_(Context, String) (Context "\004" u8##String) -#define ERR_CODE( class, err ) ErrCode(ErrCodeArea::Sw, class, err.GetRest()) -#define WARN_CODE( class, err ) ErrCode(ErrCodeArea::Sw, class, err.GetRest()) +#define ERR_CODE( class, err ) ErrCode(ErrCodeArea::Sw, class, err.GetCode()) +#define WARN_CODE( class, err ) ErrCode(ErrCodeArea::Sw, class, err.GetCode()) const ErrMsgCode RID_SW_ERRHDL[] = { diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx index 6dbe7df63e76..439c223d5e52 100644 --- a/uui/source/iahndl.cxx +++ b/uui/source/iahndl.cxx @@ -1286,7 +1286,7 @@ bool ErrorResource::getString(ErrCode nErrorCode, OUString &rString) const { for (const std::pair<const char*, ErrCode>* pStringArray = m_pStringArray; pStringArray->first != nullptr; ++pStringArray) { - if (nErrorCode.GetRest() == pStringArray->second.GetRest()) + if (nErrorCode.StripWarningAndDynamic() == pStringArray->second) { rString = Translate::get(pStringArray->first, m_rResLocale); return true; diff --git a/vcl/source/helper/errcode.cxx b/vcl/source/helper/errcode.cxx index bb8e4eaf09e9..d50bf522c7d8 100644 --- a/vcl/source/helper/errcode.cxx +++ b/vcl/source/helper/errcode.cxx @@ -138,7 +138,7 @@ VCL_DLLPUBLIC std::ostream& operator<<(std::ostream& os, const ErrCode& err) os << "Compiler"; break; } - os << " Code:" << OUString::number(err.GetRest() & 0xff); + os << " Code:" << OUString::number(err.GetCode()); } os << ")"; return os; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits