Re: colorspace converters



On Tue, Feb 06, 2001 at 01:54:40PM -0500, Havoc Pennington wrote:
> 
> Hi,
> 
> Would like to add a function to convert between colorspaces, probably
> to gdk-pixbuf. 
> 
> At the moment GTK contains code in static functions to do RGB<->HSV
> and RGB<->HLS. I need RGB<->HLS in another file, is the immediate need
> for the public converter function. Anyhow, those three colorspace
> converters would be what we'd initially support.
> 
> GdkPixbuf is already using the GdkColorspace enum, not sure whether we
> want to use this same enum for the converter function.
> 
> Anyhow, as a generic API, best idea so far is:
> 
> void
> gdk_colorspace_convert (gdouble *src_values,
>                         GdkColorspace src_format,
>                         gdouble *dest_values,
>                         GdkColorspace dest_format);
> 
> 
> Where the length and content of the gdouble arrays depends on the format.
> 
> Another option would be to have RGB always used as intermediate
> format:
> 
> void 
> gdk_rgb_to_colorspace (GdkColor *src,
>                        gdouble *dest_values,
>                        GdkColorspace dest_format);
> 
> void 
> gdk_colorspace_to_rgb (gdouble *src_values,
>                        GdkColorspace src_format,
>                        GdkColor *dest);
> 
> That's easier to implement and maybe simpler to use, but probably
> slower and loses precision/information.

The first api sounds reasonable. The HSV and HLS colorspaces are not
really considered "professional". Most of the time, when the word
"colorspace" is used, it refers to a colorimetrically-based color space.

I suggest that we define sRGB to be the default RGB color space of
Gnome. sRGB is a precise colorimetric interpretation of RGB values.
Thus, sRGB can be interconverted between other colorimetrically based
color spaces such as YCC, LAB, etc. This would not be a well defined
operation for regular RGB.

I don't believe that any code changes are needed to use sRGB as the
recommended default. I might suggest GdkColorspace include both
RGB-based and colorimetrically based colorspaces. HSV and HLS would
interconvert between RGB, but not to the colorimetrically based
colorspaces. The conversion between RGB and sRGB would be a noop.

I recommend against using RGB as the intermediate color space. There
are several problems:

* RGB is not well defined and cannot interconvert.
* sRGB, while it does interconvert, doesn't include all interesting colors.
* This is probably not relevant for Gnome now, but three components
  may not be be enough for all applications.

The internal implementation may of course use RGB (or sRGB) as an
intermediate colorspace so that you don't need n^2 conversion utilities.
Many systems (including PostScript) use CIE XYZ as the intermediate
colorspace when converting between colorimetrically-based color spaces.
This requires more precision than 8 bits, so your choice of gdouble
seems well advised.

Hope this helps.

Raph






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]