RGB and LAB color spaces: Conversion and interpolation

Jim Graham james.graham at oracle.com
Thu Oct 1 21:02:27 UTC 2015

LinearGradient only interpolates in RGB under the covers so it won't 
help you for interpolating in the other color spaces.

The regular Java ColorSpace has built-in support for a couple of color 
spaces, but their implementations are not in the base classes, they farm 
out the actual conversions to a plug-in library.  If you need other 
color spaces and can obtain their ICC profile data then you can 
instantiate any color space from that.

If those solutions aren't sufficient then you may have to roll your own 
(at least for now).

I don't think we have a feature request for color space support (beyond 
the HSB conversions we provide) so you should file one so we can track 
this issue...


On 9/30/15 2:04 AM, Benjamin Gudehus wrote:
> java.awt.color.ColorSpace (and ICC_ColorSpace) only provide an empty
> implementation and constants for the conversion between color spaces,
> but no specific implementation (at least for HSL, LAB, et cetera).
> Conversion: Interestingly the implementations in the wild rarely
> reference the source of the algorithms. So I searched through our
> university's library and found different algorithms for HSV, HSL and HSI
> (Smith 1978, Metrick 1979, Foley and van Dam 1982, Fishkin 1990, Travis
> 1991, Gonzalez and Woods 1992).
> Interpolation: JavaFX has LinearGradient. But it's rather complicated to
> retrieve a color ramp from it; we need to fill a Rectangle with a
> LinearGradient, make a snapshot and use PixelReader to extract the
> integer color values, and the implemention uses some padding for the
> colors at start and end. Then the implementation is in
> com.sun.prism.impl.paint so I can't access it directly.
> Seems I have to implement this library by myself.
> On Fri, Sep 25, 2015 at 9:33 PM, Jim Graham <james.graham at oracle.com
> <mailto:james.graham at oracle.com>> wrote:
>     JavaFX has no color conversion libraries.  The classes in
>     java.awt.color are the only alternative that ships standard with the
>     JDK...
>                              ...jim
>     On 9/25/15 7:42 AM, Benjamin Gudehus wrote:
>         Hey!
>         I want to convert colors between different color spaces and
>         interpolate
>         them within the specific color space (sRGB and its cylindrical
>         transformations HSL/HLS, HSV/HSB, and HSI. LAB and its cylindrical
>         transformations LCH, and HCL).
>         javafx.scene.paint.Color only accepts (s)RGB and HSB and seems
>         to support
>         interpolate() within RGB only. Should I use
>         java.awt.color.ICC_ColorSpace
>         (which lacks support for HSI, LCH and HCL) or is there a more
>         complete
>         library for Java or JavaFX?
>         Regards,
>         Benjamin

More information about the openjfx-dev mailing list