<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.avisynth.nl/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ianb</id>
	<title>Avisynth wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.avisynth.nl/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ianb"/>
	<link rel="alternate" type="text/html" href="http://www.avisynth.nl/index.php/Special:Contributions/Ianb"/>
	<updated>2026-08-04T23:47:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>http://www.avisynth.nl/index.php?title=Filter_SDK/Data_storage&amp;diff=831</id>
		<title>Filter SDK/Data storage</title>
		<link rel="alternate" type="text/html" href="http://www.avisynth.nl/index.php?title=Filter_SDK/Data_storage&amp;diff=831"/>
		<updated>2013-05-07T02:40:33Z</updated>

		<summary type="html">&lt;p&gt;Ianb: /* Part 2: How does this affect me as a user? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is an edited summary of [http://forum.doom9.org/showthread.php?s=&amp;amp;threadid=40413&amp;amp;highlight=YV12 this thread at Doom9&#039;s forum]&lt;br /&gt;
&lt;br /&gt;
== Part 1: Actual memory storage ==&lt;br /&gt;
&#039;&#039;&#039;&#039;&#039;Warning:&#039;&#039;&#039; technical.&#039;&#039; Most users will only need to read (and understand) Part 2.&lt;br /&gt;
&lt;br /&gt;
In AviSynth, we process pixels of video data.  These are stored in the memory in the form of data arrays. As noted elsewhere (like the [[AviSynth_FAQ|AviSynth FAQ]]) there are two different colorformats in v1.0x/2.0x, [[RGB]] and [[YUY2]], with a third [[YV12]] added in v2.5. In v2.6 the follows colorformats are added: Y8, YV411, YV16 and YV24. These [[Color_spaces|color spaces]] store their data in different ways.&lt;br /&gt;
&lt;br /&gt;
=== Interleaved formats ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;RGB&#039;&#039;&#039; (also known as [[RGB24]]): Every pixel is associated with three bytes of data: one red, one green, and one blue. They are interleaved (mixed) in the memory like this:&lt;br /&gt;
&lt;br /&gt;
 RGB|RGB|RGB|RGB&lt;br /&gt;
&lt;br /&gt;
Since data is most easily read in words of four bytes, most functions actually process 4 pixels at the same time in order to be able to read 3 words in a row. Usually memory is allocated as &#039;&#039;aligned&#039;&#039; which means that it always allocate memory in words of 4 bytes. Since the 3 to 4 relation isn&#039;t easy to map, RGB24 is very difficult to work with, and in general isn&#039;t recommended. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;RGBA&#039;&#039;&#039; (also known as [[RGB32]]): This is an extension of RGB where a fourth color channel has been added. This is called the alpha channel, and is a definition of transparency in the pixel. &lt;br /&gt;
&lt;br /&gt;
For an explanation of how the alpha channel is used see [[Layer|Mask]] and [[Layer]]. In general however, you shouldn&#039;t rely on filters processing alpha correctly - in some cases filters will even produce garbage in this channel.&lt;br /&gt;
&lt;br /&gt;
RGBA also makes this a lot easier as it requires four bytes per pixel, and thus each memory access of a word, will correspond to exactly one pixel. In fact, RGB will only be used if you have a source that returns RGB or if you explicitly use [[Convert|ConvertToRGB24]]. [[Convert|ConvertToRGB]] will by default create RGBA.  This is the recommended format for RGB-data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YUY2&#039;&#039;&#039;: In this colorformat each pair of pixels will share the color data, as well as the data being interleaved like this:&lt;br /&gt;
&lt;br /&gt;
 YUYV|YUYV|YUYV|YUYV&lt;br /&gt;
&lt;br /&gt;
A memory access of one word will get all data for &#039;&#039;&#039;two&#039;&#039;&#039; pixels. A pair should never be split, as this can create strange artifacts when almost all functions in YUY2 assume that they should read a full word and process that. Even if they return the correct width when they are done, they will most likely have used invalid data when processing valid pixels.&lt;br /&gt;
&lt;br /&gt;
=== Planar formats ===&lt;br /&gt;
&lt;br /&gt;
Now the real fun begins as this is a [[planar]] image format. This means that 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 &#039;&#039;aligned&#039;&#039; for both color and luma channels will allow easy memory access.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Y8&#039;&#039;&#039;: This colorformat is greyscale, i.e. contains no color. It is the only format which is both planar and interleaved.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YV12&#039;&#039;&#039;: Four pixels share the color data. These four pixels are a 2x2 block, i.e. two pairs on adjacent lines in the same field. As fields themselves are interleaved, this means that for field-based video line 1&amp;amp;3 share color data, as well as line 2&amp;amp;4. Frame-based video though has the more instinctive way of sharing color, line 1&amp;amp;2 share just as line 3&amp;amp;4 does. The 2x2 block should never be split as this may create strange artifacts.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YV411&#039;&#039;&#039;: Four pixels share the color data. These four pixels are a 1x4 block, i.e. a quadruple. The 1x4 block should never be split as this may create strange artifacts.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YV16&#039;&#039;&#039;: In this colorspace each pair of pixels will share the color data. The pair should never be split as this may create strange artifacts. It is a planar version of YUY2.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;YV24&#039;&#039;&#039;: This color format has full color, i.e. each pixel has a unique color (just like RGB and RGBA).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Part 2: How does this affect me as a user? ==&lt;br /&gt;
&lt;br /&gt;
# As long as you don&#039;t split a colorsharing unit it&#039;s up to the filter writers to take care of problems with memory reading at end of lines.&lt;br /&gt;
# Interlaced (fieldbased) video requires double mod on height.&lt;br /&gt;
# Required [[Modulo]]s in different colorformats.&lt;br /&gt;
#* &#039;&#039;&#039;RGB(A)&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-1 (no restriction)&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;YUY2&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-2 (even values)&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Y8&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-1 (no restriction)&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;YV411&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-4&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;YV12&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-2 (even values)&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-4                  &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;YV16&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-2 (even values)&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;YV24&#039;&#039;&#039;&lt;br /&gt;
#** width  mod-1 (no restriction)&lt;br /&gt;
#** height mod-1 (no restriction) &#039;&#039;if progressive&#039;&#039;&lt;br /&gt;
#** height mod-2 (even values)    &#039;&#039;if interlaced&#039;&#039;&lt;br /&gt;
#Examples of valid Crops with input 320x240 progressive&lt;br /&gt;
#* &#039;&#039;&#039;RGB(A)&#039;&#039;&#039;&lt;br /&gt;
#**[[Crop]](1,7,-32,-19)&lt;br /&gt;
#**Crop(2,4,300,196)&lt;br /&gt;
#* &#039;&#039;&#039;YUY2&#039;&#039;&#039;&lt;br /&gt;
#**[[Crop]](2,7,-32,-19)&lt;br /&gt;
#**Crop(2,4,300,196)&lt;br /&gt;
#* &#039;&#039;&#039;YV12&#039;&#039;&#039;&lt;br /&gt;
#**[[Crop]](2,8,-32,-18)&lt;br /&gt;
#**Crop(2,4,300,196)&lt;br /&gt;
# Note that final video may have other restrictions, most MPEG-n implementations want mod-16 on all resolutions etc.&lt;br /&gt;
&lt;br /&gt;
== More information ==&lt;br /&gt;
&lt;br /&gt;
* See more about [[Color_spaces]].&lt;br /&gt;
* See a  general introduction to [[Filter_SDK/Working_with_images|Working with images]].&lt;br /&gt;
&lt;br /&gt;
Back to [[Filter_SDK|Filter SDK]].&lt;br /&gt;
&lt;br /&gt;
[[Category:FilterSDK]]&lt;/div&gt;</summary>
		<author><name>Ianb</name></author>
	</entry>
</feed>