File indexing completed on 2024-05-12 15:56:11

0001 /*
0002  *  SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
0003  *  SPDX-FileCopyrightText: 2005 Bart Coppens <kde@bartcoppens.be>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 #ifndef KIS_IMAGEPIPE_BRUSH_
0008 #define KIS_IMAGEPIPE_BRUSH_
0009 
0010 #include <QList>
0011 #include <QMap>
0012 #include <QString>
0013 
0014 #include <KoResource.h>
0015 #include "kis_gbr_brush.h"
0016 #include "kis_global.h"
0017 
0018 class KisPipeBrushParasite;
0019 
0020 /**
0021  * Velocity won't be supported, atm Tilt isn't either,
0022  * but have chances of implementation
0023  */
0024 namespace KisParasite
0025 {
0026 enum SelectionMode {
0027     Constant,
0028     Incremental,
0029     Angular,
0030     Velocity,
0031     Random,
0032     Pressure,
0033     TiltX,
0034     TiltY
0035 };
0036 }
0037 
0038 class BRUSH_EXPORT KisImagePipeBrush : public KisGbrBrush
0039 {
0040 
0041 public:
0042     KisImagePipeBrush(const QString& filename);
0043     /**
0044      * Specialized constructor that makes a new pipe brush from a sequence of samesize
0045      * devices. The fact that it's a vector of a vector, is to support multidimensional
0046      * brushes (not yet supported!) */
0047     KisImagePipeBrush(const QString& name, int w, int h,
0048                       QVector< QVector<KisPaintDevice*> > devices,
0049                       QVector<KisParasite::SelectionMode> modes);
0050 
0051     ~KisImagePipeBrush() override;
0052 
0053     /// Will call KisBrush's saveToDevice as well
0054     KisImagePipeBrush(const KisImagePipeBrush& rhs);
0055 
0056     KisImagePipeBrush &operator=(const KisImagePipeBrush &rhs) = delete;
0057 
0058     KoResourceSP clone() const override;
0059 
0060     bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override;
0061     bool saveToDevice(QIODevice* dev) const override;
0062 
0063     /**
0064      * @return the next image in the pipe.
0065     */
0066     KisFixedPaintDeviceSP paintDevice(const KoColorSpace * colorSpace,
0067             KisDabShape const&,
0068             const KisPaintInformation& info,
0069             double subPixelX = 0, double subPixelY = 0) const override;
0070 
0071     void setAdjustmentMidPoint(quint8 value) override;
0072     void setBrightnessAdjustment(qreal value) override;
0073     void setContrastAdjustment(qreal value) override;
0074     void setAutoAdjustMidPoint(bool value) override;
0075 
0076     QString parasiteSelection(); // returns random, constant, etc
0077 
0078     KisOptimizedBrushOutline outline(bool forcePreciseOutline = false) const override;
0079 
0080     bool canPaintFor(const KisPaintInformation& info) override;
0081 
0082     void makeMaskImage(bool preserveAlpha) override;
0083 
0084 
0085     QString defaultFileExtension() const override;
0086     void setAngle(qreal _angle) override;
0087     void setScale(qreal _scale) override;
0088     void setSpacing(double _spacing) override;
0089 
0090     quint32 brushIndex() const override;
0091     qint32 maskWidth(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
0092     qint32 maskHeight(KisDabShape const&, double subPixelX, double subPixelY, const KisPaintInformation& info) const override;
0093 
0094     void notifyStrokeStarted() override;
0095     void prepareForSeqNo(const KisPaintInformation& info, int seqNo) override;
0096 
0097     void generateMaskAndApplyMaskOrCreateDab(KisFixedPaintDeviceSP dst, KisBrush::ColoringInformation* coloringInformation,
0098             KisDabShape const&,
0099             const KisPaintInformation& info,
0100             double subPixelX = 0, double subPixelY = 0, 
0101             qreal softnessFactor = DEFAULT_SOFTNESS_FACTOR, qreal lightnessStrength = DEFAULT_LIGHTNESS_STRENGTH) const override;
0102 
0103     void notifyBrushIsGoingToBeClonedForStroke() override;
0104 
0105     QVector<KisGbrBrushSP> brushes() const;
0106 
0107     const KisPipeBrushParasite &parasite() const;
0108 
0109     void setParasite(const KisPipeBrushParasite& parasite);
0110     void setDevices(QVector< QVector<KisPaintDevice*> > devices, int w, int h);
0111 
0112     void coldInitBrush() override;
0113 
0114 protected:
0115     virtual void setBrushApplication(enumBrushApplication brushApplication) override;
0116     virtual void setGradient(KoAbstractGradientSP gradient) override;
0117     /// Will call KisBrush's saveToDevice as well
0118 
0119 private:
0120     friend class KisImagePipeBrushTest;
0121 
0122     KisGbrBrushSP testingGetCurrentBrush(const KisPaintInformation& info) const;
0123     void testingSelectNextBrush(const KisPaintInformation& info) const;
0124 
0125     bool initFromData(const QByteArray &data);
0126 
0127     QString parasiteSelectionString; // incremental, random, etc.
0128 
0129 private:
0130     struct Private;
0131     Private * const d;
0132 };
0133 
0134 typedef QSharedPointer<KisImagePipeBrush> KisImagePipeBrushSP;
0135 
0136 #endif // KIS_IMAGEPIPE_BRUSH_