File indexing completed on 2024-12-22 04:15:54
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Rasyuqa A. H. <qampidh@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_rgbe_test.h" 0008 0009 #include <simpletest.h> 0010 0011 #include <QString> 0012 0013 #include <filestest.h> 0014 #include <kis_meta_data_backend_registry.h> 0015 #include <testui.h> 0016 0017 #ifndef FILES_DATA_DIR 0018 #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" 0019 #endif 0020 0021 const QString MIMETYPE = "image/vnd.radiance"; 0022 0023 void KisRGBETest::testFiles() 0024 { 0025 KisMetadataBackendRegistry::instance(); 0026 0027 const int fuzziness = 1; 0028 0029 TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", {}, {}, fuzziness, 0, true); 0030 } 0031 0032 void KisRGBETest::testHDR() 0033 { 0034 const QString inputFileName = TestUtil::fetchDataFileLazy("/sources/hdr/objects.hdr"); 0035 0036 QScopedPointer<KisDocument> doc1(qobject_cast<KisDocument *>(KisPart::instance()->createDocument())); 0037 0038 KisImportExportManager manager(doc1.data()); 0039 doc1->setFileBatchMode(true); 0040 0041 const KisImportExportErrorCode status = manager.importDocument(inputFileName, {}); 0042 QVERIFY(status.isOk()); 0043 0044 KisImageSP image = doc1->image(); 0045 0046 { 0047 const QString outputFileName = TestUtil::fetchDataFileLazy("/results/objects.kra"); 0048 0049 KisDocument *doc2 = KisPart::instance()->createDocument(); 0050 doc2->setFileBatchMode(true); 0051 const bool r = doc2->importDocument(outputFileName); 0052 0053 QVERIFY(r); 0054 QVERIFY(doc2->errorMessage().isEmpty()); 0055 QVERIFY(doc2->image()); 0056 0057 QVERIFY(TestUtil::comparePaintDevicesClever<float>(doc1->image()->root()->firstChild()->paintDevice(), 0058 doc2->image()->root()->firstChild()->paintDevice(), 0059 0.01f /* meaningless alpha */)); 0060 0061 delete doc2; 0062 } 0063 } 0064 0065 inline void testSaveColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile) 0066 { 0067 const KoColorSpace *space = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, colorProfile); 0068 if (space) { 0069 TestUtil::testExportToColorSpace(MIMETYPE, space, ImportExportCodes::OK); 0070 } 0071 } 0072 void KisRGBETest::testSaveRgbaColorSpace() 0073 { 0074 QString profile = "sRGB-elle-V2-g10"; 0075 testSaveColorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), profile); 0076 } 0077 0078 #ifndef _WIN32 0079 void KisRGBETest::testImportFromWriteonly() 0080 { 0081 TestUtil::testImportFromWriteonly(MIMETYPE); 0082 } 0083 0084 void KisRGBETest::testExportToReadonly() 0085 { 0086 TestUtil::testExportToReadonly(MIMETYPE); 0087 } 0088 #endif 0089 0090 void KisRGBETest::testImportIncorrectFormat() 0091 { 0092 TestUtil::testImportIncorrectFormat(MIMETYPE); 0093 } 0094 0095 KISTEST_MAIN(KisRGBETest)