<?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_spaces</id>
		<title>Color spaces - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=Color_spaces"/>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_spaces&amp;action=history"/>
		<updated>2026-05-12T22:41:04Z</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_spaces&amp;diff=5057&amp;oldid=prev</id>
		<title>Reel.Deal: /* RGB colorspace */  grammar</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_spaces&amp;diff=5057&amp;oldid=prev"/>
				<updated>2014-12-15T20:49:07Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;RGB colorspace: &lt;/span&gt;  grammar&lt;/span&gt;&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 20:49, 15 December 2014&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&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;Both of them contain three components, R,G and B - short for Red, Green and Blue.&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;Both of them contain three components, R,G and B - short for Red, Green and Blue.&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;/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;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;RGB24 and RGB32 are both &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;an &lt;/del&gt;[[&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Interleaved|&lt;/del&gt;interleaved]] image &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;format&lt;/del&gt;. The only difference between the two &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;are &lt;/del&gt;that RGB32 contains an extra byte for each pixel.&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;RGB24 and RGB32 are both [[interleaved]] image &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;formats&lt;/ins&gt;. The only difference between the two &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;is &lt;/ins&gt;that RGB32 contains an extra byte for each pixel.&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;/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;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The extra byte RGB32 contains is known as an alpha pixel, but it is actually quite seldom used. The reason RGB32 is considered the &amp;quot;best&amp;quot; format is purely from a programmers view. Handling RGB32 material is much easier than RGB24 &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;material&lt;/del&gt;, because most processors operate on 32bits at &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;the &lt;/del&gt;time, and not 24.&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;The extra byte RGB32 contains is known as an alpha pixel, but it is actually quite seldom used. The reason RGB32 is considered the &amp;quot;best&amp;quot; format is purely from a programmers &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;point of &lt;/ins&gt;view. Handling RGB32 material is much easier than RGB24, because most processors operate on 32bits at &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;a &lt;/ins&gt;time, and not 24.&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;/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;== YUV colorspace ==&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;== YUV colorspace ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Reel.Deal</name></author>	</entry>

	<entry>
		<id>http://avisynth.nl/index.php?title=Color_spaces&amp;diff=774&amp;oldid=prev</id>
		<title>Admin: 1 revision</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_spaces&amp;diff=774&amp;oldid=prev"/>
				<updated>2013-05-09T21:33:53Z</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:33, 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_spaces&amp;diff=773&amp;oldid=prev</id>
		<title>Wilbert: Reverted edits by 66.128.38.34 (Talk); changed back to last version by Gzarkadas</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=Color_spaces&amp;diff=773&amp;oldid=prev"/>
				<updated>2007-07-14T22:07:10Z</updated>
		
		<summary type="html">&lt;p&gt;Reverted edits by &lt;a href=&quot;/index.php/Special:Contributions/66.128.38.34&quot; title=&quot;Special:Contributions/66.128.38.34&quot;&gt;66.128.38.34&lt;/a&gt; (&lt;a href=&quot;/index.php?title=User_talk:66.128.38.34&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User talk:66.128.38.34 (page does not exist)&quot;&gt;Talk&lt;/a&gt;); changed back to last version by &lt;a href=&quot;/index.php?title=User:Gzarkadas&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;User:Gzarkadas (page does not exist)&quot;&gt;Gzarkadas&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== RGB and YUV colorspaces ==&lt;br /&gt;
&lt;br /&gt;
[[RGB]] and [[YUV]] are two different ways to represent colors. &lt;br /&gt;
&lt;br /&gt;
In YUV colorspace there is one component that represent lightness (luma) and two other components that represent color (chroma). As long as the luma is conveyed with full detail, detail in the chroma components can be reduced by subsampling (filtering, or averaging) which can be done in several ways (thus there are multiple formats for storing a picture in YUV colorspace). &lt;br /&gt;
&lt;br /&gt;
In RGB colorspace there are three components, one for the amount of Red, one for the amount of Green and one for the amount of Blue. Also in this colorspace there are multiple formats for storing a picture which differ in the amount of samples are used for one of the three colors.&lt;br /&gt;
&lt;br /&gt;
== RGB colorspace ==&lt;br /&gt;
&lt;br /&gt;
There are several RGB formats, but the two most widely used are known as [[RGB24]] and [[RGB32]].&lt;br /&gt;
Both of them contain three components, R,G and B - short for Red, Green and Blue.&lt;br /&gt;
&lt;br /&gt;
RGB24 and RGB32 are both an [[Interleaved|interleaved]] image format. The only difference between the two are that RGB32 contains an extra byte for each pixel.&lt;br /&gt;
&lt;br /&gt;
The extra byte RGB32 contains is known as an alpha pixel, but it is actually quite seldom used. The reason RGB32 is considered the &amp;quot;best&amp;quot; format is purely from a programmers view. Handling RGB32 material is much easier than RGB24 material, because most processors operate on 32bits at the time, and not 24.&lt;br /&gt;
&lt;br /&gt;
== YUV colorspace ==&lt;br /&gt;
&lt;br /&gt;
There are several YUV formats. There are [[Interleaved|interleaved]] formats and [[Planar|planar]] formats (also called packed formats). The main difference is how they are stored in memory.&lt;br /&gt;
&lt;br /&gt;
Interleaved images have all color components needed to represent a pixel placed at the same place in memory. For planar formats the data is not interleaved, but stored separately for each color channel (also called color plane). &lt;br /&gt;
&lt;br /&gt;
For filter writers this means that they can write one simple function that is called three times, one for each color channel, assuming that the operations are channel-independent (which is not always the case). Again, using aligned for both color and luma channels will allow easy memory access. The use of a planar format gives in most cases a significant speedup, since all bytes of each plane can be treated the same way. It can also give a speedup because your filter doesn't have to work on all planes, if it only modifies one or two of them.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=== YUY2 colorformat ===&lt;br /&gt;
&lt;br /&gt;
[[YUY2]] is an [[Interleaved|interleaved]] image format. Bytes are arranged in memory like this:&lt;br /&gt;
&lt;br /&gt;
 YUYV|YUYV|YUYV|YUYV|YUYV|YUYV|...&lt;br /&gt;
 ^first byte in a row.&lt;br /&gt;
&lt;br /&gt;
So each pixel horizontally shares UV (chroma) information with a neighboring pixel.&lt;br /&gt;
&lt;br /&gt;
=== YV12 colorformat ===&lt;br /&gt;
&lt;br /&gt;
The [[YV12]] colorformat is very different from RGB and YUY2 colorformats. The main difference is that it is a [[Planar|planar]] image format.&lt;br /&gt;
&lt;br /&gt;
All images are given a [[Pitch|pitch]]. The pitch is basically what can be described as &amp;quot;length of a line&amp;quot;. What's funny is that the pitch does not have to be equal to the width of the image.&lt;br /&gt;
For instance, if you crop something off your image, the only thing that changes is the width of your image; the pitch and the actual byte-count of a line remains the same.&lt;br /&gt;
&lt;br /&gt;
The image is then laid out like this:&lt;br /&gt;
&lt;br /&gt;
 rrrrrrrrrrrrrrrrpppp&lt;br /&gt;
 rrrrrrrrrrrrrrrrpppp&lt;br /&gt;
 rrrrrrrrrrrrrrrrpppp&lt;br /&gt;
&lt;br /&gt;
Where 'r' are the pixels inside the image used, and 'p' is the padding inserted after each line.&lt;br /&gt;
In YV12 the Y-plane always has a byte-count that is a multiple of 16, but it is still possible to have mod2 width images, because the rowsize is different from the pitch. Similar the UV-planes always have a pitch that is a multiple of 8.&lt;br /&gt;
&lt;br /&gt;
When you request frame-&amp;gt;GetRowSize(PLANAR_Y) you will get the rowsize of the pixels '''inside''' the image. When you request frame-&amp;gt;GetRowSize(PLANAR_Y_ALIGNED) you will ALWAYS get a rowsize that is a multiple of 16 (multiple of 8 on UV planes).&lt;br /&gt;
&lt;br /&gt;
The reason for you to use pitch to get from one line to another is that pitch can be even larger than the aligned rowsize - for instance after a crop.&lt;br /&gt;
&lt;br /&gt;
So what you should do is:&lt;br /&gt;
* Get a rowsize.&lt;br /&gt;
* For each line in the image:&lt;br /&gt;
* Process (aligned) rowsize pixels.&lt;br /&gt;
* Skip to next line, by adding pitch for the current plane. &lt;br /&gt;
&lt;br /&gt;
==== YV12 interlacing ====&lt;br /&gt;
&lt;br /&gt;
YV12 handles interlaced chroma differently than compared to YUY2, since YV12 only contains chroma information for every second line. &lt;br /&gt;
&lt;br /&gt;
To enable interlacing, chroma is stretched across two luma lines in the same field!  That means that luma and chroma aren't directly mappable to lumaline/2 and lumaline/2+1 as with frame based images.&lt;br /&gt;
&lt;br /&gt;
: line 0: Chroma for interlaced luma lines 0+2&lt;br /&gt;
: line 1: Chroma for interlaced luma lines 1+3&lt;br /&gt;
: line 2: Chroma for interlaced luma lines 4+6&lt;br /&gt;
: line 3: Chroma for interlaced luma lines 5+7&lt;br /&gt;
: ...etc!&lt;br /&gt;
&lt;br /&gt;
When viewing the individual lines in each plane this maps to:&lt;br /&gt;
&lt;br /&gt;
Consider the separate planes:&lt;br /&gt;
&lt;br /&gt;
Luma:&lt;br /&gt;
&lt;br /&gt;
 L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1L1&lt;br /&gt;
 L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2L2&lt;br /&gt;
 L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3L3&lt;br /&gt;
 L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4L4&lt;br /&gt;
&lt;br /&gt;
Chroma that maps to luma plane above:&lt;br /&gt;
&lt;br /&gt;
 C1C1C1C1C1C1C1C1C1C1C1&lt;br /&gt;
 C2C2C2C2C2C2C2C2C2C2C2&lt;br /&gt;
&lt;br /&gt;
Since luma L1 and L3 are in the same field, the chroma information in C1 is used for these lines and NOT line L1 + L2 as when the image is frame-based. C2 is used for lines 2+4 and so on.&lt;br /&gt;
&lt;br /&gt;
This is something that deinterlacers and similar programs need to take into consideration. Other filters might rely on the use of [[SeparateFields]]() and [[Weave]](), to produce framebased images. You can use the VideoInfo.IsFieldBased() to check your source, and maybe decide to throw an error, or shift to another processing mode.&lt;br /&gt;
&lt;br /&gt;
If your video is fieldbased your vertical resolution (height) must be divisible by 4, otherwise AviSynth will not create a new VideoFrame, but will throw an error.&lt;br /&gt;
&lt;br /&gt;
=== Links ===&lt;br /&gt;
&lt;br /&gt;
See more about [[Filter_SDK/Data_storage|Data storage]] in AviSynth.&lt;br /&gt;
&lt;br /&gt;
See a  general introduction to [[Filter_SDK/Working_with_images|Working with images]].&lt;br /&gt;
&lt;br /&gt;
[[Category:FilterSDK]]&lt;/div&gt;</summary>
		<author><name>Wilbert</name></author>	</entry>

	</feed>