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_importer_test.h"
0008 
0009 #include "KisPart.h"
0010 #include "kis_animation_importer.h"
0011 #include "KisDocument.h"
0012 #include <testutil.h>
0013 #include "kis_keyframe_channel.h"
0014 #include "kis_image_animation_interface.h"
0015 #include "kis_group_layer.h"
0016 #include <KoUpdater.h>
0017 
0018 #include "testui.h"
0019 
0020 void KisAnimationImporterTest::testImport()
0021 {
0022     QScopedPointer<KisDocument> document(KisPart::instance()->createDocument());
0023     TestUtil::MaskParent mp(QRect(0,0,512,512));
0024     document->setCurrentImage(mp.image);
0025 
0026     KisAnimationImporter importer(document->image());
0027 
0028     QStringList files;
0029     files.append(QString(FILES_DATA_DIR) + '/' + "file_layer_source.png");
0030     files.append(QString(FILES_DATA_DIR) + '/' + "carrot.png");
0031     files.append(QString(FILES_DATA_DIR) + '/' + "hakonepa.png");
0032 
0033     importer.import(files, 7, 3);
0034 
0035     KisGroupLayerSP root = mp.image->rootLayer();
0036     KisNodeSP importedLayer = root->lastChild();
0037 
0038     KisKeyframeChannel* contentChannel = importedLayer->getKeyframeChannel(KisKeyframeChannel::Raster.id());
0039 
0040     QVERIFY(contentChannel != 0);
0041     QCOMPARE(contentChannel->keyframeCount(), 4); // Three imported ones + blank at time 0
0042     QVERIFY(!contentChannel->keyframeAt(7).isNull());
0043     QVERIFY(!contentChannel->keyframeAt(10).isNull());
0044     QVERIFY(!contentChannel->keyframeAt(13).isNull());
0045 
0046     mp.image->animationInterface()->switchCurrentTimeAsync(7);
0047     mp.image->waitForDone();
0048     QImage imported1 = importedLayer->projection()->convertToQImage(importedLayer->colorSpace()->profile());
0049 
0050     mp.image->animationInterface()->switchCurrentTimeAsync(10);
0051     mp.image->waitForDone();
0052     QImage imported2 = importedLayer->projection()->convertToQImage(importedLayer->colorSpace()->profile());
0053 
0054     mp.image->animationInterface()->switchCurrentTimeAsync(13);
0055     mp.image->waitForDone();
0056     QImage imported3 = importedLayer->projection()->convertToQImage(importedLayer->colorSpace()->profile());
0057 
0058     QImage source1(QString(FILES_DATA_DIR) + '/' + "file_layer_source.png");
0059     QImage source2(QString(FILES_DATA_DIR) + '/' + "carrot.png");
0060     QImage source3(QString(FILES_DATA_DIR) + '/' + "hakonepa.png");
0061 
0062     QPoint pt;
0063     QVERIFY(TestUtil::compareQImages(pt, source1, imported1));
0064     QVERIFY(TestUtil::compareQImages(pt, source2, imported2));
0065     QVERIFY(TestUtil::compareQImages(pt, source3, imported3));
0066 
0067     KisPart::instance()->removeDocument(document.data(), false);
0068 }
0069 
0070 KISTEST_MAIN(KisAnimationImporterTest)