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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _KIS_BASIC_HISTOGRAM_PRODUCERS_
#define _KIS_BASIC_HISTOGRAM_PRODUCERS_
#include <tqvaluevector.h>
#include <tdelocale.h>
#include "config.h"
#include "kis_histogram_producer.h"
#include "kis_colorspace.h"
#include "kis_id.h"
class KisLabColorSpace;
class KisBasicHistogramProducer : public KisHistogramProducer {
public:
KisBasicHistogramProducer(const KisID& id, int channels, int nrOfBins, KisColorSpace *colorSpace);
virtual ~KisBasicHistogramProducer() {}
virtual void clear();
virtual void setView(double from, double size) { m_from = from; m_width = size; }
virtual const KisID& id() const { return m_id; }
virtual TQValueVector<KisChannelInfo *> channels() { return m_colorSpace->channels(); }
virtual TQ_INT32 numberOfBins() { return m_nrOfBins; }
virtual double viewFrom() const { return m_from; }
virtual double viewWidth() const { return m_width; }
virtual TQ_INT32 count() { return m_count; }
virtual TQ_INT32 getBinAt(int channel, int position)
{ return m_bins.at(externalToInternal(channel)).at(position); }
virtual TQ_INT32 outOfViewLeft(int channel)
{ return m_outLeft.at(externalToInternal(channel)); }
virtual TQ_INT32 outOfViewRight(int channel)
{ return m_outRight.at(externalToInternal(channel)); }
protected:
/**
* The order in which channels() returns is not the same as the internal representation,
* that of the pixel internally. This method converts external usage to internal usage.
* This method uses some basic assumtpions about the layout of the pixel, so _extremely_
* exotic spaces might want to override this (see makeExternalToInternal source for
* those assumptions)
**/
virtual int externalToInternal(int ext) {
if (channels().count() > 0 && m_external.count() == 0) // Set up the translation table
makeExternalToInternal();
return m_external.at(ext);
}
// not virtual since that is useless: we call it from constructor
void makeExternalToInternal();
typedef TQValueVector<TQ_UINT32> vBins;
TQValueVector<vBins> m_bins;
vBins m_outLeft, m_outRight;
double m_from, m_width;
TQ_INT32 m_count;
int m_channels, m_nrOfBins;
KisColorSpace *m_colorSpace;
KisID m_id;
TQValueVector<TQ_INT32> m_external;
};
class KisBasicU8HistogramProducer : public KisBasicHistogramProducer {
public:
KisBasicU8HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const { return 1.0; }
};
class KisBasicU16HistogramProducer : public KisBasicHistogramProducer {
public:
KisBasicU16HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const;
};
class KisBasicF32HistogramProducer : public KisBasicHistogramProducer {
public:
KisBasicF32HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const;
};
#ifdef HAVE_OPENEXR
class KisBasicF16HalfHistogramProducer : public KisBasicHistogramProducer {
public:
KisBasicF16HalfHistogramProducer(const KisID& id, KisColorSpace *colorSpace);
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const;
};
#endif
/**
* Parametrized on a specific KisHistogramProducer. Its generated producers
* will have the same KisID as the factory's. This is acceptable because we can't mix
* Factories with Producers in the code because they are incompatible types, and
* in the GUI we actually only need a producer's name, not a factory's.
*/
template<class T> class KisBasicHistogramProducerFactory : public KisHistogramProducerFactory {
public:
KisBasicHistogramProducerFactory(const KisID& id, KisColorSpace *colorSpace)
: KisHistogramProducerFactory(id), m_cs(colorSpace) {}
virtual ~KisBasicHistogramProducerFactory() {}
virtual KisHistogramProducerSP generate() { return new T(id(), m_cs); }
virtual bool isCompatibleWith(KisColorSpace* colorSpace) const { return colorSpace->id() == m_cs->id(); }
virtual float preferrednessLevelWith(KisColorSpace* /*colorSpace*/) const { return 1.0; }
protected:
KisColorSpace *m_cs;
};
/**
* This is a Producer (with associated factory) that converts the pixels of the colorspace
* to RGB8 with toTQColor, and then does its counting on RGB. This is NOT registered with the
* Registry, because it isCompatibleWith all colorspaces, and should only be used in extreme
* cases (like no other producer being available
**/
class KisGenericRGBHistogramProducer : public KisBasicHistogramProducer {
public:
KisGenericRGBHistogramProducer();
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const;
virtual TQValueVector<KisChannelInfo *> channels();
protected:
TQValueVector<KisChannelInfo *> m_channelsList;
};
/** KisGenericRGBHistogramProducer his special Factory that isCompatibleWith everything. */
class KisGenericRGBHistogramProducerFactory : public KisHistogramProducerFactory {
public:
KisGenericRGBHistogramProducerFactory()
: KisHistogramProducerFactory(KisID("GENRGBHISTO", i18n("Generic RGB"))) {}
virtual ~KisGenericRGBHistogramProducerFactory() {}
virtual KisHistogramProducerSP generate() { return new KisGenericRGBHistogramProducer(); }
virtual bool isCompatibleWith(KisColorSpace*) const { return true; }
virtual float preferrednessLevelWith(KisColorSpace*) const { return 0.0; }
};
/**
* This is a Producer (with associated factory) that converts the pixels of the colorspace
* to L*a*b*, and then does its counting.
* It isCompatibleWith all colorspaces
**/
class KisGenericLabHistogramProducer : public KisBasicHistogramProducer {
public:
KisGenericLabHistogramProducer();
virtual ~KisGenericLabHistogramProducer();
virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
virtual TQString positionToString(double pos) const;
virtual double maximalZoom() const;
virtual TQValueVector<KisChannelInfo *> channels();
protected:
TQValueVector<KisChannelInfo *> m_channelsList;
private:
static KisLabColorSpace* m_labCs;
};
/** KisGenericLabHistogramProducer his special Factory that isCompatibleWith everything. */
class KisGenericLabHistogramProducerFactory : public KisHistogramProducerFactory {
public:
KisGenericLabHistogramProducerFactory()
: KisHistogramProducerFactory(KisID("GENLABHISTO", i18n("Generic L*a*b*"))) {}
virtual ~KisGenericLabHistogramProducerFactory() {}
virtual KisHistogramProducerSP generate() { return new KisGenericLabHistogramProducer(); }
virtual bool isCompatibleWith(KisColorSpace*) const { return true; }
virtual float preferrednessLevelWith(KisColorSpace*) const { return 0.0; }
};
#endif // _KIS_BASIC_HISTOGRAM_PRODUCERS_
|