Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / source / bitmap / BitmapSymmetryCheck.cxx
blobad96a09f2c7ba4d89ff4c421d7d34dc1817889f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 */
11 #include <BitmapSymmetryCheck.hxx>
13 BitmapSymmetryCheck::BitmapSymmetryCheck()
16 BitmapSymmetryCheck::~BitmapSymmetryCheck()
19 bool BitmapSymmetryCheck::check(Bitmap& rBitmap)
21 Bitmap::ScopedReadAccess aReadAccess(rBitmap);
22 return checkImpl(aReadAccess.get());
25 bool BitmapSymmetryCheck::checkImpl(BitmapReadAccess* pReadAccess)
27 long nHeight = pReadAccess->Height();
28 long nWidth = pReadAccess->Width();
30 long nHeightHalf = nHeight / 2;
31 long nWidthHalf = nWidth / 2;
33 bool nHeightEven = (nHeight % 2) == 0;
34 bool nWidthEven = (nWidth % 2) == 0;
36 for (long y = 0; y < nHeightHalf; ++y)
38 for (long x = 0; x < nWidthHalf; ++x)
40 if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, x))
42 return false;
44 if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(y, nWidth - x - 1))
46 return false;
48 if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, nWidth - x - 1))
50 return false;
55 if (nWidthEven)
57 for (long y = 0; y < nHeightHalf; ++y)
59 if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
61 return false;
66 if (nHeightEven)
68 for (long x = 0; x < nWidthHalf; ++x)
70 if (pReadAccess->GetPixel(nHeightHalf, x) != pReadAccess->GetPixel(nHeightHalf, nWidth - x - 1))
72 return false;
77 return true;
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */