diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-25 11:35:55 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-27 10:45:15 +0900 |
commit | 44c6c4da9545d69ad02f5e8ea1314388e1eacec7 (patch) | |
tree | a5dd6a504abf7ae9374df22692d7357c2b8b7ce4 /vcl/source/bitmap | |
parent | 389bf9e196aa7b783a325d7c00d41d943511d5ba (diff) |
vcl: tests for Bitmap, check for symmetry when scaling bitmaps
Change-Id: I53d6e70018477abb9f98140a52697c1de0f90934
Diffstat (limited to 'vcl/source/bitmap')
-rw-r--r-- | vcl/source/bitmap/BitmapSymmetryCheck.cxx | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/vcl/source/bitmap/BitmapSymmetryCheck.cxx b/vcl/source/bitmap/BitmapSymmetryCheck.cxx new file mode 100644 index 000000000000..ad96a09f2c7b --- /dev/null +++ b/vcl/source/bitmap/BitmapSymmetryCheck.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <BitmapSymmetryCheck.hxx> + +BitmapSymmetryCheck::BitmapSymmetryCheck() +{} + +BitmapSymmetryCheck::~BitmapSymmetryCheck() +{} + +bool BitmapSymmetryCheck::check(Bitmap& rBitmap) +{ + Bitmap::ScopedReadAccess aReadAccess(rBitmap); + return checkImpl(aReadAccess.get()); +} + +bool BitmapSymmetryCheck::checkImpl(BitmapReadAccess* pReadAccess) +{ + long nHeight = pReadAccess->Height(); + long nWidth = pReadAccess->Width(); + + long nHeightHalf = nHeight / 2; + long nWidthHalf = nWidth / 2; + + bool nHeightEven = (nHeight % 2) == 0; + bool nWidthEven = (nWidth % 2) == 0; + + for (long y = 0; y < nHeightHalf; ++y) + { + for (long x = 0; x < nWidthHalf; ++x) + { + if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, x)) + { + return false; + } + if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(y, nWidth - x - 1)) + { + return false; + } + if (pReadAccess->GetPixel(y, x) != pReadAccess->GetPixel(nHeight - y - 1, nWidth - x - 1)) + { + return false; + } + } + } + + if (nWidthEven) + { + for (long y = 0; y < nHeightHalf; ++y) + { + if (pReadAccess->GetPixel(y, nWidthHalf) != pReadAccess->GetPixel(nHeight - y - 1, nWidthHalf)) + { + return false; + } + } + } + + if (nHeightEven) + { + for (long x = 0; x < nWidthHalf; ++x) + { + if (pReadAccess->GetPixel(nHeightHalf, x) != pReadAccess->GetPixel(nHeightHalf, nWidth - x - 1)) + { + return false; + } + } + } + + return true; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |