File indexing completed on 2024-12-22 04:10:04

0001 /*
0002  *  SPDX-FileCopyrightText: 2004, 2006-2007 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef _KIS_FILTER_H_
0007 #define _KIS_FILTER_H_
0008 
0009 #include <list>
0010 
0011 #include <QString>
0012 
0013 #include <klocalizedstring.h>
0014 
0015 #include "KoID.h"
0016 #include "KoColorSpace.h"
0017 
0018 #include "kis_types.h"
0019 #include "kis_base_processor.h"
0020 
0021 #include "kritaimage_export.h"
0022 
0023 /**
0024  * Basic interface of a Krita filter.
0025  */
0026 class KRITAIMAGE_EXPORT KisFilter : public KisBaseProcessor
0027 {
0028 public:
0029 
0030     /**
0031      * Construct a Krita filter
0032      */
0033     KisFilter(const KoID& id, const KoID & category, const QString & entry);
0034     ~KisFilter() override;
0035 
0036     /**
0037      * Override this function with the implementation of your filter.
0038      *
0039      * This is a low level function that expects all the conditions
0040      * for the @param device be met. Use usual process() methods
0041      * instead.
0042      *
0043      * @param device the paint device to filter
0044      * @param applyRect the rectangle where the filter is applied
0045      * @param config the parameters of the filter
0046      * @param progressUpdater to pass on the progress the filter is making
0047      */
0048     virtual void processImpl(KisPaintDeviceSP device,
0049                              const QRect& applyRect,
0050                              const KisFilterConfigurationSP config,
0051                              KoUpdater* progressUpdater = 0 ) const = 0;
0052 
0053     /**
0054      * Filter \p src device and write the result into \p dst device.
0055      * If \p dst is an alpha color space device, it will get special
0056      * treatment.
0057      *
0058      * @param src the source paint device
0059      * @param dst the destination paint device
0060      * @param selection the selection
0061      * @param applyRect the rectangle where the filter is applied
0062      * @param config the parameters of the filter
0063      * @param progressUpdater to pass on the progress the filter is making
0064      */
0065     void process(const KisPaintDeviceSP src,
0066                  KisPaintDeviceSP dst,
0067                  KisSelectionSP selection,
0068                  const QRect& applyRect,
0069                  const KisFilterConfigurationSP config,
0070                  KoUpdater* progressUpdater = 0 ) const;
0071 
0072 
0073     /**
0074      * A convenience method for a two-device process() function
0075      */
0076     void process(KisPaintDeviceSP device,
0077                  const QRect& applyRect,
0078                  const KisFilterConfigurationSP config,
0079                  KoUpdater* progressUpdater = 0 ) const;
0080 
0081     /**
0082      * Some filters need pixels outside the current processing rect to compute the new
0083      * value (for instance, convolution filters)
0084      */
0085     virtual QRect neededRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const;
0086 
0087     /**
0088     * Similar to @ref neededRect : some filters will alter a lot of pixels that are
0089     * near to each other at the same time. So when you changed a single rectangle
0090     * in a device, the actual rectangle that will feel the influence of this change
0091     * might be bigger. Use this function to determine that rect.
0092      */
0093     virtual QRect changedRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const;
0094 
0095     /**
0096      * Returns true if the filter is capable of handling LoD scaled planes
0097      * when generating preview.
0098      */
0099     virtual bool supportsLevelOfDetail(const KisFilterConfigurationSP config, int lod) const;
0100 
0101     virtual bool needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const;
0102 
0103     virtual bool configurationAllowedForMask(KisFilterConfigurationSP config) const;
0104     virtual void fixLoadedFilterConfigurationForMasks(KisFilterConfigurationSP config) const;
0105 
0106 protected:
0107 
0108     QString configEntryGroup() const;
0109     void setSupportsLevelOfDetail(bool value);
0110 
0111 
0112 private:
0113     bool m_supportsLevelOfDetail;
0114 };
0115 
0116 
0117 #endif