File indexing completed on 2024-12-22 04:10:28
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisOverlayPaintDeviceWrapperTest.h" 0008 0009 #include "KisOverlayPaintDeviceWrapper.h" 0010 #include <KoColorSpaceRegistry.h> 0011 #include <kis_paint_device.h> 0012 #include "kistest.h" 0013 0014 #include <KoColor.h> 0015 0016 #include <kis_paint_device_debug_utils.h> 0017 0018 0019 void KisOverlayPaintDeviceWrapperTest::test() 0020 { 0021 QVector<const KoColorSpace*> colorSpaces; 0022 colorSpaces << KoColorSpaceRegistry::instance()->rgb16(); 0023 colorSpaces << KoColorSpaceRegistry::instance()->graya8(); 0024 0025 KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0026 0027 KisOverlayPaintDeviceWrapper wrapper(dev, 2, KisOverlayPaintDeviceWrapper::PreciseMode); 0028 0029 KoColor colorR(Qt::red, dev->colorSpace()); 0030 KoColor colorG(Qt::green, dev->colorSpace()); 0031 KoColor colorB(Qt::blue, dev->colorSpace()); 0032 KoColor colorB_rgb16(Qt::blue, wrapper.overlayColorSpace()); 0033 0034 dev->fill(QRect(0,0,100,100), colorR); 0035 dev->fill(QRect(100,0,100,100), colorG); 0036 dev->fill(QRect(0,100,200,100), colorB); 0037 0038 KIS_DUMP_DEVICE_2(dev, QRect(0,0,200,200), "00_dev", "dd"); 0039 KIS_DUMP_DEVICE_2(wrapper.overlay(0), QRect(0,0,200,200), "01_ov1", "dd"); 0040 KIS_DUMP_DEVICE_2(wrapper.overlay(1), QRect(0,0,200,200), "02_ov2", "dd"); 0041 0042 wrapper.readRect(QRect(10,10,15,15)); 0043 0044 KIS_DUMP_DEVICE_2(dev, QRect(0,0,200,200), "03_dev", "dd"); 0045 KIS_DUMP_DEVICE_2(wrapper.overlay(0), QRect(0,0,200,200), "04_ov1", "dd"); 0046 KIS_DUMP_DEVICE_2(wrapper.overlay(1), QRect(0,0,200,200), "05_ov2", "dd"); 0047 0048 0049 wrapper.readRect(QRect(70,10,15,15)); 0050 0051 KIS_DUMP_DEVICE_2(dev, QRect(0,0,200,200), "07_dev", "dd"); 0052 KIS_DUMP_DEVICE_2(wrapper.overlay(0), QRect(0,0,200,200), "08_ov1", "dd"); 0053 KIS_DUMP_DEVICE_2(wrapper.overlay(1), QRect(0,0,200,200), "09_ov2", "dd"); 0054 0055 wrapper.overlay(0)->fill(QRect(10,10,15,15), colorB_rgb16); 0056 wrapper.overlay(0)->fill(QRect(70,10,15,15), colorB_rgb16); 0057 0058 wrapper.readRect(QRect(70,10,15,15)); 0059 0060 KIS_DUMP_DEVICE_2(dev, QRect(0,0,200,200), "10_dev", "dd"); 0061 KIS_DUMP_DEVICE_2(wrapper.overlay(0), QRect(0,0,200,200), "11_ov1", "dd"); 0062 KIS_DUMP_DEVICE_2(wrapper.overlay(1), QRect(0,0,200,200), "12_ov2", "dd"); 0063 0064 // todo: when writing, do not align 0065 wrapper.writeRect(QRect(10,10,15,15)); 0066 0067 KIS_DUMP_DEVICE_2(dev, QRect(0,0,200,200), "13_dev", "dd"); 0068 KIS_DUMP_DEVICE_2(wrapper.overlay(0), QRect(0,0,200,200), "14_ov1", "dd"); 0069 KIS_DUMP_DEVICE_2(wrapper.overlay(1), QRect(0,0,200,200), "15_ov2", "dd"); 0070 0071 } 0072 0073 void KisOverlayPaintDeviceWrapperTest::benchmark() 0074 { 0075 KisPaintDeviceSP dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8()); 0076 0077 KisOverlayPaintDeviceWrapper wrapper(dev, 1, KisOverlayPaintDeviceWrapper::PreciseMode); 0078 0079 KoColor colorR(Qt::red, dev->colorSpace()); 0080 KoColor colorG(Qt::green, dev->colorSpace()); 0081 KoColor colorB(Qt::blue, dev->colorSpace()); 0082 0083 dev->fill(QRect(0,0,10000,10000), colorR); 0084 dev->fill(QRect(0,0,100,100), colorG); 0085 dev->fill(QRect(9900,9900,100,100), colorB); 0086 0087 QElapsedTimer t; 0088 t.start(); 0089 wrapper.readRect(QRect(0,0,10000, 10000)); 0090 qDebug() << "Read time (ms):" << t.restart(); 0091 wrapper.writeRect(QRect(0,0,10000, 10000)); 0092 qDebug() << "Write time (ms):" << t.restart(); 0093 } 0094 0095 KISTEST_MAIN(KisOverlayPaintDeviceWrapperTest)