RGB and LAB color spaces: Conversion and interpolation

Benjamin Gudehus hastebrot at gmail.com
Wed Sep 30 09:04:42 UTC 2015


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> 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