View Full Version : YV12 code scope
If at the beginning of GetFrame I stick
if (vi.IsYV12()) {
const int dst_pitchUV = dst->GetPitch(PLANAR_U);
const int dst_widthUV = dst->GetRowSize(PLANAR_U);
const int dst_heightUV = dst->GetHeight(PLANAR_U);
)
rest of code
If I try using syntax as above, then when I refer to dst_pitchUV in the rest of my code, the variable isn't in scope (fair enough)
How do I do this in a filter that needs to work in YUY2 and YV12 colurspaces without two complete separate code paths or keep repeating the above statments every so often (or is it impossible ?)
regards
Simon (the numpty :o )
Guest
15th April 2003, 23:07
I have member variables for both YUY2 and YV12 in the private section of the class definition and then just use the right ones depending on what space I'm handling.
I had a look at Telecide -
PVideoFrame __stdcall Telecide::GetFrame(int frame, IScriptEnvironment* env)
{
if (vi.IsYV12()) return(GetFrameYV12(frame, env));
else if (vi.IsYUY2()) return(GetFrameYUY2(frame, env));
env->ThrowError("Telecide: YUY2 or YV12 data only");
return 0;
}
This looks like two separate code paths to me :confused:
Or do you do
member variables for both YUY2 and YV12 in the private section of the class definition somewhere else?
regards
Simon
sh0dan
16th April 2003, 09:44
In some cases it is possible to do both interleaced an planar processing in the same code.
If you request GetRowsize(PLANAR_U) and you are dealing with an interleaved source (as YUY2), this will return 0 - and so will GetHeight IIRC. That will make your loops fall through. For instance:
BitBlt( dst->GetWritePtr() + dst_add_pitch, dst->GetPitch()*2,
src->GetReadPtr() + src_add_pitch, src->GetPitch()*2,
src->GetRowSize(), src->GetHeight()>>1 );
BitBlt( dst->GetWritePtr(PLANAR_U) , dst->GetPitch(PLANAR_U)*2,
src->GetReadPtr(PLANAR_U) , src->GetPitch(PLANAR_U)*2,
src->GetRowSize(PLANAR_U), src->GetHeight(PLANAR_U)>>1 );
BitBlt( dst->GetWritePtr(PLANAR_V) , dst->GetPitch(PLANAR_V)*2,
src->GetReadPtr(PLANAR_V) , src->GetPitch(PLANAR_V)*2,
src->GetRowSize(PLANAR_V), src->GetHeight(PLANAR_V)>>1 );
Will work on both planar and interleaved formats.
src->GetRowSize() will return the same as src->GetRowSize(PLANAR_Y) on planar images.
src->GetRowSize(PLANAR_V) will return 0 on interleaved images.
Guest
16th April 2003, 12:50
@siwalters
If you are going to do different things for the different color spaces you have to have different code paths! Whether it is like I did it with separate functions or you with one function and some if statements. Either way the code may want to use different variables.
I put my variables in the filter class declaration when they need to be reached by code other than GetFrame. I also do it to avoid having to pass long parameter lists in function calls.
I also have filters that work your way: one GetFrame and conditional clauses for the different color spaces. Again, I use filter member variables as described.
@sh0dan
so will
1.
const int dst_pitchUV = dst->GetPitch(PLANAR_U);
const int dst_widthUV = dst->GetRowSize(PLANAR_U);
const int dst_heightUV = dst->GetHeight(PLANAR_U);
stuck in a GetFrame all give 0 if I'm dealing with anyhting other than YV12?
and
2.
Can I use it as a "safe" method?
regards
Simon
sh0dan
17th April 2003, 00:27
1) RowSize and Height will be 0 on all but YV12 (and futute planar formats).
2) Yes.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.