summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-02-12 14:42:38 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-02-21 19:44:29 +0100
commitbd4ec51f9726b1fbe4c9a3fecfe298492bd8d8e5 (patch)
tree5b5e0dda8ea914a6553603e6d083b4cc6452f844 /vcl
parent541f5b508e7d356803eac2bdce4278649ee76203 (diff)
tdf#130573 labels exchanged in export to BMP
In the commit below, I removed the 1-bit dithered output, so restore it. regression from commit b5699cd01b6a52906880c107bac6f3802ea7353d Date: Wed Feb 8 16:18:32 2017 +0200 convert BmpConversion to scoped enum Note that this bug has been around since LO5.4 which means that anyone who has adjusted their setting in officecfg/registry/schema/org/openoffice/Office/Common.xcs with key BMP runs the risk of having that setting now revert to its prior (documented) meaning. Change-Id: Ibbda8aefbac261ff37ffab7223714f5d0343c692 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88528 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit f7323482ae38c5c4bc39edeea4d1a6e282f896a2) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88794 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/source/bitmap/BitmapMonochromeMatrixFilter.cxx142
-rw-r--r--vcl/source/gdi/bitmap3.cxx9
3 files changed, 152 insertions, 0 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 38bce206f72f..6635c3fcdc43 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -329,6 +329,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/bitmapfilter \
vcl/source/bitmap/BitmapAlphaClampFilter \
vcl/source/bitmap/BitmapMonochromeFilter \
+ vcl/source/bitmap/BitmapMonochromeMatrixFilter \
vcl/source/bitmap/BitmapSmoothenFilter \
vcl/source/bitmap/BitmapLightenFilter \
vcl/source/bitmap/BitmapDisabledImageFilter \
diff --git a/vcl/source/bitmap/BitmapMonochromeMatrixFilter.cxx b/vcl/source/bitmap/BitmapMonochromeMatrixFilter.cxx
new file mode 100644
index 000000000000..12e72ad1c710
--- /dev/null
+++ b/vcl/source/bitmap/BitmapMonochromeMatrixFilter.cxx
@@ -0,0 +1,142 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <vcl/bitmap.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/BitmapMonochromeMatrixFilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+static void ImplCreateDitherMatrix(sal_uInt8 (*pDitherMatrix)[16][16])
+{
+ const double fVal = 3.125;
+ const double fVal16 = fVal / 16.;
+ const double fValScale = 254.;
+ sal_uInt16 pMtx[16][16];
+ sal_uInt16 nMax = 0;
+ static const sal_uInt8 pMagic[4][4] = { {
+ 0,
+ 14,
+ 3,
+ 13,
+ },
+ {
+ 11,
+ 5,
+ 8,
+ 6,
+ },
+ {
+ 12,
+ 2,
+ 15,
+ 1,
+ },
+ { 7, 9, 4, 10 } };
+
+ // Build MagicSquare
+ for (long i = 0; i < 4; i++)
+ for (long j = 0; j < 4; j++)
+ for (long k = 0; k < 4; k++)
+ for (long l = 0; l < 4; l++)
+ {
+ pMtx[(k << 2) + i][(l << 2) + j] = static_cast<sal_uInt16>(
+ 0.5 + pMagic[i][j] * fVal + pMagic[k][l] * fVal16);
+ nMax = std::max(pMtx[(k << 2) + i][(l << 2) + j], nMax);
+ }
+
+ // Scale to interval [0;254]
+ double tmp = fValScale / nMax;
+ for (long i = 0; i < 16; i++)
+ for (long j = 0; j < 16; j++)
+ (*pDitherMatrix)[i][j] = static_cast<sal_uInt8>(tmp * pMtx[i][j]);
+}
+
+BitmapEx BitmapMonochromeMatrixFilter::execute(BitmapEx const& aBitmapEx) const
+{
+ Bitmap aBitmap = aBitmapEx.GetBitmap();
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+ bool bRet = false;
+
+ if (pReadAcc)
+ {
+ Bitmap aNewBmp(aBitmap.GetSizePixel(), 1);
+ BitmapScopedWriteAccess pWriteAcc(aNewBmp);
+
+ if (pWriteAcc)
+ {
+ const BitmapColor aBlack(pWriteAcc->GetBestMatchingColor(COL_BLACK));
+ const BitmapColor aWhite(pWriteAcc->GetBestMatchingColor(COL_WHITE));
+ const long nWidth = pWriteAcc->Width();
+ const long nHeight = pWriteAcc->Height();
+ sal_uInt8 pDitherMatrix[16][16];
+
+ ImplCreateDitherMatrix(&pDitherMatrix);
+
+ if (pReadAcc->HasPalette())
+ {
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ for (long nX = 0, nModY = nY % 16; nX < nWidth; nX++)
+ {
+ const sal_uInt8 cIndex = pReadAcc->GetPixelIndex(nY, nX);
+ if (pReadAcc->GetPaletteColor(cIndex).GetLuminance()
+ > pDitherMatrix[nModY][nX % 16])
+ {
+ pWriteAcc->SetPixel(nY, nX, aWhite);
+ }
+ else
+ pWriteAcc->SetPixel(nY, nX, aBlack);
+ }
+ }
+ }
+ else
+ {
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ for (long nX = 0, nModY = nY % 16; nX < nWidth; nX++)
+ {
+ if (pReadAcc->GetPixel(nY, nX).GetLuminance()
+ > pDitherMatrix[nModY][nX % 16])
+ {
+ pWriteAcc->SetPixel(nY, nX, aWhite);
+ }
+ else
+ pWriteAcc->SetPixel(nY, nX, aBlack);
+ }
+ }
+ }
+
+ pWriteAcc.reset();
+ bRet = true;
+ }
+
+ pReadAcc.reset();
+
+ if (bRet)
+ {
+ const MapMode aMap(aBitmap.GetPrefMapMode());
+ const Size aSize(aBitmap.GetPrefSize());
+
+ aBitmap = aNewBmp;
+
+ aBitmap.SetPrefMapMode(aMap);
+ aBitmap.SetPrefSize(aSize);
+ }
+ }
+
+ if (bRet)
+ return BitmapEx(aBitmap);
+
+ return BitmapEx();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index e35636044f3f..159b5feed3fa 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -30,6 +30,7 @@
#include <vcl/opengl/OpenGLHelper.hxx>
#endif
#include <vcl/BitmapMonochromeFilter.hxx>
+#include <vcl/BitmapMonochromeMatrixFilter.hxx>
#include <BitmapScaleSuperFilter.hxx>
#include <BitmapScaleConvolutionFilter.hxx>
@@ -255,6 +256,14 @@ bool Bitmap::Convert( BmpConversion eConversion )
}
break;
+ case BmpConversion::N1BitMatrix:
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapMonochromeMatrixFilter());
+ *this = aBmpEx.GetBitmap();
+ }
+ break;
+
case BmpConversion::N4BitGreys:
bRet = ImplMakeGreyscales( 16 );
break;