Krita
14#include <KoColorModelStandardIds.h>
16#include <KoColorSpaceRegistry.h>
17#include <KoColorSpace.h>
18#include <kis_sequential_iterator.h>
25struct Channel::Private {
29 KoChannelInfo *channel {0};
33Channel::Channel(KisNodeSP node, KoChannelInfo *channel,
QObject *parent)
47bool Channel::operator==(
const Channel &other)
const
49 return (d->node == other.d->node
50 && d->channel == other.d->channel);
53bool Channel::operator!=(
const Channel &other)
const
55 return !(operator==(other));
61 if (!d->node || !d->channel)
return false;
62 if (!d->node->inherits(
"KisLayer"))
return false;
66 for (uint i = 0; i < channelInfo.
size(); ++i) {
67 if (channelInfo[i] == d->channel) {
69 const QBitArray& flags = layer->channelFlags();
79 if (!d->node || !d->channel)
return;
80 if (!d->node->inherits(
"KisLayer"))
return;
90 for (uint i = 0; i < channelInfo.
size(); ++i) {
91 if (channelInfo[i] == d->channel) {
93 layer->setChannelFlags(flags);
102 return d->channel->name();
107 return d->channel->pos();
112 return d->channel->size();
117 if (!d->node || !d->channel)
return QRect();
119 QRect rect = d->node->exactBounds();
121 KisPaintDeviceSP dev;
122 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
123 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
125 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
126 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16());
129 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
130 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16f());
133 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
134 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha32f());
137 KisSequentialConstIterator srcIt(d->node->projection(), rect);
138 KisSequentialIterator dstIt(dev, rect);
140 while(srcIt.nextPixel() && dstIt.nextPixel()) {
141 const quint8 *srcPtr = srcIt.rawDataConst();
142 memcpy(dstIt.rawData(), srcPtr + d->channel->pos(), d->channel->size());
147 return dev->exactBounds();
157 if (!d->node || !d->channel)
return ba;
160 KisSequentialConstIterator srcIt(d->node->projection(), rect);
162 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
163 while(srcIt.nextPixel()) {
165 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(),
sizeof(v));
169 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
170 while(srcIt.nextPixel()) {
172 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(),
sizeof(v));
177 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
178 while(srcIt.nextPixel()) {
180 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(),
sizeof(v));
185 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
186 while(srcIt.nextPixel()) {
188 memcpy(&v, srcIt.rawDataConst() + d->channel->pos(),
sizeof(v));
199 if (!d->node || !d->channel || d->node->paintDevice() == 0)
return;
202 KisSequentialIterator dstIt(d->node->paintDevice(), rect);
204 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
205 while (dstIt.nextPixel()) {
208 memcpy(dstIt.rawData() + d->channel->pos(), &v,
sizeof(v));
211 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
212 while (dstIt.nextPixel()) {
215 memcpy(dstIt.rawData() + d->channel->pos(), &v,
sizeof(v));
219 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
220 while (dstIt.nextPixel()) {
224 memcpy(dstIt.rawData() + d->channel->pos(), &v,
sizeof(v));
229 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
230 while (dstIt.nextPixel()) {
233 memcpy(dstIt.rawData() + d->channel->pos(), &v,
sizeof(v));
A Channel represents a single channel in a Node.
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
void setPixelData(QByteArray value, const QRect &rect)
setPixelData writes the given data to the relevant channel in the Node.
QByteArray 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 ch...
bool fill(bool value, qsizetype size)
bool isEmpty() const const
bool testBit(qsizetype i) const const
qsizetype size() const const
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:55:31 by
doxygen 1.13.2 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.