File indexing completed on 2025-03-23 12:43:50
0001 /* 0002 SPDX-FileCopyrightText: 2014 Alex Merry <alex.merry@kdemail.net> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 template<class Trait> 0008 static bool fuzzyeq(const QImage &im1, const QImage &im2, uchar fuzziness) 0009 { 0010 Q_ASSERT(im1.format() == im2.format()); 0011 Q_ASSERT(im1.depth() == 24 || im1.depth() == 32 || im1.depth() == 64); 0012 0013 const int height = im1.height(); 0014 const int width = im1.width(); 0015 for (int i = 0; i < height; ++i) { 0016 const Trait *line1 = reinterpret_cast<const Trait *>(im1.scanLine(i)); 0017 const Trait *line2 = reinterpret_cast<const Trait *>(im2.scanLine(i)); 0018 for (int j = 0; j < width; ++j) { 0019 if (line1[j] > line2[j]) { 0020 if (line1[j] - line2[j] > fuzziness) { 0021 return false; 0022 } 0023 } else { 0024 if (line2[j] - line1[j] > fuzziness) { 0025 return false; 0026 } 0027 } 0028 } 0029 } 0030 return true; 0031 } 0032 0033 // allow each byte to be different by up to 1, to allow for rounding errors 0034 static bool fuzzyeq(const QImage &im1, const QImage &im2, uchar fuzziness) 0035 { 0036 return (im1.depth() == 64) ? fuzzyeq<quint16>(im1, im2, fuzziness) : fuzzyeq<quint8>(im1, im2, fuzziness); 0037 }