File indexing completed on 2024-12-22 04:11:22
0001 /* SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org> 0002 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 #include "TestChannel.h" 0006 #include <simpletest.h> 0007 #include <QColor> 0008 #include <QDataStream> 0009 #include <QLoggingCategory> 0010 0011 #include <KritaVersionWrapper.h> 0012 #include <Node.h> 0013 #include <Channel.h> 0014 #include <Krita.h> 0015 0016 #include <KoColorSpaceRegistry.h> 0017 #include <KoColorProfile.h> 0018 #include <KoColor.h> 0019 0020 #include <kis_fill_painter.h> 0021 #include <kis_image.h> 0022 #include <kis_paint_layer.h> 0023 #include <testui.h> 0024 0025 void TestChannel::testPixelDataU8() 0026 { 0027 KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb8(), "test"); 0028 KisNodeSP layer = new KisPaintLayer(image, "test1", 255); 0029 KisFillPainter gc(layer->paintDevice()); 0030 gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); 0031 NodeSP node = NodeSP(Node::createNode(image, layer)); 0032 QList<Channel*> channels = node->channels(); 0033 Q_FOREACH(Channel *channel, channels) { 0034 QVERIFY(channel->channelSize() == 1); 0035 } 0036 0037 } 0038 0039 void TestChannel::testPixelDataU16() 0040 { 0041 KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->rgb16(), "test"); 0042 KisNodeSP layer = new KisPaintLayer(image, "test1", 255); 0043 KisFillPainter gc(layer->paintDevice()); 0044 gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); 0045 NodeSP node = NodeSP(Node::createNode(image, layer)); 0046 QList<Channel*> channels = node->channels(); 0047 Q_FOREACH(Channel *channel, channels) { 0048 QVERIFY(channel->channelSize() == 2); 0049 } 0050 } 0051 0052 void TestChannel::testPixelDataF16() 0053 { 0054 #ifdef HAVE_OPENEXR 0055 const KoColorSpace * cs = KoColorSpaceRegistry::instance()->colorSpace("RGBA", "F16", ""); 0056 KisImageSP image = new KisImage(0, 100, 100, cs, "test"); 0057 KisNodeSP layer = new KisPaintLayer(image, "test1", 255); 0058 KisFillPainter gc(layer->paintDevice()); 0059 gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); 0060 NodeSP node = NodeSP(Node::createNode(image, layer)); 0061 QList<Channel*> channels = node->channels(); 0062 Q_FOREACH(Channel *channel, channels) { 0063 qDebug() << "channelsize" << channel->channelSize(); 0064 QVERIFY(channel->channelSize() == 2); 0065 } 0066 #endif 0067 } 0068 0069 void TestChannel::testPixelDataF32() 0070 { 0071 KisImageSP image = new KisImage(0, 100, 100, KoColorSpaceRegistry::instance()->colorSpace("RGBA", "F32", ""), "test"); 0072 KisNodeSP layer = new KisPaintLayer(image, "test1", 255); 0073 KisFillPainter gc(layer->paintDevice()); 0074 gc.fillRect(0, 0, 100, 100, KoColor(Qt::red, layer->colorSpace())); 0075 NodeSP node = NodeSP(Node::createNode(image, layer)); 0076 QList<Channel*> channels = node->channels(); 0077 Q_FOREACH(Channel *channel, channels) { 0078 QVERIFY(channel->channelSize() == 4); 0079 } 0080 } 0081 0082 void TestChannel::testReadWritePixelData() 0083 { 0084 KisImageSP image = new KisImage(0, 2, 2, KoColorSpaceRegistry::instance()->colorSpace("RGBA", "U8", ""), "test"); 0085 KisNodeSP layer = new KisPaintLayer(image, "test1", 255); 0086 KisFillPainter gc(layer->paintDevice()); 0087 gc.fillRect(0, 0, 2, 2, KoColor(Qt::yellow, layer->colorSpace())); 0088 NodeSP node = NodeSP(Node::createNode(image, layer)); 0089 QList<Channel*> channels = node->channels(); 0090 Channel *greenChan = channels[1]; 0091 QVERIFY(greenChan->name() == "Green"); 0092 QRect rc = greenChan->bounds(); 0093 QVERIFY(rc == QRect(0, 0, 2, 2)); 0094 QByteArray ba = greenChan->pixelData(rc); 0095 ba.fill('\x80', 4); 0096 greenChan->setPixelData(ba, rc); 0097 image->refreshGraph(); 0098 QColor c; 0099 layer->paintDevice()->pixel(0, 0, &c); 0100 QVERIFY(c == QColor(255, 128, 0)); 0101 0102 } 0103 0104 0105 KISTEST_MAIN(TestChannel) 0106