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 <BitmapSymmetryCheck.hxx>
12 
14 {}
15 
17 {}
18 
20 {
21  Bitmap::ScopedReadAccess aReadAccess(rBitmap);
22  return checkImpl(aReadAccess.get());
23 }
24 
26 {
27  long nHeight = pReadAccess->Height();
28  long nWidth = pReadAccess->Width();
29 
30  long nHeightHalf = nHeight / 2;
31  long nWidthHalf = nWidth / 2;
32 
33  bool bHeightEven = (nHeight % 2) == 0;
34  bool bWidthEven = (nWidth % 2) == 0;
35 
36  for (long y = 0; y < nHeightHalf; ++y)
37  {
38  Scanline pScanlineRead = pReadAccess->GetScanline( y );
39  Scanline pScanlineRead2 = pReadAccess->GetScanline( nHeight - y - 1 );
40  for (long x = 0; x < nWidthHalf; ++x)
41  {
42  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, x))
43  {
44  return false;
45  }
46  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
47  {
48  return false;
49  }
50  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, nWidth - x - 1))
51  {
52  return false;
53  }
54  }
55  }
56 
57  if (bWidthEven)
58  {
59  for (long y = 0; y < nHeightHalf; ++y)
60  {
61  if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
62  {
63  return false;
64  }
65  }
66  }
67 
68  if (bHeightEven)
69  {
70  Scanline pScanlineRead = pReadAccess->GetScanline( nHeightHalf );
71  for (long x = 0; x < nWidthHalf; ++x)
72  {
73  if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
74  {
75  return false;
76  }
77  }
78  }
79 
80  return true;
81 }
82 
83 
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Scanline GetScanline(long nY) const
long Width() const
float x
float y
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
BitmapColor GetPixel(long nY, long nX) const
long Height() const
static bool checkImpl(BitmapReadAccess const *pReadAccess)
static bool check(Bitmap &rBitmap)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, long nX) const