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
|