filters/convolution.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 | |||
| 36 | |||
| 37 | // Avisynth filter: general convolution 3d | ||
| 38 | // by Richard Berg (avisynth-dev@richardberg.net) | ||
| 39 | // adapted from General Convolution 3D for VDub by Gunnar Thalin (guth@home.se) | ||
| 40 | |||
| 41 | #ifndef __GeneralConvolution_H__ | ||
| 42 | #define __GeneralConvolution_H__ | ||
| 43 | |||
| 44 | #include <avisynth.h> | ||
| 45 | #include <vector> | ||
| 46 | |||
| 47 | /***************************************** | ||
| 48 | ****** General Convolution 2D filter ***** | ||
| 49 | *****************************************/ | ||
| 50 | |||
| 51 | |||
| 52 | class GeneralConvolution : public GenericVideoFilter | ||
| 53 | /** This class exposes a video filter that applies general convolutions -- up to a 5x5 | ||
| 54 | * kernel -- to a clip. Smaller (3x3) kernels have their own code path. SIMD support forthcoming. | ||
| 55 | **/ | ||
| 56 | { | ||
| 57 | using do_conv_int_t = void(BYTE* dstp8, int dst_pitch, const BYTE *srcp8, int src_pitch, int width, int height, const int *matrix, int iCountDiv, int iBias, int bits_per_pixel); | ||
| 58 | using do_conv_float_t = void(BYTE* dstp8, int dst_pitch, const BYTE *srcp8, int src_pitch, int width, int height, const float *matrix, float fCountDiv, float fBias); | ||
| 59 | |||
| 60 | public: | ||
| 61 | GeneralConvolution(PClip _child, double _divisor, float _nBias, const char * _matrix, bool _autoscale, bool _luma, bool _chroma, bool _alpha, IScriptEnvironment* _env); | ||
| 62 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 63 | static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env); | ||
| 64 | |||
| 65 | 1 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 66 | AVS_UNUSED(frame_range); | ||
| 67 |
1/2✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 4 not taken.
|
1 | return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; |
| 68 | } | ||
| 69 | |||
| 70 | protected: | ||
| 71 | void setMatrix(const char * _matrix, bool _isinteger, IScriptEnvironment* env); | ||
| 72 | |||
| 73 | private: | ||
| 74 | double divisor; | ||
| 75 | size_t nSize; | ||
| 76 | int nBias; | ||
| 77 | float fBias; | ||
| 78 | bool autoscale; | ||
| 79 | |||
| 80 | int iCountDiv; | ||
| 81 | float fCountDiv; | ||
| 82 | bool int64needed; | ||
| 83 | |||
| 84 | bool luma; | ||
| 85 | bool chroma; | ||
| 86 | bool alpha; | ||
| 87 | |||
| 88 | std::vector<int> iMatrix; | ||
| 89 | std::vector<float> fMatrix; | ||
| 90 | float fNormalizeSum; | ||
| 91 | int iNormalizeSum; | ||
| 92 | int iWeightSumPositives; | ||
| 93 | int iWeightSumNegatives; | ||
| 94 | |||
| 95 | do_conv_int_t *conversionFnPtr; | ||
| 96 | do_conv_float_t *FconversionFnPtr; | ||
| 97 | |||
| 98 | }; | ||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | #endif // __GeneralConvolution_H__ | ||
| 103 |