File indexing completed on 2024-05-12 15:59:04

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 #ifndef LIBKIS_CHANNEL_H
0007 #define LIBKIS_CHANNEL_H
0008 
0009 #include <QObject>
0010 
0011 #include "kritalibkis_export.h"
0012 #include "libkis.h"
0013 
0014 #include <KoChannelInfo.h>
0015 #include <kis_node.h>
0016 
0017 /**
0018  * A Channel represents a single channel in a Node. Krita does not
0019  * use channels to store local selections: these are strictly the
0020  * color and alpha channels.
0021  */
0022 class KRITALIBKIS_EXPORT Channel : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit Channel(KisNodeSP node, KoChannelInfo *channel, QObject *parent = 0);
0028     ~Channel() override;
0029 
0030     bool operator==(const Channel &other) const;
0031     bool operator!=(const Channel &other) const;
0032     
0033     /**
0034      * @brief visible checks whether this channel is visible in the node
0035      * @return the status of this channel
0036      */
0037     bool visible() const;
0038 
0039     /**
0040      * @brief setvisible set the visibility of the channel to the given value.
0041      */
0042     void setVisible(bool value);
0043 
0044     /**
0045      * @return the name of the channel
0046      */
0047     QString name() const;
0048 
0049     /**
0050      * @returns the position of the first byte of the channel in the pixel
0051      */
0052     int position() const;
0053 
0054     /**
0055      * @return the number of bytes this channel takes
0056      */
0057     int channelSize() const;
0058 
0059     /**
0060      * @return the exact bounds of the channel. This can be smaller than the bounds of the Node this channel is part of.
0061      */
0062     QRect bounds() const;
0063 
0064     /**
0065      * 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.
0066      *
0067      * Note that if Krita is built with OpenEXR and the Node has the 16 bits floating point channel depth type, Krita returns
0068      * 32 bits float for every channel; the libkis scripting API does not support half.
0069      */
0070     QByteArray pixelData(const QRect &rect) const;
0071 
0072     /**
0073      * @brief setPixelData writes the given data to the relevant channel in the Node. This is only possible for Nodes
0074      * that have a paintDevice, so nothing will happen when trying to write to e.g. a group layer.
0075      *
0076      * Note that if Krita is built with OpenEXR and the Node has the 16 bits floating point channel depth type, Krita expects
0077      * to be given a 4 byte, 32 bits float for every channel; the libkis scripting API does not support half.
0078      *
0079      * @param value a byte array with exactly enough bytes.
0080      * @param rect the rectangle to write the bytes into
0081      */
0082     void setPixelData(QByteArray value, const QRect &rect);
0083 
0084 private:
0085 
0086     struct Private;
0087     Private *const d;
0088 
0089 };
0090 
0091 #endif // LIBKIS_CHANNEL_H