LibreOffice Module vcl (master)  1
BitmapSymmetryCheck.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  */
10 
11 #include <vcl/BitmapReadAccess.hxx>
12 
13 #include <BitmapSymmetryCheck.hxx>
14 
16 {}
17 
19 {}
20 
22 {
23  Bitmap::ScopedReadAccess aReadAccess(rBitmap);
24  return checkImpl(aReadAccess.get());
25 }
26 
28 {
29  tools::Long nHeight = pReadAccess->Height();
30  tools::Long nWidth = pReadAccess->Width();
31 
32  tools::Long nHeightHalf = nHeight / 2;
33  tools::Long nWidthHalf = nWidth / 2;
34 
35  bool bHeightEven = (nHeight % 2) == 0;
36  bool bWidthEven = (nWidth % 2) == 0;
37 
38  for (tools::Long y = 0; y < nHeightHalf; ++y)
39  {
40  Scanline pScanlineRead = pReadAccess->GetScanline( y );
41  Scanline pScanlineRead2 = pReadAccess->GetScanline( nHeight - y - 1 );
42  for (tools::Long x = 0; x < nWidthHalf; ++x)
43  {
44  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, x))
45  {
46  return false;
47  }
48  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
49  {
50  return false;
51  }
52  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, nWidth - x - 1))
53  {
54  return false;
55  }
56  }
57  }
58 
59  if (bWidthEven)
60  {
61  for (tools::Long y = 0; y < nHeightHalf; ++y)
62  {
63  if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
64  {
65  return false;
66  }
67  }
68  }
69 
70  if (bHeightEven)
71  {
72  Scanline pScanlineRead = pReadAccess->GetScanline( nHeightHalf );
73  for (tools::Long x = 0; x < nWidthHalf; ++x)
74  {
75  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
76  {
77  return false;
78  }
79  }
80  }
81 
82  return true;
83 }
84 
85 
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long Height() const
long Long
float x
Scanline GetScanline(tools::Long nY) const
float y
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
tools::Long Width() const
static bool checkImpl(BitmapReadAccess const *pReadAccess)
static bool check(Bitmap &rBitmap)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
BitmapColor GetPixel(tools::Long nY, tools::Long nX) const