[Libreoffice-commits] core.git: 2 commits - drawinglayer/source include/vcl vcl/source

2020-05-28 Thread Mike Kaganski (via logerrit)
 drawinglayer/source/processor2d/vclpixelprocessor2d.cxx |   11 +++
 include/vcl/alpha.hxx   |1 
 vcl/source/gdi/alpha.cxx|   23 
 3 files changed, 29 insertions(+), 6 deletions(-)

New commits:
commit 6806616023242aded27b1fae8637d32c9626d472
Author: Mike Kaganski 
AuthorDate: Thu May 14 14:42:24 2020 +0300
Commit: Mike Kaganski 
CommitDate: Fri May 29 06:23:50 2020 +0200

Add AlphaMask::BlendWith method to blend 8-bit alpha masks

Required for subsequent soft edge effect improvement

Change-Id: I9351b827a83c5651100e73a6846c834f491b861d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95027
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx
index f87ac133970a..159c61243efa 100644
--- a/include/vcl/alpha.hxx
+++ b/include/vcl/alpha.hxx
@@ -56,6 +56,7 @@ public:
 voidErase( sal_uInt8 cTransparency );
 voidReplace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
 voidReplace( sal_uInt8 cSearchTransparency, sal_uInt8 
cReplaceTransparency );
+voidBlendWith(const Bitmap& rOther);
 
 BitmapReadAccess*  AcquireAlphaReadAccess() { return 
Bitmap::AcquireReadAccess(); }
 BitmapWriteAccess* AcquireAlphaWriteAccess() { return 
Bitmap::AcquireWriteAccess(); }
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index fde0e94583a9..1385f803be8d 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -138,6 +138,29 @@ void AlphaMask::Replace( sal_uInt8 cSearchTransparency, 
sal_uInt8 cReplaceTransp
 }
 }
 
+void AlphaMask::BlendWith(const Bitmap& rOther)
+{
+AlphaMask aOther(rOther); // to 8 bits
+Bitmap::ScopedReadAccess pOtherAcc(aOther);
+AlphaScopedWriteAccess pAcc(*this);
+if (pOtherAcc && pAcc && pOtherAcc->GetBitCount() == 8 && 
pAcc->GetBitCount() == 8)
+{
+const long nHeight = std::min(pOtherAcc->Height(), pAcc->Height());
+const long nWidth = std::min(pOtherAcc->Width(), pAcc->Width());
+for (long x = 0; x < nWidth; ++x)
+{
+for (long y = 0; y < nHeight; ++y)
+{
+// Use sal_uInt16 for following multiplication
+const sal_uInt16 nGrey1 = pOtherAcc->GetPixelIndex(y, x);
+const sal_uInt16 nGrey2 = pAcc->GetPixelIndex(y, x);
+const double fGrey = std::round(nGrey1 + nGrey2 - nGrey1 * 
nGrey2 / 255.0);
+pAcc->SetPixelIndex(y, x, static_cast(fGrey));
+}
+}
+}
+}
+
 void AlphaMask::ReleaseAccess( BitmapReadAccess* pAccess )
 {
 if( pAccess )
commit 2cfe93da835eb500c9a170d22fce19fbd1de9473
Author: Mike Kaganski 
AuthorDate: Thu May 28 12:48:28 2020 +0300
Commit: Mike Kaganski 
CommitDate: Fri May 29 06:23:37 2020 +0200

tdf#49247, tdf#101181: don't rely on automatic scaling of alpha mask

Scale it back explicitly in ProcessAndBlurAlphaMask

Change-Id: I8e8a58c117d8b59db40b416edadc559b47dc300a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95021
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx 
b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
index 32afe33e6147..9e44ef292d34 100644
--- a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx
@@ -917,18 +917,17 @@ void 
VclPixelProcessor2D::processMetaFilePrimitive2D(const primitive2d::BasePrim
 
 namespace
 {
-/* Returns 8-bit alpha mask created from passed mask. The result may be scaled 
down; it's
-   expected that it will be automatically scaled up back when applied to the 
bitmap.
+/* Returns 8-bit alpha mask created from passed mask.
 
Negative fErodeDilateRadius values mean erode, positive - dilate.
nTransparency defines minimal transparency level.
 */
-AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rBWMask, double 
fErodeDilateRadius,
+AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rMask, double 
fErodeDilateRadius,
   double fBlurRadius, sal_uInt8 nTransparency)
 {
 // Only completely white pixels on the initial mask must be considered for 
transparency. Any
 // other color must be treated as black. This creates 1-bit B bitmap.
-BitmapEx mask(rBWMask.CreateMask(COL_WHITE));
+BitmapEx mask(rMask.CreateMask(COL_WHITE));
 
 // Scaling down increases performance without noticeable quality loss. 
Additionally,
 // current blur implementation can only handle blur radius between 2 and 
254.
@@ -963,6 +962,8 @@ AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rBWMask, 
double fErodeDilateRadi
 // calculate blurry effect
 BitmapFilter::Filter(mask, BitmapFilterStackBlur(fBlurRadius));
 
+mask.Scale(rMask.GetSizePixel());
+
 return 

[Libreoffice-commits] core.git: 2 commits - drawinglayer/source include/vcl vcl/source

2013-05-02 Thread Caolán McNamara
 drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx |  322 +++--
 include/vcl/textview.hxx   |4 
 vcl/source/edit/textview.cxx   |9 
 3 files changed, 197 insertions(+), 138 deletions(-)

New commits:
commit 92e5232dcbda1696a0e7c05defb3b6a00f4abdd7
Author: Caolán McNamara caol...@redhat.com
Date:   Thu May 2 09:55:04 2013 +0100

double lock drawinglayer statics

move related statics into classes and the make safe static singleton 
instances
of those clases.

We still have to have the additional mutex (now per singleton) on the
methods that return the buffered data, as it may be modified per
call

Change-Id: I5873ae8271f48a0ebf4b584c1734688b77cd1d42

diff --git a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx 
b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
index 495c06f..266738a 100644
--- a/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
+++ b/drawinglayer/source/primitive3d/polygontubeprimitive3d.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include boost/noncopyable.hpp
 #include drawinglayer/primitive3d/polygontubeprimitive3d.hxx
 #include drawinglayer/attribute/materialattribute3d.hxx
 #include basegfx/matrix/b3dhommatrix.hxx
@@ -25,6 +26,7 @@
 #include basegfx/polygon/b3dpolypolygontools.hxx
 #include drawinglayer/primitive3d/transformprimitive3d.hxx
 #include drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx
+#include rtl/instance.hxx
 
 //
 
@@ -34,190 +36,254 @@ namespace drawinglayer
 {
 namespace // anonymous namespace
 {
-Primitive3DSequence getLineTubeSegments(
-sal_uInt32 nSegments,
-const attribute::MaterialAttribute3D rMaterial)
+class TubeBuffer : boost::noncopyable
 {
-// static data for buffered tube primitives
-static Primitive3DSequence aLineTubeList;
-static sal_uInt32 nLineTubeSegments(0L);
-static attribute::MaterialAttribute3D aLineMaterial;
-static ::osl::Mutex aMutex;
-
-// may exclusively change static data, use mutex
-::osl::MutexGuard aGuard(aMutex);
-
-if(nSegments != nLineTubeSegments || !(rMaterial == 
aLineMaterial))
+private:
+// data for buffered tube primitives
+Primitive3DSequence m_aLineTubeList;
+sal_uInt32 m_nLineTubeSegments;
+attribute::MaterialAttribute3D m_aLineMaterial;
+::osl::Mutex m_aMutex;
+public:
+TubeBuffer()
+: m_nLineTubeSegments(0L)
 {
-nLineTubeSegments = nSegments;
-aLineMaterial = rMaterial;
-aLineTubeList = Primitive3DSequence();
 }
 
-if(!aLineTubeList.hasElements()  0L != nLineTubeSegments)
+Primitive3DSequence getLineTubeSegments(
+sal_uInt32 nSegments,
+const attribute::MaterialAttribute3D rMaterial)
 {
-const basegfx::B3DPoint aLeft(0.0, 0.0, 0.0);
-const basegfx::B3DPoint aRight(1.0, 0.0, 0.0);
-basegfx::B3DPoint aLastLeft(0.0, 1.0, 0.0);
-basegfx::B3DPoint aLastRight(1.0, 1.0, 0.0);
-basegfx::B3DHomMatrix aRot;
-aRot.rotate(F_2PI / (double)nLineTubeSegments, 0.0, 0.0);
-aLineTubeList.realloc(nLineTubeSegments);
-
-for(sal_uInt32 a(0L); a  nLineTubeSegments; a++)
+// may exclusively change cached data, use mutex
+::osl::MutexGuard aGuard(m_aMutex);
+
+if (nSegments != m_nLineTubeSegments || !(rMaterial == 
m_aLineMaterial))
 {
-const basegfx::B3DPoint aNextLeft(aRot * aLastLeft);
-const basegfx::B3DPoint aNextRight(aRot * aLastRight);
-basegfx::B3DPolygon aNewPolygon;
+m_nLineTubeSegments = nSegments;
+m_aLineMaterial = rMaterial;
+m_aLineTubeList = Primitive3DSequence();
+}
 
-aNewPolygon.append(aNextLeft);
-aNewPolygon.setNormal(0L, basegfx::B3DVector(aNextLeft 
- aLeft));
+if (!m_aLineTubeList.hasElements()  m_nLineTubeSegments 
!= 0)
+{
+const basegfx::B3DPoint aLeft(0.0, 0.0, 0.0);
+const basegfx::B3DPoint aRight(1.0, 0.0, 0.0);
+basegfx::B3DPoint aLastLeft(0.0,