YIQ2RGB

Blitz3D Forums/Blitz3D Programming/YIQ2RGB

_33(Posted 2007) [#1]
Hello,

I'm trying to make an YIQ2RGB function, but I have no clue how it works. I've read some simple docs about what is YIQ, got some C++ code examples. But I don't know how to use the function. A while back I posted on the general forum for a color palette. But finally I came to the conclusion that it was impossible to properly emulate the color palette since the colors were based on an YIQ system. Thus, I would need to calculate an YIQ palette which would in turn be translated in RGB. So I coded the YIQ2RGB.

Firstly, I wish to know if my YIQ2RGB function is good. Second, I'd like for someone to explain to me how to properly use it to get the needed colors.

;YIQ
;A bandwidth optimized, matrixed, composite video <glossary_c.html> signal format used by NTSC <glossary_n.html>
;video systems employing separate luminance <glossary_l.html> And two derived blue And red chroma <glossary_c.html>
;components derived from the YUV <glossary_y.html> format. 
;The modulated carriers (U) And (V) (phased 90 degrees apart) are what carry the Color information in an NTSC-encoded
;composite Color picture. This is called “quadrature”. We call the modulated carriers “I” And “Q” in NTSC ("In phase"
;And "Quadrature phase"). I And Q are bandwidth-limited differently so they’ll fit into the NTSC transmission spectrum. 
;The human visual system has less spatial acuity For magenta-green transitions than it does For red-cyan. Thus,
;If signals I And Q are formed from a 123 degree rotation of U And V respectively, the “Q” signal can be more severely
;filtered than “I” without being perceptible To a viewer at typical TV viewing distance. YIQ is equivalent To YUV with
;a 33 degree rotation And an axis Flip in the UV plane. The First edition of W.K. Pratt “Digital Image Processing”,
;And presumably other authors that follow that bible, has a matrix that erroneously omits the axis Flip; the second
;edition corrects the error. 
;Since an analog NTSC decoder has no way of knowing whether the encoder was encoding YUV Or YIQ, it cannot detect
;whether the encoder was running at 0 degree Or 33 degree phase. In analog usage the terms YUV And YIQ are often used
;somewhat interchangeably. YIQ was important in the early days of NTSC but most broadcasting equipment now encodes
;equiband U And V. 
;The D-2 composite digital DVTR (And the associated interface standard) conveys NTSC modulated on the YIQ axes in
;the 525-Line version And PAL modulated on the YUV axes in the 625-Line version.
Function yiq_rgb(y#,i#,q#)
;Y = range [0.,1.]
;I = range [-.6,.6]
;Q = range [-.52,.52]
   red% = ((1.00309 * y) + (0.95485 * i) + (0.61786 * q)) * 255
   green% = ((0.99678 * y) + (-0.27071 * i) + (-0.64479 * q)) * 255
   blue% = ((1.00850 * y) + (-1.11049 * i) + (1.69957 * q)) * 255
   If red < 0   Then red = 0 ElseIf red > 255 Then red = 255
   If green < 0   Then green = 0 ElseIf green > 255 Then green = 255
   If blue < 0   Then blue = 0 ElseIf blue > 255 Then blue = 255
   Return ((red And $FF) Shl 16) Or ((green And $FF) Shl 8) Or (blue And $FF)
End Function


Related topic: http://www.atariage.com/forums/index.php?showtopic=107853&st=0#entry1306393


_33(Posted 2007) [#2]
I think I found proper use:

Function yiq_rgb(y#,i#,q#, r#, g#, b#)
;Y = range [0.,1.] (luminance)
;I = range [-0.5957161349127745527,0.5957161349127745527] (red/green)
;Q = range [-0.5225910452916111684,0.5225910452916111684] (blue/yellow)
   red%   = (y + (0.956294832320893995 * i) + (0.621025125444728741 * q)) * r
   green% = (y - (0.2721214740839773195 * i) - (0.6473809535176157223 * q)) * g
   blue%  = (y - (1.106989908567128216 * i) + (1.704614975498829329 * q)) * b
   If red < 0   Then red = 0 ElseIf red > 255 Then red = 255
   If green < 0   Then green = 0 ElseIf green > 255 Then green = 255
   If blue < 0   Then blue = 0 ElseIf blue > 255 Then blue = 255
   Return ((red And $FF) Shl 16) Or ((green And $FF) Shl 8) Or (blue And $FF)
End Function



rendomizer(Posted 2015) [#3]
how do it use ? i'm verry interest


steve_ancell(Posted 2015) [#4]
_33:
I'm trying to make an YIQ2RGB function, but I have no clue how it works


Never mind how it works, I don't even know what YIQ2RGB is!


stayne(Posted 2015) [#5]
Looks old school big time


steve_ancell(Posted 2015) [#6]
To set the record straight I can see that it means "YIQ to Red Green Blue", what I don't understand is the "YIQ" part.