digiKam
Digikam::DImgThreadedFilter Class Referenceabstract
+ Inheritance diagram for Digikam::DImgThreadedFilter:

Classes

class  DefaultFilterAction
 

Public Types

enum  State { Inactive , Scheduled , Running , Deactivating }
 

Public Slots

void start ()
 
void stop ()
 
void wait ()
 

Signals

void finished ()
 
void finished (bool success)
 
void progress (int progress)
 
void started ()
 
void starting ()
 

Public Member Functions

virtual void cancelFilter ()
 
 DImgThreadedFilter (DImg *const orgImage, QObject *const parent, const QString &name=QString())
 
 DImgThreadedFilter (QObject *const parent=nullptr, const QString &name=QString())
 
virtual FilterAction filterAction ()=0
 
virtual QString filterIdentifier () const =0
 
const QString & filterName ()
 
int filterVersion () const
 
DImg getTargetImage ()
 
bool isFinished () const
 
bool isRunning () const
 
QList< int > multithreadedSteps (int stop, int start=0) const
 
virtual bool parametersSuccessfullyRead () const
 
QThread::Priority priority () const
 
virtual void readParameters (const FilterAction &)=0
 
virtual QString readParametersError (const FilterAction &actionThatFailed) const
 
void setEmitSignals (bool emitThem)
 
void setFilterName (const QString &name)
 
void setFilterVersion (int version)
 
void setOriginalImage (const DImg &orgImage)
 
void setPriority (QThread::Priority priority)
 
void setupAndStartDirectly (const DImg &orgImage, DImgThreadedFilter *const master, int progressBegin=0, int progressEnd=100)
 
void setupFilter (const DImg &orgImage)
 
virtual void startFilter ()
 
virtual void startFilterDirectly ()
 
State state () const
 
virtual QList< int > supportedVersions () const
 
 ~DImgThreadedFilter () override
 

Protected Member Functions

virtual void cleanupFilter ()
 
 DImgThreadedFilter (DImgThreadedFilter *const master, const DImg &orgImage, const DImg &destImage, int progressBegin=0, int progressEnd=100, const QString &name=QString())
 
virtual void filterImage ()=0
 
virtual void initFilter ()
 
void initMaster ()
 
void initSlave (DImgThreadedFilter *const master, int progressBegin=0, int progressEnd=100)
 
virtual int modulateProgress (int progress)
 
void postProgress (int progress)
 
virtual void prepareDestImage ()
 
void run () override
 
bool runningFlag () const volatile
 
void setSlave (DImgThreadedFilter *const slave)
 
void shutDown ()
 
void start (QMutexLocker &locker)
 
void stop (QMutexLocker &locker)
 
QMutex * threadMutex () const
 
void wait (QMutexLocker &locker)
 

Protected Attributes

DImg m_destImage
 
DImgThreadedFilterm_master
 
QString m_name
 
DImg m_orgImage
 
int m_progressBegin
 
int m_progressCurrent
 To prevent signals bombarding with progress indicator value in postProgress(). More...
 
int m_progressSpan
 
DImgThreadedFilterm_slave
 
int m_version
 
bool m_wasCancelled
 

Member Enumeration Documentation

◆ State

Enumerator
Inactive 
Scheduled 
Running 
Deactivating 

Constructor & Destructor Documentation

◆ DImgThreadedFilter() [1/3]

Digikam::DImgThreadedFilter::DImgThreadedFilter ( QObject *const  parent = nullptr,
const QString &  name = QString() 
)
explicit

Constructs a filter without argument. You need to call setupFilter() and startFilter() to start the threaded computation. To run filter without to use multithreading, call startFilterDirectly().

References initMaster(), setFilterName(), and setOriginalImage().

◆ DImgThreadedFilter() [2/3]

Digikam::DImgThreadedFilter::DImgThreadedFilter ( DImg *const  orgImage,
QObject *const  parent,
const QString &  name = QString() 
)

Constructs a filter with all arguments (ready to use). The given original image will be copied. You need to call startFilter() to start the threaded computation. To run filter without to use multithreading, call startFilterDirectly().

References Digikam::DImg::copyImageData(), initMaster(), setFilterName(), and setOriginalImage().

◆ ~DImgThreadedFilter()

Digikam::DImgThreadedFilter::~DImgThreadedFilter ( )
override

References cancelFilter(), m_master, and setSlave().

◆ DImgThreadedFilter() [3/3]

Digikam::DImgThreadedFilter::DImgThreadedFilter ( DImgThreadedFilter *const  master,
const DImg orgImage,
const DImg destImage,
int  progressBegin = 0,
int  progressEnd = 100,
const QString &  name = QString() 
)
protected

Support for chaining two filters as master and thread.

Do not call startFilter() or startFilterDirectly() on this. The computation will be started from initFilter() which you must call from the derived class constructor.

Constructor for slave mode: Constructs a new slave filter with the specified master. The filter will be executed in the current thread. orgImage and destImage will not be copied. Note that the slave is still free to reallocate his destImage. progressBegin and progressEnd can indicate the progress span that the slave filter uses in the parent filter's progress. Any derived filter class that is publicly available to other filters should implement an additional constructor using this constructor.

References initSlave(), setFilterName(), and setOriginalImage().

Member Function Documentation

◆ cancelFilter()

void Digikam::DImgThreadedFilter::cancelFilter ( )
virtual

Cancel the threaded computation.

Reimplemented in Digikam::GreycstorationFilter.

References cleanupFilter(), Digikam::DynamicThread::isRunning(), m_slave, m_wasCancelled, Digikam::DynamicThread::stop(), and Digikam::DynamicThread::wait().

Referenced by DigikamBqmRestorationPlugin::RedEyeCorrection::cancel(), Digikam::GreycstorationFilter::cancelFilter(), Digikam::EditorToolThreaded::slotAbort(), Digikam::PreviewThreadWrapper::stopFilters(), Digikam::AntiVignettingFilter::~AntiVignettingFilter(), Digikam::AutoLevelsFilter::~AutoLevelsFilter(), Digikam::BCGFilter::~BCGFilter(), Digikam::BlurFilter::~BlurFilter(), Digikam::BlurFXFilter::~BlurFXFilter(), Digikam::BorderFilter::~BorderFilter(), Digikam::BWSepiaFilter::~BWSepiaFilter(), Digikam::CBFilter::~CBFilter(), Digikam::CharcoalFilter::~CharcoalFilter(), Digikam::ColorFXFilter::~ColorFXFilter(), Digikam::CurvesFilter::~CurvesFilter(), ~DImgThreadedFilter(), Digikam::DistortionFXFilter::~DistortionFXFilter(), Digikam::EmbossFilter::~EmbossFilter(), Digikam::FilmFilter::~FilmFilter(), Digikam::FilmGrainFilter::~FilmGrainFilter(), Digikam::FreeRotationFilter::~FreeRotationFilter(), Digikam::HotPixelFixer::~HotPixelFixer(), Digikam::HSLFilter::~HSLFilter(), Digikam::IccTransformFilter::~IccTransformFilter(), Digikam::InfraredFilter::~InfraredFilter(), Digikam::InvertFilter::~InvertFilter(), Digikam::LensDistortionFilter::~LensDistortionFilter(), Digikam::LensFunFilter::~LensFunFilter(), Digikam::LevelsFilter::~LevelsFilter(), Digikam::LocalContrastFilter::~LocalContrastFilter(), Digikam::MixerFilter::~MixerFilter(), Digikam::NormalizeFilter::~NormalizeFilter(), Digikam::NRFilter::~NRFilter(), Digikam::OilPaintFilter::~OilPaintFilter(), Digikam::RainDropFilter::~RainDropFilter(), DigikamRawImportNativePlugin::RawPostProcessing::~RawPostProcessing(), Digikam::RawProcessingFilter::~RawProcessingFilter(), Digikam::RedEyeCorrectionFilter::~RedEyeCorrectionFilter(), Digikam::RefocusFilter::~RefocusFilter(), Digikam::SharpenFilter::~SharpenFilter(), Digikam::ShearFilter::~ShearFilter(), Digikam::StretchFilter::~StretchFilter(), Digikam::TextureFilter::~TextureFilter(), Digikam::TonalityFilter::~TonalityFilter(), Digikam::UnsharpMaskFilter::~UnsharpMaskFilter(), and Digikam::WBFilter::~WBFilter().

◆ cleanupFilter()

virtual void Digikam::DImgThreadedFilter::cleanupFilter ( )
inlineprotectedvirtual

Clean up filter data if necessary, called by stopComputation() method. Override in subclass.

Referenced by cancelFilter().

◆ filterAction()

◆ filterIdentifier()

◆ filterImage()

virtual void Digikam::DImgThreadedFilter::filterImage ( )
protectedpure virtual

Main image filter method. Override in subclass.

Implemented in Digikam::WBFilter, Digikam::RawProcessingFilter, Digikam::IccTransformFilter, and Digikam::FilterActionFilter.

Referenced by startFilterDirectly().

◆ filterName()

const QString& Digikam::DImgThreadedFilter::filterName ( )
inline

◆ filterVersion()

int Digikam::DImgThreadedFilter::filterVersion ( ) const

References m_version.

◆ finished [1/2]

void Digikam::DynamicThread::finished ( )
signalinherited

◆ finished [2/2]

void Digikam::DImgThreadedFilter::finished ( bool  success)
signal

Emitted when the computation has completed.

Parameters
successTrue if computation finished without interruption on valid data False if the thread was canceled, or no data is available.

◆ getTargetImage()

◆ initFilter()

void Digikam::DImgThreadedFilter::initFilter ( )
protectedvirtual

Start filter operation before threaded method. Must be called by your constructor.

References m_master, prepareDestImage(), and startFilterDirectly().

Referenced by Digikam::AntiVignettingFilter::AntiVignettingFilter(), Digikam::AutoExpoFilter::AutoExpoFilter(), Digikam::AutoLevelsFilter::AutoLevelsFilter(), Digikam::BCGFilter::BCGFilter(), Digikam::BlurFilter::BlurFilter(), Digikam::BlurFXFilter::BlurFXFilter(), Digikam::BorderFilter::BorderFilter(), Digikam::BWSepiaFilter::BWSepiaFilter(), Digikam::CBFilter::CBFilter(), Digikam::CharcoalFilter::CharcoalFilter(), Digikam::ColorFXFilter::ColorFXFilter(), Digikam::ContentAwareFilter::ContentAwareFilter(), Digikam::CurvesFilter::CurvesFilter(), Digikam::DistortionFXFilter::DistortionFXFilter(), Digikam::EmbossFilter::EmbossFilter(), Digikam::EqualizeFilter::EqualizeFilter(), Digikam::FilmFilter::FilmFilter(), Digikam::FilmGrainFilter::FilmGrainFilter(), Digikam::FilterActionFilter::FilterActionFilter(), Digikam::FreeRotationFilter::FreeRotationFilter(), Digikam::HotPixelFixer::HotPixelFixer(), Digikam::HSLFilter::HSLFilter(), Digikam::IccTransformFilter::IccTransformFilter(), Digikam::InfraredFilter::InfraredFilter(), Digikam::InvertFilter::InvertFilter(), Digikam::LensDistortionFilter::LensDistortionFilter(), Digikam::LensFunFilter::LensFunFilter(), Digikam::LevelsFilter::LevelsFilter(), Digikam::LocalContrastFilter::LocalContrastFilter(), Digikam::MixerFilter::MixerFilter(), Digikam::NormalizeFilter::NormalizeFilter(), Digikam::NRFilter::NRFilter(), Digikam::OilPaintFilter::OilPaintFilter(), Digikam::RainDropFilter::RainDropFilter(), DigikamRawImportNativePlugin::RawPostProcessing::RawPostProcessing(), Digikam::RawProcessingFilter::RawProcessingFilter(), Digikam::RedEyeCorrectionFilter::RedEyeCorrectionFilter(), Digikam::RefocusFilter::RefocusFilter(), setupFilter(), Digikam::SharpenFilter::SharpenFilter(), Digikam::ShearFilter::ShearFilter(), Digikam::StretchFilter::StretchFilter(), Digikam::TextureFilter::TextureFilter(), Digikam::TonalityFilter::TonalityFilter(), Digikam::UnsharpMaskFilter::UnsharpMaskFilter(), and Digikam::WBFilter::WBFilter().

◆ initMaster()

void Digikam::DImgThreadedFilter::initMaster ( )
protected

◆ initSlave()

void Digikam::DImgThreadedFilter::initSlave ( DImgThreadedFilter *const  master,
int  progressBegin = 0,
int  progressEnd = 100 
)
protected

Initialize the filter for use as a slave - reroutes progress info to master. Note: Computation will be started from setupFilter().

References m_master, m_progressBegin, m_progressCurrent, m_progressSpan, m_slave, and setSlave().

Referenced by DImgThreadedFilter(), Digikam::RawProcessingFilter::setObserver(), and setupAndStartDirectly().

◆ isFinished()

bool Digikam::DynamicThread::isFinished ( ) const
inherited

◆ isRunning()

bool Digikam::DynamicThread::isRunning ( ) const
inherited

◆ modulateProgress()

int Digikam::DImgThreadedFilter::modulateProgress ( int  progress)
protectedvirtual

This method modulates the progress value from the 0..100 span to the span of this slave. Called by postProgress if master is not null.

References m_progressBegin, m_progressSpan, and progress().

Referenced by postProgress(), and Digikam::RawProcessingFilter::postProgress().

◆ multithreadedSteps()

QList< int > Digikam::DImgThreadedFilter::multithreadedSteps ( int  stop,
int  start = 0 
) const

This method return a list of steps to process parallelized operation in filter using QtConcurrents API. Usually, start and stop are rows or columns from image to process. By default, whole image will be processed and start value is 0. In this case stop will be last row or column to process. Between range [start,stop], this method will divide by equal steps depending of number of CPU cores available. To be sure that all values will be processed, in case of CPU core division give rest, the last step compensate the difference. See Blur filter loop implementation for example to see how to use this method with QtConcurrents API.

References Digikam::DynamicThread::start(), and Digikam::DynamicThread::stop().

◆ parametersSuccessfullyRead()

bool Digikam::DImgThreadedFilter::parametersSuccessfullyRead ( ) const
virtual

Optional: error handling for readParameters. When readParameters() has been called, this method will return true if the call was successful, and false if not. If returning false, readParametersError() will give an error message. The default implementation always returns success. You only need to reimplement when a filter is likely to fail in a different environment, e.g. depending on availability of installed files. These methods have an undefined return value if readParameters() was not called previously.

Reimplemented in Digikam::IccTransformFilter.

◆ postProgress()

◆ prepareDestImage()

void Digikam::DImgThreadedFilter::prepareDestImage ( )
protectedvirtual

◆ priority()

QThread::Priority Digikam::DynamicThread::priority ( ) const
inherited

◆ progress

void Digikam::DImgThreadedFilter::progress ( int  progress)
signal

◆ readParameters()

◆ readParametersError()

QString Digikam::DImgThreadedFilter::readParametersError ( const FilterAction actionThatFailed) const
virtual

Reimplemented in Digikam::IccTransformFilter.

◆ run()

void Digikam::DImgThreadedFilter::run ( )
overrideprotectedvirtual

List of threaded operations by filter.

Implements Digikam::DynamicThread.

References startFilterDirectly().

◆ runningFlag()

bool Digikam::DynamicThread::runningFlag ( ) const volatile
protectedinherited

◆ setEmitSignals()

void Digikam::DynamicThread::setEmitSignals ( bool  emitThem)
inherited

◆ setFilterName()

void Digikam::DImgThreadedFilter::setFilterName ( const QString &  name)

◆ setFilterVersion()

void Digikam::DImgThreadedFilter::setFilterVersion ( int  version)

Replaying a filter action: Set the filter version. A filter may implement different versions, to preserve image history when the algorithm is changed. Any value set here must be contained in supportedVersions, otherwise this call will be ignored. Default value is 1. (Note: If you intend to record a filter action, please look at FilterAction's m_version)

References m_version, and supportedVersions().

◆ setOriginalImage()

◆ setPriority()

void Digikam::DynamicThread::setPriority ( QThread::Priority  priority)
inherited

Sets the priority for this dynamic thread. Can be set anytime. If the thread is currently not running, the priority will be set when it is run next time. When you set QThread::InheritPriority (default), the priority is not changed but inherited from the thread pool.

References Digikam::DynamicThread::priority().

Referenced by Digikam::FacePipeline::Private::applyPriority(), and Digikam::FacePipeline::Private::createThumbnailLoadThread().

◆ setSlave()

void Digikam::DImgThreadedFilter::setSlave ( DImgThreadedFilter *const  slave)
protected

Inform the master that there is currently a slave. At destruction of the slave, call with slave=0.

References m_slave.

Referenced by initSlave(), and ~DImgThreadedFilter().

◆ setupAndStartDirectly()

void Digikam::DImgThreadedFilter::setupAndStartDirectly ( const DImg orgImage,
DImgThreadedFilter *const  master,
int  progressBegin = 0,
int  progressEnd = 100 
)

Initializes the filter for use as a slave and directly starts computation (in-thread)

References initSlave(), and setupFilter().

◆ setupFilter()

void Digikam::DImgThreadedFilter::setupFilter ( const DImg orgImage)

You need to call this and then start filter of you used the constructor not setting an original image. The original image's data will not be copied.

References initFilter(), and setOriginalImage().

Referenced by DigikamRAWDImgPlugin::DImgRAWLoader::postProcess(), and setupAndStartDirectly().

◆ shutDown()

void Digikam::DynamicThread::shutDown ( )
protectedinherited

If you are deleting data in your destructor which is accessed from the thread, do one of the following from your destructor to guarantee a safe shutdown: 1) Call this method 2) Call stop() and wait(), knowing that nothing will call start() anymore after this 3) Be sure the thread will never be running at destruction. Note: This irrevocably stops this object. Note: It is not sufficient that your parent class does this. Calling this method, or providing one of the above mentioned equivalent guarantees, must be done by every single last class in the hierarchy with an implemented destructor deleting data. (the base class destructor is always called after the derived class)

References Digikam::DynamicThread::stop(), and Digikam::DynamicThread::wait().

Referenced by Digikam::ManagedLoadSaveThread::shutDown(), Digikam::DynamicThread::~DynamicThread(), and Digikam::LoadSaveThread::~LoadSaveThread().

◆ start [1/2]

◆ start() [2/2]

void Digikam::DynamicThread::start ( QMutexLocker &  locker)
protectedinherited

Doing the same as start(), stop() and wait above, provide it with a locked QMutexLocker on mutex(). Note the start() will unlock and relock for scheduling once, after state change.

References Digikam::ThreadManager::instance(), and Digikam::ThreadManager::schedule().

◆ started

void Digikam::DImgThreadedFilter::started ( )
signal

This signal is emitted when image data is available and the computation has started.

Referenced by startFilterDirectly().

◆ startFilter()

void Digikam::DImgThreadedFilter::startFilter ( )
virtual

◆ startFilterDirectly()

◆ starting

void Digikam::DynamicThread::starting ( )
signalinherited

Emitted if emitSignals is enabled

◆ state()

◆ stop [1/2]

◆ stop() [2/2]

void Digikam::DynamicThread::stop ( QMutexLocker &  locker)
protectedinherited

◆ supportedVersions()

QList< int > Digikam::DImgThreadedFilter::supportedVersions ( ) const
virtual

Referenced by setFilterVersion().

◆ threadMutex()

QMutex * Digikam::DynamicThread::threadMutex ( ) const
protectedinherited

◆ wait [1/2]

◆ wait() [2/2]

void Digikam::DynamicThread::wait ( QMutexLocker &  locker)
protectedinherited

Member Data Documentation

◆ m_destImage

◆ m_master

DImgThreadedFilter* Digikam::DImgThreadedFilter::m_master
protected

The master of this slave filter. Progress info will be routed to this one.

Referenced by initFilter(), initMaster(), initSlave(), postProgress(), and ~DImgThreadedFilter().

◆ m_name

QString Digikam::DImgThreadedFilter::m_name
protected

◆ m_orgImage

◆ m_progressBegin

int Digikam::DImgThreadedFilter::m_progressBegin
protected

The progress span that a slave filter uses in the parent filter's progress.

Referenced by initMaster(), initSlave(), and modulateProgress().

◆ m_progressCurrent

int Digikam::DImgThreadedFilter::m_progressCurrent
protected

To prevent signals bombarding with progress indicator value in postProgress().

Referenced by initMaster(), initSlave(), and postProgress().

◆ m_progressSpan

int Digikam::DImgThreadedFilter::m_progressSpan
protected

◆ m_slave

DImgThreadedFilter* Digikam::DImgThreadedFilter::m_slave
protected

The current slave. Any filter might want to use another filter while processing.

Referenced by cancelFilter(), initMaster(), initSlave(), and setSlave().

◆ m_version

int Digikam::DImgThreadedFilter::m_version
protected

Referenced by filterVersion(), and setFilterVersion().

◆ m_wasCancelled

bool Digikam::DImgThreadedFilter::m_wasCancelled
protected

The documentation for this class was generated from the following files: