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 0007 #include "filter/kis_filter.h" 0008 0009 #include <QString> 0010 0011 #include <KoCompositeOpRegistry.h> 0012 #include "kis_bookmarked_configuration_manager.h" 0013 #include "filter/kis_filter_configuration.h" 0014 #include "kis_processing_information.h" 0015 #include "kis_transaction.h" 0016 #include "kis_paint_device.h" 0017 #include "kis_selection.h" 0018 #include "kis_types.h" 0019 #include <kis_painter.h> 0020 #include <KoUpdater.h> 0021 0022 KisFilter::KisFilter(const KoID& _id, const KoID & category, const QString & entry) 0023 : KisBaseProcessor(_id, category, entry), 0024 m_supportsLevelOfDetail(false) 0025 { 0026 init(id() + "_filter_bookmarks"); 0027 } 0028 0029 KisFilter::~KisFilter() 0030 { 0031 } 0032 0033 void KisFilter::process(KisPaintDeviceSP device, 0034 const QRect& applyRect, 0035 const KisFilterConfigurationSP config, 0036 KoUpdater* progressUpdater) const 0037 { 0038 process(device, device, KisSelectionSP(), applyRect, config, progressUpdater); 0039 } 0040 0041 void KisFilter::process(const KisPaintDeviceSP src, 0042 KisPaintDeviceSP dst, 0043 KisSelectionSP selection, 0044 const QRect& applyRect, 0045 const KisFilterConfigurationSP config, 0046 KoUpdater* progressUpdater ) const 0047 { 0048 KIS_SAFE_ASSERT_RECOVER_NOOP(config->hasLocalResourcesSnapshot()); 0049 0050 if (applyRect.isEmpty()) return; 0051 QRect needRect = neededRect(applyRect, config, src->defaultBounds()->currentLevelOfDetail()); 0052 0053 KisPaintDeviceSP temporary; 0054 KisTransaction *transaction = 0; 0055 0056 bool weirdDstColorSpace = 0057 dst->colorSpace() != dst->compositionSourceColorSpace() && 0058 *dst->colorSpace() != *dst->compositionSourceColorSpace(); 0059 0060 if(src == dst && !selection && !weirdDstColorSpace) { 0061 temporary = src; 0062 } 0063 else { 0064 temporary = dst->createCompositionSourceDevice(src, needRect); 0065 transaction = new KisTransaction(temporary); 0066 } 0067 0068 try { 0069 QScopedPointer<KoDummyUpdaterHolder> updaterHolder; 0070 0071 if (!progressUpdater) { 0072 // TODO: remove dependency on KoUpdater, depend on KoProgressProxy, 0073 // it is more lightweight 0074 updaterHolder.reset(new KoDummyUpdaterHolder()); 0075 progressUpdater = updaterHolder->updater(); 0076 } 0077 0078 processImpl(temporary, applyRect, config, progressUpdater); 0079 } 0080 catch (const std::bad_alloc&) { 0081 warnKrita << "Filter" << name() << "failed to allocate enough memory to run."; 0082 } 0083 0084 0085 if(transaction) { 0086 delete transaction; 0087 KisPainter::copyAreaOptimized(applyRect.topLeft(), temporary, dst, applyRect, selection); 0088 } 0089 } 0090 0091 QRect KisFilter::neededRect(const QRect & rect, const KisFilterConfigurationSP c, int lod) const 0092 { 0093 Q_UNUSED(c); 0094 Q_UNUSED(lod); 0095 return rect; 0096 } 0097 0098 QRect KisFilter::changedRect(const QRect & rect, const KisFilterConfigurationSP c, int lod) const 0099 { 0100 Q_UNUSED(c); 0101 Q_UNUSED(lod); 0102 return rect; 0103 } 0104 0105 bool KisFilter::supportsLevelOfDetail(const KisFilterConfigurationSP config, int lod) const 0106 { 0107 Q_UNUSED(config); 0108 Q_UNUSED(lod); 0109 return m_supportsLevelOfDetail; 0110 } 0111 0112 void KisFilter::setSupportsLevelOfDetail(bool value) 0113 { 0114 m_supportsLevelOfDetail = value; 0115 } 0116 0117 bool KisFilter::needsTransparentPixels(const KisFilterConfigurationSP config, const KoColorSpace *cs) const 0118 { 0119 Q_UNUSED(config); 0120 Q_UNUSED(cs); 0121 0122 return false; 0123 } 0124 0125 bool KisFilter::configurationAllowedForMask(KisFilterConfigurationSP config) const 0126 { 0127 Q_UNUSED(config); 0128 return supportsAdjustmentLayers(); 0129 } 0130 0131 void KisFilter::fixLoadedFilterConfigurationForMasks(KisFilterConfigurationSP config) const 0132 { 0133 Q_UNUSED(config); 0134 }