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  Bitmap::ScopedReadAccess aReadAccess(rBitmap);
21  return checkImpl(aReadAccess.get());
22 }
23 
25 {
26  tools::Long nHeight = pReadAccess->Height();
27  tools::Long nWidth = pReadAccess->Width();
28 
29  tools::Long nHeightHalf = nHeight / 2;
30  tools::Long nWidthHalf = nWidth / 2;
31 
32  bool bHeightEven = (nHeight % 2) == 0;
33  bool bWidthEven = (nWidth % 2) == 0;
34 
35  for (tools::Long y = 0; y < nHeightHalf; ++y)
36  {
37  Scanline pScanlineRead = pReadAccess->GetScanline( y );
38  Scanline pScanlineRead2 = pReadAccess->GetScanline( nHeight - y - 1 );
39  for (tools::Long x = 0; x < nWidthHalf; ++x)
40  {
41  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, x))
42  {
43  return false;
44  }
45  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
46  {
47  return false;
48  }
49  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, nWidth - x - 1))
50  {
51  return false;
52  }
53  }
54  }
55 
56  if (bWidthEven)
57  {
58  for (tools::Long y = 0; y < nHeightHalf; ++y)
59  {
60  if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
61  {
62  return false;
63  }
64  }
65  }
66 
67  if (bHeightEven)
68  {
69  Scanline pScanlineRead = pReadAccess->GetScanline( nHeightHalf );
70  for (tools::Long x = 0; x < nWidthHalf; ++x)
71  {
72  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
73  {
74  return false;
75  }
76  }
77  }
78 
79  return true;
80 }
81 
82 
83 /* 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