Log in

View Full Version : interpolation added to YV12ToYUY2


scmccarthy
14th November 2002, 05:52
@Sh0dan
This code could replace the current ConvertYV12ToYUY2() method in the sources.

The filter ConvertYV12ToYUY2() uses an asysmetric filter kernel with an even number of components:

(*32)(1, 7, 21, 3)

The kernel is reversed every other line. Every two lines share a uv chroma between them. It is not placed on either line, but is a half line away from a pair of luma lines. So each uv chroma pair is alternately shifted up a half line and down a half line. The filter extends beyond just a weighting between chroma sites in order to blend the new colors together just as other filters do, so four is as small as it can get. I like to preserve as much detail as possible, so I think four exponents is ideal.

Help me out with the terminalogy, how do you spell kernel and what do you call the exponents? I am not sure it these are the right exponents, just that the right one will always be asymetrical. If you know about other alternatives, I'd like to hear about it. It is hard to this on the web, because there are just too many other needs for other FIR interpolating filter kernals.

MPEG Simultation Group used (*256)(5, -21, 70, 228, -37, 11)
Is it a good idea to use theirs? I'd rather not. And I guess I will not have to now that I wrote my own filter! Yeah.

I unrolled the loop to handle the boundary condtions rather than put any conditional statements inside the loop.
Here's the inner loop:

for (int x = 0; x < row_size; x++) { // (*32)(1, 7, 21, 3) Kernal; Which is this better?

yuv2p[x*4 + 0] = srcpY[x*2];
yuv2p[x*4 + 1] = (srcpU[x-src_pitchUV*2]+srcpU[x-src_pitchUV]*7+srcpU[x]*21+srcpU[x+src_pitchUV]*3)>>5;
yuv2p[x*4 + 2] = srcpY[x*2+1];
yuv2p[x*4 + 3] = (srcpV[x-src_pitchUV*2]+srcpV[x-src_pitchUV]*7+srcpV[x]*21+srcpV[x+src_pitchUV]*3)>>5;

yuv2p[x*4 + 0 +dst_pitch] = srcpY[x*2 +src_pitchY];
yuv2p[x*4 + 1 +dst_pitch] = (srcpU[x-src_pitchUV]*3+srcpU[x]*21+srcpU[x+src_pitchUV]*7+srcpU[x+src_pitchUV*2])>>5;
yuv2p[x*4 + 2 +dst_pitch] = srcpY[x*2+1 +src_pitchY];
yuv2p[x*4 + 3 +dst_pitch] = (srcpV[x-src_pitchUV]*3+srcpV[x]*21+srcpV[x+src_pitchUV]*7+srcpV[x+src_pitchUV*2])>>5;

}

I hi-lighted the exponents to make it easier to follow.
And here's the zipfile:


By the way, the interpolation for the next step from 4:2:2 to 4:4:4 is symetrical. That is because for MPEG-2 the chroma is sited on every other column, not between the columns as it is in MPEG-1.