Krita Source Code Documentation
Loading...
Searching...
No Matches
Channel Class Reference

#include <Channel.h>

+ Inheritance diagram for Channel:

Classes

struct  Private
 

Public Member Functions

QRect bounds () const
 
 Channel (KisNodeSP node, KoChannelInfo *channel, QObject *parent=0)
 
int channelSize () const
 
QString name () const
 
bool operator!= (const Channel &other) const
 
bool operator== (const Channel &other) const
 
QByteArray pixelData (const QRect &rect) const
 
int position () const
 
void setPixelData (QByteArray value, const QRect &rect)
 setPixelData writes the given data to the relevant channel in the Node. This is only possible for Nodes that have a paintDevice, so nothing will happen when trying to write to e.g. a group layer.
 
void setVisible (bool value)
 setvisible set the visibility of the channel to the given value.
 
bool visible () const
 visible checks whether this channel is visible in the node
 
 ~Channel () override
 

Private Attributes

Private *const d
 

Detailed Description

A Channel represents a single channel in a Node. Krita does not use channels to store local selections: these are strictly the color and alpha channels.

Definition at line 22 of file Channel.h.

Constructor & Destructor Documentation

◆ Channel()

Channel::Channel ( KisNodeSP node,
KoChannelInfo * channel,
QObject * parent = 0 )
explicit

Definition at line 33 of file Channel.cpp.

34 : QObject(parent)
35 , d(new Private)
36{
37 d->node = node;
38 d->channel = channel;
39}
Private *const d
Definition Channel.h:87
KoChannelInfo * channel
Definition Channel.cpp:29
KisNodeSP node
Definition Channel.cpp:28

References Channel::Private::channel, d, and Channel::Private::node.

◆ ~Channel()

Channel::~Channel ( )
override

Definition at line 41 of file Channel.cpp.

42{
43 delete d;
44}

References d.

Member Function Documentation

◆ bounds()

QRect Channel::bounds ( ) const
Returns
the exact bounds of the channel. This can be smaller than the bounds of the Node this channel is part of.

Definition at line 115 of file Channel.cpp.

116{
117 if (!d->node || !d->channel) return QRect();
118
119 QRect rect = d->node->exactBounds();
120
123 dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
124 }
126 dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16());
127 }
128#ifdef HAVE_OPENEXR
130 dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16f());
131 }
132#endif
134 dev = new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha32f());
135 }
136
138 KisSequentialIterator dstIt(dev, rect);
139
140 while(srcIt.nextPixel() && dstIt.nextPixel()) {
141 const quint8 *srcPtr = srcIt.rawDataConst();
142 memcpy(dstIt.rawData(), srcPtr + d->channel->pos(), d->channel->size());
143
144 }
145
146 if (dev) {
147 return dev->exactBounds();
148 }
149
150 return QRect();
151}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
QRect exactBounds() const
qint32 size() const
qint32 pos() const
virtual KoID colorDepthId() const =0
virtual KisPaintDeviceSP projection() const =0
virtual QRect exactBounds() const
virtual const KoColorSpace * colorSpace() const =0
static KoColorSpaceRegistry * instance()

References Channel::Private::channel, KoColorSpace::colorDepthId(), KisBaseNode::colorSpace(), d, KisBaseNode::exactBounds(), KisPaintDevice::exactBounds(), Float16BitsColorDepthID, Float32BitsColorDepthID, KoColorSpaceRegistry::instance(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), Channel::Private::node, KoChannelInfo::pos(), KisBaseNode::projection(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawDataConst(), and KoChannelInfo::size().

◆ channelSize()

int Channel::channelSize ( ) const
Returns
the number of bytes this channel takes

Definition at line 110 of file Channel.cpp.

111{
112 return d->channel->size();
113}

References Channel::Private::channel, d, and KoChannelInfo::size().

◆ name()

QString Channel::name ( ) const
Returns
the name of the channel

Definition at line 100 of file Channel.cpp.

101{
102 return d->channel->name();
103}
QString name() const

References Channel::Private::channel, d, and KoChannelInfo::name().

◆ operator!=()

bool Channel::operator!= ( const Channel & other) const

Definition at line 53 of file Channel.cpp.

54{
55 return !(operator==(other));
56}
bool operator==(const Channel &other) const
Definition Channel.cpp:47

References operator==().

◆ operator==()

bool Channel::operator== ( const Channel & other) const

Definition at line 47 of file Channel.cpp.

48{
49 return (d->node == other.d->node
50 && d->channel == other.d->channel);
51}

References Channel::Private::channel, d, and Channel::Private::node.

◆ pixelData()

QByteArray Channel::pixelData ( const QRect & rect) const

Read the values of the channel into the a byte array for each pixel in the rect from the Node this channel is part of, and returns it.

Note that if Krita is built with OpenEXR and the Node has the 16 bits floating point channel depth type, Krita returns 32 bits float for every channel; the libkis scripting API does not support half.

Definition at line 153 of file Channel.cpp.

154{
155 QByteArray ba;
156
157 if (!d->node || !d->channel) return ba;
158
159 QDataStream stream(&ba, QIODevice::WriteOnly);
161
163 while(srcIt.nextPixel()) {
164 quint8 v;
165 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(), sizeof(v));
166 stream << v;
167 }
168 }
170 while(srcIt.nextPixel()) {
171 quint16 v;
172 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(), sizeof(v));
173 stream << v;
174 }
175 }
176#ifdef HAVE_OPENEXR
178 while(srcIt.nextPixel()) {
179 half v;
180 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(), sizeof(v));
181 stream << (float) v;
182 }
183 }
184#endif
186 while(srcIt.nextPixel()) {
187 float v;
188 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(), sizeof(v));
189 stream << v;
190 }
191
192 }
193
194 return ba;
195}
qreal v

References Channel::Private::channel, KoColorSpace::colorDepthId(), KisBaseNode::colorSpace(), d, Float16BitsColorDepthID, Float32BitsColorDepthID, Integer16BitsColorDepthID, Integer8BitsColorDepthID, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), Channel::Private::node, KoChannelInfo::pos(), KisBaseNode::projection(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawDataConst(), and v.

◆ position()

int Channel::position ( ) const
Returns
the position of the first byte of the channel in the pixel

Definition at line 105 of file Channel.cpp.

106{
107 return d->channel->pos();
108}

References Channel::Private::channel, d, and KoChannelInfo::pos().

◆ setPixelData()

void Channel::setPixelData ( QByteArray value,
const QRect & rect )

setPixelData writes the given data to the relevant channel in the Node. This is only possible for Nodes that have a paintDevice, so nothing will happen when trying to write to e.g. a group layer.

Note that if Krita is built with OpenEXR and the Node has the 16 bits floating point channel depth type, Krita expects to be given a 4 byte, 32 bits float for every channel; the libkis scripting API does not support half.

Parameters
valuea byte array with exactly enough bytes.
rectthe rectangle to write the bytes into

Definition at line 197 of file Channel.cpp.

198{
199 if (!d->node || !d->channel || d->node->paintDevice() == 0) return;
200
201 QDataStream stream(&value, QIODevice::ReadOnly);
203
205 while (dstIt.nextPixel()) {
206 quint8 v;
207 stream >> v;
208 memcpy(dstIt.rawData() + d->channel->pos(), &v, sizeof(v));
209 }
210 }
212 while (dstIt.nextPixel()) {
213 quint16 v;
214 stream >> v;
215 memcpy(dstIt.rawData() + d->channel->pos(), &v, sizeof(v));
216 }
217 }
218#ifdef HAVE_OPENEXR
220 while (dstIt.nextPixel()) {
221 float f;
222 stream >> f;
223 half v = f;
224 memcpy(dstIt.rawData() + d->channel->pos(), &v, sizeof(v));
225 }
226
227 }
228#endif
230 while (dstIt.nextPixel()) {
231 float v;
232 stream >> v;
233 memcpy(dstIt.rawData() + d->channel->pos(), &v, sizeof(v));
234 }
235 }
236}
float value(const T *src, size_t ch)
virtual KisPaintDeviceSP paintDevice() const =0

References Channel::Private::channel, KoColorSpace::colorDepthId(), KisBaseNode::colorSpace(), d, Float16BitsColorDepthID, Float32BitsColorDepthID, Integer16BitsColorDepthID, Integer8BitsColorDepthID, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), Channel::Private::node, KisBaseNode::paintDevice(), KoChannelInfo::pos(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), v, and value().

◆ setVisible()

void Channel::setVisible ( bool value)

setvisible set the visibility of the channel to the given value.

Definition at line 77 of file Channel.cpp.

78{
79 if (!d->node || !d->channel) return;
80 if (!d->node->inherits("KisLayer")) return;
81
82 const QList<KoChannelInfo *> channelInfo = d->node->colorSpace()->channels();
83
84 KisLayerSP layer = qobject_cast<KisLayer*>(d->node.data());
85 QBitArray flags = layer->channelFlags();
86 if (flags.isEmpty()) {
87 flags.fill(1, channelInfo.size());
88 }
89
90 for (uint i = 0; i < channelInfo.size(); ++i) {
91 if (channelInfo[i] == d->channel) {
92 flags.setBit(i, value);
93 layer->setChannelFlags(flags);
94 break;
95 }
96 }
97
98}
unsigned int uint
QList< KoChannelInfo * > channels
QBitArray channelFlags
Definition kis_layer.cc:167
virtual void setChannelFlags(const QBitArray &channelFlags)
Definition kis_layer.cc:342

References Channel::Private::channel, KisLayer::channelFlags, KoColorSpace::channels, KisBaseNode::colorSpace(), d, KisSharedPtr< T >::data(), Channel::Private::node, KisLayer::setChannelFlags(), and value().

◆ visible()

bool Channel::visible ( ) const

visible checks whether this channel is visible in the node

Returns
the status of this channel

Definition at line 59 of file Channel.cpp.

60{
61 if (!d->node || !d->channel) return false;
62 if (!d->node->inherits("KisLayer")) return false;
63
64 const QList<KoChannelInfo *> channelInfo = d->node->colorSpace()->channels();
65
66 for (uint i = 0; i < channelInfo.size(); ++i) {
67 if (channelInfo[i] == d->channel) {
68 KisLayerSP layer = qobject_cast<KisLayer*>(d->node.data());
69 const QBitArray& flags = layer->channelFlags();
70 return flags.isEmpty() || flags.testBit(i);
71 }
72 }
73
74 return false;
75}

References Channel::Private::channel, KisLayer::channelFlags, KoColorSpace::channels, KisBaseNode::colorSpace(), d, KisSharedPtr< T >::data(), and Channel::Private::node.

Member Data Documentation

◆ d

Private* const Channel::d
private

Definition at line 87 of file Channel.h.


The documentation for this class was generated from the following files: