GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 20.2% 21 / 0 / 104
Functions: 33.3% 4 / 0 / 12
Branches: 8.9% 18 / 0 / 202

filters/misc.cpp
Line Branch Exec Source
1 // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al.
2 // http://avisynth.nl
3
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // Linking Avisynth statically or dynamically with other modules is making a
20 // combined work based on Avisynth. Thus, the terms and conditions of the GNU
21 // General Public License cover the whole combination.
22 //
23 // As a special exception, the copyright holders of Avisynth give you
24 // permission to link Avisynth with independent modules that communicate with
25 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
26 // terms of these independent modules, and to copy and distribute the
27 // resulting combined work under terms of your choice, provided that
28 // every copy of the combined work is accompanied by a complete copy of
29 // the source code of Avisynth (the version of Avisynth used to produce the
30 // combined work), being distributed under the terms of the GNU General
31 // Public License plus this exception. An independent module is a module
32 // which is not derived from or based on Avisynth, such as 3rd-party filters,
33 // import and export plugins, or graphical user interfaces.
34
35
36 #include "misc.h"
37 #include <avs/minmax.h>
38 #include "../core/bitblt.h"
39 #include "../core/internal.h"
40
41
42
43
44 /********************************************************************
45 ***** Declare index of new filters for Avisynth's filter engine *****
46 ********************************************************************/
47
48 extern const AVSFunction Misc_filters[] = {
49 { "FixLuminance", BUILTIN_FUNC_PREFIX, "cif", FixLuminance::Create }, // clip, intercept, slope
50 { "PeculiarBlend", BUILTIN_FUNC_PREFIX, "ci", PeculiarBlend::Create }, // clip, cutoff
51 { "SkewRows", BUILTIN_FUNC_PREFIX, "ci", SkewRows::Create }, // clip, skew
52 { "FixBrokenChromaUpsampling", BUILTIN_FUNC_PREFIX, "c", FixBrokenChromaUpsampling::Create },
53 { NULL }
54 };
55
56
57
58
59
60
61
62 /********************************
63 ******* Fix Luminance ******
64 ********************************/
65
66 1 FixLuminance::FixLuminance(PClip _child, int _vertex, int _slope, IScriptEnvironment* env)
67
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 11 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 9 not taken.
1 : GenericVideoFilter(_child), vertex(_vertex), slope(_slope)
68 {
69
2/4
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 12 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1 time.
1 if (!vi.IsYUY2())
70 ✗ env->ThrowError("FixLuminance: requires YUY2 input");
71 1 }
72
73
74 ✗ PVideoFrame FixLuminance::GetFrame(int n, IScriptEnvironment* env)
75 {
76 ✗ PVideoFrame frame = child->GetFrame(n, env);
77 ✗ env->MakeWritable(&frame);
78 ✗ BYTE* p = frame->GetWritePtr();
79 ✗ const int pitch = frame->GetPitch();
80 ✗ for (int y=0; y<=vertex-slope/16; ++y)
81 {
82 ✗ const int subtract = (vertex-y)*16/slope;
83 ✗ for (int x=0; x<vi.width; ++x)
84 ✗ p[x*2] = (BYTE)max(0, p[x*2]-subtract);
85 ✗ p += pitch;
86 }
87 ✗ return frame;
88 ✗ }
89
90
91 ✗ AVSValue __cdecl FixLuminance::Create(AVSValue args, void*, IScriptEnvironment* env)
92 {
93 ✗ return new FixLuminance(args[0].AsClip(), args[1].AsInt(), int(args[2].AsFloat()*16), env);
94 }
95
96
97
98
99
100
101 /***********************************************
102 ******* Fix Broken Chroma Upsampling ******
103 ***********************************************/
104
105 ✗ FixBrokenChromaUpsampling::FixBrokenChromaUpsampling(PClip _clip, IScriptEnvironment* env)
106 ✗ : GenericVideoFilter(_clip)
107 {
108 ✗ if (!vi.IsYUY2())
109 ✗ env->ThrowError("FixBrokenChromaUpsampling: requires YUY2 input");
110 ✗ }
111
112
113 ✗ PVideoFrame __stdcall FixBrokenChromaUpsampling::GetFrame(int n, IScriptEnvironment* env)
114 {
115 ✗ PVideoFrame frame = child->GetFrame(n, env);
116 ✗ env->MakeWritable(&frame);
117 ✗ const int pitch = frame->GetPitch();
118 ✗ BYTE* p = frame->GetWritePtr() + pitch;
119 ✗ for (int y = (frame->GetHeight()+1)/4; y > 0; --y) {
120 ✗ for (int x = 0; x < frame->GetRowSize(); x += 4) {
121 ✗ BYTE t1 = p[x+1], t3 = p[x+3];
122 ✗ p[x+1] = p[pitch+x+1]; p[x+3] = p[pitch+x+3];
123 ✗ p[pitch+x+1] = t1; p[pitch+x+3] = t3;
124 }
125 ✗ p += pitch*4;
126 }
127 ✗ return frame;
128 ✗ }
129
130
131 ✗ AVSValue __cdecl FixBrokenChromaUpsampling::Create( AVSValue args, void*,
132 IScriptEnvironment* env )
133 {
134 ✗ return new FixBrokenChromaUpsampling(args[0].AsClip(), env);
135 }
136
137
138
139
140
141
142 /*********************************
143 ******* Peculiar Blend ******
144 *********************************/
145
146 1 PeculiarBlend::PeculiarBlend(PClip _child, int _cutoff, IScriptEnvironment* env)
147
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 11 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 9 not taken.
1 : GenericVideoFilter(_child), cutoff(_cutoff)
148 {
149
2/4
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 12 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1 time.
1 if (!vi.IsYUY2())
150 ✗ env->ThrowError("PeculiarBlend: requires YUY2 input");
151 1 }
152
153
154 1 PVideoFrame PeculiarBlend::GetFrame(int n, IScriptEnvironment* env) {
155
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 48 not taken.
1 PVideoFrame a = child->GetFrame(n, env);
156
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 46 taken 1 time.
1 PVideoFrame b = child->GetFrame(n+1, env);
157 ✗ env->MakeWritable(&a);
158 ✗ BYTE* main = a->GetWritePtr();
159 ✗ const BYTE* other = b->GetReadPtr();
160 ✗ const int main_pitch = a->GetPitch();
161 ✗ const int other_pitch = b->GetPitch();
162 ✗ const int row_size = a->GetRowSize();
163
164 ✗ if (cutoff-31 > 0) {
165 ✗ int copy_top = min(cutoff-31, vi.height);
166 ✗ env->BitBlt(main, main_pitch, other, other_pitch, row_size, copy_top);
167 ✗ main += main_pitch * copy_top;
168 ✗ other += other_pitch * copy_top;
169 }
170 ✗ for (int y = max(0, cutoff-31); y < min(cutoff, vi.height-1); ++y) {
171 ✗ int scale = cutoff - y;
172 ✗ for (int x = 0; x < row_size; ++x)
173 ✗ main[x] = main[x] + BYTE(((other[x] - main[x]) * scale + 16) >> 5);
174 ✗ main += main_pitch;
175 ✗ other += other_pitch;
176 }
177
178 ✗ return a;
179 1 }
180
181
182 ✗ AVSValue __cdecl PeculiarBlend::Create(AVSValue args, void*, IScriptEnvironment* env)
183 {
184 ✗ return new PeculiarBlend(args[0].AsClip(), args[1].AsInt(), env);
185 }
186
187
188
189
190
191
192 /********************************
193 ******* SkewRows ******
194 ********************************/
195
196 1 SkewRows::SkewRows(PClip _child, int skew, IScriptEnvironment* env)
197
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 23 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 21 not taken.
1 : GenericVideoFilter(_child)
198 {
199
3/10
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 24 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 1 time.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 24 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1 time.
1 if ((vi.NumComponents() > 1) && vi.IsPlanar())
200 ✗ env->ThrowError("SkewRows: requires non-planar or greyscale input");
201
202
3/8
✓ Branch 13 → 14 taken 1 time.
✗ Branch 13 → 24 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 1 time.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 1 time.
1 if (vi.IsYUY2() && skew&1)
203 ✗ env->ThrowError("SkewRows: For YUY2 skew must be even");
204
205 1 vi.height *= vi.width;
206 1 vi.width += skew;
207 1 vi.height += vi.width-1; // Ceiling
208 1 vi.height /= vi.width;
209 1 }
210
211
212 ✗ PVideoFrame SkewRows::GetFrame(int n, IScriptEnvironment* env) {
213
214 ✗ PVideoFrame src = child->GetFrame(n, env);
215 ✗ PVideoFrame dst = env->NewVideoFrameP(vi, &src);
216
217 ✗ const int srowsize = src->GetRowSize();
218 ✗ const int spitch = src->GetPitch();
219 ✗ const BYTE *sptr = src->GetReadPtr();
220
221 ✗ const int drowsize = dst->GetRowSize();
222 ✗ const int dpitch = dst->GetPitch();
223 ✗ BYTE *dptr = dst->GetWritePtr();
224
225 ✗ const int ssize = src->GetHeight()*srowsize;
226
227 ✗ int s=0, d=0;
228 ✗ for (int i=0; i < ssize; i++) {
229 ✗ if (s >= srowsize) {
230 ✗ s = 0;
231 ✗ sptr += spitch;
232 }
233 ✗ if (d >= drowsize) {
234 ✗ d = 0;
235 ✗ dptr += dpitch;
236 }
237 ✗ dptr[d++] = sptr[s++];
238 }
239
240 ✗ while (d < drowsize)
241 ✗ dptr[d++] = 128;
242
243 ✗ return dst;
244
245 ✗ }
246
247
248 ✗ AVSValue __cdecl SkewRows::Create(AVSValue args, void*, IScriptEnvironment* env)
249 {
250 ✗ return new SkewRows(args[0].AsClip(), args[1].AsInt(), env);
251 }
252