digiKam Developer Documentation
Professional Photo Management with the Power of Open Source
Loading...
Searching...
No Matches
Digikam::DImgThreadedFilter Class Referenceabstract
+ Inheritance diagram for Digikam::DImgThreadedFilter:

Classes

class  DefaultFilterAction
 Convenience class to spare the few repeating lines of code. More...
 

Signals

void signalFinished (bool success)
 Emitted when the computation has completed.
 
void signalProgress (int progress)
 Emitted when progress info from the calculation is available.
 
void signalStarted ()
 This signal is emitted when image data is available and the computation has started.
 
- Signals inherited from Digikam::DynamicThread
void finished ()
 
void starting ()
 Emitted if emitSignals is enabled.
 

Public Member Functions

 DImgThreadedFilter (DImg *const orgImage, QObject *const parent, const QString &name=QString())
 Constructs a filter with all arguments (ready to use).
 
 DImgThreadedFilter (QObject *const parent=nullptr, const QString &name=QString())
 Constructs a filter without argument.
 
virtual void cancelFilter ()
 Cancel the threaded computation.
 
virtual FilterAction filterAction ()=0
 
virtual QString filterIdentifier () const =0
 
const QString & filterName ()
 
int filterVersion () const
 
DImg getTargetImage ()
 
QList< int > multithreadedSteps (int stop, int start=0) const
 This method return a list of steps to process parallelized operation in filter using QtConcurrents API.
 
virtual bool parametersSuccessfullyRead () const
 Optional error handling for readParameters.
 
virtual void readParameters (const FilterAction &)=0
 
virtual QString readParametersError (const FilterAction &actionThatFailed) const
 
void setFilterName (const QString &name)
 
void setFilterVersion (int version)
 Replaying a filter action: Set the filter version.
 
void setOriginalImage (const DImg &orgImage)
 
void 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)
 
void setupFilter (const DImg &orgImage)
 You need to call this and then start filter of you used the constructor not setting an original image.
 
virtual void startFilter ()
 Start the threaded computation.
 
virtual void startFilterDirectly ()
 Start computation of this filter, directly in this thread.
 
virtual QList< int > supportedVersions () const
 
- Public Member Functions inherited from Digikam::DynamicThread
 DynamicThread (QObject *const parent=nullptr)
 This class extends QRunnable, so you have to reimplement virtual void run().
 
 ~DynamicThread () override
 The destructor calls stop() and wait(), but if you, in your destructor, delete any data that is accessed by your run() method, you must call stop() and wait() before yourself.
 
bool isFinished () const
 
bool isRunning () const
 
QThread::Priority priority () const
 
void setEmitSignals (bool emitThem)
 
void setPriority (QThread::Priority priority)
 Sets the priority for this dynamic thread.
 
State state () const
 

Protected Member Functions

 DImgThreadedFilter (DImgThreadedFilter *const master, const DImg &orgImage, const DImg &destImage, int progressBegin=0, int progressEnd=100, const QString &name=QString())
 Support for chaining two filters as master and thread.
 
virtual void cleanupFilter ()
 Clean up filter data if necessary, called by stopComputation() method.
 
virtual void filterImage ()=0
 Main image filter method.
 
virtual void initFilter ()
 Start filter operation before threaded method.
 
void initMaster ()
 
void initSlave (DImgThreadedFilter *const master, int progressBegin=0, int progressEnd=100)
 Initialize the filter for use as a slave - reroutes progress info to master.
 
virtual int modulateProgress (int progress)
 This method modulates the progress value from the 0..100 span to the span of this slave.
 
virtual void postProgress (int progress)
 Emit progress info.
 
virtual void prepareDestImage ()
 
void run () override
 List of threaded operations by filter.
 
void setSlave (DImgThreadedFilter *const slave)
 Inform the master that there is currently a slave.
 
- Protected Member Functions inherited from Digikam::DynamicThread
bool runningFlag () const volatile
 In you run() method, you shall regularly check for runningFlag() and cleanup and return if false.
 
virtual void shutDown ()
 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.
 
void start (QMutexLocker< QMutex > &locker)
 Doing the same as start(), stop() and wait above, provide it with a locked QMutexLocker on mutex().
 
void stop (const QMutexLocker< QMutex > &locker)
 
QMutex * threadMutex () const
 This is the non-recursive mutex used to protect state variables and waiting in this class.
 
void wait (QMutexLocker< QMutex > &locker)
 

Protected Attributes

DImg m_destImage
 Output image data.
 
DImgThreadedFilterm_master = nullptr
 The master of this slave filter.
 
QString m_name
 Filter name.
 
DImg m_orgImage
 Copy of original Image data.
 
int m_progressBegin = 0
 The progress span that a slave filter uses in the parent filter's progress.
 
int m_progressCurrent = 0
 To prevent signals bombarding with progress indicator value in postProgress().
 
int m_progressSpan = 0
 
DImgThreadedFilterm_slave = nullptr
 The current slave.
 
int m_version = 1
 
bool m_wasCancelled = false
 

Additional Inherited Members

- Public Types inherited from Digikam::DynamicThread
enum  State { Inactive , Scheduled , Running , Deactivating }
 
- Public Slots inherited from Digikam::DynamicThread
void start ()
 
void stop ()
 Stop computation, sets the running flag to false.
 
void wait ()
 Waits until the thread finishes.
 

Constructor & Destructor Documentation

◆ DImgThreadedFilter() [1/3]

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

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

◆ DImgThreadedFilter() [2/3]

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

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().

◆ 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

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.

Member Function Documentation

◆ cancelFilter()

void Digikam::DImgThreadedFilter::cancelFilter ( )
virtual

Reimplemented in Digikam::GreycstorationFilter.

◆ cleanupFilter()

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

Override in subclass.

◆ filterAction()

◆ filterIdentifier()

◆ filterImage()

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

◆ initFilter()

void Digikam::DImgThreadedFilter::initFilter ( )
protectedvirtual

Must be called by your constructor.

◆ initSlave()

void Digikam::DImgThreadedFilter::initSlave ( DImgThreadedFilter *const  master,
int  progressBegin = 0,
int  progressEnd = 100 
)
protected
Note
Computation will be started from setupFilter().

◆ modulateProgress()

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

Called by postProgress if master is not null.

◆ multithreadedSteps()

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

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.

◆ parametersSuccessfullyRead()

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

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()

void Digikam::DImgThreadedFilter::postProgress ( int  progress)
protectedvirtual

Reimplemented in Digikam::RawProcessingFilter.

◆ run()

void Digikam::DImgThreadedFilter::run ( )
overrideprotectedvirtual

◆ setFilterVersion()

void Digikam::DImgThreadedFilter::setFilterVersion ( int  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

◆ setSlave()

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

At destruction of the slave, call with slave=0.

◆ setupFilter()

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

The original image's data will not be copied.

◆ signalFinished

void Digikam::DImgThreadedFilter::signalFinished ( bool  success)
signal
Parameters
successTrue if computation finished without interruption on valid data False if the thread was canceled, or no data is available.

Member Data Documentation

◆ m_master

DImgThreadedFilter* Digikam::DImgThreadedFilter::m_master = nullptr
protected

Progress info will be routed to this one.

◆ m_slave

DImgThreadedFilter* Digikam::DImgThreadedFilter::m_slave = nullptr
protected

Any filter might want to use another filter while processing.