GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 50.0% 8 / 0 / 16
Functions: 50.0% 4 / 0 / 8
Branches: 28.6% 4 / 0 / 14

convert/convert_planar.h
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 // ConvertPlanar (c) 2005 by Klaus Post
36
37 #ifndef __Convert_PLANAR_H__
38 #define __Convert_PLANAR_H__
39
40 #include <avisynth.h>
41 #include <stdint.h>
42 #include "convert.h"
43 #include "convert_matrix.h"
44 #include "../filters/resample.h"
45 #include "convert_helper.h"
46 #include "convert_bits.h"
47
48 enum YuvRgbConversionType {
49 NATIVE_INT, // Same bit depth, integer matrix arithmetic, no conversion
50 FORCE_FLOAT, // Float matrix workflow (required for float input, optional for accuracy)
51 FLOAT_OUTPUT, // Integer matrix -> float output (for int->float conversions)
52 BITCONV_INT_LIMITED, // Bit-depth change with limited range (shift-based scaling)
53 BITCONV_INT_FULL // Bit-depth change with full range (requires float coefficients)
54 };
55
56 // Dispatcher matching AVX2/SSE2 structure
57 template<ConversionDirection direction, typename pixel_t_src, bool lessthan16bit>
58 void convert_yuv_to_planarrgb_c(BYTE* dstp[3], int dstPitch[3], const BYTE* srcp[3], const int srcPitch[3], int width, int height, const ConversionMatrix& m,
59 int bits_per_pixel, int bits_per_pixel_target, bool force_float);
60
61 // useful functions
62 template <typename pixel_t>
63 void fill_chroma(uint8_t * dstp_u, uint8_t * dstp_v, int height, int row_size, int pitch, pixel_t val);
64
65 template <typename pixel_t>
66 void fill_plane(uint8_t * dstp, int height, int row_size, int pitch, pixel_t val);
67
68 ResamplingFunction* getResampler(const char* resampler, AVSValue param1, AVSValue param2, AVSValue param3, bool throw_on_error, IScriptEnvironment* env);
69
70 class ConvertRGBToYUV444 : public GenericVideoFilter
71 {
72 public:
73 ConvertRGBToYUV444(PClip src, const char *matrix_name, bool keep_packedrgb_alpha, int _target_bit_depth, bool _quality, bool& bitdepthConverted, bool _to_y, IScriptEnvironment* env);
74 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
75
76 7 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
77 AVS_UNUSED(frame_range);
78
1/2
✓ Branch 2 → 3 taken 7 times.
✗ Branch 2 → 4 not taken.
7 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
79 }
80
81 private:
82 int theMatrix;
83 int theColorRange;
84 int theOutColorRange;
85 ConversionMatrix matrix;
86 int pixel_step;
87 bool targetHasAlpha;
88 bool isPlanarRGBfamily;
89 int source_bit_depth;
90 int target_bit_depth;
91 bool quality;
92 bool to_y;
93 // primarily for alpha plane conversion
94 BitDepthConvFuncPtr conv_function;
95 BitDepthConvFuncPtr conv_function_chroma; // 32bit float YUV chroma
96 BitDepthConvFuncPtr conv_function_a;
97 };
98
99 class ConvertYUY2ToYV16_or_Y : public GenericVideoFilter
100 {
101 public:
102 ConvertYUY2ToYV16_or_Y(PClip src, bool _to_y, IScriptEnvironment* env);
103 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
104
105 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
106 AVS_UNUSED(frame_range);
107 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
108 }
109
110 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
111
112 private:
113 bool to_y;
114 };
115
116 class ConvertYUV444ToRGB : public GenericVideoFilter
117 {
118 public:
119 ConvertYUV444ToRGB(PClip src, const char* matrix_name, int _pixel_step, int _target_bit_depth, bool quality, bool& bitdepthConverted, IScriptEnvironment* env);
120 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
121
122 3 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
123 AVS_UNUSED(frame_range);
124
1/2
✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 4 not taken.
3 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
125 }
126
127 private:
128 int theMatrix;
129 int theColorRange;
130 // separate out set for rgb target
131 int theOutMatrix;
132 int theOutColorRange;
133 ConversionMatrix matrix;
134 int pixel_step;
135 int source_bit_depth;
136 int target_bit_depth;
137 bool quality; // true: forced float matrix multiplication
138 // primarily for alpha plane conversion
139 BitDepthConvFuncPtr conv_function;
140 BitDepthConvFuncPtr conv_function_chroma; // 32bit float YUV chroma
141 BitDepthConvFuncPtr conv_function_a;
142
143 };
144
145 class ConvertYV16ToYUY2 : public GenericVideoFilter
146 {
147 public:
148 ConvertYV16ToYUY2(PClip src, IScriptEnvironment* env);
149 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
150
151 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
152 AVS_UNUSED(frame_range);
153 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
154 }
155
156 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
157 };
158
159 class ConvertToPlanarGeneric : public GenericVideoFilter
160 {
161 public:
162 ConvertToPlanarGeneric(PClip src, int dst_space, bool interlaced,
163 int _ChromaLocation_In,
164 const AVSValue& ChromaResampler, const AVSValue& param1, const AVSValue& param2, const AVSValue& param3,
165 int _ChromaLocation_Out,
166 IScriptEnvironment* env);
167 8 ~ConvertToPlanarGeneric() {}
168 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
169
170 24 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
171 AVS_UNUSED(frame_range);
172
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 15 times.
24 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
173 }
174
175 static AVSValue __cdecl CreateY(AVSValue args, void* user_data, IScriptEnvironment* env);
176 static AVSValue __cdecl CreateYV411(AVSValue args, void* user_data, IScriptEnvironment* env);
177 static AVSValue __cdecl CreateYUV420(AVSValue args, void* user_data, IScriptEnvironment* env);
178 static AVSValue __cdecl CreateYUV422(AVSValue args, void* user_data, IScriptEnvironment* env);
179 static AVSValue __cdecl CreateYUV444(AVSValue args, void* user_data, IScriptEnvironment* env);
180 // YUY2 targets: route through YV16, no GetFrame in this class needed.
181 // Placed here as the natural hub for all YUV format conversion routing.
182 static AVSValue __cdecl CreateConvertToYUY2(AVSValue args, void* user_data, IScriptEnvironment* env);
183 static AVSValue __cdecl CreateConvertBackToYUY2(AVSValue args, void* user_data, IScriptEnvironment* env);
184
185
186 private:
187 static AVSValue Create(AVSValue& args, const char* filter, bool strip_alpha_legacy_8bit, bool to_yuva, IScriptEnvironment* env);
188 bool Yinput;
189 int pixelsize;
190 int ChromaLocation_In;
191 int ChromaLocation_Out; // future _ChromaLocation
192 PClip Usource;
193 PClip Vsource;
194 };
195
196 class AddAlphaPlane : public GenericVideoFilter
197 {
198 public:
199 AddAlphaPlane(PClip _child, PClip _maskClip, float _mask_f, bool isMaskDefined, IScriptEnvironment* env);
200 PVideoFrame __stdcall GetFrame(int n,IScriptEnvironment* env) override;
201
202 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
203 AVS_UNUSED(frame_range);
204 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
205 }
206
207 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
208 private:
209 int mask;
210 float mask_f;
211 PClip alphaClip;
212 int pixelsize;
213 int bits_per_pixel;
214 };
215
216 class RemoveAlphaPlane : public GenericVideoFilter
217 {
218 public:
219 RemoveAlphaPlane(PClip _child, IScriptEnvironment* env);
220 PVideoFrame __stdcall GetFrame(int n,IScriptEnvironment* env) override;
221
222 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
223 AVS_UNUSED(frame_range);
224 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
225 }
226
227 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
228 private:
229 };
230
231 #endif
232