<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://avisynth.nl/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=Color_conversions</id>
		<title>Color conversions - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=Color_conversions"/>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_conversions&amp;action=history"/>
		<updated>2026-04-15T23:47:02Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.24</generator>

	<entry>
		<id>http://avisynth.nl/index.php?title=Color_conversions&amp;diff=13315&amp;oldid=prev</id>
		<title>73.73.126.68: Corrected spelling of Poynton</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_conversions&amp;diff=13315&amp;oldid=prev"/>
				<updated>2024-01-26T14:15:32Z</updated>
		
		<summary type="html">&lt;p&gt;Corrected spelling of Poynton&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:15, 26 January 2024&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 115:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 115:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== References: ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== References: ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html ColorFAQ &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Poyton&lt;/del&gt;] &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html ColorFAQ &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Poynton&lt;/ins&gt;] &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;ITU BT.601 ... &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;ITU BT.601 ... &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;ITU BT.709 ... &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;ITU BT.709 ... &amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>73.73.126.68</name></author>	</entry>

	<entry>
		<id>http://avisynth.nl/index.php?title=Color_conversions&amp;diff=982&amp;oldid=prev</id>
		<title>Admin: 1 revision</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_conversions&amp;diff=982&amp;oldid=prev"/>
				<updated>2013-05-09T21:49:07Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;tr valign='top'&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='1' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 21:49, 9 May 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://avisynth.nl/index.php?title=Color_conversions&amp;diff=981&amp;oldid=prev</id>
		<title>Wilbert at 21:42, 9 May 2013</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_conversions&amp;diff=981&amp;oldid=prev"/>
				<updated>2013-05-09T21:42:04Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Work under construction. to do: http://forum.doom9.org/showthread.php?p=1084293#post1084293&lt;br /&gt;
&lt;br /&gt;
Should cover RGB-&amp;gt;YUV conversions and lumarange scaling/preservation and when to use which conversion (latter in a different page).&lt;br /&gt;
&lt;br /&gt;
YUV ranges for valid RGB ranges: http://forum.doom9.org/showthread.php?t=154731&lt;br /&gt;
&lt;br /&gt;
blabla ...&lt;br /&gt;
&lt;br /&gt;
=== Color coefficients ===&lt;br /&gt;
&lt;br /&gt;
The most common coefficient and the conversions are given below:&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;height:100px&amp;quot; border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;4&amp;quot;&lt;br /&gt;
!width=55%| coefficients&lt;br /&gt;
!width=15%| Rec.601&lt;br /&gt;
!width=15%| Rec.709&lt;br /&gt;
!width=15%| FCC&lt;br /&gt;
|- &lt;br /&gt;
| Kr : Red channel coefficient&lt;br /&gt;
| 0.299&lt;br /&gt;
| 0.2126&lt;br /&gt;
| 0.3&lt;br /&gt;
|- &lt;br /&gt;
| Kg : Green channel coefficient&lt;br /&gt;
| 0.587&lt;br /&gt;
| 0.7152&lt;br /&gt;
| 0.59&lt;br /&gt;
|- &lt;br /&gt;
| Kb : Blue channel coefficient&lt;br /&gt;
| 0.114&lt;br /&gt;
| 0.0722&lt;br /&gt;
| 0.11&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The RGB &amp;lt;-&amp;gt; YUV conversion is given by:&lt;br /&gt;
&lt;br /&gt;
 Y = Kr*R + Kg*G + Kb*B&lt;br /&gt;
 V = (R-Y)/(1-Kr) = R - G * Kg/(1-Kr) - B * Kb/(1-Kr)&lt;br /&gt;
 U = (B-Y)/(1-Kb) = - R * Kr/(1-Kb) - G * Kg/(1-Kb) + B&lt;br /&gt;
 &lt;br /&gt;
 R = Y + V*(1-Kr)&lt;br /&gt;
 G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg&lt;br /&gt;
 B = Y + U*(1-Kb)&lt;br /&gt;
&lt;br /&gt;
with (0.0 &amp;lt;= [Y,R,G,B] &amp;lt;= 1.0) ; (-1.0 &amp;lt;= [U,V] &amp;lt;= 1.0) and  Kr + Kg + Kb = 1.&lt;br /&gt;
&lt;br /&gt;
=== Converting to programming values ===&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;height:100px&amp;quot; border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;4&amp;quot;&lt;br /&gt;
!width=25%| color format&lt;br /&gt;
!width=25%| channel 1&lt;br /&gt;
!width=25%| channel 2&lt;br /&gt;
!width=25%| channel 3&lt;br /&gt;
|-&lt;br /&gt;
| '''yuv [0,255]'''&lt;br /&gt;
| y = Y * 255&lt;br /&gt;
| v = V * 127.5 + 128&lt;br /&gt;
| u = U * 127.5 + 128&lt;br /&gt;
|-&lt;br /&gt;
| '''yuv [16,235]'''&lt;br /&gt;
| y = Y * 219 +  16&lt;br /&gt;
| v = V * 112 + 128&lt;br /&gt;
| u = U * 112 + 128&lt;br /&gt;
|-&lt;br /&gt;
| '''rgb [0,255]'''&lt;br /&gt;
| r = R * 255&lt;br /&gt;
| g = G * 255&lt;br /&gt;
| b = B * 255&lt;br /&gt;
|-&lt;br /&gt;
| '''rgb [16,235]'''&lt;br /&gt;
| r = R * 219 + 16&lt;br /&gt;
| g = G * 219 + 16&lt;br /&gt;
| b = B * 219 + 16&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The following two conversions are implemented in AviSynth:&lt;br /&gt;
&lt;br /&gt;
'''yuv [0,255] &amp;lt;-&amp;gt; rgb [0,255]''' (0 &amp;lt;= [r,g,b] &amp;lt;= 255, 0 &amp;lt;= y &amp;lt;= 255, 0 &amp;lt;= [u,v] &amp;lt;= 255)&lt;br /&gt;
&lt;br /&gt;
Substituting (Y,V,U,R,G,B) in the equations above and multiplying with 127.5 and respectively 255 gives&lt;br /&gt;
&lt;br /&gt;
 y = Kr*r + Kg*g + Kb*b &amp;lt;br&amp;gt;&lt;br /&gt;
 v - 128 = 0.5*(r-y)/(1-Kr) = 0.5 * r - 0.5 * g * Kg/(1-Kr) - 0.5 * b * Kb/(1-Kr) &amp;lt;br&amp;gt;&lt;br /&gt;
 u - 128 = 0.5*(b-y)/(1-Kb) = - 0.5 * r * Kr/(1-Kb) - 0.5 * g * Kg/(1-Kb) + 0.5 * b &amp;lt;br&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 r = y + 2*(v-128)*(1-Kr) &amp;lt;br&amp;gt;&lt;br /&gt;
 g = y - 2*(u-128)*(1-Kb)*Kb/Kg - 2*(v-128)*(1-Kr)*Kr/Kg &amp;lt;br&amp;gt;&lt;br /&gt;
 b = y + 2*(u-128)*(1-Kb) &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''yuv [16,235] &amp;lt;-&amp;gt; rgb [0,255]''' (0 &amp;lt;= [r,g,b] &amp;lt;= 255, 16 &amp;lt;= y &amp;lt;= 235, 16 &amp;lt;= [u,v] &amp;lt;= 240)&lt;br /&gt;
&lt;br /&gt;
Substituting (Y,V,U,R,G,B) in the equations above gives&lt;br /&gt;
&lt;br /&gt;
 y - 16 = (Kr*219/255)*r + (Kg*219/255)*g + (Kb*219/255)*b &lt;br /&gt;
 v - 128 = 112/255*r - Kg*112/255*g/(1-Kr) - Kb*112/255*b/(1-Kr) &lt;br /&gt;
 u - 128 = - Kr*112/255*r/(1-Kb) - Kg*112/255*g/(1-Kb) + 112/255*b &lt;br /&gt;
 &lt;br /&gt;
 r = (255/219)*y + (255/112)*v*(1-Kr) - (255*16/219 + 255*128/112*(1-Kr)) &lt;br /&gt;
 g = (255/219)*y - (255/112)*u*(1-Kb)*Kb/Kg - (255/112)*v*(1-Kr)*Kr/Kg&lt;br /&gt;
     - (255*16/219 - 255/112*128*(1-Kb)*Kb/Kg - 255/112*128*(1-Kr)*Kr/Kg) &lt;br /&gt;
 b = (255/219)*y + (255/112)*u*(1-Kb) - (255*16/219 + 255*128/112*(1-Kb))&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
As an example, the colors black, white and yellow will be computed in various color formats:&lt;br /&gt;
&lt;br /&gt;
In RGB [0,255] black is given by r=0, g=0, b=0. It follows that R=0, G=0, B=0. Calculating the Y, V and U values using the Rec.601 coefficients gives: Y=0, V=0 and U=0. In YUV [16,235] this corresponds to y=16, v=128, u=128.&lt;br /&gt;
&lt;br /&gt;
In RGB [0,255] white is given by r=255, g=255, b=255. It follows that R=1, G=1, B=1. Calculating the Y, V and U values using the Rec.601 coefficients gives: Y=1, V=0 and U=0. In YUV [16,235] this corresponds to y=235, v=128, u=128.&lt;br /&gt;
&lt;br /&gt;
In RGB [0,255] yellow is given by r=255, g=255, b=0. It follows that R=1, G=1, B=0. Calculating the Y, V and U values using the Rec.601 coefficients gives: Y = Kr*R + Kg*G + Kb*B = 0.299*1 + 0.587*1 + 0.114*0 = 0.886, V = (R-Y)/(1-Kr) = (1-0.886)/(1-0.299) = 0.1626 and U = (B-Y)/(1-Kb) = (0-0.886)/(1-0.114) = -1.000. In YUV [16,235] this corresponds to y=210, v=146, u=16. In YUV [0,255] this corresponds to y=226, v=149, u=0.&lt;br /&gt;
&lt;br /&gt;
For other examples, see [[ColorBars theory]].&lt;br /&gt;
&lt;br /&gt;
== References: ==&lt;br /&gt;
[http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html ColorFAQ Poyton] &amp;lt;br&amp;gt;&lt;br /&gt;
ITU BT.601 ... &amp;lt;br&amp;gt;&lt;br /&gt;
ITU BT.709 ... &amp;lt;br&amp;gt;&lt;br /&gt;
ITU BT.1700 ...&lt;br /&gt;
&lt;br /&gt;
[http://www.itu.int/rec/R-REC-BT/e All ITU-R Recommendations]&lt;br /&gt;
&lt;br /&gt;
[[Category:Advanced topics]]&lt;/div&gt;</summary>
		<author><name>Wilbert</name></author>	</entry>

	</feed>