28#include "kis_global.h"
29#include "kis_basic_histogram_producers.h"
30#include "kis_integer_maths.h"
31#include "kis_channelinfo.h"
32#include "kis_colorspace.h"
33#include "kis_lab_colorspace.h"
35KisLabColorSpace* KisGenericLabHistogramProducer::m_labCs = 0;
38KisBasicHistogramProducer::KisBasicHistogramProducer(
const KisID&
id,
int channels,
int nrOfBins,
KisColorSpace *cs)
39 : m_channels(channels),
44 m_bins.resize(m_channels);
45 for (
int i = 0; i < m_channels; i++)
46 m_bins.at(i).resize(m_nrOfBins);
47 m_outLeft.resize(m_channels);
48 m_outRight.resize(m_channels);
56 for (
int i = 0; i < m_channels; i++) {
57 for (
int j = 0; j < m_nrOfBins; j++) {
58 m_bins.at(i).at(j) = 0;
65void KisBasicHistogramProducer::makeExternalToInternal() {
69 TQValueVector<KisChannelInfo *> c = channels();
70 uint count = c.count();
73 for (uint i = 0; i < count; i++) {
74 for (uint j = 0; j < count; j++) {
75 if (c.at(j)->pos() == currentPos) {
80 currentPos += c.at(m_external.at(m_external.count() - 1))->size();
86KisBasicU8HistogramProducer::KisBasicU8HistogramProducer(
const KisID&
id,
KisColorSpace *cs)
87 : KisBasicHistogramProducer(id, cs->nChannels(), 256, cs)
91TQString KisBasicU8HistogramProducer::positionToString(
double pos)
const {
92 return TQString(
"%1").arg(
static_cast<TQ_UINT8
>(pos * UINT8_MAX));
95void KisBasicU8HistogramProducer::addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels,
KisColorSpace *cs)
99 if (nPixels == 0)
return;
103 if ( selectionMask ) {
104 while (nPixels > 0) {
105 if ( ! (m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT) ) {
107 for (
int i = 0; i < m_channels; i++) {
108 m_bins.at(i).at(pixels[i])++;
120 while (nPixels > 0) {
121 if ( ! (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT) ) {
123 for (
int i = 0; i < m_channels; i++) {
124 m_bins.at(i).at(pixels[i])++;
138KisBasicU16HistogramProducer::KisBasicU16HistogramProducer(
const KisID&
id,
KisColorSpace *cs)
139 : KisBasicHistogramProducer(id, cs->nChannels(), 256, cs)
143TQString KisBasicU16HistogramProducer::positionToString(
double pos)
const
145 return TQString(
"%1").arg(
static_cast<TQ_UINT8
>(pos * UINT8_MAX));
148double KisBasicU16HistogramProducer::maximalZoom()
const
153void KisBasicU16HistogramProducer::addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels,
KisColorSpace *cs)
156 TQ_UINT16 from =
static_cast<TQ_UINT16
>(m_from * UINT16_MAX);
157 TQ_UINT16 width =
static_cast<TQ_UINT16
>(m_width * UINT16_MAX + 0.5);
158 TQ_UINT16 to = from + width;
159 double factor = 255.0 / width;
163 if ( selectionMask ) {
164 TQ_UINT16* pixel =
reinterpret_cast<TQ_UINT16*
>(pixels);
165 while (nPixels > 0) {
166 if ( ! ((m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) ) {
167 for (
int i = 0; i < m_channels; i++) {
168 TQ_UINT16 value = pixel[i];
171 else if (value < from)
174 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
184 while (nPixels > 0) {
185 TQ_UINT16* pixel =
reinterpret_cast<TQ_UINT16*
>(pixels);
187 if ( ! (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) {
188 for (
int i = 0; i < m_channels; i++) {
189 TQ_UINT16 value = pixel[i];
192 else if (value < from)
195 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
207KisBasicF32HistogramProducer::KisBasicF32HistogramProducer(
const KisID&
id,
KisColorSpace *cs)
208 : KisBasicHistogramProducer(id, cs->nChannels(), 256, cs)
212TQString KisBasicF32HistogramProducer::positionToString(
double pos)
const {
213 return TQString(
"%1").arg(
static_cast<float>(pos));
216double KisBasicF32HistogramProducer::maximalZoom()
const {
221void KisBasicF32HistogramProducer::addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels,
KisColorSpace *cs) {
223 float from =
static_cast<float>(m_from);
224 float width =
static_cast<float>(m_width);
225 float to = from + width;
226 float factor = 255.0 / width;
230 if ( selectionMask ) {
231 while (nPixels > 0) {
233 float* pixel =
reinterpret_cast<float*
>(pixels);
234 if ( !((m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) ) {
235 for (
int i = 0; i < m_channels; i++) {
236 float value = pixel[i];
239 else if (value < from)
242 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
254 while (nPixels > 0) {
256 float* pixel =
reinterpret_cast<float*
>(pixels);
257 if ( !(m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) {
258 for (
int i = 0; i < m_channels; i++) {
259 float value = pixel[i];
262 else if (value < from)
265 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
279KisBasicF16HalfHistogramProducer::KisBasicF16HalfHistogramProducer(
const KisID&
id,
281 : KisBasicHistogramProducer(id, cs->nChannels(), 256, cs) {
284TQString KisBasicF16HalfHistogramProducer::positionToString(
double pos)
const {
285 return TQString(
"%1").arg(
static_cast<float>(pos));
288double KisBasicF16HalfHistogramProducer::maximalZoom()
const {
293void KisBasicF16HalfHistogramProducer::addRegionToBin(TQ_UINT8 * pixels, TQ_UINT8 * selectionMask, TQ_UINT32 nPixels,
KisColorSpace *cs) {
295 float from =
static_cast<float>(m_from);
296 float width =
static_cast<float>(m_width);
297 float to = from + width;
298 float factor = 255.0 / width;
301 if ( selectionMask ) {
302 while (nPixels > 0) {
303 half* pixel =
reinterpret_cast<half*
>(pixels);
304 if ( !((m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) ) {
305 for (
int i = 0; i < m_channels; i++) {
306 float value = pixel[i];
309 else if (value < from)
312 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
322 while (nPixels > 0) {
323 half* pixel =
reinterpret_cast<half*
>(pixels);
324 if ( !(m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) {
325 for (
int i = 0; i < m_channels; i++) {
326 float value = pixel[i];
329 else if (value < from)
332 m_bins.at(i).at(
static_cast<TQ_UINT8
>((value - from) * factor))++;
344KisGenericRGBHistogramProducer::KisGenericRGBHistogramProducer()
345 : KisBasicHistogramProducer(
KisID(
"GENRGBHISTO", i18n(
"Generic RGB Histogram")),
349 m_channelsList.append(
new KisChannelInfo(i18n(
"R"), i18n(
"R"), 0, KisChannelInfo::COLOR, KisChannelInfo::UINT8, 1, TQColor(255,0,0)));
350 m_channelsList.append(
new KisChannelInfo(i18n(
"G"), i18n(
"G"), 1, KisChannelInfo::COLOR, KisChannelInfo::UINT8, 1, TQColor(0,255,0)));
351 m_channelsList.append(
new KisChannelInfo(i18n(
"B"), i18n(
"B"), 2, KisChannelInfo::COLOR, KisChannelInfo::UINT8, 1, TQColor(0,0,255)));
354TQValueVector<KisChannelInfo *> KisGenericRGBHistogramProducer::channels() {
355 return m_channelsList;
358TQString KisGenericRGBHistogramProducer::positionToString(
double pos)
const {
359 return TQString(
"%1").arg(
static_cast<TQ_UINT8
>(pos * UINT8_MAX));
362double KisGenericRGBHistogramProducer::maximalZoom()
const {
369 for (
int i = 0; i < m_channels; i++) {
370 m_outRight.at(i) = 0;
377 while (nPixels > 0) {
378 if ( !((m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) ) {
380 m_bins.at(0).at(c.red())++;
381 m_bins.at(1).at(c.green())++;
382 m_bins.at(2).at(c.blue())++;
393 while (nPixels > 0) {
395 if ( !(m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) {
397 m_bins.at(0).at(c.red())++;
398 m_bins.at(1).at(c.green())++;
399 m_bins.at(2).at(c.blue())++;
410KisGenericLabHistogramProducer::KisGenericLabHistogramProducer()
411 : KisBasicHistogramProducer(
KisID(
"GENLABHISTO", i18n(
"L*a*b* Histogram")), 3, 256, 0) {
414 m_channelsList.append(
new KisChannelInfo(i18n(
"L*"), i18n(
"L"), 0, KisChannelInfo::COLOR, KisChannelInfo::UINT8));
415 m_channelsList.append(
new KisChannelInfo(i18n(
"a*"), i18n(
"a"), 1, KisChannelInfo::COLOR, KisChannelInfo::UINT8));
416 m_channelsList.append(
new KisChannelInfo(i18n(
"b*"), i18n(
"b"), 2, KisChannelInfo::COLOR, KisChannelInfo::UINT8));
419 KisProfile *labProfile =
new KisProfile(cmsCreateLabProfile(NULL));
420 m_labCs =
new KisLabColorSpace(0, labProfile);
422 m_colorSpace = m_labCs;
424KisGenericLabHistogramProducer::~KisGenericLabHistogramProducer()
426 delete m_channelsList[0];
427 delete m_channelsList[1];
428 delete m_channelsList[2];
431TQValueVector<KisChannelInfo *> KisGenericLabHistogramProducer::channels() {
432 return m_channelsList;
435TQString KisGenericLabHistogramProducer::positionToString(
double pos)
const {
436 return TQString(
"%1").arg(
static_cast<TQ_UINT16
>(pos * UINT16_MAX));
439double KisGenericLabHistogramProducer::maximalZoom()
const {
446 for (
int i = 0; i < m_channels; i++) {
447 m_outRight.at(i) = 0;
455 while (nPixels > 0) {
456 if ( !((m_skipUnselected && *selectionMask == 0) || (m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) ) {
469 while (nPixels > 0) {
470 if ( !(m_skipTransparent && cs->
getAlpha(pixels) == OPACITY_TRANSPARENT)) {
473 m_bins.at(0).at(m_colorSpace->scaleToU8(dst, 0))++;
474 m_bins.at(1).at(m_colorSpace->scaleToU8(dst, 1))++;
475 m_bins.at(2).at(m_colorSpace->scaleToU8(dst, 2))++;
This class gives some basic information about a channel, that is, one of the components that makes up...
A colorspace is the definition of a certain color model in Chalk.
virtual void toTQColor(const TQ_UINT8 *src, TQColor *c, KisProfile *profile=0)=0
The toTQColor methods take a byte array that is at least pixelSize() long and converts the contents t...
virtual TQ_UINT8 getAlpha(const TQ_UINT8 *pixel) const =0
Get the alpha value of the given pixel, downscaled to an 8-bit value.
virtual bool convertPixelsTo(const TQ_UINT8 *src, TQ_UINT8 *dst, KisColorSpace *dstColorSpace, TQ_UINT32 numPixels, TQ_INT32 renderingIntent=INTENT_PERCEPTUAL)=0
Convert a byte array of srcLen pixels *src to the specified color space and put the converted bytes i...
virtual TQ_UINT32 pixelSize() const =0
The size in bytes of a single pixel in this color model.
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.
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.
virtual void clear()=0
Clears the data in this producer, but keeps its other settings.
Chalk has a large number of extensible resources.