File indexing completed on 2025-01-26 04:10:29
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Lukáš Tvrdý <lukast.dev@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include <kis_paint_device.h> 0009 #include <kis_paint_layer.h> 0010 #include <KoColorSpaceRegistry.h> 0011 #include <kis_image.h> 0012 #include <KoColorSpace.h> 0013 #include <KoResourcePaths.h> 0014 #include <KoColorModelStandardIds.h> 0015 #include <KoColor.h> 0016 0017 #include <simpletest.h> 0018 #include <QImage> 0019 0020 #include <kis_qmic_simple_convertor.h> 0021 #include <kis_group_layer.h> 0022 #include <kis_painter.h> 0023 #include <kis_selection.h> 0024 #include <commands/kis_set_global_selection_command.h> 0025 #include <kis_processing_applicator.h> 0026 #include <testutil.h> 0027 0028 #include "../kis_qmic_interface.h" 0029 #include "kis_qmic_tests.h" 0030 0031 #ifndef FILES_DATA_DIR 0032 #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" 0033 #endif 0034 0035 void KisQmicTests::initTestCase() 0036 { 0037 m_qimage = QImage(QString(FILES_DATA_DIR) + "/" + "poster_rodents_bunnysize.jpg"); 0038 m_qimage.convertTo(QImage::Format_ARGB32); 0039 } 0040 0041 void KisQmicTests::cleanupTestCase() 0042 { 0043 } 0044 0045 void KisQmicTests::testConvertGrayScaleQmic() 0046 { 0047 KisPaintDeviceSP resultDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0048 KisPaintDeviceSP resultDevFast = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0049 0050 KisQMicImage qmicImage({}, m_qimage.width(), m_qimage.height(), 1); 0051 0052 KisQmicSimpleConvertor::convertFromQImage(m_qimage, qmicImage, 1.0); 0053 KisQmicSimpleConvertor::convertFromGmicImage(qmicImage, resultDev, 1.0); 0054 KisQmicSimpleConvertor::convertFromGmicFast(qmicImage, resultDevFast, 1.0); 0055 0056 QImage slowQImage = resultDev->convertToQImage(nullptr, 0057 0, 0058 0, 0059 qmicImage.m_width, 0060 qmicImage.m_height); 0061 QImage fastQImage = resultDevFast->convertToQImage(nullptr, 0062 0, 0063 0, 0064 qmicImage.m_width, 0065 qmicImage.m_height); 0066 0067 QPoint errpoint; 0068 if (!TestUtil::compareQImages(errpoint, slowQImage, fastQImage)) { 0069 QFAIL(QString("Slow method produces different result then fast to convert qmic grayscale pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0070 slowQImage.save("grayscale.bmp"); 0071 fastQImage.save("grayscale_fast.bmp"); 0072 } 0073 } 0074 0075 void KisQmicTests::testConvertGrayScaleAlphaQmic() 0076 { 0077 KisPaintDeviceSP resultDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0078 KisPaintDeviceSP resultDevFast = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0079 0080 KisQMicImage qmicImage({}, m_qimage.width(), m_qimage.height(), 2); 0081 0082 KisQmicSimpleConvertor::convertFromQImage(m_qimage, qmicImage, 1.0); 0083 KisQmicSimpleConvertor::convertFromGmicImage(qmicImage, resultDev, 1.0); 0084 KisQmicSimpleConvertor::convertFromGmicFast(qmicImage, resultDevFast, 1.0); 0085 0086 QImage slowQImage = resultDev->convertToQImage(nullptr, 0087 0, 0088 0, 0089 qmicImage.m_width, 0090 qmicImage.m_height); 0091 QImage fastQImage = resultDevFast->convertToQImage(nullptr, 0092 0, 0093 0, 0094 qmicImage.m_width, 0095 qmicImage.m_height); 0096 0097 QPoint errpoint; 0098 if (!TestUtil::compareQImages(errpoint, slowQImage, fastQImage)) { 0099 QFAIL(QString("Slow method produces different result then fast to convert qmic grayscale pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0100 slowQImage.save("grayscale.bmp"); 0101 fastQImage.save("grayscale_fast.bmp"); 0102 } 0103 } 0104 0105 void KisQmicTests::testConvertRGBqmic() 0106 { 0107 KisPaintDeviceSP resultDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0108 KisPaintDeviceSP resultDevFast = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0109 0110 KisQMicImage qmicImage({}, m_qimage.width(), m_qimage.height(), 3); 0111 0112 KisQmicSimpleConvertor::convertFromQImage(m_qimage, qmicImage, 1.0); 0113 KisQmicSimpleConvertor::convertFromGmicImage(qmicImage, resultDev, 1.0); 0114 KisQmicSimpleConvertor::convertFromGmicFast(qmicImage, resultDevFast, 1.0); 0115 0116 QImage slowQImage = resultDev->convertToQImage(nullptr, 0117 0, 0118 0, 0119 qmicImage.m_width, 0120 qmicImage.m_height); 0121 QPoint errpoint; 0122 0123 if (!TestUtil::compareQImages(errpoint, slowQImage, m_qimage)) { 0124 QFAIL(QString("Slow method failed to convert qmic RGB pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0125 slowQImage.save("RGB.bmp"); 0126 } 0127 0128 QImage fastQImage = resultDevFast->convertToQImage(nullptr, 0129 0, 0130 0, 0131 qmicImage.m_width, 0132 qmicImage.m_height); 0133 0134 if (!TestUtil::compareQImages(errpoint,fastQImage,m_qimage)) { 0135 QFAIL(QString("Fast method failed to convert qmic RGB pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0136 fastQImage.save("RGB_fast.bmp"); 0137 } 0138 } 0139 0140 0141 void KisQmicTests::testConvertRGBAqmic() 0142 { 0143 KisPaintDeviceSP resultDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0144 KisPaintDeviceSP resultDevFast = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0145 0146 KisQMicImage qmicImage({}, m_qimage.width(), m_qimage.height(), 4); 0147 0148 KisQmicSimpleConvertor::convertFromQImage(m_qimage, qmicImage, 1.0); 0149 KisQmicSimpleConvertor::convertFromGmicImage(qmicImage, resultDev, 1.0); 0150 KisQmicSimpleConvertor::convertFromGmicFast(qmicImage, resultDevFast, 1.0); 0151 0152 QImage slowQImage = resultDev->convertToQImage(nullptr, 0153 0, 0154 0, 0155 qmicImage.m_width, 0156 qmicImage.m_height); 0157 QPoint errpoint; 0158 if (!TestUtil::compareQImages(errpoint,slowQImage,m_qimage)) { 0159 QFAIL(QString("Slow method failed to convert qmic RGBA pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0160 slowQImage.save("RGBA.bmp"); 0161 } 0162 0163 QImage fastQImage = resultDevFast->convertToQImage(nullptr, 0164 0, 0165 0, 0166 qmicImage.m_width, 0167 qmicImage.m_height); 0168 0169 if (!TestUtil::compareQImages(errpoint,fastQImage,m_qimage)) { 0170 QFAIL(QString("Fast method failed to convert qmic RGBA pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0171 fastQImage.save("RGBA_fast.bmp"); 0172 } 0173 } 0174 0175 void KisQmicTests::testConvertToGmic() 0176 { 0177 KisPaintDeviceSP srcDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0178 srcDev->convertFromQImage(m_qimage, nullptr); 0179 0180 KisQMicImage qmicImage({}, m_qimage.width(), m_qimage.height(), 4); 0181 0182 KisQmicSimpleConvertor::convertToGmicImageFast(srcDev, 0183 qmicImage, 0184 srcDev->exactBounds()); 0185 0186 QPoint errpoint; 0187 QImage resultQImage = KisQmicSimpleConvertor::convertToQImage(qmicImage); 0188 if (!TestUtil::compareQImages(errpoint, resultQImage, m_qimage)) { 0189 QFAIL(QString("Failed to convert qmic RGBA pixel format to QImage, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0190 resultQImage.save("testConvertToGmic_qimage.bmp"); 0191 } 0192 0193 KisPaintDeviceSP resultDevFast = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0194 KisQmicSimpleConvertor::convertFromGmicFast(qmicImage, resultDevFast, 255.0f); 0195 QImage fastQImage = resultDevFast->convertToQImage(nullptr, 0196 0, 0197 0, 0198 qmicImage.m_width, 0199 qmicImage.m_height); 0200 0201 if (!TestUtil::compareQImages(errpoint, fastQImage, m_qimage)) { 0202 QFAIL(QString("Fast method failed to convert qmic RGBA pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0203 fastQImage.save("testConvertToGmic_fast.bmp"); 0204 } 0205 0206 KisPaintDeviceSP resultDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0207 KisQmicSimpleConvertor::convertFromGmicImage(qmicImage, resultDev, 255.0f); 0208 QImage slowQImage = resultDev->convertToQImage(nullptr, 0209 0, 0210 0, 0211 qmicImage.m_width, 0212 qmicImage.m_height); 0213 if (!TestUtil::compareQImages(errpoint, slowQImage, m_qimage)) { 0214 QFAIL(QString("Slow method failed to convert qmic RGBA pixel format, first different pixel: %1,%2 ").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); 0215 slowQImage.save("testConvertToGmic_slow.bmp"); 0216 } 0217 0218 0219 } 0220 0221 0222 SIMPLE_TEST_MAIN(KisQmicTests) 0223