Color Spaces - RGB, CMYK, YUV

Bart Coppens kde at bartcoppens.be
Sat Jun 4 12:02:39 CEST 2005


On Saturday 04 June 2005 11:08, Grzegorz Borowiak wrote:
> I wonder if it is possible to modify Krita in such way that it could
> handle images in YUV color space, as well as Photoshop handled CMYK, and
> if this won't disturb long term plans of Krita development.
Yes, that should be possible (well, mostly). And since implementing 'other' 
color spaces is actually on the TODO list of Krita, you would most certainly 
not disturb the development plans :-)

> If yes, I would gladly implement this, as I need this for FX. So far I use
> GIMP on video frames converted to RGB and I convert it back to YUV
> (conversion by mplayer/mencoder), but it is ugly. I need a tool which
> would allow me painting immediately on YUV frames.
Now this would be possible with krita, for the most part of it. If you know 
how, Krita would be able to display YUV frames, and you would be able to draw 
on them. As far as I know, the main problem is that at the moment, that the 
paint brush still works only in RGB, and is converted on-the-fly to the 
current colorspace. Now fixing this is on the TODO list as well, but I have 
no idea on how difficult that would be, and how big the implications would 
be. But this should not be too big a problem, I think.
You can (probably) hack around this a bit, if it would be really needed. The 
brush itself is either loaded from a gimp brush file (which don't support yuv 
anyway, as far as I know), or from a mask. This mask will than be colored 
with the current color in the function
KisPaintOp::computeDab(KisAlphaMaskSP mask) (in core/paintop/kis_paintop.cc)
where you'll see that it uses a QColor. Now you could probably play with this 
a bit, to work around the curent limitations. But that's of course for after 
getting YUV working, I think :-)

> Could you advise me, how to do it? I planned to see how CMYK is
> implemented, but I can't see it at work: Krita does not allow me to use
> CMYK colorspace, although there is some code for this.
I guess you have downloaded the KOffice/Krita 1.4 RC1 release? This release 
does unfortunately not include working CMYK code. The problem with it is, 
that most of us aren't really experts with different color spaces, so we had 
some issues getting it to work. It is however, available, and working 
(mostly) in the current Trunk version of Krita (that you can download using 
anonymous svn, or your kde svn account, if you have one). 

Now as I said, the state of the CMYK code is not really very good, so it is 
probable that you will get a bit confused by it. So it's best to have a look 
at, not only CMYK code, but also the RGB(A) code (or even the Grey(A) code, 
that's very simple as it only deals with 1 channel). You can find them in the 
modules/ and core/color_strategy/ directories.

Now to implement YUV(A) (it's best to add an alpha channel, or painting on a 
device would work with brushes that have smooth edges, which you'll probably 
want), the most work will probably be in implementing the pure virtual 
functions your class will inherit from KisStrategyColorSpace. This class also 
includes some basic virtual methods that are already implemented in a more 
generic way. It would be a good idea, after getting the basics working, to 
look at some of them, to see if you could do better (even if for very 
specific cases).

Now if you have any problems making YUV to work good (especially if it's the 
krita design that's not suited in any place), be sure to ask it. It's very 
likely that you'll encounter something that we didn't think of when the color 
space code was written, but maybe we can fix that :-)

Bart Coppens


More information about the kimageshop mailing list