-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanar.cpp
117 lines (100 loc) · 2.69 KB
/
planar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#define VC_EXTRALEAN
#include "wrap_windows.h"
#include "planar.h"
#if 1
void debug_printf(const char *format, ...);
#endif
using namespace avxsynth;
const int plane[3] = {PLANAR_Y, PLANAR_U, PLANAR_V};
int __stdcall PlanarAccess::YV12_GetPitch(VideoFrame *frame, int i)
{
return frame->GetPitch(plane[i]);
}
int __stdcall PlanarAccess::YUY2_GetPitch(VideoFrame *frame, int i)
{
return frame->GetPitch();
}
const BYTE *__stdcall PlanarAccess::YV12_GetReadPtr(VideoFrame *frame, int i)
{
return frame->GetReadPtr(plane[i]);
}
const BYTE *__stdcall PlanarAccess::YUY2_GetReadPtr(VideoFrame *frame, int i)
{
return frame->GetReadPtr() + planeoffset[i];
}
BYTE *__stdcall PlanarAccess::YV12_GetWritePtr(VideoFrame *frame, int i)
{
return frame->GetWritePtr(plane[i]);
}
BYTE *__stdcall PlanarAccess::YUY2_GetWritePtr(VideoFrame *frame, int i)
{
return frame->GetWritePtr() + planeoffset[i];
}
PlanarAccess::PlanarAccess(const VideoInfo &vi, bool planar)
{
_GetPitch = &PlanarAccess::YUY2_GetPitch;
_GetReadPtr = &PlanarAccess::YUY2_GetReadPtr;
_GetWritePtr = &PlanarAccess::YUY2_GetWritePtr;
width[1] = width[0] = vi.width;
height[1] = height[0] = vi.height;
if( vi.IsYUV() )
{
width[1] /= 2;
if( vi.IsYV12() )
{
height[1] /= 2;
_GetPitch = &PlanarAccess::YV12_GetPitch;
_GetReadPtr = &PlanarAccess::YV12_GetReadPtr;
_GetWritePtr = &PlanarAccess::YV12_GetWritePtr;
}
}
width[2] = width[1];
height[2] = height[1];
planeoffset[0] = 0;
planeoffset[1] = width[0];
planeoffset[2] = planeoffset[1] + width[1];
planes = 2;
if( planar + vi.IsYV12() == 0 )
{
planes = 0;
width[0] = vi.RowSize();
}
}
HomogeneousChild::HomogeneousChild(PClip _child, bool grey, IScriptEnvironment* env) : child(_child)
{
vi = _child->GetVideoInfo();
width[2] = width[1] = (width[0] = vi.width) / 2;
height[2] = height[1] = (height[0] = vi.height) / 2;
if( !vi.IsYV12() )
{
if( !grey ) width[0] = vi.RowSize();
grey = true;
}
PVideoFrame nf = env->NewVideoFrame(vi);
pitch[0] = nf->GetPitch();
if( vi.IsYV12() )
{
pitch[1] = nf->GetPitch(PLANAR_U);
}
else
{
if( !grey ) width[0] = vi.RowSize();
pitch[1] = pitch[0];
grey = true;
}
planes = 2*(1-grey);
pitch[2] = pitch[1];
}
PVideoFrame __stdcall HomogeneousChild::GetFrame(int n, IScriptEnvironment* env)
{
PVideoFrame rf = child->GetFrame(n, env);
if( rf->GetPitch() - pitch[0] == 0 ) return rf;
PVideoFrame nf = env->NewVideoFrame(vi);
int i = planes;
do
{
int j = plane[i];
env->BitBlt(nf->GetWritePtr(j), pitch[i], rf->GetReadPtr(j), rf->GetPitch(j), width[i], height[i]);
} while( --i >= 0 );
return nf;
}