filters/merge.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 | // Avisynth filter: YUV merge | ||
| 37 | // by Klaus Post | ||
| 38 | // adapted by Richard Berg (avisynth-dev@richardberg.net) | ||
| 39 | |||
| 40 | |||
| 41 | #ifndef __Merge_H__ | ||
| 42 | #define __Merge_H__ | ||
| 43 | |||
| 44 | #include <avisynth.h> | ||
| 45 | #include "overlay/blend_common.h" | ||
| 46 | #ifdef INTEL_INTRINSICS | ||
| 47 | #include "overlay/intel/blend_common_avx2.h" | ||
| 48 | #include "overlay/intel/blend_common_sse.h" | ||
| 49 | #endif | ||
| 50 | #ifdef NEON_INTRINSICS | ||
| 51 | #include "overlay/aarch64/blend_common_neon.h" | ||
| 52 | #endif | ||
| 53 | |||
| 54 | |||
| 55 | /**************************************************** | ||
| 56 | ****************************************************/ | ||
| 57 | |||
| 58 | class MergeChroma : public GenericVideoFilter | ||
| 59 | /** | ||
| 60 | * Merge the chroma planes of one clip into another, preserving luma | ||
| 61 | **/ | ||
| 62 | { | ||
| 63 | public: | ||
| 64 | MergeChroma(PClip _child, PClip _clip, float _weight, IScriptEnvironment* env); | ||
| 65 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 66 | |||
| 67 | 3 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 68 | AVS_UNUSED(frame_range); | ||
| 69 |
1/2✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 4 not taken.
|
3 | return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; |
| 70 | } | ||
| 71 | |||
| 72 | static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env); | ||
| 73 | |||
| 74 | private: | ||
| 75 | PClip clip; | ||
| 76 | float weight; | ||
| 77 | int pixelsize; | ||
| 78 | int bits_per_pixel; | ||
| 79 | }; | ||
| 80 | |||
| 81 | |||
| 82 | class MergeLuma : public GenericVideoFilter | ||
| 83 | /** | ||
| 84 | * Merge the luma plane of one clip into another, preserving chroma | ||
| 85 | **/ | ||
| 86 | { | ||
| 87 | public: | ||
| 88 | MergeLuma(PClip _child, PClip _clip, float _weight, IScriptEnvironment* env); | ||
| 89 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 90 | |||
| 91 | 3 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 92 | AVS_UNUSED(frame_range); | ||
| 93 |
1/2✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 4 not taken.
|
3 | return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; |
| 94 | } | ||
| 95 | |||
| 96 | static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env); | ||
| 97 | |||
| 98 | private: | ||
| 99 | PClip clip; | ||
| 100 | float weight; | ||
| 101 | int pixelsize; | ||
| 102 | int bits_per_pixel; | ||
| 103 | }; | ||
| 104 | |||
| 105 | |||
| 106 | class MergeAll : public GenericVideoFilter | ||
| 107 | /** | ||
| 108 | * Merge the planes of one clip into another | ||
| 109 | **/ | ||
| 110 | { | ||
| 111 | public: | ||
| 112 | MergeAll(PClip _child, PClip _clip, float _weight, IScriptEnvironment* env); | ||
| 113 | PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env) override; | ||
| 114 | |||
| 115 | 3 | int __stdcall SetCacheHints(int cachehints, int frame_range) override { | |
| 116 | AVS_UNUSED(frame_range); | ||
| 117 |
1/2✓ Branch 2 → 3 taken 3 times.
✗ Branch 2 → 4 not taken.
|
3 | return cachehints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; |
| 118 | } | ||
| 119 | |||
| 120 | static AVSValue __cdecl Create(AVSValue args, void* user_data, IScriptEnvironment* env); | ||
| 121 | |||
| 122 | private: | ||
| 123 | PClip clip; | ||
| 124 | float weight; | ||
| 125 | int pixelsize; | ||
| 126 | int bits_per_pixel; | ||
| 127 | }; | ||
| 128 | |||
| 129 | void merge_plane(BYTE* srcp, const BYTE* otherp, int src_pitch, int other_pitch, int src_rowsize, int src_height, float weight, int bits_per_pixel, bool use_padded_width, IScriptEnvironment* env); | ||
| 130 | |||
| 131 | // Dispatch helpers for weighted (non-average) merges using the unified API. | ||
| 132 | // Callers compute: | ||
| 133 | // pixelsize = bits_per_pixel <= 8 ? 1 : (bits_per_pixel == 32 ? 4 : 2) | ||
| 134 | // width = rowsize / pixelsize | ||
| 135 | // weight_i = (int)(weight_f * 32768.0f + 0.5f) | ||
| 136 | // invweight_i = 32768 - weight_i | ||
| 137 | // Float clips use get_weighted_merge_float_fn; integer clips use get_weighted_merge_fn. | ||
| 138 | 26 | inline weighted_merge_fn_t* get_weighted_merge_fn(int cpuFlags, int weight_i) { | |
| 139 |
2/4✓ Branch 2 → 3 taken 26 times.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 26 times.
|
26 | if (weight_i == 0 || weight_i == 32768) |
| 140 | ✗ | return &weighted_merge_return_a_or_b; | |
| 141 | |||
| 142 | #ifdef INTEL_INTRINSICS | ||
| 143 |
1/2✓ Branch 5 → 6 taken 26 times.
✗ Branch 5 → 7 not taken.
|
26 | if (cpuFlags & CPUF_AVX2) return &weighted_merge_avx2; |
| 144 | ✗ | if (cpuFlags & CPUF_SSE2) return &weighted_merge_sse2; | |
| 145 | #endif | ||
| 146 | #ifdef NEON_INTRINSICS | ||
| 147 | if (cpuFlags & CPUF_ARM_NEON) return &weighted_merge_neon; | ||
| 148 | #endif | ||
| 149 | ✗ | return &weighted_merge_c; | |
| 150 | } | ||
| 151 | ✗ | inline weighted_merge_float_fn_t* get_weighted_merge_float_fn(int cpuFlags) { | |
| 152 | #ifdef INTEL_INTRINSICS | ||
| 153 | ✗ | if (cpuFlags & CPUF_AVX2) return &weighted_merge_float_avx2; | |
| 154 | ✗ | if (cpuFlags & CPUF_SSE2) return &weighted_merge_float_sse2; | |
| 155 | #endif | ||
| 156 | #ifdef NEON_INTRINSICS | ||
| 157 | if (cpuFlags & CPUF_ARM_NEON) return &weighted_merge_float_neon; | ||
| 158 | #endif | ||
| 159 | ✗ | return &weighted_merge_float_c; | |
| 160 | } | ||
| 161 | |||
| 162 | #endif // __Merge_H__ | ||
| 163 |