11 #include <KoColorModelStandardIds.h>
13 #include <KoColorSpaceRegistry.h>
14 #include <KoColorSpace.h>
15 #include <kis_sequential_iterator.h>
16 #include <kis_layer.h>
22 struct Channel::Private {
26 KoChannelInfo *channel {0};
30 Channel::Channel(KisNodeSP node, KoChannelInfo *channel,
QObject *parent)
44 bool Channel::operator==(
const Channel &other)
const
46 return (d->node == other.d->node
47 && d->channel == other.d->channel);
50 bool Channel::operator!=(
const Channel &other)
const
52 return !(operator==(other));
58 if (!d->node || !d->channel)
return false;
59 if (!d->node->inherits(
"KisLayer"))
return false;
63 for (uint i = 0; i < channelInfo.
size(); ++i) {
64 if (channelInfo[i] == d->channel) {
65 KisLayerSP layer = qobject_cast<KisLayer*>(d->node.data());
66 const QBitArray& flags = layer->channelFlags();
76 if (!d->node || !d->channel)
return;
77 if (!d->node->inherits(
"KisLayer"))
return;
81 KisLayerSP layer = qobject_cast<KisLayer*>(d->node.data());
87 for (uint i = 0; i < channelInfo.
size(); ++i) {
88 if (channelInfo[i] == d->channel) {
90 layer->setChannelFlags(flags);
99 return d->channel->name();
104 return d->channel->pos();
109 return d->channel->size();
114 if (!d->node || !d->channel)
return QRect();
116 QRect rect = d->node->exactBounds();
118 KisPaintDeviceSP dev;
119 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
120 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha8());
122 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
123 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16());
126 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
127 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha16f());
130 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
131 dev =
new KisPaintDevice(KoColorSpaceRegistry::instance()->alpha32f());
134 KisSequentialConstIterator srcIt(d->node->projection(), rect);
135 KisSequentialIterator dstIt(dev, rect);
137 while(srcIt.nextPixel() && dstIt.nextPixel()) {
138 const quint8 *srcPtr = srcIt.rawDataConst();
139 memcpy(dstIt.rawData(), srcPtr + d->channel->pos(), d->channel->size());
144 return dev->exactBounds();
154 if (!d->node || !d->channel)
return ba;
157 KisSequentialConstIterator srcIt(d->node->projection(), rect);
159 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
160 while(srcIt.nextPixel()) {
161 stream << (quint8) *srcIt.rawDataConst() + (d->channel->pos() * d->channel->size());
164 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
165 while(srcIt.nextPixel()) {
166 stream << (quint16) *srcIt.rawDataConst() + (d->channel->pos() * d->channel->size());
170 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
171 while(srcIt.nextPixel()) {
172 half h = (half)*srcIt.rawDataConst() + (d->channel->pos() * d->channel->size());
177 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
178 while(srcIt.nextPixel()) {
179 stream << (float) *srcIt.rawDataConst() + (d->channel->pos() * d->channel->size());
189 if (!d->node || !d->channel || d->node->paintDevice() == 0)
return;
192 KisSequentialIterator dstIt(d->node->paintDevice(), rect);
194 if (d->node->colorSpace()->colorDepthId() == Integer8BitsColorDepthID) {
195 while (dstIt.nextPixel()) {
198 *(dstIt.rawData() + (d->channel->pos() * d->channel->size())) = v ;
201 else if (d->node->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {
202 while (dstIt.nextPixel()) {
205 *(dstIt.rawData() + (d->channel->pos() * d->channel->size())) = v ;
209 else if (d->node->colorSpace()->colorDepthId() == Float16BitsColorDepthID) {
210 while (dstIt.nextPixel()) {
214 *(dstIt.rawData() + (d->channel->pos() * d->channel->size())) = v ;
219 else if (d->node->colorSpace()->colorDepthId() == Float32BitsColorDepthID) {
220 while (dstIt.nextPixel()) {
223 *(dstIt.rawData() + (d->channel->pos() * d->channel->size())) = v ;