Line data Source code
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 :
13 2 : BitmapSymmetryCheck::BitmapSymmetryCheck()
14 2 : {}
15 :
16 2 : BitmapSymmetryCheck::~BitmapSymmetryCheck()
17 2 : {}
18 :
19 3 : bool BitmapSymmetryCheck::check(Bitmap& rBitmap)
20 : {
21 3 : Bitmap::ScopedReadAccess aReadAccess(rBitmap);
22 3 : return checkImpl(aReadAccess.get());
23 : }
24 :
25 3 : bool BitmapSymmetryCheck::checkImpl(BitmapReadAccess* pReadAccess)
26 : {
27 3 : long nHeight = pReadAccess->Height();
28 3 : long nWidth = pReadAccess->Width();
29 :
30 3 : long nHeightHalf = nHeight / 2;
31 3 : long nWidthHalf = nWidth / 2;
32 :
33 3 : bool nHeightEven = (nHeight % 2) == 0;
34 3 : bool nWidthEven = (nWidth % 2) == 0;
35 :
36 35 : for (long y = 0; y < nHeightHalf; ++y)
37 : {
38 531 : for (long x = 0; x < nWidthHalf; ++x)
39 : {
40 499 : if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, x))
41 : {
42 0 : return false;
43 : }
44 499 : if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(y, nWidth - x - 1))
45 : {
46 0 : return false;
47 : }
48 499 : if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, nWidth - x - 1))
49 : {
50 0 : return false;
51 : }
52 : }
53 : }
54 :
55 3 : if (nWidthEven)
56 : {
57 17 : for (long y = 0; y < nHeightHalf; ++y)
58 : {
59 15 : if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
60 : {
61 0 : return false;
62 : }
63 : }
64 : }
65 :
66 3 : if (nHeightEven)
67 : {
68 17 : for (long x = 0; x < nWidthHalf; ++x)
69 : {
70 15 : if (pReadAccess->GetPixel(nHeightHalf, x) != pReadAccess->GetPixel(nHeightHalf, nWidth - x - 1))
71 : {
72 0 : return false;
73 : }
74 : }
75 : }
76 :
77 3 : return true;
78 : }
79 :
80 :
81 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|