how to create a new histogram type

Casper Boemann cbr at boemann.dk
Fri Sep 16 14:02:38 CEST 2005


Hi

I asked Bart on irc how to create a new histogram that shows the L part of Lab 
for any colorspace

Here is what he wrote:

what you need is basically a copy of KisGenericRGBHistogramProducer

 just like that GenericRGB producer, you inherit from 
KisBasicHistogramProducer

probably you can call it KisGenericLightnessHistogramProducer

ok, so for the class declaration just copy from the GenericRGB one, but with 
the name changed

that's all you'll need to override for that one



KisBasicHistogramProducer(KisID("GENLIGHTHISTO", "Generic Lab Lightness 
Histogram"), 1, 256, 0)
 {
  m_channelsList.append(new KisChannelInfo(i18n("L"), 0, COLOR));
}

channels() and maximalZoom() const implementations can be copied from 
genericRGB

 positionToString(double pos) const will be the same, but replace the UINT8 
with UINT16

that leaves you with only addRegionToBin to be implemented with actual Lab 
logic

Only if you want it to show up in the histogram as well you'll need to add a 
bit of code


so addRegionToBin is basically not too hard as well if you know how to convert 
from any colorspace to Lab

what you'll basically will need to do is the basic iterating logic, which you 
can copy as well from genericRGB

 but instead of calling the colorspace's toQColor then, you'll need to 
transform the Q_UINT8* pixel to Lab

m_bins.at(0).at(UINT16_TO_UINT8(L value of your conversion));

and basically you're done

you can now make a histogram from it, but I forgot that if you want to display 
it in the histogram view you'll need to register it with the registry anyway

 which is again as simple as copying from 
KisGenericRGBHistogramProducerFactory, and replacing the RGB references to 
your new Lightness thing

and then you need to register that factory with the producer by doing a normal 
add on it

and then you can use the histogram in the view as well
-- 
best regards / venlig hilsen
Casper Boemann


More information about the kimageshop mailing list