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

0001 /*
0002  * SPDX-FileCopyrightText: 2005 Adrian Page <adrian@pagenet.plus.com>
0003  * SPDX-FileCopyrightText: 2011 Silvio Heinrich <plassy@web.de>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 #ifndef KOCOMPOSITEOP_H
0008 #define KOCOMPOSITEOP_H
0009 
0010 #include <QString>
0011 #include <QList>
0012 #include <QMultiMap>
0013 #include <QBitArray>
0014 
0015 #include <boost/optional.hpp>
0016 
0017 #include "kritapigment_export.h"
0018 
0019 class KoColorSpace;
0020 
0021 class KoColorSpace;
0022 
0023 /**
0024  * Base for colorspace-specific blending modes.
0025  */
0026 class KRITAPIGMENT_EXPORT KoCompositeOp
0027 {
0028 public:
0029     static QString categoryArithmetic();
0030     static QString categoryBinary();
0031     static QString categoryModulo();
0032     static QString categoryNegative();
0033     static QString categoryLight();
0034     static QString categoryDark();
0035     static QString categoryHSY();
0036     static QString categoryHSI();
0037     static QString categoryHSL();
0038     static QString categoryHSV();
0039     static QString categoryMix();
0040     static QString categoryMisc();    
0041     static QString categoryQuadratic();
0042 
0043     struct KRITAPIGMENT_EXPORT ParameterInfo
0044     {
0045         ParameterInfo();
0046         ParameterInfo(const ParameterInfo &rhs);
0047         ParameterInfo& operator=(const ParameterInfo &rhs);
0048 
0049         quint8*       dstRowStart {0};
0050         qint32        dstRowStride {0};
0051         const quint8* srcRowStart {0};
0052         qint32        srcRowStride {0};
0053         const quint8* maskRowStart {0};
0054         qint32        maskRowStride {0};
0055         qint32        rows {0};
0056         qint32        cols {0};
0057         float         opacity {0.0};
0058         float         flow {0.0};
0059         float         _lastOpacityData {0.0};
0060         float*        lastOpacity {0};
0061         QBitArray     channelFlags;
0062 
0063         void setOpacityAndAverage(float _opacity, float _averageOpacity);
0064 
0065         void updateOpacityAndAverage(float value);
0066     private:
0067         inline void copy(const ParameterInfo &rhs);
0068     };
0069 
0070 public:
0071 
0072     /**
0073      * @param cs a pointer to the color space that can be used with this composite op
0074      * @param id the identifier for this composite op (not user visible)
0075      * @param category the name of the category where to put that composite op when displayed
0076      * @param userVisible define whether or not that composite op should be visible in a user
0077      *                    interface
0078      */
0079     KoCompositeOp(const KoColorSpace * cs, const QString& id, const QString & category = KoCompositeOp::categoryMisc());
0080     virtual ~KoCompositeOp();
0081 
0082     /**
0083      * @return the identifier of this composite op
0084      */
0085     QString id() const;
0086     /**
0087      * @return the user visible string for this composite op
0088      */
0089     QString description() const;
0090     /**
0091      * @return the color space that can use and own this composite op
0092      */
0093     const KoColorSpace * colorSpace() const;
0094     /**
0095      * @return the category associated with the composite op
0096      */
0097     QString category() const;
0098 
0099     // WARNING: A derived class needs to overwrite at least one
0100     //          of the following virtual methods or a call to
0101     //          composite(...) will lead to an endless recursion/stack overflow
0102 
0103     /**
0104      * @param dstRowStart pointer to the start of the byte array we will composite the source on
0105      * @param dstRowStride length of the rows of the block of destination pixels in bytes
0106      * @param srcRowStart pointer to the start of the byte array we will mix with dest
0107      * @param srcRowStride length of the rows of the block of src in bytes
0108      * pixels (may be different from the rowstride of the dst pixels,
0109      * in which case the smaller value is used). If srcRowStride is null
0110      * it is assumed that the source is a constant color.
0111      * @param maskRowStart start of the byte mask that determines whether and if so, then how much of src is used for blending
0112      * @param maskRowStride length of the mask scanlines in bytes
0113      * @param rows number of scanlines to blend
0114      * @param numColumns length of the row of pixels in pixels
0115      * @param opacity transparency with which to blend
0116      * @param channelFlags a bit array that determines which channels should be processed (channels are in the order of the channels in the colorspace)
0117      */
0118     virtual void composite(quint8 *dstRowStart, qint32 dstRowStride,
0119                             const quint8 *srcRowStart, qint32 srcRowStride,
0120                             const quint8 *maskRowStart, qint32 maskRowStride,
0121                             qint32 rows, qint32 numColumns,
0122                             quint8 opacity, const QBitArray& channelFlags=QBitArray()) const;
0123 
0124     /**
0125     * Same as previous, but uses a parameter structure
0126     */
0127     virtual void composite(const ParameterInfo& params) const;
0128 
0129 private:
0130     KoCompositeOp();
0131     struct Private;
0132     Private* const d;
0133 };
0134 
0135 #endif // KOCOMPOSITEOP_H