|
openlayer HLS colourspace |
fuzinavl
Member #4,105
December 2003
|
openlayer feature request: Hlsa( float hue, float lightness, float saturation, float alpha = 1.0) { //returns an Rgba object or 32-bit packed pixel ??? //therefore can be used anywhere Rgba(,,,) is used. :) }
__________________________ |
Krzysztof Kluczek
Member #4,191
January 2004
|
hsv_to_rgb ________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Well, just give me the equations and I'll implement it That might be useful, but it requires a named constructor as the parameter types are the same as with the RGBA constructor. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Thomas Harte
Member #33
April 2000
|
Quote: Well, just give me the equations and I'll implement it Here you go: http://www.easyrgb.com/math.php I haven't read that page at all, but from memory all the ordinary colour conversions are just linear transforms so you could abstract it with a 3x3 matrix for every colour space conversion. Unless you want also to provide support for both linear and exponential scales, but that doesn't seem to be part of the request! EDIT: completely off topic, but while you're here and because I've just been messing around on an OpenGL thingy myself - does OpenLayer prefer GL_ARB_texture_non_power_of_two to GL_ARB/EXT/NV_texture_rectangle where both are available? [My site] [Tetrominoes] |
Krzysztof Kluczek
Member #4,191
January 2004
|
Quote: I haven't read that page at all, but from memory all the ordinary colour conversions are just linear transforms so you could abstract it with a 3x3 matrix for every colour space conversion. This is not the case for HSV and HSL, as H is in fact an angle (0 is red, 0.33 is green, 0.67 is blue and 1 is red again). ________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: does OpenLayer prefer GL_ARB_texture_non_power_of_two to GL_ARB/EXT/NV_texture_rectangle where both are available? Well, OpenLayer doesn't support the *_texture_rectangle extensions yet. But since the GL_ARB_texture_non_power_of_two extension doesn't require using an another texture target it sounds better... especially as no code has to be changed in order to support it. Performance wise I don't know. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Andrei Ellman
Member #3,434
April 2003
|
Here is an implementation of RGB <-> HLS colourspace conversion code. This particular implementation uses the same scale of units as Allegro's RGB <-> HSV functions. This is to maintain consistency with Allegro's functions, but this could be speeded up by making it accept a hue in the range 0..6 instead of 0..360 hls_to_rgb:
rgb_to_hls:
If you want to convert a float value from 0..1 to an int value from 0..0xff, then use the following macro #define ap01FTO0255INT(fl) ((int)(fl * 255.0f + 0.5f))
For converting a foat value from 0..360 to an int value from 0..0x600, use this: #define ap0360FTO01536INT(fl) ((int)(fl * 1536.0f / 360.0f + 0.5f)) /* 0x600 = 1536 */
Note that because Hue is a cyclic paramater, the range of conversion is 0..0x600 rather than 0..0x5FF . However, due to the nature of the input values (the nature being that they are only 8-bit RGB values), no likely set of inputs to rgb_to_hls() (or for that matter, rgb_to_hsv()) is going to yield a value greater than 0x5FF. The hue wheel is divided into six segments, and each segment can produce 256 discrete values with 8-bit RGB colour. This means that ((256*6)-1) / (256*6) * 360 = 359.765625 (which is the maximum value of H that the function can yield for 8-bit RGB values), and plugging in 359.765625 to the macro above gives 1535.5, which when converted to a hexadecimal int, is rounded down to 0x5FF I have implemented much faster versions of RGB <-> HLS and RGB <-> HSV, that takes the saturation and value as chars, and the hue as a short (no floats for the paramaters, but it still uses floats internally). This code can be found in the sourcecode of my ChromaPlas screensaver which also demonstrates a nice effect and shows the difference between HSV and HLS. For further reading, see: AE. -- |
fuzinavl
Member #4,105
December 2003
|
Woah there! int Hsva( float hue, float saturation, float value, float alpha = 1.0) { int r,g,b = 0; hsv_to_rgb(hue, saturation, value, &r, &g, &b); return Rgba( r, g, b, int(alpha) * 255.0); //I'm rusty with c++! Does this return an int? } int Hlsa( float hue, float lightness, float saturation, float alpha = 1.0) { return Hsva( hue, saturation, lightness * 0.5f, alpha); //wrong wrong wrong wrong wrong! }
__________________________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: //I'm rusty with c++! Does this return an int? It's a constructor call which creates a new Rgba object. So the return value should be Rgba. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
fuzinavl
Member #4,105
December 2003
|
yay
works! __________________________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: int(alpha) * 255 I guess you mean: int(alpha * 255) Or otherwise the alpha would be rounded either to one or zero. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
fuzinavl
Member #4,105
December 2003
|
Thanks all! __________________________ |
|