Forums > Jitter

HSL/RGB conversion

December 10, 2011 | 6:13 am

I’m looking to convert between HSL and RGB, 3 floats in the range 0.,1. This is going to be inside a patcher which I am going to have multiple copies of using [poly~], so I’d like to keep it as tight as possible.

I was a bit surprised that I couldn’t find a built-in object to do this, but it seems like I have a few options:

1. Implement using [expr] and consume via [bpatcher]. Optionally use a [swatch] to do HSL to RGB and get the saturation from RGB.

2. Implement in Javascript in a [js] object

3. Convert to a 1x1x3 matrix and use [jit.rgb2hsl] / [jit.hsl2rgb]

#1 seems easiest, but I have a feeling #3 is more efficient. #2 just seems like a bad idea, if there are going to be a few dozen copies of it. (I’m still on Max 5 and the old JS for now.)


December 11, 2011 | 10:23 pm

I’ve been using a Jasch object, hsv2rgb to do this. Works fine for me, but I came upon your post because I was looking to see if there’s a way to do it without the external. I was doing the conversion with swatch before, but it was slower – I presume because it has to update the swatch GUI interface.

December 12, 2011 | 10:59 pm

Thinking about this a bit over the last couple of days, I landed on moving this to a color manager object and taking the logic out of the poly~’ed object entirely (that one would only field (color $1 $2 $3 $4) as a property message and passes it on to its In the color manager I will probably use approach #3. I’ll post it when it’s done.

November 14, 2015 | 3:06 am

I know this thread is old – I remember seeing it back when I was looking for a solution. So for anyone searching for a list/float version of RGB to HSL and/or HSL to RGB, here are some patches I built. They may not be pretty, but they are accurate.

The only standard objects in Max that output accurate values for HSL are the Gen objects – even if they are erroneously referred to as "hue, saturation and luminance" conversions. They are lightness, not luminance, but they are precise.

The Jitter objects [jit.hsl2rgb] and [jit.rgb2hsl] use char data (0-255) to handle degrees (0-360).. resulting in less than precise output. iirc, the same is true for [jit.colorspace]. If you need accurate Jitter, gen or gl.gen versions, let me know.

— Pasted Max Patch, click to expand. —
November 14, 2015 | 12:38 pm

I’ve also written shaders that translate from RBG->HSL and HSL->RGB, as well as many other colorspaces. You can download them here:

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > Jitter