KoHistogramProducer.h 5.38 KB
Newer Older
1 2 3
/*
 *  Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be>
 *
4
 *  This library is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU Lesser General Public License as published by
6
 *  the Free Software Foundation; either version 2.1 of the License, or
7 8
 *  (at your option) any later version.
 *
9
 *  This library is distributed in the hope that it will be useful,
10 11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU Lesser General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU Lesser General Public License
15 16 17 18
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

Boudewijn Rempt's avatar
Boudewijn Rempt committed
19 20
#ifndef _KO_HISTOGRAM_PRODUCER_
#define _KO_HISTOGRAM_PRODUCER_
21

22
#include <QtGlobal>
23

24
#include "kritapigment_export.h"
25

26 27
#include <KoGenericRegistry.h>
#include <KoID.h>
28 29

class QString;
30
class KoChannelInfo;
Cyrille Berger's avatar
Cyrille Berger committed
31
class KoColorSpace;
32 33 34

/**
 * This class is an interface used in the generation of a histogram. It is a container of
Boudewijn Rempt's avatar
Boudewijn Rempt committed
35
 * data, all mathematically interesting things will calculated by an histogram.
36
 *
37 38
 * The default view will be the entire range each color can be in. And don't let the
 * numberOfBins return anything else then 256 unless you have a very good reason for it.
39
 *
40 41
 * About the views: a view is a zoom combined with a start level: the entire
 * range of a channel is 0.0 - 1.0: this is the position. Combined with a zoom, we can
42
 * calculate what part of a channel will fall in a bin. This gives us an interface to
43 44
 * that the views that is not dependent of the actual colorspace of the histogram.
 * The 'size' value is the size, again from 0.0 to 1.0 of the displayed range.
45
 *
46 47 48
 * For comfort of the GUI, and because it is logical, channels are accessed in the order
 * in which they are found in the channels() method. This is potentially different from
 * the order in which they are internally ordered!
49
 **/
50
class KRITAPIGMENT_EXPORT KoHistogramProducer
51
{
52
public:
53
    KoHistogramProducer() : m_skipTransparent(true), m_skipUnselected(true) {}
54
    virtual ~KoHistogramProducer() {}
55 56

    // Methods to change the bins
57

58 59
    /** Clears the data in this producer, but keeps its other settings */
    virtual void clear() = 0;
60

61
    /**
62 63
     * Adds the values from the specified array of pixels to the bins -- does not
     * reset anything.
64 65
     *
     * @param pixels A pointer an array of pixeldata in the given colorspace
Adriaan de Groot's avatar
Adriaan de Groot committed
66
     * @param selectionMask a pointer to an array of bytes, where 0 is unselected and 1-255 is degree of selectedness. The array
67 68 69 70
     *                      must be just as long as the array of pixels.
     * @param nPixels The number of pixels
     * @param colorSpace the colorspace that can decode the pixel data.
     */
71
    virtual void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace* colorSpace) = 0;
72 73

    // Methods to set what exactly is being added to the bins
74
    virtual void setView(qreal from, qreal width) = 0;
75 76 77 78 79 80
    virtual void setSkipTransparent(bool set) {
        m_skipTransparent = set;
    }
    virtual void setSkipUnselected(bool set) {
        m_skipUnselected = set;
    }
81 82

    // Methods with general information about this specific producer
83
    virtual const KoID& id() const = 0;
Adrian Page's avatar
q3--  
Adrian Page committed
84
    virtual QList<KoChannelInfo *> channels() = 0;
Laurent Montel's avatar
Laurent Montel committed
85
    virtual qint32 numberOfBins() = 0;
86 87 88 89
    virtual QString positionToString(qreal pos) const = 0;
    virtual qreal viewFrom() const = 0;
    virtual qreal viewWidth() const = 0;
    virtual qreal maximalZoom() const = 0;
90 91

    // Methods to get information on the data we have seen
Laurent Montel's avatar
Laurent Montel committed
92 93 94 95
    virtual qint32 count() = 0;
    virtual qint32 getBinAt(qint32 channel, qint32 position) = 0;
    virtual qint32 outOfViewLeft(qint32 channel) = 0;
    virtual qint32 outOfViewRight(qint32 channel) = 0;
96 97 98 99 100
protected:
    bool m_skipTransparent;
    bool m_skipUnselected;
};

101
class KRITAPIGMENT_EXPORT KoHistogramProducerFactory
102
{
103
public:
104
    explicit KoHistogramProducerFactory(const KoID &id) : m_id(id) {}
105
    virtual ~KoHistogramProducerFactory() {}
106

107
    /// Factory method, generates a new KoHistogramProducer
108 109
    virtual KoHistogramProducer *generate() = 0;

110
    /// Returns if a colorspace can be used with this producer
Boudewijn Rempt's avatar
Boudewijn Rempt committed
111
    virtual bool isCompatibleWith(const KoColorSpace* colorSpace, bool strict = false) const = 0;
112

113
    /// Returns a float in the [0.0, 1.0] range, 0.0 means this is a very generic method
114
    virtual float preferrednessLevelWith(const KoColorSpace* colorSpace) const = 0;
115

116 117 118
    virtual QString id() const {
        return m_id.id();
    }
119

120 121 122
    virtual QString name() const {
        return m_id.name();
    }
123
protected:
124
    KoID m_id;
125 126
};

127

128
class KRITAPIGMENT_EXPORT KoHistogramProducerFactoryRegistry
Cyrille Berger's avatar
Cyrille Berger committed
129
        : public KoGenericRegistry<KoHistogramProducerFactory*>
130
{
131
public:
132
    KoHistogramProducerFactoryRegistry();
133
    ~KoHistogramProducerFactoryRegistry() override;
134
    static KoHistogramProducerFactoryRegistry* instance();
135
    /// returns a list, sorted by preferrence: higher preferance comes first
Boudewijn Rempt's avatar
Boudewijn Rempt committed
136
    QList<QString> keysCompatibleWith(const KoColorSpace* colorSpace, bool isStrict=false) const;
137 138

private:
139 140
    KoHistogramProducerFactoryRegistry(const KoHistogramProducerFactoryRegistry&);
    KoHistogramProducerFactoryRegistry operator=(const KoHistogramProducerFactoryRegistry&);
141 142
};

Boudewijn Rempt's avatar
Boudewijn Rempt committed
143
#endif // _KO_HISTOGRAM_PRODUCER