kis_basic_histogram_producers.h
1/*
2 * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef _KIS_BASIC_HISTOGRAM_PRODUCERS_
20#define _KIS_BASIC_HISTOGRAM_PRODUCERS_
21
22#include <tqvaluevector.h>
23#include <tdelocale.h>
24
25#include "config.h"
26
27#include "kis_histogram_producer.h"
28#include "kis_colorspace.h"
29#include "kis_id.h"
30
31class KisLabColorSpace;
32
33class KisBasicHistogramProducer : public KisHistogramProducer {
34public:
35 KisBasicHistogramProducer(const KisID& id, int channels, int nrOfBins, KisColorSpace *colorSpace);
36 virtual ~KisBasicHistogramProducer() {}
37
38 virtual void clear();
39
40 virtual void setView(double from, double size) { m_from = from; m_width = size; }
41
42 virtual const KisID& id() const { return m_id; }
43 virtual TQValueVector<KisChannelInfo *> channels() { return m_colorSpace->channels(); }
44 virtual TQ_INT32 numberOfBins() { return m_nrOfBins; }
45 virtual double viewFrom() const { return m_from; }
46 virtual double viewWidth() const { return m_width; }
47
48 virtual TQ_INT32 count() { return m_count; }
49
50 virtual TQ_INT32 getBinAt(int channel, int position)
51 { return m_bins.at(externalToInternal(channel)).at(position); }
52
53 virtual TQ_INT32 outOfViewLeft(int channel)
54 { return m_outLeft.at(externalToInternal(channel)); }
55
56 virtual TQ_INT32 outOfViewRight(int channel)
57 { return m_outRight.at(externalToInternal(channel)); }
58
59protected:
67 virtual int externalToInternal(int ext) {
68 if (channels().count() > 0 && m_external.count() == 0) // Set up the translation table
69 makeExternalToInternal();
70 return m_external.at(ext);
71 }
72 // not virtual since that is useless: we call it from constructor
73 void makeExternalToInternal();
74 typedef TQValueVector<TQ_UINT32> vBins;
75 TQValueVector<vBins> m_bins;
76 vBins m_outLeft, m_outRight;
77 double m_from, m_width;
78 TQ_INT32 m_count;
79 int m_channels, m_nrOfBins;
80 KisColorSpace *m_colorSpace;
81 KisID m_id;
82 TQValueVector<TQ_INT32> m_external;
83};
84
85class KisBasicU8HistogramProducer : public KisBasicHistogramProducer {
86public:
87 KisBasicU8HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
88 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
89 virtual TQString positionToString(double pos) const;
90 virtual double maximalZoom() const { return 1.0; }
91};
92
93class KisBasicU16HistogramProducer : public KisBasicHistogramProducer {
94public:
95 KisBasicU16HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
96 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
97 virtual TQString positionToString(double pos) const;
98 virtual double maximalZoom() const;
99};
100
101class KisBasicF32HistogramProducer : public KisBasicHistogramProducer {
102public:
103 KisBasicF32HistogramProducer(const KisID& id, KisColorSpace *colorSpace);
104 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
105 virtual TQString positionToString(double pos) const;
106 virtual double maximalZoom() const;
107};
108
109#ifdef HAVE_OPENEXR
110class KisBasicF16HalfHistogramProducer : public KisBasicHistogramProducer {
111public:
112 KisBasicF16HalfHistogramProducer(const KisID& id, KisColorSpace *colorSpace);
113 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
114 virtual TQString positionToString(double pos) const;
115 virtual double maximalZoom() const;
116};
117#endif
118
125template<class T> class KisBasicHistogramProducerFactory : public KisHistogramProducerFactory {
126public:
128 : KisHistogramProducerFactory(id), m_cs(colorSpace) {}
130 virtual KisHistogramProducerSP generate() { return new T(id(), m_cs); }
131 virtual bool isCompatibleWith(KisColorSpace* colorSpace) const { return colorSpace->id() == m_cs->id(); }
132 virtual float preferrednessLevelWith(KisColorSpace* /*colorSpace*/) const { return 1.0; }
133protected:
134 KisColorSpace *m_cs;
135};
136
143class KisGenericRGBHistogramProducer : public KisBasicHistogramProducer {
144public:
146 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
147 virtual TQString positionToString(double pos) const;
148 virtual double maximalZoom() const;
149 virtual TQValueVector<KisChannelInfo *> channels();
150protected:
151 TQValueVector<KisChannelInfo *> m_channelsList;
152};
153
155class KisGenericRGBHistogramProducerFactory : public KisHistogramProducerFactory {
156public:
158 : KisHistogramProducerFactory(KisID("GENRGBHISTO", i18n("Generic RGB"))) {}
160 virtual KisHistogramProducerSP generate() { return new KisGenericRGBHistogramProducer(); }
161 virtual bool isCompatibleWith(KisColorSpace*) const { return true; }
162 virtual float preferrednessLevelWith(KisColorSpace*) const { return 0.0; }
163};
164
165
171class KisGenericLabHistogramProducer : public KisBasicHistogramProducer {
172 public:
175 virtual void addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace);
176 virtual TQString positionToString(double pos) const;
177 virtual double maximalZoom() const;
178 virtual TQValueVector<KisChannelInfo *> channels();
179 protected:
180 TQValueVector<KisChannelInfo *> m_channelsList;
181 private:
182 static KisLabColorSpace* m_labCs;
183};
184
186class KisGenericLabHistogramProducerFactory : public KisHistogramProducerFactory {
187 public:
189 : KisHistogramProducerFactory(KisID("GENLABHISTO", i18n("Generic L*a*b*"))) {}
191 virtual KisHistogramProducerSP generate() { return new KisGenericLabHistogramProducer(); }
192 virtual bool isCompatibleWith(KisColorSpace*) const { return true; }
193 virtual float preferrednessLevelWith(KisColorSpace*) const { return 0.0; }
194};
195
196
197#endif // _KIS_BASIC_HISTOGRAM_PRODUCERS_
Parametrized on a specific KisHistogramProducer.
A colorspace is the definition of a certain color model in Chalk.
virtual KisID id() const =0
Chalk definition for use in .kra files and internally: unchanging name + i18n'able description.
KisGenericLabHistogramProducer his special Factory that isCompatibleWith everything.
This is a Producer (with associated factory) that converts the pixels of the colorspace to L*a*b*,...
virtual void addRegionToBin(TQ_UINT8 *pixels, TQ_UINT8 *selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace)
Adds the values from the specified array of pixels to the bins – does not reset anything.
KisGenericRGBHistogramProducer his special Factory that isCompatibleWith everything.
This is a Producer (with associated factory) that converts the pixels of the colorspace to RGB8 with ...
virtual void addRegionToBin(TQ_UINT8 *pixels, TQ_UINT8 *selectionMask, TQ_UINT32 nPixels, KisColorSpace *colorSpace)
Adds the values from the specified array of pixels to the bins – does not reset anything.
This class is an interface used in the generation of a histogram.
virtual void clear()=0
Clears the data in this producer, but keeps its other settings.
Chalk has a large number of extensible resources.
Definition kis_id.h:57