filters/limiter.cpp
| 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 | #include "limiter.h" | ||
| 37 | #ifdef INTEL_INTRINSICS | ||
| 38 | #include "intel/limiter_sse.h" | ||
| 39 | #endif | ||
| 40 | #include <avs/alignment.h> | ||
| 41 | |||
| 42 | #ifdef AVS_WINDOWS | ||
| 43 | #include <avs/win.h> | ||
| 44 | #else | ||
| 45 | #include <avs/posix.h> | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #include <../core/internal.h> | ||
| 49 | |||
| 50 | |||
| 51 | 8 | Limiter::Limiter(PClip _child, float _min_luma, float _max_luma, float _min_chroma, float _max_chroma, int _show, bool paramscale, IScriptEnvironment* env) : | |
| 52 | GenericVideoFilter(_child), | ||
| 53 | 8 | max_luma((int)_max_luma), | |
| 54 | 8 | min_luma((int)_min_luma), | |
| 55 | 8 | max_chroma((int)_max_chroma), | |
| 56 | 8 | min_chroma((int)_min_chroma), | |
| 57 | 8 | max_luma_f(_max_luma), | |
| 58 | 8 | min_luma_f(_min_luma), | |
| 59 | 8 | max_chroma_f(_max_chroma), | |
| 60 | 8 | min_chroma_f(_min_chroma), | |
| 61 |
2/4✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 61 not taken.
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 59 not taken.
|
8 | show(show_e(_show)) |
| 62 | { | ||
| 63 |
6/10✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 62 not taken.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 10 taken 7 times.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 62 not taken.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 8 times.
|
8 | if (!vi.IsYUV() && !vi.IsYUVA()) |
| 64 | ✗ | env->ThrowError("Limiter: Source must be YUV or YUVA"); | |
| 65 | |||
| 66 |
2/16✗ Branch 13 → 14 not taken.
✓ Branch 13 → 21 taken 8 times.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 62 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 21 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 62 not taken.
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 21 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 62 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 8 times.
|
8 | if(show != show_none && !vi.IsYUY2() && !vi.Is444() && !vi.Is420()) |
| 67 | ✗ | env->ThrowError("Limiter: Source must be YUV(A) 4:4:4, 4:2:0 or YUY2 with show option."); | |
| 68 | |||
| 69 |
1/2✓ Branch 24 → 25 taken 8 times.
✗ Branch 24 → 62 not taken.
|
8 | pixelsize = vi.ComponentSize(); |
| 70 |
1/2✓ Branch 25 → 26 taken 8 times.
✗ Branch 25 → 62 not taken.
|
8 | bits_per_pixel = vi.BitsPerComponent(); // 8,10..16 |
| 71 | 8 | int pixel_max = (1 << bits_per_pixel) - 1; // 255, 1023, 4095, 16383, 65535 | |
| 72 | |||
| 73 | 8 | const bool isFloat = bits_per_pixel == 32; | |
| 74 |
1/2✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 8 times.
|
8 | int tv_range_low = isFloat ? 16 : (16 << (bits_per_pixel - 8)); // 16 |
| 75 |
1/2✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 8 times.
|
8 | int tv_range_hi_luma = isFloat ? 235 : (235 << (bits_per_pixel - 8)); // 16-235 |
| 76 |
1/2✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 8 times.
|
8 | int tv_range_hi_chroma = isFloat ? 240 : (240 << (bits_per_pixel - 8)); // 16-240,64-960, ... |
| 77 | |||
| 78 | 8 | float tv_range_low_luma_f = 16 / 255.0f; | |
| 79 | 8 | float tv_range_hi_luma_f = 235 / 255.0f; | |
| 80 | #ifdef FLOAT_CHROMA_IS_HALF_CENTERED | ||
| 81 | float tv_range_low_chroma = (16-128) / 255.0f + 0.5f; | ||
| 82 | float tv_range_hi_chroma_f = (240 - 128) / 255.0f + 0.5f; | ||
| 83 | #else | ||
| 84 | 8 | float tv_range_low_chroma_f = (16 - 128) / 255.0f; | |
| 85 | 8 | float tv_range_hi_chroma_f = (240 - 128) / 255.0f; | |
| 86 | #endif | ||
| 87 | |||
| 88 |
2/2✓ Branch 35 → 36 taken 2 times.
✓ Branch 35 → 37 taken 6 times.
|
8 | if (paramscale) { |
| 89 | // int versions, scale from the original float accuracy (e.g. 127.5) | ||
| 90 | 2 | min_luma = (int)(_min_luma * (1 << (bits_per_pixel - 8)) + 0.5f); | |
| 91 | 2 | max_luma = (int)(_max_luma * (1 << (bits_per_pixel - 8)) + 0.5f); | |
| 92 | 2 | min_chroma = (int)(_min_chroma * (1 << (bits_per_pixel - 8)) + 0.5f); | |
| 93 | 2 | max_chroma = (int)(_max_chroma * (1 << (bits_per_pixel - 8)) + 0.5f); | |
| 94 | |||
| 95 | // float versions | ||
| 96 | 2 | min_luma_f = min_luma_f / 255.0f; | |
| 97 | 2 | max_luma_f = max_luma_f / 255.0f; | |
| 98 | #ifdef FLOAT_CHROMA_IS_HALF_CENTERED | ||
| 99 | min_chroma_f = (min_chroma_f - 128) / 255.0f + 0.5f; | ||
| 100 | max_chroma_f = (max_chroma_f - 128) / 255.0f + 0.5f; | ||
| 101 | #else | ||
| 102 | 2 | min_chroma_f = (min_chroma_f - 128) / 255.0f; | |
| 103 | 2 | max_chroma_f = (max_chroma_f - 128) / 255.0f; | |
| 104 | #endif | ||
| 105 | } | ||
| 106 | |||
| 107 | |||
| 108 | // default min and max values by bitdepths | ||
| 109 |
1/2✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 8 times.
|
8 | if (_min_luma == -9999.0f) { |
| 110 | ✗ | min_luma = tv_range_low; | |
| 111 | ✗ | min_luma_f = tv_range_low_luma_f; | |
| 112 | } | ||
| 113 |
1/2✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 8 times.
|
8 | if (_max_luma == -9999.0f) { |
| 114 | ✗ | max_luma = tv_range_hi_luma; | |
| 115 | ✗ | max_luma_f = tv_range_hi_luma_f; | |
| 116 | } | ||
| 117 |
1/2✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 8 times.
|
8 | if (_min_chroma == -9999.0f) { |
| 118 | ✗ | min_chroma = tv_range_low; | |
| 119 | ✗ | min_chroma_f = tv_range_low_chroma_f; | |
| 120 | } | ||
| 121 |
1/2✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 8 times.
|
8 | if (_max_chroma == -9999.0f) { |
| 122 | ✗ | max_chroma = tv_range_hi_chroma; | |
| 123 | ✗ | max_chroma_f = tv_range_hi_chroma_f; | |
| 124 | } | ||
| 125 | |||
| 126 |
1/2✓ Branch 45 → 46 taken 8 times.
✗ Branch 45 → 58 not taken.
|
8 | if (pixelsize != 4) { |
| 127 | // no check for float | ||
| 128 |
3/4✓ Branch 46 → 47 taken 7 times.
✓ Branch 46 → 48 taken 1 time.
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 7 times.
|
8 | if ((min_luma < 0) || (min_luma > pixel_max)) |
| 129 |
1/2✗ Branch 48 → 49 not taken.
✓ Branch 48 → 62 taken 1 time.
|
1 | env->ThrowError("Limiter: Invalid minimum luma"); |
| 130 |
2/4✓ Branch 49 → 50 taken 7 times.
✗ Branch 49 → 51 not taken.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 7 times.
|
7 | if ((max_luma < 0) || (max_luma > pixel_max)) |
| 131 | ✗ | env->ThrowError("Limiter: Invalid maximum luma"); | |
| 132 |
2/4✓ Branch 52 → 53 taken 7 times.
✗ Branch 52 → 54 not taken.
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 55 taken 7 times.
|
7 | if ((min_chroma < 0) || (min_chroma > pixel_max)) |
| 133 | ✗ | env->ThrowError("Limiter: Invalid minimum chroma"); | |
| 134 |
3/4✓ Branch 55 → 56 taken 6 times.
✓ Branch 55 → 57 taken 1 time.
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 58 taken 6 times.
|
7 | if ((max_chroma < 0) || (max_chroma > pixel_max)) |
| 135 |
1/2✗ Branch 57 → 58 not taken.
✓ Branch 57 → 62 taken 1 time.
|
1 | env->ThrowError("Limiter: Invalid maximum chroma"); |
| 136 | } | ||
| 137 | |||
| 138 | 8 | } | |
| 139 | |||
| 140 | template<typename pixel_t> | ||
| 141 | ✗ | static void limit_plane_c(BYTE *srcp8, int pitch, int min, int max, int width, int height) { | |
| 142 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 143 | ✗ | pitch /= sizeof(pixel_t); | |
| 144 | ✗ | for(int y = 0; y < height; y++) { | |
| 145 | ✗ | for(int x = 0; x < width; x++) { | |
| 146 | ✗ | if(srcp[x] < min ) | |
| 147 | ✗ | srcp[x] = (pixel_t)min; | |
| 148 | ✗ | else if(srcp[x] > max) | |
| 149 | ✗ | srcp[x] = (pixel_t)max; | |
| 150 | } | ||
| 151 | ✗ | srcp += pitch; | |
| 152 | } | ||
| 153 | ✗ | } | |
| 154 | |||
| 155 | ✗ | static void limit_plane_f_c(BYTE *srcp8, int pitch, float min, float max, int width, int height) { | |
| 156 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 157 | ✗ | pitch /= sizeof(float); | |
| 158 | ✗ | for (int y = 0; y < height; y++) { | |
| 159 | ✗ | for (int x = 0; x < width; x++) { | |
| 160 | ✗ | if (srcp[x] < min) | |
| 161 | ✗ | srcp[x] = min; | |
| 162 | ✗ | else if (srcp[x] > max) | |
| 163 | ✗ | srcp[x] = max; | |
| 164 | } | ||
| 165 | ✗ | srcp += pitch; | |
| 166 | } | ||
| 167 | ✗ | } | |
| 168 | |||
| 169 | template<typename pixel_t, bool show_luma_grey> | ||
| 170 | ✗ | static void show_luma_with_grey_opt_yuv444(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_luma, int max_luma, int bits_per_pixel) | |
| 171 | { | ||
| 172 | // show_luma Mark clamped pixels red/green over a colour image | ||
| 173 | // show_luma_grey Mark clamped pixels red/green over a greyscaled image | ||
| 174 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 175 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 176 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 177 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 178 | ✗ | pitch /= sizeof(pixel_t); | |
| 179 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 180 | |||
| 181 | ✗ | for (int h=0; h < height; h+=1) { | |
| 182 | ✗ | for (int x = 0; x < width; x+=1) { | |
| 183 | ✗ | if (srcp[x] < min_luma) { srcp[x] = 81 << shift; srcpU[x] = 91 << shift; srcpV[x] = 240 << shift; } // red: Y=81, U=91 and V=240 | |
| 184 | ✗ | else if (srcp[x] > max_luma) { srcp[x] = 145 << shift; srcpU[x] = 54 << shift; srcpV[x] = 34 << shift; } // green: Y=145, U=54 and V=34 | |
| 185 | // this differs from show_luma | ||
| 186 | ✗ | else if(show_luma_grey) { srcpU[x] = srcpV[x] = 128 << shift; } // grey | |
| 187 | } | ||
| 188 | ✗ | srcp += pitch; | |
| 189 | ✗ | srcpV += pitchUV; | |
| 190 | ✗ | srcpU += pitchUV; | |
| 191 | } | ||
| 192 | ✗ | } | |
| 193 | |||
| 194 | template<typename pixel_t, bool show_luma_grey> | ||
| 195 | ✗ | static void show_luma_with_grey_opt_yuv420(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_luma, int max_luma, int bits_per_pixel) | |
| 196 | { | ||
| 197 | // show_luma Mark clamped pixels red/green over a colour image | ||
| 198 | // show_luma_grey Mark clamped pixels red/green over a greyscaled image | ||
| 199 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 200 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 201 | ✗ | pixel_t *srcn = reinterpret_cast<pixel_t *>(srcp8 + pitch); // next line | |
| 202 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 203 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 204 | ✗ | pitch /= sizeof(pixel_t); | |
| 205 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 206 | |||
| 207 | ✗ | for (int h=0; h < height; h+=2) { | |
| 208 | ✗ | for (int x = 0; x < width; x+=2) { | |
| 209 | ✗ | int uv = 0; | |
| 210 | ✗ | if (srcp[x ] < min_luma) { srcp[x ] = 81 << shift; uv |= 1;} | |
| 211 | ✗ | else if (srcp[x ] > max_luma) { srcp[x ] = 145 << shift; uv |= 2;} | |
| 212 | ✗ | if (srcp[x+1] < min_luma) { srcp[x+1] = 81 << shift; uv |= 1;} | |
| 213 | ✗ | else if (srcp[x+1] > max_luma) { srcp[x+1] = 145 << shift; uv |= 2;} | |
| 214 | ✗ | if (srcn[x ] < min_luma) { srcn[x ] = 81 << shift; uv |= 1;} | |
| 215 | ✗ | else if (srcn[x ] > max_luma) { srcn[x ] = 145 << shift; uv |= 2;} | |
| 216 | ✗ | if (srcn[x+1] < min_luma) { srcn[x+1] = 81 << shift; uv |= 1;} | |
| 217 | ✗ | else if (srcn[x+1] > max_luma) { srcn[x+1] = 145 << shift; uv |= 2;} | |
| 218 | ✗ | switch (uv) { | |
| 219 | ✗ | case 1: srcpU[x/2] = 91 << shift; srcpV[x/2] = 240 << shift; break; // red: Y=81, U=91 and V=240 | |
| 220 | ✗ | case 2: srcpU[x/2] = 54 << shift; srcpV[x/2] = 34 << shift; break; // green: Y=145, U=54 and V=34 | |
| 221 | // this differs from show_luma_grey | ||
| 222 | ✗ | case 3: | |
| 223 | if(show_luma_grey) { | ||
| 224 | ✗ | srcpU[x/2] = 90 << shift; | |
| 225 | ✗ | srcpV[x/2] = 134 << shift; break; // puke: Y=81, U=90 and V=134 olive: Y=145, U=90 and V=134 | |
| 226 | } else { | ||
| 227 | ✗ | srcp[x]=srcp[x+2]=srcn[x]=srcn[x+2]=210 << shift; // yellow:Y=210, U=16 and V=146 | |
| 228 | ✗ | srcpU[x/2] = 16 << shift; | |
| 229 | ✗ | srcpV[x/2] = 146 << shift; | |
| 230 | } | ||
| 231 | ✗ | break; | |
| 232 | ✗ | default: | |
| 233 | if(show_luma_grey) { | ||
| 234 | ✗ | srcpU[x/2] = srcpV[x/2] = 128 << shift; // olive: Y=145, U=90 and V=134 | |
| 235 | } | ||
| 236 | ✗ | break; | |
| 237 | } | ||
| 238 | } | ||
| 239 | ✗ | srcp += pitch*2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 240 | ✗ | srcn += pitch*2; | |
| 241 | ✗ | srcpV += pitchUV; | |
| 242 | ✗ | srcpU += pitchUV; | |
| 243 | } | ||
| 244 | ✗ | } | |
| 245 | |||
| 246 | template<bool show_luma_grey> | ||
| 247 | ✗ | static void show_luma_with_grey_opt_yuv444_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_luma, float max_luma) | |
| 248 | { | ||
| 249 | // show_luma Mark clamped pixels red/green over a colour image | ||
| 250 | // show_luma_grey Mark clamped pixels red/green over a greyscaled image | ||
| 251 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 252 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 253 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 254 | ✗ | pitch /= sizeof(float); | |
| 255 | ✗ | pitchUV /= sizeof(float); | |
| 256 | |||
| 257 | ✗ | for (int h = 0; h < height; h += 1) { | |
| 258 | ✗ | for (int x = 0; x < width; x += 1) { | |
| 259 | ✗ | if (srcp[x] < min_luma) { srcp[x] = c8tof(81); srcpU[x] = uv8tof(91); srcpV[x] = uv8tof(240); } // red: Y=81, U=91 and V=240 | |
| 260 | ✗ | else if (srcp[x] > max_luma) { srcp[x] = c8tof(145); srcpU[x] = uv8tof(54); srcpV[x] = uv8tof(34); } // green: Y=145, U=54 and V=34 | |
| 261 | // this differs from show_luma | ||
| 262 | ✗ | else if (show_luma_grey) { srcpU[x] = srcpV[x] = uv8tof(128); } // grey | |
| 263 | } | ||
| 264 | ✗ | srcp += pitch; | |
| 265 | ✗ | srcpV += pitchUV; | |
| 266 | ✗ | srcpU += pitchUV; | |
| 267 | } | ||
| 268 | ✗ | } | |
| 269 | |||
| 270 | template<bool show_luma_grey> | ||
| 271 | ✗ | static void show_luma_with_grey_opt_yuv420_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_luma, float max_luma) | |
| 272 | { | ||
| 273 | // show_luma Mark clamped pixels red/green over a colour image | ||
| 274 | // show_luma_grey Mark clamped pixels red/green over a greyscaled image | ||
| 275 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 276 | ✗ | float *srcn = reinterpret_cast<float *>(srcp8 + pitch); // next line | |
| 277 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 278 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 279 | ✗ | pitch /= sizeof(float); | |
| 280 | ✗ | pitchUV /= sizeof(float); | |
| 281 | |||
| 282 | ✗ | for (int h = 0; h < height; h += 2) { | |
| 283 | ✗ | for (int x = 0; x < width; x += 2) { | |
| 284 | ✗ | int uv = 0; | |
| 285 | ✗ | if (srcp[x] < min_luma) { srcp[x] = c8tof(81); uv |= 1; } | |
| 286 | ✗ | else if (srcp[x] > max_luma) { srcp[x] = c8tof(145); uv |= 2; } | |
| 287 | ✗ | if (srcp[x + 1] < min_luma) { srcp[x + 1] = c8tof(81); uv |= 1; } | |
| 288 | ✗ | else if (srcp[x + 1] > max_luma) { srcp[x + 1] = c8tof(145); uv |= 2; } | |
| 289 | ✗ | if (srcn[x] < min_luma) { srcn[x] = c8tof(81); uv |= 1; } | |
| 290 | ✗ | else if (srcn[x] > max_luma) { srcn[x] = c8tof(145); uv |= 2; } | |
| 291 | ✗ | if (srcn[x + 1] < min_luma) { srcn[x + 1] = c8tof(81); uv |= 1; } | |
| 292 | ✗ | else if (srcn[x + 1] > max_luma) { srcn[x + 1] = c8tof(145); uv |= 2; } | |
| 293 | ✗ | switch (uv) { | |
| 294 | ✗ | case 1: srcpU[x / 2] = uv8tof(91); srcpV[x / 2] = uv8tof(240); break; // red: Y=81, U=91 and V=240 | |
| 295 | ✗ | case 2: srcpU[x / 2] = uv8tof(54); srcpV[x / 2] = uv8tof(34); break; // green: Y=145, U=54 and V=34 | |
| 296 | // this differs from show_luma_grey | ||
| 297 | ✗ | case 3: | |
| 298 | if (show_luma_grey) { | ||
| 299 | ✗ | srcpU[x / 2] = uv8tof(90); | |
| 300 | ✗ | srcpV[x / 2] = uv8tof(134); break; // puke: Y=81, U=90 and V=134 olive: Y=145, U=90 and V=134 | |
| 301 | } | ||
| 302 | else { | ||
| 303 | ✗ | srcp[x] = srcp[x + 2] = srcn[x] = srcn[x + 2] = c8tof(210); // yellow:Y=210, U=16 and V=146 | |
| 304 | ✗ | srcpU[x / 2] = uv8tof(16); | |
| 305 | ✗ | srcpV[x / 2] = uv8tof(146); | |
| 306 | } | ||
| 307 | ✗ | break; | |
| 308 | ✗ | default: | |
| 309 | if (show_luma_grey) { | ||
| 310 | ✗ | srcpU[x / 2] = srcpV[x / 2] = uv8tof(128); // olive: Y=145, U=90 and V=134 | |
| 311 | } | ||
| 312 | ✗ | break; | |
| 313 | } | ||
| 314 | } | ||
| 315 | ✗ | srcp += pitch * 2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 316 | ✗ | srcn += pitch * 2; | |
| 317 | ✗ | srcpV += pitchUV; | |
| 318 | ✗ | srcpU += pitchUV; | |
| 319 | } | ||
| 320 | ✗ | } | |
| 321 | |||
| 322 | template<typename pixel_t> | ||
| 323 | ✗ | static void show_chroma_yuv444(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_chroma, int max_chroma, int bits_per_pixel) | |
| 324 | { | ||
| 325 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 326 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 327 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 328 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 329 | ✗ | pitch /= sizeof(pixel_t); | |
| 330 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 331 | |||
| 332 | ✗ | for (int h=0; h < height; h+=1) { | |
| 333 | ✗ | for (int x = 0; x < width; x+=1) { | |
| 334 | ✗ | if ( (srcpU[x] < min_chroma) // U- | |
| 335 | ✗ | || (srcpU[x] > max_chroma) // U+ | |
| 336 | ✗ | || (srcpV[x] < min_chroma) // V- | |
| 337 | ✗ | || (srcpV[x] > max_chroma) )// V+ | |
| 338 | ✗ | { srcp[x]=210 << shift; srcpU[x]= 16 << shift; srcpV[x]=146 << shift; } // yellow:Y=210, U=16 and V=146 | |
| 339 | } | ||
| 340 | ✗ | srcp += pitch; | |
| 341 | ✗ | srcpV += pitchUV; | |
| 342 | ✗ | srcpU += pitchUV; | |
| 343 | } | ||
| 344 | ✗ | } | |
| 345 | |||
| 346 | template<typename pixel_t> | ||
| 347 | ✗ | static void show_chroma_yuv420(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_chroma, int max_chroma, int bits_per_pixel) | |
| 348 | { | ||
| 349 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 350 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 351 | ✗ | pixel_t *srcn = reinterpret_cast<pixel_t *>(srcp8 + pitch); // next line | |
| 352 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 353 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 354 | ✗ | pitch /= sizeof(pixel_t); | |
| 355 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 356 | |||
| 357 | ✗ | for (int h=0; h < height; h+=2) { | |
| 358 | ✗ | for (int x = 0; x < width; x+=2) { | |
| 359 | ✗ | if ( (srcpU[x/2] < min_chroma) // U- | |
| 360 | ✗ | || (srcpU[x/2] > max_chroma) // U+ | |
| 361 | ✗ | || (srcpV[x/2] < min_chroma) // V- | |
| 362 | ✗ | || (srcpV[x/2] > max_chroma) )// V+ | |
| 363 | ✗ | { srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=210 << shift; srcpU[x/2]= 16 << shift; srcpV[x/2]=146 << shift; } // yellow:Y=210, U=16 and V=146 | |
| 364 | } | ||
| 365 | ✗ | srcp += pitch*2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 366 | ✗ | srcn += pitch*2; | |
| 367 | ✗ | srcpV += pitchUV; | |
| 368 | ✗ | srcpU += pitchUV; | |
| 369 | } | ||
| 370 | ✗ | } | |
| 371 | |||
| 372 | template<typename pixel_t> | ||
| 373 | ✗ | static void show_chroma_grey_yuv444(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_chroma, int max_chroma, int bits_per_pixel) | |
| 374 | { | ||
| 375 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 376 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 377 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 378 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 379 | ✗ | pitch /= sizeof(pixel_t); | |
| 380 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 381 | |||
| 382 | ✗ | for (int h=0; h < height; h+=1) { | |
| 383 | ✗ | for (int x = 0; x < width; x+=1) { | |
| 384 | ✗ | int uv = 0; | |
| 385 | ✗ | if (srcpU[x] < min_chroma) uv |= 1; // U- | |
| 386 | ✗ | else if (srcpU[x] > max_chroma) uv |= 2; // U+ | |
| 387 | ✗ | if (srcpV[x] < min_chroma) uv |= 4; // V- | |
| 388 | ✗ | else if (srcpV[x] > max_chroma) uv |= 8; // V+ | |
| 389 | ✗ | switch (uv) { | |
| 390 | ✗ | case 8: srcp[x]= 81 << shift; srcpU[x]= 91 << shift; srcpV[x]=240 << shift; break; // +V Red | |
| 391 | ✗ | case 9: srcp[x]=146 << shift; srcpU[x]= 53 << shift; srcpV[x]=193 << shift; break; // -U+V Orange | |
| 392 | ✗ | case 1: srcp[x]=210 << shift; srcpU[x]= 16 << shift; srcpV[x]=146 << shift; break; // -U Yellow | |
| 393 | ✗ | case 5: srcp[x]=153 << shift; srcpU[x]= 49 << shift; srcpV[x]= 49 << shift; break; // -U-V Green | |
| 394 | ✗ | case 4: srcp[x]=170 << shift; srcpU[x]=165 << shift; srcpV[x]= 16 << shift; break; // -V Cyan | |
| 395 | ✗ | case 6: srcp[x]=105 << shift; srcpU[x]=203 << shift; srcpV[x]= 63 << shift; break; // +U-V Teal | |
| 396 | ✗ | case 2: srcp[x]= 41 << shift; srcpU[x]=240 << shift; srcpV[x]=110 << shift; break; // +U Blue | |
| 397 | ✗ | case 10: srcp[x]=106 << shift; srcpU[x]=202 << shift; srcpV[x]=222 << shift; break; // +U+V Magenta | |
| 398 | ✗ | default: srcpU[x]= srcpV[x]=128 << shift; break; | |
| 399 | } | ||
| 400 | } | ||
| 401 | ✗ | srcp += pitch; | |
| 402 | ✗ | srcpV += pitchUV; | |
| 403 | ✗ | srcpU += pitchUV; | |
| 404 | } | ||
| 405 | ✗ | } | |
| 406 | |||
| 407 | template<typename pixel_t> | ||
| 408 | ✗ | static void show_chroma_grey_yuv420(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, int min_chroma, int max_chroma, int bits_per_pixel) | |
| 409 | { | ||
| 410 | ✗ | const int shift = sizeof(pixel_t) == 1 ? 0 : (bits_per_pixel - 8); | |
| 411 | ✗ | pixel_t *srcp = reinterpret_cast<pixel_t *>(srcp8); | |
| 412 | ✗ | pixel_t *srcn = reinterpret_cast<pixel_t *>(srcp8 + pitch); // next line | |
| 413 | ✗ | pixel_t *srcpU = reinterpret_cast<pixel_t *>(srcpU8); | |
| 414 | ✗ | pixel_t *srcpV = reinterpret_cast<pixel_t *>(srcpV8); | |
| 415 | ✗ | pitch /= sizeof(pixel_t); | |
| 416 | ✗ | pitchUV /= sizeof(pixel_t); | |
| 417 | |||
| 418 | ✗ | for (int h=0; h < height; h+=2) { | |
| 419 | ✗ | for (int x = 0; x < width; x+=2) { | |
| 420 | ✗ | int uv = 0; | |
| 421 | ✗ | if (srcpU[x/2] < min_chroma) uv |= 1; // U- | |
| 422 | ✗ | else if (srcpU[x/2] > max_chroma) uv |= 2; // U+ | |
| 423 | ✗ | if (srcpV[x/2] < min_chroma) uv |= 4; // V- | |
| 424 | ✗ | else if (srcpV[x/2] > max_chroma) uv |= 8; // V+ | |
| 425 | ✗ | switch (uv) { | |
| 426 | ✗ | case 8: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]= 81 << shift; srcpU[x/2]= 91 << shift; srcpV[x/2]=240 << shift; break; // +V Red | |
| 427 | ✗ | case 9: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=146 << shift; srcpU[x/2]= 53 << shift; srcpV[x/2]=193 << shift; break; // -U+V Orange | |
| 428 | ✗ | case 1: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=210 << shift; srcpU[x/2]= 16 << shift; srcpV[x/2]=146 << shift; break; // -U Yellow | |
| 429 | ✗ | case 5: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=153 << shift; srcpU[x/2]= 49 << shift; srcpV[x/2]= 49 << shift; break; // -U-V Green | |
| 430 | ✗ | case 4: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=170 << shift; srcpU[x/2]=165 << shift; srcpV[x/2]= 16 << shift; break; // -V Cyan | |
| 431 | ✗ | case 6: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=105 << shift; srcpU[x/2]=203 << shift; srcpV[x/2]= 63 << shift; break; // +U-V Teal | |
| 432 | ✗ | case 2: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]= 41 << shift; srcpU[x/2]=240 << shift; srcpV[x/2]=110 << shift; break; // +U Blue | |
| 433 | ✗ | case 10: srcp[x]=srcp[x+1]=srcn[x]=srcn[x+1]=106 << shift; srcpU[x/2]=202 << shift; srcpV[x/2]=222 << shift; break; // +U+V Magenta | |
| 434 | ✗ | default: srcpU[x/2] = srcpV[x/2] = 128 << shift; break; | |
| 435 | } | ||
| 436 | } | ||
| 437 | ✗ | srcp += pitch*2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 438 | ✗ | srcn += pitch*2; | |
| 439 | ✗ | srcpV += pitchUV; | |
| 440 | ✗ | srcpU += pitchUV; | |
| 441 | } | ||
| 442 | ✗ | } | |
| 443 | |||
| 444 | ✗ | static void show_chroma_yuv444_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_chroma, float max_chroma) | |
| 445 | { | ||
| 446 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 447 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 448 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 449 | ✗ | pitch /= sizeof(float); | |
| 450 | ✗ | pitchUV /= sizeof(float); | |
| 451 | |||
| 452 | ✗ | for (int h = 0; h < height; h += 1) { | |
| 453 | ✗ | for (int x = 0; x < width; x += 1) { | |
| 454 | ✗ | if ((srcpU[x] < min_chroma) // U- | |
| 455 | ✗ | || (srcpU[x] > max_chroma) // U+ | |
| 456 | ✗ | || (srcpV[x] < min_chroma) // V- | |
| 457 | ✗ | || (srcpV[x] > max_chroma))// V+ | |
| 458 | { | ||
| 459 | ✗ | srcp[x] = c8tof(210); srcpU[x] = uv8tof(16); srcpV[x] = uv8tof(146); | |
| 460 | } // yellow:Y=210, U=16 and V=146 | ||
| 461 | } | ||
| 462 | ✗ | srcp += pitch; | |
| 463 | ✗ | srcpV += pitchUV; | |
| 464 | ✗ | srcpU += pitchUV; | |
| 465 | } | ||
| 466 | ✗ | } | |
| 467 | |||
| 468 | ✗ | static void show_chroma_yuv420_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_chroma, float max_chroma) | |
| 469 | { | ||
| 470 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 471 | ✗ | float *srcn = reinterpret_cast<float *>(srcp8 + pitch); // next line | |
| 472 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 473 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 474 | ✗ | pitch /= sizeof(float); | |
| 475 | ✗ | pitchUV /= sizeof(float); | |
| 476 | |||
| 477 | ✗ | for (int h = 0; h < height; h += 2) { | |
| 478 | ✗ | for (int x = 0; x < width; x += 2) { | |
| 479 | ✗ | if ((srcpU[x / 2] < min_chroma) // U- | |
| 480 | ✗ | || (srcpU[x / 2] > max_chroma) // U+ | |
| 481 | ✗ | || (srcpV[x / 2] < min_chroma) // V- | |
| 482 | ✗ | || (srcpV[x / 2] > max_chroma))// V+ | |
| 483 | { | ||
| 484 | ✗ | srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(210); srcpU[x / 2] = uv8tof(16); srcpV[x / 2] = uv8tof(146); | |
| 485 | } // yellow:Y=210, U=16 and V=146 | ||
| 486 | } | ||
| 487 | ✗ | srcp += pitch * 2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 488 | ✗ | srcn += pitch * 2; | |
| 489 | ✗ | srcpV += pitchUV; | |
| 490 | ✗ | srcpU += pitchUV; | |
| 491 | } | ||
| 492 | ✗ | } | |
| 493 | |||
| 494 | ✗ | static void show_chroma_grey_yuv444_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_chroma, float max_chroma) | |
| 495 | { | ||
| 496 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 497 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 498 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 499 | ✗ | pitch /= sizeof(float); | |
| 500 | ✗ | pitchUV /= sizeof(float); | |
| 501 | |||
| 502 | ✗ | for (int h = 0; h < height; h += 1) { | |
| 503 | ✗ | for (int x = 0; x < width; x += 1) { | |
| 504 | ✗ | int uv = 0; | |
| 505 | ✗ | if (srcpU[x] < min_chroma) uv |= 1; // U- | |
| 506 | ✗ | else if (srcpU[x] > max_chroma) uv |= 2; // U+ | |
| 507 | ✗ | if (srcpV[x] < min_chroma) uv |= 4; // V- | |
| 508 | ✗ | else if (srcpV[x] > max_chroma) uv |= 8; // V+ | |
| 509 | ✗ | switch (uv) { | |
| 510 | ✗ | case 8: srcp[x] = c8tof(81); srcpU[x] = uv8tof(91); srcpV[x] = uv8tof(240); break; // +V Red | |
| 511 | ✗ | case 9: srcp[x] = c8tof(146); srcpU[x] = uv8tof(53); srcpV[x] = uv8tof(193); break; // -U+V Orange | |
| 512 | ✗ | case 1: srcp[x] = c8tof(210); srcpU[x] = uv8tof(16); srcpV[x] = uv8tof(146); break; // -U Yellow | |
| 513 | ✗ | case 5: srcp[x] = c8tof(153); srcpU[x] = uv8tof(49); srcpV[x] = uv8tof(49); break; // -U-V Green | |
| 514 | ✗ | case 4: srcp[x] = c8tof(170); srcpU[x] = uv8tof(165); srcpV[x] = uv8tof(16); break; // -V Cyan | |
| 515 | ✗ | case 6: srcp[x] = c8tof(105); srcpU[x] = uv8tof(203); srcpV[x] = uv8tof(63); break; // +U-V Teal | |
| 516 | ✗ | case 2: srcp[x] = c8tof(41); srcpU[x] = uv8tof(240); srcpV[x] = uv8tof(110); break; // +U Blue | |
| 517 | ✗ | case 10: srcp[x] = c8tof(106); srcpU[x] = uv8tof(202); srcpV[x] = uv8tof(222); break; // +U+V Magenta | |
| 518 | ✗ | default: srcpU[x] = srcpV[x] = uv8tof(128); break; | |
| 519 | } | ||
| 520 | } | ||
| 521 | ✗ | srcp += pitch; | |
| 522 | ✗ | srcpV += pitchUV; | |
| 523 | ✗ | srcpU += pitchUV; | |
| 524 | } | ||
| 525 | ✗ | } | |
| 526 | |||
| 527 | ✗ | static void show_chroma_grey_yuv420_f(BYTE *srcp8, BYTE *srcpU8, BYTE *srcpV8, int pitch, int pitchUV, int width, int height, float min_chroma, float max_chroma) | |
| 528 | { | ||
| 529 | ✗ | float *srcp = reinterpret_cast<float *>(srcp8); | |
| 530 | ✗ | float *srcn = reinterpret_cast<float *>(srcp8 + pitch); // next line | |
| 531 | ✗ | float *srcpU = reinterpret_cast<float *>(srcpU8); | |
| 532 | ✗ | float *srcpV = reinterpret_cast<float *>(srcpV8); | |
| 533 | ✗ | pitch /= sizeof(float); | |
| 534 | ✗ | pitchUV /= sizeof(float); | |
| 535 | |||
| 536 | ✗ | for (int h = 0; h < height; h += 2) { | |
| 537 | ✗ | for (int x = 0; x < width; x += 2) { | |
| 538 | ✗ | int uv = 0; | |
| 539 | ✗ | if (srcpU[x / 2] < min_chroma) uv |= 1; // U- | |
| 540 | ✗ | else if (srcpU[x / 2] > max_chroma) uv |= 2; // U+ | |
| 541 | ✗ | if (srcpV[x / 2] < min_chroma) uv |= 4; // V- | |
| 542 | ✗ | else if (srcpV[x / 2] > max_chroma) uv |= 8; // V+ | |
| 543 | ✗ | switch (uv) { | |
| 544 | ✗ | case 8: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(81); srcpU[x / 2] = uv8tof(91); srcpV[x / 2] = uv8tof(240); break; // +V Red | |
| 545 | ✗ | case 9: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(146); srcpU[x / 2] = uv8tof(53); srcpV[x / 2] = uv8tof(193); break; // -U+V Orange | |
| 546 | ✗ | case 1: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(210); srcpU[x / 2] = uv8tof(16); srcpV[x / 2] = uv8tof(146); break; // -U Yellow | |
| 547 | ✗ | case 5: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(153); srcpU[x / 2] = uv8tof(49); srcpV[x / 2] = uv8tof(49); break; // -U-V Green | |
| 548 | ✗ | case 4: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(170); srcpU[x / 2] = uv8tof(165); srcpV[x / 2] = uv8tof(16); break; // -V Cyan | |
| 549 | ✗ | case 6: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(105); srcpU[x / 2] = uv8tof(203); srcpV[x / 2] = uv8tof(63); break; // +U-V Teal | |
| 550 | ✗ | case 2: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(41); srcpU[x / 2] = uv8tof(240); srcpV[x / 2] = uv8tof(110); break; // +U Blue | |
| 551 | ✗ | case 10: srcp[x] = srcp[x + 1] = srcn[x] = srcn[x + 1] = c8tof(106); srcpU[x / 2] = uv8tof(202); srcpV[x / 2] = uv8tof(222); break; // +U+V Magenta | |
| 552 | ✗ | default: srcpU[x / 2] = srcpV[x / 2] = uv8tof(128); break; | |
| 553 | } | ||
| 554 | } | ||
| 555 | ✗ | srcp += pitch * 2; // 2x2 pixels at a time (4:2:0 subsampling) | |
| 556 | ✗ | srcn += pitch * 2; | |
| 557 | ✗ | srcpV += pitchUV; | |
| 558 | ✗ | srcpU += pitchUV; | |
| 559 | } | ||
| 560 | ✗ | } | |
| 561 | |||
| 562 | 4 | PVideoFrame __stdcall Limiter::GetFrame(int n, IScriptEnvironment* env) { | |
| 563 | 4 | PVideoFrame frame = child->GetFrame(n, env); | |
| 564 |
1/2✓ Branch 4 → 5 taken 4 times.
✗ Branch 4 → 286 not taken.
|
4 | env->MakeWritable(&frame); |
| 565 |
1/2✓ Branch 6 → 7 taken 4 times.
✗ Branch 6 → 286 not taken.
|
4 | unsigned char* srcp = frame->GetWritePtr(); |
| 566 |
1/2✓ Branch 8 → 9 taken 4 times.
✗ Branch 8 → 286 not taken.
|
4 | int pitch = frame->GetPitch(); |
| 567 |
1/2✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 286 not taken.
|
4 | int row_size = frame->GetRowSize(); |
| 568 | 4 | int width = vi.width; | |
| 569 | 4 | int height = vi.height; | |
| 570 | |||
| 571 |
2/4✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 286 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 114 taken 4 times.
|
4 | if (vi.IsYUY2()) { |
| 572 | |||
| 573 | ✗ | if (show == show_luma) { // Mark clamped pixels red/yellow/green over a colour image | |
| 574 | ✗ | for (int y = 0; y < height; y++) { | |
| 575 | ✗ | for (int x = 0; x < row_size; x+=4) { | |
| 576 | ✗ | int uv = 0; | |
| 577 | ✗ | if (srcp[x ] < min_luma) { srcp[x ] = 81; uv |= 1;} | |
| 578 | ✗ | else if (srcp[x ] > max_luma) { srcp[x ] = 145; uv |= 2;} | |
| 579 | ✗ | if (srcp[x+2] < min_luma) { srcp[x+2] = 81; uv |= 1;} | |
| 580 | ✗ | else if (srcp[x+2] > max_luma) { srcp[x+2] = 145; uv |= 2;} | |
| 581 | ✗ | switch (uv) { | |
| 582 | ✗ | case 1: srcp[x+1] = 91; srcp[x+3] = 240; break; // red: Y= 81, U=91 and V=240 | |
| 583 | ✗ | case 2: srcp[x+1] = 54; srcp[x+3] = 34; break; // green: Y=145, U=54 and V=34 | |
| 584 | ✗ | case 3: srcp[x ] = srcp[x+2] = 210; | |
| 585 | ✗ | srcp[x+1] = 16; srcp[x+3] = 146; break; // yellow:Y=210, U=16 and V=146 | |
| 586 | ✗ | default: break; | |
| 587 | } | ||
| 588 | } | ||
| 589 | ✗ | srcp += pitch; | |
| 590 | } | ||
| 591 | ✗ | return frame; | |
| 592 | } | ||
| 593 | ✗ | else if (show == show_luma_grey) { // Mark clamped pixels coloured over a greyscaled image | |
| 594 | ✗ | for (int y = 0; y < height; y++) { | |
| 595 | ✗ | for (int x = 0; x < row_size; x+=4) { | |
| 596 | ✗ | int uv = 0; | |
| 597 | ✗ | if (srcp[x ] < min_luma) { srcp[x ] = 81; uv |= 1;} | |
| 598 | ✗ | else if (srcp[x ] > max_luma) { srcp[x ] = 145; uv |= 2;} | |
| 599 | ✗ | if (srcp[x+2] < min_luma) { srcp[x+2] = 81; uv |= 1;} | |
| 600 | ✗ | else if (srcp[x+2] > max_luma) { srcp[x+2] = 145; uv |= 2;} | |
| 601 | ✗ | switch (uv) { | |
| 602 | ✗ | case 1: srcp[x+1] = 91; srcp[x+3] = 240; break; // red: Y=81, U=91 and V=240 | |
| 603 | ✗ | case 2: srcp[x+1] = 54; srcp[x+3] = 34; break; // green: Y=145, U=54 and V=34 | |
| 604 | ✗ | case 3: srcp[x+1] = 90; srcp[x+3] = 134; break; // puke: Y=81, U=90 and V=134 | |
| 605 | ✗ | default: srcp[x+1] = srcp[x+3] = 128; break; // olive: Y=145, U=90 and V=134 | |
| 606 | } | ||
| 607 | } | ||
| 608 | ✗ | srcp += pitch; | |
| 609 | } | ||
| 610 | ✗ | return frame; | |
| 611 | } | ||
| 612 | ✗ | else if (show == show_chroma) { // Mark clamped pixels yellow over a colour image | |
| 613 | ✗ | for (int y = 0; y < height; y++) { | |
| 614 | ✗ | for (int x = 0; x < row_size; x+=4) { | |
| 615 | ✗ | if ( (srcp[x+1] < min_chroma) // U- | |
| 616 | ✗ | || (srcp[x+1] > max_chroma) // U+ | |
| 617 | ✗ | || (srcp[x+3] < min_chroma) // V- | |
| 618 | ✗ | || (srcp[x+3] > max_chroma) )// V+ | |
| 619 | ✗ | { srcp[x]=srcp[x+2]=210; srcp[x+1]=16; srcp[x+3]=146; } // yellow:Y=210, U=16 and V=146 | |
| 620 | } | ||
| 621 | ✗ | srcp += pitch; | |
| 622 | } | ||
| 623 | ✗ | return frame; | |
| 624 | } | ||
| 625 | ✗ | else if (show == show_chroma_grey) { // Mark clamped pixels coloured over a greyscaled image | |
| 626 | ✗ | for (int y = 0; y < height; y++) { | |
| 627 | ✗ | for (int x = 0; x < row_size; x+=4) { | |
| 628 | ✗ | int uv = 0; | |
| 629 | ✗ | if (srcp[x+1] < min_chroma) uv |= 1; // U- | |
| 630 | ✗ | else if (srcp[x+1] > max_chroma) uv |= 2; // U+ | |
| 631 | ✗ | if (srcp[x+3] < min_chroma) uv |= 4; // V- | |
| 632 | ✗ | else if (srcp[x+3] > max_chroma) uv |= 8; // V+ | |
| 633 | ✗ | switch (uv) { | |
| 634 | ✗ | case 8: srcp[x] = srcp[x+2] = 81; srcp[x+1] = 91; srcp[x+3] = 240; break; // +V Red | |
| 635 | ✗ | case 9: srcp[x] = srcp[x+2] = 146; srcp[x+1] = 53; srcp[x+3] = 193; break; // -U+V Orange | |
| 636 | ✗ | case 1: srcp[x] = srcp[x+2] = 210; srcp[x+1] = 16; srcp[x+3] = 146; break; // -U Yellow | |
| 637 | ✗ | case 5: srcp[x] = srcp[x+2] = 153; srcp[x+1] = 49; srcp[x+3] = 49; break; // -U-V Green | |
| 638 | ✗ | case 4: srcp[x] = srcp[x+2] = 170; srcp[x+1] = 165; srcp[x+3] = 16; break; // -V Cyan | |
| 639 | ✗ | case 6: srcp[x] = srcp[x+2] = 105; srcp[x+1] = 203; srcp[x+3] = 63; break; // +U-V Teal | |
| 640 | ✗ | case 2: srcp[x] = srcp[x+2] = 41; srcp[x+1] = 240; srcp[x+3] = 110; break; // +U Blue | |
| 641 | ✗ | case 10: srcp[x] = srcp[x+2] = 106; srcp[x+1] = 202; srcp[x+3] = 222; break; // +U+V Magenta | |
| 642 | ✗ | default: srcp[x+1] = srcp[x+3] = 128; break; | |
| 643 | } | ||
| 644 | } | ||
| 645 | ✗ | srcp += pitch; | |
| 646 | } | ||
| 647 | ✗ | return frame; | |
| 648 | } | ||
| 649 | #ifdef INTEL_INTRINSICS | ||
| 650 | ✗ | if (env->GetCPUFlags() & CPUF_SSE2) { | |
| 651 | ✗ | limit_plane_sse2(srcp, min_luma | (min_chroma << 8), max_luma | (max_chroma << 8), pitch, row_size, height); | |
| 652 | ✗ | return frame; | |
| 653 | } | ||
| 654 | |||
| 655 | /** Run emulator if CPU supports it**/ | ||
| 656 | #ifdef X86_32 | ||
| 657 | if (env->GetCPUFlags() & CPUF_INTEGER_SSE) | ||
| 658 | { | ||
| 659 | //limit_plane_mmx(srcp, min_luma, max_luma, pitch, row_size, height); | ||
| 660 | limit_plane_isse(srcp, min_luma | (min_chroma << 8), max_luma | (max_chroma << 8), pitch, row_size, height); | ||
| 661 | return frame; | ||
| 662 | } | ||
| 663 | #endif | ||
| 664 | // If not ISSE | ||
| 665 | #endif | ||
| 666 | ✗ | for(int y = 0; y < height; y++) { | |
| 667 | ✗ | for(int x = 0; x < row_size; x++) { | |
| 668 | ✗ | if(srcp[x] < min_luma ) | |
| 669 | ✗ | srcp[x++] = (unsigned char)min_luma; | |
| 670 | ✗ | else if(srcp[x] > max_luma) | |
| 671 | ✗ | srcp[x++] = (unsigned char)max_luma; | |
| 672 | else | ||
| 673 | ✗ | x++; | |
| 674 | ✗ | if(srcp[x] < min_chroma) | |
| 675 | ✗ | srcp[x] = (unsigned char)min_chroma; | |
| 676 | ✗ | else if(srcp[x] > max_chroma) | |
| 677 | ✗ | srcp[x] = (unsigned char)max_chroma; | |
| 678 | } | ||
| 679 | ✗ | srcp += pitch; | |
| 680 | } | ||
| 681 | ✗ | return frame; | |
| 682 | // YUY end | ||
| 683 |
5/8✓ Branch 114 → 115 taken 4 times.
✗ Branch 114 → 286 not taken.
✓ Branch 115 → 116 taken 1 time.
✓ Branch 115 → 118 taken 3 times.
✗ Branch 116 → 117 not taken.
✓ Branch 116 → 118 taken 1 time.
✗ Branch 119 → 120 not taken.
✓ Branch 119 → 154 taken 4 times.
|
4 | } else if(vi.Is420() && show != show_none) { |
| 684 | ✗ | const int pitchUV = frame->GetPitch(PLANAR_U); | |
| 685 | ✗ | unsigned char* srcpV = frame->GetWritePtr(PLANAR_V); | |
| 686 | ✗ | unsigned char* srcpU = frame->GetWritePtr(PLANAR_U); | |
| 687 | |||
| 688 | ✗ | if (show == show_luma || show == show_luma_grey) { // Mark clamped pixels red/yellow/green over a colour image | |
| 689 | ✗ | if (pixelsize == 1) { | |
| 690 | ✗ | if (show == show_luma) | |
| 691 | ✗ | show_luma_with_grey_opt_yuv420<uint8_t, false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 692 | else // show_luma_grey | ||
| 693 | ✗ | show_luma_with_grey_opt_yuv420<uint8_t, true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 694 | ✗ | } else if (pixelsize == 2) { // pixelsize == 2 | |
| 695 | ✗ | if (show == show_luma) | |
| 696 | ✗ | show_luma_with_grey_opt_yuv420<uint16_t, false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 697 | else // show_luma_grey | ||
| 698 | ✗ | show_luma_with_grey_opt_yuv420<uint16_t, true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 699 | } | ||
| 700 | else { // pixelsize == 4 | ||
| 701 | ✗ | if (show == show_luma) | |
| 702 | ✗ | show_luma_with_grey_opt_yuv420_f<false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma_f, max_luma_f); | |
| 703 | else // show_luma_grey | ||
| 704 | ✗ | show_luma_with_grey_opt_yuv420_f<true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma_f, max_luma_f); | |
| 705 | } | ||
| 706 | ✗ | return frame; | |
| 707 | } | ||
| 708 | ✗ | else if (show == show_chroma) { // Mark clamped pixels yellow over a colour image | |
| 709 | ✗ | if (pixelsize == 1) | |
| 710 | ✗ | show_chroma_yuv420<uint8_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 711 | ✗ | else if (pixelsize == 2) | |
| 712 | ✗ | show_chroma_yuv420<uint16_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 713 | else // float | ||
| 714 | ✗ | show_chroma_yuv420_f(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma_f, max_chroma_f); | |
| 715 | ✗ | return frame; | |
| 716 | } | ||
| 717 | ✗ | else if (show == show_chroma_grey) { // Mark clamped pixels coloured over a greyscaled image | |
| 718 | ✗ | if (pixelsize == 1) | |
| 719 | ✗ | show_chroma_grey_yuv420<uint8_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 720 | ✗ | else if (pixelsize == 2) | |
| 721 | ✗ | show_chroma_grey_yuv420<uint16_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 722 | else // float | ||
| 723 | ✗ | show_chroma_grey_yuv420_f(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma_f, max_chroma_f); | |
| 724 | ✗ | return frame; | |
| 725 | } | ||
| 726 | // YV12 (4:2:0) end | ||
| 727 |
5/8✓ Branch 154 → 155 taken 4 times.
✗ Branch 154 → 286 not taken.
✓ Branch 155 → 156 taken 2 times.
✓ Branch 155 → 158 taken 2 times.
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 158 taken 2 times.
✗ Branch 159 → 160 not taken.
✓ Branch 159 → 194 taken 4 times.
|
4 | } else if(vi.Is444() && show != show_none) { |
| 728 | |||
| 729 | ✗ | const int pitchUV = frame->GetPitch(PLANAR_U); | |
| 730 | ✗ | unsigned char* srcpV = frame->GetWritePtr(PLANAR_V); | |
| 731 | ✗ | unsigned char* srcpU = frame->GetWritePtr(PLANAR_U); | |
| 732 | |||
| 733 | ✗ | if (show == show_luma || show == show_luma_grey) { | |
| 734 | ✗ | if (pixelsize == 1) { | |
| 735 | ✗ | if (show == show_luma) | |
| 736 | ✗ | show_luma_with_grey_opt_yuv444<uint8_t, false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 737 | else // show_luma_grey | ||
| 738 | ✗ | show_luma_with_grey_opt_yuv444<uint8_t, true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 739 | ✗ | } else if (pixelsize == 2) { | |
| 740 | ✗ | if (show == show_luma) | |
| 741 | ✗ | show_luma_with_grey_opt_yuv444<uint16_t, false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 742 | else // show_luma_grey | ||
| 743 | ✗ | show_luma_with_grey_opt_yuv444<uint16_t, true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma, max_luma, bits_per_pixel); | |
| 744 | } | ||
| 745 | else { // pixelsize == 4 | ||
| 746 | ✗ | if (show == show_luma) | |
| 747 | ✗ | show_luma_with_grey_opt_yuv444_f<false>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma_f, max_luma_f); | |
| 748 | else // show_luma_grey | ||
| 749 | ✗ | show_luma_with_grey_opt_yuv444_f<true>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_luma_f, max_luma_f); | |
| 750 | } | ||
| 751 | ✗ | return frame; | |
| 752 | } | ||
| 753 | ✗ | else if (show == show_chroma) { // Mark clamped pixels yellow over a colour image | |
| 754 | ✗ | if (pixelsize == 1) | |
| 755 | ✗ | show_chroma_yuv444<uint8_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 756 | ✗ | else if (pixelsize == 2) | |
| 757 | ✗ | show_chroma_yuv444<uint16_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 758 | else // float | ||
| 759 | ✗ | show_chroma_yuv444_f(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma_f, max_chroma_f); | |
| 760 | ✗ | return frame; | |
| 761 | } | ||
| 762 | ✗ | else if (show == show_chroma_grey) { // Mark clamped pixels coloured over a greyscaled image | |
| 763 | ✗ | if (pixelsize == 1) | |
| 764 | ✗ | show_chroma_grey_yuv444<uint8_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 765 | ✗ | else if (pixelsize == 2) | |
| 766 | ✗ | show_chroma_grey_yuv444<uint16_t>(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma, max_chroma, bits_per_pixel); | |
| 767 | else // float | ||
| 768 | ✗ | show_chroma_grey_yuv444_f(srcp, srcpU, srcpV, pitch, pitchUV, width, height, min_chroma_f, max_chroma_f); | |
| 769 | ✗ | return frame; | |
| 770 | } | ||
| 771 | // YV24 (4:4:4) end | ||
| 772 | } | ||
| 773 |
2/4✓ Branch 194 → 195 taken 4 times.
✗ Branch 194 → 286 not taken.
✓ Branch 195 → 196 taken 4 times.
✗ Branch 195 → 284 not taken.
|
4 | if (vi.IsPlanar()) |
| 774 | { | ||
| 775 | #ifdef INTEL_INTRINSICS | ||
| 776 | //todo: separate to functions and use sse2 for aligned planes even if some are unaligned | ||
| 777 |
6/8✓ Branch 196 → 197 taken 2 times.
✓ Branch 196 → 200 taken 2 times.
✓ Branch 197 → 198 taken 2 times.
✗ Branch 197 → 286 not taken.
✓ Branch 198 → 199 taken 2 times.
✗ Branch 198 → 200 not taken.
✓ Branch 201 → 202 taken 2 times.
✓ Branch 201 → 222 taken 2 times.
|
4 | if ((pixelsize==1) && (env->GetCPUFlags() & CPUF_SSE2)) { |
| 778 |
1/2✓ Branch 202 → 203 taken 2 times.
✗ Branch 202 → 286 not taken.
|
2 | limit_plane_sse2(srcp, min_luma | (min_luma << 8), max_luma | (max_luma << 8), pitch, row_size, height); |
| 779 | |||
| 780 |
5/10✓ Branch 204 → 205 taken 2 times.
✗ Branch 204 → 286 not taken.
✓ Branch 206 → 207 taken 2 times.
✗ Branch 206 → 286 not taken.
✓ Branch 208 → 209 taken 2 times.
✗ Branch 208 → 286 not taken.
✓ Branch 210 → 211 taken 2 times.
✗ Branch 210 → 286 not taken.
✓ Branch 211 → 212 taken 2 times.
✗ Branch 211 → 286 not taken.
|
2 | limit_plane_sse2(frame->GetWritePtr(PLANAR_U), min_chroma | (min_chroma << 8), max_chroma | (max_chroma << 8), |
| 781 | frame->GetPitch(PLANAR_U), frame->GetRowSize(PLANAR_U), frame->GetHeight(PLANAR_U)); | ||
| 782 | |||
| 783 |
5/10✓ Branch 213 → 214 taken 2 times.
✗ Branch 213 → 286 not taken.
✓ Branch 215 → 216 taken 2 times.
✗ Branch 215 → 286 not taken.
✓ Branch 217 → 218 taken 2 times.
✗ Branch 217 → 286 not taken.
✓ Branch 219 → 220 taken 2 times.
✗ Branch 219 → 286 not taken.
✓ Branch 220 → 221 taken 2 times.
✗ Branch 220 → 286 not taken.
|
2 | limit_plane_sse2(frame->GetWritePtr(PLANAR_V), min_chroma | (min_chroma << 8), max_chroma | (max_chroma << 8), |
| 784 | frame->GetPitch(PLANAR_V), frame->GetRowSize(PLANAR_V), frame->GetHeight(PLANAR_V)); | ||
| 785 | |||
| 786 | 2 | return frame; | |
| 787 | } | ||
| 788 | |||
| 789 | #ifdef X86_32 | ||
| 790 | if ((pixelsize==1) && (env->GetCPUFlags() & CPUF_INTEGER_SSE)) | ||
| 791 | { | ||
| 792 | limit_plane_isse(srcp, min_luma | (min_luma << 8), max_luma | (max_luma << 8), pitch, row_size, height); | ||
| 793 | limit_plane_isse(frame->GetWritePtr(PLANAR_U), min_chroma | (min_chroma << 8), max_chroma | (max_chroma << 8), | ||
| 794 | frame->GetPitch(PLANAR_U), frame->GetRowSize(PLANAR_U), frame->GetHeight(PLANAR_U)); | ||
| 795 | limit_plane_isse(frame->GetWritePtr(PLANAR_V), min_chroma | (min_chroma << 8), max_chroma | (max_chroma << 8), | ||
| 796 | frame->GetPitch(PLANAR_V), frame->GetRowSize(PLANAR_V), frame->GetHeight(PLANAR_V)); | ||
| 797 | |||
| 798 | return frame; | ||
| 799 | } | ||
| 800 | #endif | ||
| 801 | |||
| 802 |
1/2✓ Branch 222 → 223 taken 2 times.
✗ Branch 222 → 259 not taken.
|
2 | if (pixelsize == 2 ) |
| 803 | { | ||
| 804 |
2/4✓ Branch 223 → 224 taken 2 times.
✗ Branch 223 → 286 not taken.
✓ Branch 224 → 225 taken 2 times.
✗ Branch 224 → 241 not taken.
|
2 | if (env->GetCPUFlags() & CPUF_SSE4_1) { |
| 805 |
1/2✓ Branch 225 → 226 taken 2 times.
✗ Branch 225 → 286 not taken.
|
2 | limit_plane_uint16_sse4(srcp, min_luma, max_luma, pitch, height); |
| 806 | |||
| 807 |
4/8✓ Branch 227 → 228 taken 2 times.
✗ Branch 227 → 286 not taken.
✓ Branch 229 → 230 taken 2 times.
✗ Branch 229 → 286 not taken.
✓ Branch 231 → 232 taken 2 times.
✗ Branch 231 → 286 not taken.
✓ Branch 232 → 233 taken 2 times.
✗ Branch 232 → 286 not taken.
|
2 | limit_plane_uint16_sse4(frame->GetWritePtr(PLANAR_U), min_chroma, max_chroma, |
| 808 | frame->GetPitch(PLANAR_U), frame->GetHeight(PLANAR_U)); | ||
| 809 | |||
| 810 |
4/8✓ Branch 234 → 235 taken 2 times.
✗ Branch 234 → 286 not taken.
✓ Branch 236 → 237 taken 2 times.
✗ Branch 236 → 286 not taken.
✓ Branch 238 → 239 taken 2 times.
✗ Branch 238 → 286 not taken.
✓ Branch 239 → 240 taken 2 times.
✗ Branch 239 → 286 not taken.
|
2 | limit_plane_uint16_sse4(frame->GetWritePtr(PLANAR_V), min_chroma, max_chroma, |
| 811 | frame->GetPitch(PLANAR_V), frame->GetHeight(PLANAR_V)); | ||
| 812 | |||
| 813 | 2 | return frame; | |
| 814 | } | ||
| 815 | ✗ | if (env->GetCPUFlags() & CPUF_SSE2) { | |
| 816 | ✗ | limit_plane_uint16_sse2(srcp, min_luma, max_luma, pitch, height); | |
| 817 | |||
| 818 | ✗ | limit_plane_uint16_sse2(frame->GetWritePtr(PLANAR_U), min_chroma, max_chroma, | |
| 819 | frame->GetPitch(PLANAR_U), frame->GetHeight(PLANAR_U)); | ||
| 820 | |||
| 821 | ✗ | limit_plane_uint16_sse2(frame->GetWritePtr(PLANAR_V), min_chroma, max_chroma, | |
| 822 | frame->GetPitch(PLANAR_V), frame->GetHeight(PLANAR_V)); | ||
| 823 | |||
| 824 | ✗ | return frame; | |
| 825 | } | ||
| 826 | } | ||
| 827 | #endif | ||
| 828 | // C | ||
| 829 | // luma | ||
| 830 | ✗ | if(pixelsize == 1) | |
| 831 | ✗ | limit_plane_c<uint8_t>(srcp, pitch, min_luma, max_luma, width, height); | |
| 832 | ✗ | else if(pixelsize == 2) | |
| 833 | ✗ | limit_plane_c<uint16_t>(srcp, pitch, min_luma, max_luma, width, height); | |
| 834 | else // pixelsize == 4: 32 bit float | ||
| 835 | ✗ | limit_plane_f_c(srcp, pitch, min_luma_f, max_luma_f, width, height); | |
| 836 | |||
| 837 | // chroma if exists | ||
| 838 | ✗ | srcp = frame->GetWritePtr(PLANAR_U); | |
| 839 | ✗ | width = frame->GetRowSize(PLANAR_U) / pixelsize; | |
| 840 | ✗ | height = frame->GetHeight(PLANAR_U); | |
| 841 | ✗ | pitch = frame->GetPitch(PLANAR_U); | |
| 842 | ✗ | if (!pitch) | |
| 843 | ✗ | return frame; | |
| 844 | ✗ | BYTE* srcpV = frame->GetWritePtr(PLANAR_V); | |
| 845 | ✗ | if(pixelsize == 1) { | |
| 846 | ✗ | limit_plane_c<uint8_t>(srcp, pitch, min_chroma, max_chroma, width, height); | |
| 847 | ✗ | limit_plane_c<uint8_t>(srcpV, pitch, min_chroma, max_chroma, width, height); | |
| 848 | ✗ | } else if(pixelsize == 2) { | |
| 849 | ✗ | limit_plane_c<uint16_t>(srcp, pitch, min_chroma, max_chroma, width, height); | |
| 850 | ✗ | limit_plane_c<uint16_t>(srcpV, pitch, min_chroma, max_chroma, width, height); | |
| 851 | } | ||
| 852 | else { | ||
| 853 | // pixelsize == 4: 32 bit float | ||
| 854 | ✗ | limit_plane_f_c(srcp, pitch, min_chroma_f, max_chroma_f, width, height); | |
| 855 | ✗ | limit_plane_f_c(srcpV, pitch, min_chroma_f, max_chroma_f, width, height); | |
| 856 | } | ||
| 857 | } | ||
| 858 | ✗ | return frame; | |
| 859 | ✗ | } | |
| 860 | |||
| 861 | ✗ | AVSValue __cdecl Limiter::Create(AVSValue args, void*, IScriptEnvironment* env) | |
| 862 | { | ||
| 863 | ✗ | const char* option = args[5].AsString(nullptr); | |
| 864 | ✗ | show_e show = show_none; | |
| 865 | |||
| 866 | ✗ | if (option) { | |
| 867 | ✗ | if (lstrcmpi(option, "luma") == 0) | |
| 868 | ✗ | show = show_luma; | |
| 869 | ✗ | else if (lstrcmpi(option, "luma_grey") == 0) | |
| 870 | ✗ | show = show_luma_grey; | |
| 871 | ✗ | else if (lstrcmpi(option, "chroma") == 0) | |
| 872 | ✗ | show = show_chroma; | |
| 873 | ✗ | else if (lstrcmpi(option, "chroma_grey") == 0) | |
| 874 | ✗ | show = show_chroma_grey; | |
| 875 | else | ||
| 876 | ✗ | env->ThrowError("Limiter: show must be \"luma\", \"luma_grey\", \"chroma\" or \"chroma_grey\""); | |
| 877 | } | ||
| 878 | |||
| 879 | ✗ | const bool paramscale = args[6].AsBool(false); | |
| 880 | ✗ | return new Limiter(args[0].AsClip(), args[1].AsFloatf(-9999.0f), args[2].AsFloatf(-9999.0f), args[3].AsFloatf(-9999.0f), args[4].AsFloatf(-9999.0f), show, paramscale, env); | |
| 881 | } | ||
| 882 |