Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Color-LAB - RGB to HSB converting

 [1/3] from: oliva:david:seznam:cz at: 8-Nov-2001 19:39


Color-LAB - RGB to HSB converting ================================= Hi there, has anyone some script for RGB <-> HSB convertion or knows some link to the specification? I would like to use it in my unfinished Color-LAB script... viz: http://sweb.cz/r-mud/index.r Thanks Oldes

 [2/3] from: tomc::darkwing::uoregon::edu at: 8-Nov-2001 11:48


do a google on 'colorspace faq' see: http://www.inforamp.net/~poynton/Poynton-color.html or if someone does not get to it, I'll look into translating the algos given in Foley et.al On Thu, 8 Nov 2001 [oliva--david--seznam--cz] wrote:

 [3/3] from: tomc::darkwing::uoregon::edu at: 10-Nov-2001 1:03

Re: Color-LAB - RGB to HSB convertin


On Thu, 8 Nov 2001 [oliva--david--seznam--cz] wrote:
> Color-LAB - RGB to HSB converting > >
<<quoted lines omitted: 7>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
Hi Oldes, these are not perfect i.e. (t - hsv-rgb rgb-hsv t) is not always 0.0.0 but they might be of some service rgb-hsv: func [rgb [tuple!] {From "Computer Graphics Principles and Practice", Foley et.al. pg. 592, Fig. 13.33 tuplized by tomc} /local hsv hue d ][ hsv: 0.0.0 hsv/3: maximum maximum rgb/1 rgb/2 rgb/3 hsv/2: either zero? hsv/3 [0] [to-integer ((d: hsv/3 - (minimum minimum rgb/1 rgb/2 rgb/3)) / hsv/3 * 255)] either zero? hsv/2 [ hue: 0 d: 0.0.0.0 d/2: hsv/2 d/3: hsv/3 hsv: d] [ either hsv/3 = rgb/1 [ hue: rgb/2 - rgb/3 / d] [ either hsv/3 = rgb/2 [ hue: rgb/3 - rgb/1 / d + 2] [ hue: rgb/1 - rgb/2 / d + 4] ] hue: to-integer (hue * 128 / 3) if negative? hue [hue: hue + 255] ] hsv/1: hue hsv ; if tuple has fouth place hue is undefined ] hsv-rgb: func [hsv [tuple!] {From "Computer Graphics Principles and Practice", Foley et.al. pg. 593, Fig. 13.34, tuplized by tomc} /local rgb f p q t i s v ][ rgb: 0.0.0 either zero? hsv/2 [ either (length? hsv) > 3 [rgb/1: hsv/3 rgb/2: hsv/3 rgb/3: hsv/3] [ print "error"] ; do something beter here ][ hue: hsv/1 // 255 hue: hue * 3 / 128 i: to-integer hue f: hue - i s: hsv/2 / 255 v: hsv/3 / 255 p: to-integer (255 * (v * (1 - s))) q: to-integer (255 * (v * (1 - (s * f)))) t: to-integer (255 * (v * (1 - (s * (1 - f))))) switch i [ 0 [rgb/1: hsv/3 rgb/2: t rgb/3: p] 1 [rgb/1: q rgb/2: hsv/3 rgb/3: p] 2 [rgb/1: p rgb/2: hsv/3 rgb/3: t] 3 [rgb/1: p rgb/2: q rgb/3: hsv/3] 4 [rgb/1: t rgb/2: p rgb/3: hsv/3] 5 [rgb/1: hsv/3 rgb/2: p rgb/3: q] ] ] rgb ] usage example -- (my very first use view - go easy) hsv: 128.128.128 view layout [ b: box 128.128.128 255x64 t: text to-string hsv below across h: slider 255x16 128[ hsv: rgb-hsv to-tuple b/color hsv/1: to-integer (h/data * 255) b/color: hsv-rgb hsv t/text: to-string hsv ht/text: hsv/1 show b show t show ht ] ht: text "000" below across s: slider 255x16 128[ hsv: rgb-hsv to-tuple b/color hsv/2: to-integer (s/data * 255) b/color: hsv-rgb hsv t/text: to-string hsv st/text: to-string hsv/2 show b show t show st ] st: text "000" below across v: slider 255x16 128[ hsv: rgb-hsv to-tuple b/color hsv/3: to-integer (v/data * 255) b/color: hsv-rgb hsv t/text: to-string hsv vt/text: to-string hsv/3 show b show t show vt ] vt: text "000" ]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted