I think I’ve found a bug, as the title suggests. Probably none of you reading this know about AvsP, so this is more of a reminder to myself once my probationary period on Doom9 is over and I can make a post.

This bug is actually poorly correlated to a side project that I’m working on at the moment, but would eventually become a show stopper. The offending line is line 327 in avisynth.py, in the GetHeight function of a class called PVideoFrame:

if self.p.contents.pitchUV!=0 and (plane==PLANAR_U or PLANAR_V):

Here’s a bit of background. Instead of RGB for a video colour scheme, frames are encoded using one luminance and two chrominance values. While more ethereal and not as intuitive as RGB, it is more efficient and is the foundation of the three major analog TV standards. PLANAR_U and PLANAR_V denote the chrominance values, so it makes sense to keep chrominance operations on U and V separate from the luminance channel, which is PLANAR_Y.

But with the above line, operations that should be exclusive to U and V will are opened up to Y as well! Why?

In Python, any non-zero value evaluates to “true” in an if statement, much like in C. Now consider the if statement. As long as pitchUV is non-zero, the first condition is true. But notice that the second half is always true. Why? Because PLANAR_V is non-zero, so it’s true. Even if plane was not equal to PLANAR_U, we would have “false or true”, which is always true, so the bracketed condition is always true overall.

The solution, then would be to do something like this:

if self.p.contents.pitchUV!=0 and (plane==PLANAR_U or plane==PLANAR_V):

Now the second sub-condition won’t evaluate to true all the time. But better yet, we should step back and ask, “What is it do we want to accomplish with this line?” We want to determine if plane is either PLANAR_U or PLANAR_V, but at a more abstract level, we want to know if plane belongs to a set whose elements are PLANAR_U and PLANAR_V. Python supports just such a construct:

if self.p.contents.pitchUV!=0 and (plane in (PLANAR_U, PLANAR_V)):

Tags: ,
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>