Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Clipper Visual-Objects > Re: Colorconver...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 8 Topic 11303 of 11795
Post > Topic >>

Re: Colorconversion RGB->HSL ->RGB

by johan.nel@[EMAIL PROTECTED] Apr 10, 2008 at 09:52 AM

Hi Paul,

I hacked this from somewhere I cannot remember so not sure it work but
you can try, sorry for no indentation:
FUNCTION RGB2HSV(nR, nG, nB) AS ARRAY
LOCAL nDelta, nMin, nV, nS, nH AS REAL8
LOCAL aHSV AS ARRAY
nMin := Min(nR, Min(nG, nB))
nV := Max(nR, Max(nG, nB))
nDelta := nV - nMin
BEGIN SEQUENCE
IF nV = 0.0
nS := 0.0
ELSE
nS := nDelta / nV
ENDIF
IF nS = 0.0
aHSV := {NIL, nS, nV}
BREAK // nH undefined
ELSEIF nR = nV
nH := 60.0 * (nG - nB) / nDelta
ELSEIF nG = nV
nH := 120.0 + 60.0 * (nB - nR) / nDelta
ELSEIF nB = nV
nH := 240.0 + 60.0 * (nR - nG) / nDelta
ENDIF
IF nH < 0.0
nH := nH + 360.0
ENDIF
aHSV := {nH, nS, nV}
END SEQUENCE
RETURN aHSV

FUNCTION HSV2RGB(nH, nS, nV) AS ARRAY
LOCAL nF, nHTemp, nP, nQ, nT, nR, nG, nB AS REAL8
LOCAL aRGB AS ARRAY
LOCAL nI AS INT
BEGIN SEQUENCE
IF nS = 0.0
IF nH = NIL
nR := nV
nG := nV
nB := nV
ELSE
aRGB := {NIL, NIL, NIL}
BREAK
ENDIF
ELSE
IF nH = 360.0
nHTemp := 0.0
ELSE
nHTemp := nH
ENDIF
nHTemp := nHTemp / 60
nI := Floor(nHTemp)
nF := nHTemp - nI
nP := nV * (1.0 - nS)
nQ := nV * (1.0 - (nS * nF))
nT := nV * (1.0 - (nS * (1.0 - nF)))
DO CASE
CASE nI = 0
nR := nV; nG := nT; nB := nP
CASE nI = 1
nR := nQ; nG := nV; nB := nP
CASE nI = 2
nR := nP; nG := nV; nB := nT
CASE nI = 3
nR := nP; nG := nQ; nB := nV
CASE nI = 4
nR := nT; nG := nP; nB := nV
CASE nI = 5
nR := nV; nG := nP; nB := nQ
ENDCASE
ENDIF
aRGB := {nR, nG, nB}
END SEQUENCE
RETURN aRGB

HTH,

Johan Nel
Pretoria, South Africa.
 




 8 Posts in Topic:
Colorconversion RGB->HSL ->RGB
"Paul D B" <  2008-04-10 16:33:54 
Re: Colorconversion RGB->HSL ->RGB
"Norbert Kolb"   2008-04-10 18:34:24 
Re: Colorconversion RGB->HSL ->RGB
"Paul D B" <  2008-04-14 10:18:51 
Re: Colorconversion RGB->HSL ->RGB
"Norbert Kolb"   2008-04-14 12:41:36 
Re: Colorconversion RGB->HSL ->RGB
"Paul D B" <  2008-04-14 13:05:01 
Re: Colorconversion RGB->HSL ->RGB
"Norbert Kolb"   2008-04-14 14:20:05 
Re: Colorconversion RGB->HSL ->RGB
johan.nel@[EMAIL PROTECTE  2008-04-10 09:52:28 
Re: Colorconversion RGB->HSL ->RGB
"Paul D B" <  2008-04-14 10:36:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 6:18:19 CST 2008.