Warning, file /office/calligra/libs/pigment/KoBasicHistogramProducers.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be> 0003 * 0004 * This library is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Lesser General Public License as published 0006 * by the Free Software Foundation; either version 2.1 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #ifndef _Ko_BASIC_HISTOGRAM_PRODUCERS_ 0020 #define _Ko_BASIC_HISTOGRAM_PRODUCERS_ 0021 0022 #include "KoHistogramProducer.h" 0023 0024 #include <QVector> 0025 0026 #include <KoConfig.h> 0027 0028 #include "KoColorSpace.h" 0029 #include "KoID.h" 0030 #include "pigment_export.h" 0031 #include "KoColorSpaceRegistry.h" 0032 0033 class PIGMENTCMS_EXPORT KoBasicHistogramProducer : public KoHistogramProducer 0034 { 0035 public: 0036 explicit KoBasicHistogramProducer(const KoID& id, int channelCount, int nrOfBins); 0037 explicit KoBasicHistogramProducer(const KoID& id, int nrOfBins, const KoColorSpace *colorSpace); 0038 ~KoBasicHistogramProducer() override {} 0039 0040 void clear() override; 0041 0042 void setView(qreal from, qreal size) override { 0043 m_from = from; m_width = size; 0044 } 0045 0046 const KoID& id() const override { 0047 return m_id; 0048 } 0049 QList<KoChannelInfo *> channels() override { 0050 return m_colorSpace->channels(); 0051 } 0052 qint32 numberOfBins() override { 0053 return m_nrOfBins; 0054 } 0055 qreal viewFrom() const override { 0056 return m_from; 0057 } 0058 qreal viewWidth() const override { 0059 return m_width; 0060 } 0061 0062 qint32 count() override { 0063 return m_count; 0064 } 0065 0066 qint32 getBinAt(int channel, int position) override { 0067 return m_bins.at(externalToInternal(channel)).at(position); 0068 } 0069 0070 qint32 outOfViewLeft(int channel) override { 0071 return m_outLeft.at(externalToInternal(channel)); 0072 } 0073 0074 qint32 outOfViewRight(int channel) override { 0075 return m_outRight.at(externalToInternal(channel)); 0076 } 0077 0078 protected: 0079 /** 0080 * The order in which channels() returns is not the same as the internal representation, 0081 * that of the pixel internally. This method converts external usage to internal usage. 0082 * This method uses some basic assumptions about the layout of the pixel, so _extremely_ 0083 * exotic spaces might want to override this (see makeExternalToInternal source for 0084 * those assumptions) 0085 **/ 0086 virtual int externalToInternal(int ext) { 0087 if (channels().count() > 0 && m_external.count() == 0) // Set up the translation table 0088 makeExternalToInternal(); 0089 return m_external.at(ext); 0090 } 0091 // not virtual since that is useless: we call it from constructor 0092 void makeExternalToInternal(); 0093 typedef QVector<quint32> vBins; 0094 QVector<vBins> m_bins; 0095 vBins m_outLeft, m_outRight; 0096 qreal m_from, m_width; 0097 qint32 m_count; 0098 int m_channels, m_nrOfBins; 0099 const KoColorSpace *m_colorSpace; 0100 KoID m_id; 0101 QVector<qint32> m_external; 0102 }; 0103 0104 class PIGMENTCMS_EXPORT KoBasicU8HistogramProducer : public KoBasicHistogramProducer 0105 { 0106 public: 0107 KoBasicU8HistogramProducer(const KoID& id, const KoColorSpace *colorSpace); 0108 void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace) override; 0109 QString positionToString(qreal pos) const override; 0110 qreal maximalZoom() const override { 0111 return 1.0; 0112 } 0113 }; 0114 0115 class PIGMENTCMS_EXPORT KoBasicU16HistogramProducer : public KoBasicHistogramProducer 0116 { 0117 public: 0118 KoBasicU16HistogramProducer(const KoID& id, const KoColorSpace *colorSpace); 0119 void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace) override; 0120 QString positionToString(qreal pos) const override; 0121 qreal maximalZoom() const override; 0122 }; 0123 0124 class PIGMENTCMS_EXPORT KoBasicF32HistogramProducer : public KoBasicHistogramProducer 0125 { 0126 public: 0127 KoBasicF32HistogramProducer(const KoID& id, const KoColorSpace *colorSpace); 0128 void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace) override; 0129 QString positionToString(qreal pos) const override; 0130 qreal maximalZoom() const override; 0131 }; 0132 0133 0134 #ifdef HAVE_OPENEXR 0135 class PIGMENTCMS_EXPORT KoBasicF16HalfHistogramProducer : public KoBasicHistogramProducer 0136 { 0137 public: 0138 KoBasicF16HalfHistogramProducer(const KoID& id, const KoColorSpace *colorSpace); 0139 virtual void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace); 0140 virtual QString positionToString(qreal pos) const; 0141 virtual qreal maximalZoom() const; 0142 }; 0143 #endif 0144 0145 /** 0146 * Parametrized on a specific KoHistogramProducer. Its generated producers 0147 * will have the same KoID as the factory's. This is acceptable because we can't mix 0148 * Factories with Producers in the code because they are incompatible types, and 0149 * in the GUI we actually only need a producer's name, not a factory's. 0150 */ 0151 template<class T> class KoBasicHistogramProducerFactory : public KoHistogramProducerFactory 0152 { 0153 public: 0154 KoBasicHistogramProducerFactory(const KoID& id, const QString& modelId, const QString& depthId ) 0155 : KoHistogramProducerFactory(id), m_modelId(modelId), m_depthId(depthId) { 0156 } 0157 ~KoBasicHistogramProducerFactory() override {} 0158 0159 KoHistogramProducer *generate() override { 0160 KoHistogramProducer *producer = 0; 0161 const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(m_modelId, m_depthId, 0); 0162 if (cs) { 0163 producer = new T(KoID(id(), name()), cs); 0164 } 0165 return producer; 0166 0167 } 0168 bool isCompatibleWith(const KoColorSpace* colorSpace) const override { 0169 return colorSpace->colorModelId().id() == m_modelId || colorSpace->colorDepthId().id() == m_depthId; 0170 } 0171 float preferrednessLevelWith(const KoColorSpace* colorSpace) const override { 0172 return 0.5 * ( (colorSpace->colorModelId().id() == m_modelId) + (colorSpace->colorDepthId().id() == m_depthId) ); 0173 } 0174 protected: 0175 QString m_modelId, m_depthId; 0176 }; 0177 0178 /** 0179 * This is a Producer (with associated factory) that converts the pixels of the colorspace 0180 * to RGB8 with toQColor, and then does its counting on RGB. This is NOT registered with the 0181 * Registry, because it isCompatibleWith all colorspaces, and should only be used in extreme 0182 * cases (like no other producer being available 0183 **/ 0184 class PIGMENTCMS_EXPORT KoGenericRGBHistogramProducer : public KoBasicHistogramProducer 0185 { 0186 public: 0187 KoGenericRGBHistogramProducer(); 0188 void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace) override; 0189 QString positionToString(qreal pos) const override; 0190 qreal maximalZoom() const override; 0191 QList<KoChannelInfo *> channels() override; 0192 protected: 0193 QList<KoChannelInfo *> m_channelsList; 0194 }; 0195 0196 /** KoGenericRGBHistogramProducer his special Factory that isCompatibleWith everything. */ 0197 class PIGMENTCMS_EXPORT KoGenericRGBHistogramProducerFactory : public KoHistogramProducerFactory 0198 { 0199 public: 0200 KoGenericRGBHistogramProducerFactory(); 0201 0202 ~KoGenericRGBHistogramProducerFactory() override {} 0203 0204 KoHistogramProducer *generate() override { 0205 return new KoGenericRGBHistogramProducer(); 0206 } 0207 0208 bool isCompatibleWith(const KoColorSpace*) const override { 0209 return true; 0210 } 0211 0212 float preferrednessLevelWith(const KoColorSpace*) const override { 0213 return 0.0; 0214 } 0215 }; 0216 0217 0218 /** 0219 * This is a Producer (with associated factory) that converts the pixels of the colorspace 0220 * to L*a*b*, and then does its counting. 0221 * It isCompatibleWith all colorspaces 0222 **/ 0223 class PIGMENTCMS_EXPORT KoGenericLabHistogramProducer : public KoBasicHistogramProducer 0224 { 0225 public: 0226 KoGenericLabHistogramProducer(); 0227 ~KoGenericLabHistogramProducer() override; 0228 void addRegionToBin(const quint8 * pixels, const quint8 * selectionMask, quint32 nPixels, const KoColorSpace *colorSpace) override; 0229 QString positionToString(qreal pos) const override; 0230 qreal maximalZoom() const override; 0231 QList<KoChannelInfo *> channels() override; 0232 protected: 0233 QList<KoChannelInfo *> m_channelsList; 0234 }; 0235 0236 /** KoGenericLabHistogramProducer his special Factory that isCompatibleWith everything. */ 0237 class /*PIGMENTCMS_EXPORT*/ KoGenericLabHistogramProducerFactory : public KoHistogramProducerFactory 0238 { 0239 public: 0240 KoGenericLabHistogramProducerFactory(); 0241 ~KoGenericLabHistogramProducerFactory() override {} 0242 0243 KoHistogramProducer *generate() override { 0244 return new KoGenericLabHistogramProducer(); 0245 } 0246 0247 bool isCompatibleWith(const KoColorSpace*) const override { 0248 return true; 0249 } 0250 0251 float preferrednessLevelWith(const KoColorSpace*) const override { 0252 return 0.0; 0253 } 0254 }; 0255 0256 0257 #endif // _Ko_BASIC_HISTOGRAM_PRODUCERS_