GCC Code Coverage Report


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

filters/levels.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 #ifndef __Levels_H__
36 #define __Levels_H__
37
38 #include <avisynth.h>
39 #include <stdint.h>
40
41
42 /********************************************************************
43 ********************************************************************/
44
45 typedef struct {
46 int tv_range_low;
47 int tv_range_hi_luma;
48 int range_luma;
49
50 int tv_range_hi_chroma;
51 int range_chroma;
52
53 int middle_chroma;
54
55 // float things
56 float full_range_low_luma_f;
57 float full_range_hi_luma_f;
58 float tv_range_low_luma_f;
59 float tv_range_hi_luma_f;
60 float range_luma_f;
61
62 float full_range_low_chroma_f;
63 float full_range_hi_chroma_f;
64 float tv_range_low_chroma_f;
65 float tv_range_hi_chroma_f;
66 float range_chroma_f;
67
68 float middle_chroma_f;
69 } luma_chroma_limits_t;
70
71 class Levels : public GenericVideoFilter
72 /**
73 * Class for adjusting levels in a clip
74 **/
75 {
76 public:
77 Levels(PClip _child, float _in_min, double _gamma, float _in_max, float _out_min, float _out_max, bool _coring, bool _dither,
78 IScriptEnvironment* env );
79 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
80
81 1 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
82 AVS_UNUSED(frame_range);
83
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 4 not taken.
1 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
84 }
85
86 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
87
88 private:
89 BYTE *map, *mapchroma;
90 bool need_chroma;
91 bool coring;
92 bool dither;
93 double gamma;
94 bool use_gamma;
95 float in_min_f, in_max_f, out_min_f, out_max_f;
96
97 // avs+
98 int pixelsize;
99 int bits_per_pixel; // 8,10..16
100 bool use_lut;
101
102 int real_lookup_size;
103
104 luma_chroma_limits_t limits;
105
106 float divisor_f;
107 float out_diff_f; // precalc for speed
108
109 float ditherMap_f[256];
110
111 float bias_dither;
112 float dither_strength;
113
114 template<bool chroma, bool use_gamma>
115 AVS_FORCEINLINE float calcPixel(const float pixel);
116 };
117
118
119 struct RGBAdjustPlaneConfig
120 {
121 double scale;
122 double bias;
123 double gamma;
124 bool changed; // for lut recalc
125 };
126
127 struct RGBAdjustConfig
128 {
129 RGBAdjustPlaneConfig rgba[4];
130 };
131
132 struct RGBPlaneStat
133 {
134 double sum;
135 float real_min, real_max;
136 };
137
138 struct RGBStats
139 {
140 RGBPlaneStat data[3];
141 };
142
143 class RGBAdjust : public GenericVideoFilter
144 /**
145 * Class for adjusting and analyzing colors in RGBA space
146 **/
147 {
148 public:
149 RGBAdjust(PClip _child, double r, double g, double b, double a,
150 double rb, double gb, double bb, double ab,
151 double rg, double gg, double bg, double ag,
152 bool _analyze, bool _dither, bool _conditional, const char *_condVarSuffix, IScriptEnvironment* env);
153 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
154 ~RGBAdjust();
155
156 1 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
157 AVS_UNUSED(frame_range);
158
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 4 not taken.
1 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
159 }
160
161 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
162
163 private:
164 bool analyze;
165 bool dither;
166 bool conditional;
167 const char* condVarSuffix;
168
169 RGBAdjustConfig config;
170
171 int number_of_maps;
172 BYTE *map_holder;
173 BYTE *maps[4];
174 // avs+
175 int pixelsize;
176 int bits_per_pixel; // 8,10..16
177 bool use_lut;
178
179 int max_pixel_value;
180 int real_lookup_size;
181
182 float dither_strength;
183
184
185 void CheckAndConvertParams(RGBAdjustConfig &config, IScriptEnvironment *env);
186 void rgbadjust_create_lut(BYTE *lut_buf, const int plane, RGBAdjustConfig &config);
187 };
188
189
190
191
192 class Tweak : public GenericVideoFilter
193 {
194 public:
195 Tweak(PClip _child, double _hue, double _sat, double _bright, double _cont, bool _coring,
196 double _startHue, double _endHue, double _maxSat, double _minSat, double _interp,
197 bool _dither, bool _realcalc, double _dither_strength, IScriptEnvironment* env);
198
199 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
200
201 3 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
202 AVS_UNUSED(frame_range);
203
1/2
✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 4 not taken.
3 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
204 }
205
206 static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env);
207
208 private:
209 template<typename pixel_t, bool bpp10_14, bool dither>
210 void tweak_calc_luma(BYTE *srcp, int src_pitch, float minY, float maxY, int width, int height);
211
212 template<typename pixel_t, bool dither>
213 void tweak_calc_chroma(BYTE *srcpU, BYTE *srcpV, int src_pitch, int width, int height, float minUV, float maxUV);
214
215 int Sin, Cos;
216 int Sat, Bright, Cont;
217 bool coring, dither;
218
219 const bool realcalc; // no lookup, realtime calculation, always for 16/32 bits
220 double dhue, dsat, dbright, dcont, dstartHue, dendHue, dmaxSat, dminSat, dinterp;
221
222 bool allPixels;
223
224 BYTE *map;
225 uint16_t *mapUV;
226 // avs+
227 bool realcalc_luma;
228 bool realcalc_chroma;
229
230 int pixelsize;
231 int bits_per_pixel; // 8,10..16
232 int max_pixel_value;
233 int lut_size;
234
235 luma_chroma_limits_t limits;
236
237 int scale_dither_luma;
238 int divisor_dither_luma;
239 float bias_dither_luma;
240
241 int scale_dither_chroma;
242 int divisor_dither_chroma;
243 float bias_dither_chroma;
244
245 float dither_strength;
246 };
247
248
249 class MaskHS : public GenericVideoFilter
250 {
251 public:
252 MaskHS( PClip _child, double _startHue, double _endHue, double _maxSat, double _minSat, bool _coring, bool _realcalc, IScriptEnvironment* env );
253
254 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override;
255
256 2 int __stdcall SetCacheHints(int cachehints, int frame_range) override {
257 AVS_UNUSED(frame_range);
258
1/2
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 4 not taken.
2 return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0;
259 }
260
261 static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env);
262
263 private:
264 const double dstartHue, dendHue, dmaxSat, dminSat;
265 const bool coring;
266 const bool realcalc;
267
268 double minSat, maxSat; // corrected values
269
270 uint8_t *mapUV;
271 // avs+
272 bool realcalc_chroma;
273
274 int pixelsize;
275 int bits_per_pixel; // 8,10..16
276 int max_pixel_value;
277 int lut_size;
278
279 luma_chroma_limits_t limits;
280
281 int mask_low;
282 int mask_high;
283 float mask_low_f;
284 float mask_high_f;
285
286 };
287
288 #endif // __Levels_H__
289
290