filters/resample.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 __Resample_H__ | ||
| 36 | #define __Resample_H__ | ||
| 37 | |||
| 38 | #include <avisynth.h> | ||
| 39 | #include "resample_functions.h" | ||
| 40 | |||
| 41 | void resize_prepare_coeffs(ResamplingProgram* p, IScriptEnvironment* env, int alignFilterSize8or16); | ||
| 42 | |||
| 43 | // Resizer function pointer | ||
| 44 | typedef void (*ResamplerV)(BYTE* dst, const BYTE* src, int dst_pitch, int src_pitch, ResamplingProgram* program, int width, int target_height, int bits_per_pixel); | ||
| 45 | typedef void (*ResamplerH)(BYTE* dst, const BYTE* src, int dst_pitch, int src_pitch, ResamplingProgram* program, int width, int target_height, int bits_per_pixel); | ||
| 46 | |||
| 47 | // Turn function pointer -- copied from turn.h | ||
| 48 | typedef void (*TurnFuncPtr) (const BYTE* srcp, BYTE* dstp, int width, int height, int src_pitch, int dst_pitch); | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Class to resize in the horizontal direction using a specified sampling filter | ||
| 52 | * Helper for resample functions | ||
| 53 | **/ | ||
| 54 | class FilteredResizeH : public GenericVideoFilter | ||
| 55 | { | ||
| 56 | public: | ||
| 57 | FilteredResizeH(PClip _child, double subrange_left, double subrange_width, int target_width, ResamplingFunction* func, | ||
| 58 | bool preserve_center, int chroma_placement, IScriptEnvironment* env); | ||
| 59 | virtual ~FilteredResizeH(void); | ||
| 60 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 61 | |||
| 62 | 8 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 63 | AVS_UNUSED(frame_range); | ||
| 64 |
1/2✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 4 not taken.
|
8 | if (cachehints == CACHE_GET_MTMODE) return MT_NICE_FILTER; |
| 65 | ✗ | if (cachehints == CACHE_INFORM_NUM_THREADS) { | |
| 66 | ✗ | num_threads = frame_range; | |
| 67 | } | ||
| 68 | ✗ | return 0; | |
| 69 | } | ||
| 70 | |||
| 71 | static ResamplerH GetResampler(int CPU, int pixelsize, int bits_per_pixel, ResamplingProgram* program, ResamplerH& resampler_h_alternative_for_mt, IScriptEnvironment* env); | ||
| 72 | |||
| 73 | private: | ||
| 74 | // Resampling | ||
| 75 | ResamplingProgram* resampling_program_luma; | ||
| 76 | ResamplingProgram* resampling_program_chroma; | ||
| 77 | |||
| 78 | int temp_1_pitch, temp_2_pitch; | ||
| 79 | |||
| 80 | int src_width, src_height, dst_width, dst_height; | ||
| 81 | bool grey; | ||
| 82 | int pixelsize; // AVS16 | ||
| 83 | int bits_per_pixel; | ||
| 84 | |||
| 85 | ResamplerH resampler_h_luma; | ||
| 86 | ResamplerH resampler_h_chroma; | ||
| 87 | // if the base version performs poorly, we decide to use MT version | ||
| 88 | // Unfortunately the information about number of threads is not available at construction time | ||
| 89 | // we get num_threads later via SetCacheHints callback with constants CACHE_INFORM_NUM_THREADS. | ||
| 90 | ResamplerH resampler_h_luma_mt; | ||
| 91 | ResamplerH resampler_h_chroma_mt; | ||
| 92 | // when false, _mt fallback pointers are cleared and the primary resampler is always used. | ||
| 93 | bool use_alternative_h_avx512_mt_fallback; | ||
| 94 | bool fast_resize; | ||
| 95 | |||
| 96 | ResamplerV resampler_luma; | ||
| 97 | ResamplerV resampler_chroma; | ||
| 98 | |||
| 99 | TurnFuncPtr turn_left, turn_right; | ||
| 100 | |||
| 101 | int num_threads; // set by MTGuard by calling SetCacheHints(CACHE_INFORM_NUM_THREADS, n) | ||
| 102 | }; | ||
| 103 | |||
| 104 | |||
| 105 | /** | ||
| 106 | * Class to resize in the vertical direction using a specified sampling filter | ||
| 107 | * Helper for resample functions | ||
| 108 | **/ | ||
| 109 | class FilteredResizeV : public GenericVideoFilter | ||
| 110 | { | ||
| 111 | public: | ||
| 112 | FilteredResizeV(PClip _child, double subrange_top, double subrange_height, int target_height, ResamplingFunction* func, | ||
| 113 | bool preserve_center, int chroma_placement, IScriptEnvironment* env); | ||
| 114 | virtual ~FilteredResizeV(void); | ||
| 115 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 116 | |||
| 117 | 12 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 118 | AVS_UNUSED(frame_range); | ||
| 119 |
2/2✓ Branch 2 → 3 taken 8 times.
✓ Branch 2 → 4 taken 4 times.
|
12 | return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; |
| 120 | } | ||
| 121 | |||
| 122 | static ResamplerV GetResampler(int CPU, int pixelsize, int bits_per_pixel, ResamplingProgram* program, IScriptEnvironment* env); | ||
| 123 | |||
| 124 | private: | ||
| 125 | bool grey; | ||
| 126 | int pixelsize; // AVS16 | ||
| 127 | int bits_per_pixel; | ||
| 128 | |||
| 129 | ResamplingProgram* resampling_program_luma; | ||
| 130 | ResamplingProgram* resampling_program_chroma; | ||
| 131 | |||
| 132 | ResamplerV resampler_luma; | ||
| 133 | ResamplerV resampler_chroma; | ||
| 134 | }; | ||
| 135 | |||
| 136 | |||
| 137 | /*** Resample factory methods ***/ | ||
| 138 | |||
| 139 | class FilteredResize | ||
| 140 | /** | ||
| 141 | * Helper for resample functions | ||
| 142 | **/ | ||
| 143 | { | ||
| 144 | public: | ||
| 145 | static PClip CreateResizeH(PClip clip, double subrange_left, double subrange_width, int target_width, bool force, | ||
| 146 | ResamplingFunction* func, | ||
| 147 | bool preserve_center, int chroma_placement, | ||
| 148 | IScriptEnvironment* env); | ||
| 149 | |||
| 150 | static PClip CreateResizeV(PClip clip, double subrange_top, double subrange_height, int target_height, bool force, | ||
| 151 | ResamplingFunction* func, | ||
| 152 | bool preserve_center, int chroma_placement, | ||
| 153 | IScriptEnvironment* env); | ||
| 154 | |||
| 155 | static PClip CreateResize(PClip clip, int target_width, int target_height, const AVSValue* args, int force, | ||
| 156 | ResamplingFunction* f, | ||
| 157 | bool preserve_center, const char *placement_name, int forced_chroma_placement, | ||
| 158 | IScriptEnvironment* env); | ||
| 159 | |||
| 160 | static AVSValue __cdecl Create_PointResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 161 | |||
| 162 | static AVSValue __cdecl Create_BilinearResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 163 | |||
| 164 | static AVSValue __cdecl Create_BicubicResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 165 | |||
| 166 | // 09-14-2002 - Vlad59 - Lanczos3Resize - | ||
| 167 | static AVSValue __cdecl Create_LanczosResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 168 | |||
| 169 | static AVSValue __cdecl Create_Lanczos4Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 170 | |||
| 171 | static AVSValue __cdecl Create_BlackmanResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 172 | |||
| 173 | static AVSValue __cdecl Create_Spline16Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 174 | |||
| 175 | static AVSValue __cdecl Create_Spline36Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 176 | |||
| 177 | static AVSValue __cdecl Create_Spline64Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 178 | |||
| 179 | static AVSValue __cdecl Create_GaussianResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 180 | |||
| 181 | static AVSValue __cdecl Create_SincResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 182 | |||
| 183 | static AVSValue __cdecl Create_SinPowerResize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 184 | |||
| 185 | static AVSValue __cdecl Create_SincLin2Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 186 | |||
| 187 | static AVSValue __cdecl Create_UserDefined2Resize(AVSValue args, void*, IScriptEnvironment* env); | ||
| 188 | }; | ||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | #endif // __Resample_H__ | ||
| 193 |