1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2005-05-25
* Description : threaded image filter class.
*
* Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#ifndef DIMGTHREADEDFILTER_H
#define DIMGTHREADEDFILTER_H
// TQt includes.
#include <tqthread.h>
#include <tqstring.h>
// KDE includes.
#include <tdeapplication.h>
// Local includes.
#include "dimg.h"
#include "digikam_export.h"
class TQObject;
namespace Digikam
{
class DIGIKAM_EXPORT DImgThreadedFilter : public TQThread
{
public:
/** Class used to post status of computation to parent. */
class EventData
{
public:
EventData()
{
starting = false;
success = false;
}
bool starting;
bool success;
int progress;
};
public:
DImgThreadedFilter(DImg *orgImage, TQObject *parent=0,
const TQString& name=TQString());
~DImgThreadedFilter();
DImg getTargetImage(void) { return m_destImage; };
virtual void startComputation(void);
virtual void stopComputation(void);
const TQString &filterName() { return m_name; };
protected:
/** Start filter operation before threaded method. Must be calls by your constructor. */
virtual void initFilter(void);
/** List of threaded operations by filter. */
virtual void run(){ startComputation(); };
/** Main image filter method. */
virtual void filterImage(void){};
/** Clean up filter data if necessary. Call by stopComputation() method. */
virtual void cleanupFilter(void){};
/** Post Event to parent about progress. Warning: you need to delete
'EventData' instance to 'customEvent' parent implementation. */
void postProgress(int progress=0, bool starting=true, bool success=false);
protected:
/**
Support for chaining two filters as master and thread.
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.
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.
*/
DImgThreadedFilter(DImgThreadedFilter *master, const DImg &orgImage, const DImg &destImage,
int progressBegin=0, int progressEnd=100, const TQString& name=TQString());
/** Inform the master that there is currently a slave. At destruction of the slave, call with slave=0. */
void setSlave(DImgThreadedFilter *slave);
/** 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. */
virtual int modulateProgress(int progress);
protected:
/** Used to stop compution loop. */
bool m_cancel;
/** The progress span that a slave filter uses in the parent filter's progress. */
int m_progressBegin;
int m_progressSpan;
/** To post event from thread to parent. */
TQObject *m_parent;
/** Filter name.*/
TQString m_name;
/** Copy of original Image data. */
DImg m_orgImage;
/** Output image data. */
DImg m_destImage;
/** The current slave. Any filter might want to use another filter while processing. */
DImgThreadedFilter *m_slave;
/** The master of this slave filter. Progress info will be routed to this one. */
DImgThreadedFilter *m_master;
};
} // NameSpace Digikam
#endif /* DIMGTHREADEDFILTER_H */
|