File indexing completed on 2024-12-22 04:10:21

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Jouni Pentikäinen <joupent@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_onion_skin_compositor_test.h"
0008 
0009 #include <simpletest.h>
0010 
0011 #include "kis_onion_skin_compositor.h"
0012 #include "kis_paint_device.h"
0013 #include "kis_raster_keyframe_channel.h"
0014 #include "kis_image_animation_interface.h"
0015 #include <testutil.h>
0016 #include "KoColor.h"
0017 #include "kis_image_config.h"
0018 
0019 void KisOnionSkinCompositorTest::testComposite()
0020 {
0021     TestUtil::ReferenceImageChecker chk("composite", "onion_skins", TestUtil::ReferenceImageChecker::InternalStorage);
0022 
0023     KisImageConfig config(false);
0024     config.setOnionSkinTintFactor(64);
0025     config.setOnionSkinTintColorBackward(Qt::blue);
0026     config.setOnionSkinTintColorForward(Qt::red);
0027     config.setNumberOfOnionSkins(1);
0028     config.setOnionSkinOpacity(-1, 128);
0029     config.setOnionSkinOpacity(1, 128);
0030 
0031     KisOnionSkinCompositor *compositor = KisOnionSkinCompositor::instance();
0032 
0033     TestUtil::MaskParent p;
0034 
0035     KisImageAnimationInterface *i = p.image->animationInterface();
0036     KisPaintDeviceSP paintDevice = p.layer->paintDevice();
0037     paintDevice->createKeyframeChannel(KoID());
0038     KisKeyframeChannel *keyframes = paintDevice->keyframeChannel();
0039 
0040     keyframes->addKeyframe(0);
0041     keyframes->addKeyframe(10);
0042     keyframes->addKeyframe(20);
0043 
0044     paintDevice->fill(QRect(0,0,256,512), KoColor(Qt::red, paintDevice->colorSpace()));
0045 
0046     i->switchCurrentTimeAsync(10);
0047     p.image->waitForDone();
0048 
0049     paintDevice->fill(QRect(0,0,512,256), KoColor(Qt::green, paintDevice->colorSpace()));
0050 
0051     i->switchCurrentTimeAsync(20);
0052     p.image->waitForDone();
0053 
0054     paintDevice->fill(QRect(0,256,512,256), KoColor(Qt::blue, paintDevice->colorSpace()));
0055 
0056     KisPaintDeviceSP compositeDevice = new KisPaintDevice(p.image->colorSpace());
0057 
0058     // Frame 0
0059 
0060     i->switchCurrentTimeAsync(0);
0061     p.image->waitForDone();
0062     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0063 
0064     QVERIFY(chk.checkDevice(compositeDevice, p.image, "frame00"));
0065 
0066     // Frame 10
0067 
0068     i->switchCurrentTimeAsync(10);
0069     p.image->waitForDone();
0070     compositeDevice->clear();
0071     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0072 
0073     QVERIFY(chk.checkDevice(compositeDevice, p.image, "frame10"));
0074 
0075     // Frame 20
0076 
0077     i->switchCurrentTimeAsync(20);
0078     p.image->waitForDone();
0079     compositeDevice->clear();
0080     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0081 
0082     QVERIFY(chk.checkDevice(compositeDevice, p.image, "frame20"));
0083 }
0084 
0085 void KisOnionSkinCompositorTest::testSettings()
0086 {
0087     TestUtil::ReferenceImageChecker chk("settings", "onion_skins", TestUtil::ReferenceImageChecker::InternalStorage);
0088 
0089     KisOnionSkinCompositor *compositor = KisOnionSkinCompositor::instance();
0090 
0091     TestUtil::MaskParent p;
0092     KisImageAnimationInterface *i = p.image->animationInterface();
0093     KisPaintDeviceSP paintDevice = p.layer->paintDevice();
0094     paintDevice->createKeyframeChannel(KoID());
0095     KisKeyframeChannel *keyframes = paintDevice->keyframeChannel();
0096 
0097     keyframes->addKeyframe(0);
0098     keyframes->addKeyframe(1);
0099     keyframes->addKeyframe(2);
0100     keyframes->addKeyframe(3);
0101 
0102     paintDevice->fill(QRect(0,0,512,512), KoColor(Qt::red, paintDevice->colorSpace()));
0103 
0104     i->switchCurrentTimeAsync(2);
0105     p.image->waitForDone();
0106 
0107     paintDevice->fill(QRect(0,0,512,512), KoColor(Qt::green, paintDevice->colorSpace()));
0108 
0109     i->switchCurrentTimeAsync(3);
0110     p.image->waitForDone();
0111 
0112     paintDevice->fill(QRect(0,0,512,512), KoColor(Qt::blue, paintDevice->colorSpace()));
0113 
0114     i->switchCurrentTimeAsync(1);
0115     p.image->waitForDone();
0116 
0117     KisImageConfig config(false);
0118     config.setOnionSkinOpacity(-1, 32);
0119     config.setOnionSkinOpacity(1, 192);
0120     config.setOnionSkinOpacity(2, 64);
0121     config.setOnionSkinTintFactor(0);
0122 
0123     KisPaintDeviceSP compositeDevice = new KisPaintDevice(p.image->colorSpace());
0124 
0125     config.setNumberOfOnionSkins(1);
0126     compositor->configChanged();
0127     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0128 
0129     QVERIFY(chk.checkDevice(compositeDevice, p.image, "00_single_skin"));
0130 
0131     config.setNumberOfOnionSkins(2);
0132     compositor->configChanged();
0133 
0134     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0135     QVERIFY(chk.checkDevice(compositeDevice, p.image, "01_double_skin"));
0136 
0137     // Test tint options
0138 
0139     config.setNumberOfOnionSkins(1);
0140     config.setOnionSkinTintFactor(64);
0141     config.setOnionSkinTintColorBackward(Qt::blue);
0142     config.setOnionSkinTintColorForward(Qt::red);
0143     compositor->configChanged();
0144 
0145     compositor->composite(paintDevice, compositeDevice, QRect(0,0,512,512));
0146     QVERIFY(chk.checkDevice(compositeDevice, p.image, "02_single_skin_tinted"));
0147 }
0148 
0149 SIMPLE_TEST_MAIN(KisOnionSkinCompositorTest)