giovedì 15 luglio 2010

Lightspark: YUV420 to YUV0 explained

Theory

Lightspark is a free, open source flash player which aims to be a good, lightweight and fast friend for all flash's sites.
It uses SSE2 extension to to a special job, which is transform from planar YUV420 to packet YUV0. 

  • Planar YUV: each component (Y, U, V) is stored as a separate array
  • Packed YUV: Y, U (Cb) and V (Cr) samples are packed together into macropixels which are stored in a single array

So, what's the 420 and the 0 stands for? 

  • 420: For each U and V sample, there are two Y.
  • 0: After The YUV, there is a NULL byte of padding.

Now, there is the signature of the function:

void fun (uint8_t* y, uint8_t* u, uint8_t* v, uint8_t* out, uint32_t width, uint32_t height);

The u and v array are width*height, and the y array is 4 times width*height (there are two samples of Y for each U and V.. remember).

Naming the Y buffer in this way:

Y1, Y2, Y3... (each Y is one byte)

and V and U respectively

V1,V2.... and U1,U2.... (same, each U or V are one byte)

Our out array needs to be (and this is the YUV0 stands for):

Y1U1V1[0]   Y2U1V1[0]   Y3U2V2[0]   Y4U2V2[0].....

Y7U1V1[0]   Y8U1V1[0]   Y9U2V2[0]   Y10U2V2[0].....

And we need to get this for every line.

A graphical explanation of this: http://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12.29

Next we'll see an implementation on altivec-capable processors.

Nessun commento: