1 /*
2 * Copyright (c) 2015 Jouni Pentikäinen <joupent@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "kis_animation_exporter_test.h"
20
21 #include "dialogs/KisAsyncAnimationFramesSaveDialog.h"
22
23 #include <QTest>
24 #include <testutil.h>
25 #include "KisPart.h"
26 #include "kis_image.h"
27 #include "KisDocument.h"
28 #include "kis_image_animation_interface.h"
29 #include "KoColor.h"
30 #include <KoUpdater.h>
31 #include "kis_time_range.h"
32 #include "kis_keyframe_channel.h"
33 #include <kistest.h>
34
testAnimationExport()35 void KisAnimationExporterTest::testAnimationExport()
36 {
37 KisDocument *document = KisPart::instance()->createDocument();
38 QRect rect(0,0,512,512);
39 QRect fillRect(10,0,502,512);
40 TestUtil::MaskParent p(rect);
41 document->setCurrentImage(p.image);
42 const KoColorSpace *cs = p.image->colorSpace();
43
44 KUndo2Command parentCommand;
45
46 p.layer->enableAnimation();
47 KisKeyframeChannel *rasterChannel = p.layer->getKeyframeChannel(KisKeyframeChannel::Content.id(), true);
48
49 rasterChannel->addKeyframe(1, &parentCommand);
50 rasterChannel->addKeyframe(2, &parentCommand);
51 p.image->animationInterface()->setFullClipRange(KisTimeRange::fromTime(0, 2));
52
53 KisPaintDeviceSP dev = p.layer->paintDevice();
54
55 dev->fill(fillRect, KoColor(Qt::red, cs));
56 QImage frame0 = dev->convertToQImage(0, rect);
57
58 p.image->animationInterface()->switchCurrentTimeAsync(1);
59 p.image->waitForDone();
60 dev->fill(fillRect, KoColor(Qt::green, cs));
61 QImage frame1 = dev->convertToQImage(0, rect);
62
63 p.image->animationInterface()->switchCurrentTimeAsync(2);
64 p.image->waitForDone();
65 dev->fill(fillRect, KoColor(Qt::blue, cs));
66 QImage frame2 = dev->convertToQImage(0, rect);
67
68 KisAsyncAnimationFramesSaveDialog exporter(document->image(),
69 KisTimeRange::fromTime(0,2),
70 "export-test.png",
71 0,
72 false,
73 0);
74
75
76
77 exporter.setBatchMode(true);
78 exporter.regenerateRange(0);
79
80 QTest::qWait(1000);
81
82 QImage exported;
83
84 QPoint errpoint;
85 exported.load("export-test0000.png");
86 qDebug() << exported.size() << frame0.size();
87 if (!TestUtil::compareQImages(errpoint, exported, frame0)) {
88 QFAIL(QString("Failed to export identical frame0, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
89 }
90
91 exported.load("export-test0001.png");
92 if (!TestUtil::compareQImages(errpoint, exported, frame1)) {
93 QFAIL(QString("Failed to export identical frame1, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
94 }
95
96 exported.load("export-test0002.png");
97 if (!TestUtil::compareQImages(errpoint, exported, frame2)) {
98 QFAIL(QString("Failed to export identical frame2, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
99 }
100 }
101
102 KISTEST_MAIN(KisAnimationExporterTest)
103