Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / bitmap / BitmapSymmetryCheck.cxx
blob9abb480864e23644c6c75f44a9134820e33995ad
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 const * pReadAccess)
27 long nHeight = pReadAccess->Height();
28 long nWidth = pReadAccess->Width();
30 long nHeightHalf = nHeight / 2;
31 long nWidthHalf = nWidth / 2;
33 bool bHeightEven = (nHeight % 2) == 0;
34 bool bWidthEven = (nWidth % 2) == 0;
36 for (long y = 0; y < nHeightHalf; ++y)
38 Scanline pScanlineRead = pReadAccess->GetScanline( y );
39 Scanline pScanlineRead2 = pReadAccess->GetScanline( nHeight - y - 1 );
40 for (long x = 0; x < nWidthHalf; ++x)
42 if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, x))
44 return false;
46 if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
48 return false;
50 if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead2, nWidth - x - 1))
52 return false;
57 if (bWidthEven)
59 for (long y = 0; y < nHeightHalf; ++y)
61 if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf))
63 return false;
68 if (bHeightEven)
70 Scanline pScanlineRead = pReadAccess->GetScanline( nHeightHalf );
71 for (long x = 0; x < nWidthHalf; ++x)
73 if (pReadAccess->GetPixelFromData(pScanlineRead, x) != pReadAccess->GetPixelFromData(pScanlineRead, nWidth - x - 1))
75 return false;
80 return true;
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */