KoCompositeOp.h 5.45 KB
Newer Older
Adrian Page's avatar
Adrian Page committed
1
/*
2
 * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
3
 * Copyright (c) 2011 Silvio Heinrich <plassy@web.de>
Adrian Page's avatar
Adrian Page committed
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
Adrian Page's avatar
Adrian Page committed
9
 *
10 11 12
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
Adrian Page's avatar
Adrian Page committed
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16 17 18 19
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
20 21
#ifndef KOCOMPOSITEOP_H
#define KOCOMPOSITEOP_H
Adrian Page's avatar
Adrian Page committed
22

23 24
#include <QString>
#include <QList>
25
#include <QMultiMap>
Silvio Heinrich's avatar
Silvio Heinrich committed
26
#include <QBitArray>
27

28 29
#include <boost/optional.hpp>

30
#include "kritapigment_export.h"
31

32 33
class KoColorSpace;

34
class KoColorSpace;
35

36 37 38
/**
 * Base for colorspace-specific blending modes.
 */
39
class KRITAPIGMENT_EXPORT KoCompositeOp
40
{
41 42
public:
    static QString categoryColor();
43

44
    static QString categoryArithmetic();
45 46
    static QString categoryBinary();
    static QString categoryModulo();
47 48 49 50 51 52 53 54
    static QString categoryNegative();
    static QString categoryLight();
    static QString categoryDark();
    static QString categoryHSY();
    static QString categoryHSI();
    static QString categoryHSL();
    static QString categoryHSV();
    static QString categoryMix();
55
    static QString categoryMisc();    
Miguel Lopez's avatar
Miguel Lopez committed
56
    static QString categoryQuadratic();
57

58
    struct KRITAPIGMENT_EXPORT ParameterInfo
59
    {
60 61 62
        ParameterInfo();
        ParameterInfo(const ParameterInfo &rhs);
        ParameterInfo& operator=(const ParameterInfo &rhs);
63

64 65 66 67 68 69 70 71
        quint8*       dstRowStart;
        qint32        dstRowStride;
        const quint8* srcRowStart;
        qint32        srcRowStride;
        const quint8* maskRowStart;
        qint32        maskRowStride;
        qint32        rows;
        qint32        cols;
72 73
        float         opacity;
        float         flow;
74 75
        float         _lastOpacityData;
        float*        lastOpacity;
76
        QBitArray     channelFlags;
77

78 79
        void setOpacityAndAverage(float _opacity, float _averageOpacity);

80
        void updateOpacityAndAverage(float value);
81 82
    private:
        inline void copy(const ParameterInfo &rhs);
83
    };
84

Adrian Page's avatar
Adrian Page committed
85 86
public:

Cyrille Berger's avatar
dox++  
Cyrille Berger committed
87 88
    /**
     * @param cs a pointer to the color space that can be used with this composite op
Boudewijn Rempt's avatar
Boudewijn Rempt committed
89
     * @param id the identifier for this composite op (not user visible)
90
     * @param description a user visible string describing this composite operation
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
91
     * @param category the name of the category where to put that composite op when displayed
92
     * @param userVisible define whether or not that composite op should be visible in a user
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
93 94
     *                    interface
     */
Boudewijn Rempt's avatar
Boudewijn Rempt committed
95
    KoCompositeOp(const KoColorSpace * cs, const QString& id, const QString& description, const QString & category = KoCompositeOp::categoryMisc());
Dirk Mueller's avatar
Dirk Mueller committed
96
    virtual ~KoCompositeOp();
Adrian Page's avatar
Adrian Page committed
97

Cyrille Berger's avatar
dox++  
Cyrille Berger committed
98
    /**
Boudewijn Rempt's avatar
Boudewijn Rempt committed
99
     * @return the identifier of this composite op
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
100
     */
Cyrille Berger's avatar
Cyrille Berger committed
101
    QString id() const;
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
102 103 104
    /**
     * @return the user visible string for this composite op
     */
Cyrille Berger's avatar
Cyrille Berger committed
105
    QString description() const;
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
106 107 108
    /**
     * @return the color space that can use and own this composite op
     */
109
    const KoColorSpace * colorSpace() const;
Cyrille Berger's avatar
dox++  
Cyrille Berger committed
110 111 112
    /**
     * @return the category associated with the composite op
     */
113
    QString category() const;
114

115 116 117
    // WARNING: A derived class needs to overwrite at least one
    //          of the following virtual methods or a call to
    //          composite(...) will lead to an endless recursion/stack overflow
118

119
    /**
120 121 122 123 124 125 126 127 128 129 130 131 132 133
     * @param dstRowStart pointer to the start of the byte array we will composite the source on
     * @param dstRowStride length of the rows of the block of destination pixels in bytes
     * @param srcRowStart pointer to the start of the byte array we will mix with dest
     * @param srcRowStride length of the rows of the block of src in bytes
     * pixels (may be different from the rowstride of the dst pixels,
     * in which case the smaller value is used). If srcRowStride is null
     * it is assumed that the source is a constant color.
     * @param maskRowStart start of the byte mask that determines whether and if so, then how much of src is used for blending
     * @param maskRowStride length of the mask scanlines in bytes
     * @param rows number of scanlines to blend
     * @param numColumns length of the row of pixels in pixels
     * @param opacity transparency with which to blend
     * @param channelFlags a bit array that determines which channels should be processed (channels are in the order of the channels in the colorspace)
     */
134
    virtual void composite(quint8 *dstRowStart, qint32 dstRowStride,
135 136 137
                            const quint8 *srcRowStart, qint32 srcRowStride,
                            const quint8 *maskRowStart, qint32 maskRowStride,
                            qint32 rows, qint32 numColumns,
138
                            quint8 opacity, const QBitArray& channelFlags=QBitArray()) const;
139

140
    /**
141 142
    * Same as previous, but uses a parameter structure
    */
143
    virtual void composite(const ParameterInfo& params) const;
144

145 146 147 148
private:
    KoCompositeOp();
    struct Private;
    Private* const d;
Adrian Page's avatar
Adrian Page committed
149 150
};

151
#endif // KOCOMPOSITEOP_H