File indexing completed on 2024-12-22 04:12:50

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_animation_exporter_test.h"
0008 
0009 #include "dialogs/KisAsyncAnimationFramesSaveDialog.h"
0010 
0011 #include <simpletest.h>
0012 #include <testutil.h>
0013 #include "KisPart.h"
0014 #include "kis_image.h"
0015 #include "KisDocument.h"
0016 #include "kis_image_animation_interface.h"
0017 #include "KoColor.h"
0018 #include <KoUpdater.h>
0019 #include "kis_time_span.h"
0020 #include "kis_keyframe_channel.h"
0021 #include <testui.h>
0022 
0023 void KisAnimationExporterTest::testAnimationExport()
0024 {
0025     KisDocument *document = KisPart::instance()->createDocument();
0026     QRect rect(0,0,512,512);
0027     QRect fillRect(10,0,502,512);
0028     TestUtil::MaskParent p(rect);
0029     document->setCurrentImage(p.image);
0030     const KoColorSpace *cs = p.image->colorSpace();
0031 
0032     KUndo2Command parentCommand;
0033 
0034     p.layer->enableAnimation();
0035     KisKeyframeChannel *rasterChannel = p.layer->getKeyframeChannel(KisKeyframeChannel::Raster.id(), true);
0036 
0037     rasterChannel->addKeyframe(1, &parentCommand);
0038     rasterChannel->addKeyframe(2, &parentCommand);
0039     p.image->animationInterface()->setDocumentRange(KisTimeSpan::fromTimeToTime(0, 2));
0040 
0041     KisPaintDeviceSP dev = p.layer->paintDevice();
0042 
0043     dev->fill(fillRect, KoColor(Qt::red, cs));
0044     QImage frame0 = dev->convertToQImage(0, rect);
0045 
0046     p.image->animationInterface()->switchCurrentTimeAsync(1);
0047     p.image->waitForDone();
0048     dev->fill(fillRect, KoColor(Qt::green, cs));
0049     QImage frame1 = dev->convertToQImage(0, rect);
0050 
0051     p.image->animationInterface()->switchCurrentTimeAsync(2);
0052     p.image->waitForDone();
0053     dev->fill(fillRect, KoColor(Qt::blue, cs));
0054     QImage frame2 = dev->convertToQImage(0, rect);
0055 
0056     KisAsyncAnimationFramesSaveDialog exporter(document->image(),
0057                                                KisTimeSpan::fromTimeToTime(0,2),
0058                                                "export-test.png",
0059                                                0,
0060                                                false,
0061                                                0);
0062 
0063 
0064 
0065     exporter.setBatchMode(true);
0066     exporter.regenerateRange(0);
0067 
0068     QTest::qWait(1000);
0069 
0070     QImage exported;
0071 
0072     QPoint errpoint;
0073     exported.load("export-test0000.png");
0074     qDebug() << exported.size() << frame0.size();
0075     if (!TestUtil::compareQImages(errpoint, exported, frame0)) {
0076         QFAIL(QString("Failed to export identical frame0, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
0077     }
0078 
0079     exported.load("export-test0001.png");
0080     if (!TestUtil::compareQImages(errpoint, exported, frame1)) {
0081         QFAIL(QString("Failed to export identical frame1, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
0082     }
0083 
0084     exported.load("export-test0002.png");
0085     if (!TestUtil::compareQImages(errpoint, exported, frame2)) {
0086         QFAIL(QString("Failed to export identical frame2, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
0087     }
0088 }
0089 
0090 KISTEST_MAIN(KisAnimationExporterTest)