Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -56,6 +56,7 @@ static const enum AVPixelFormat supported_formats[] = { · 55 unmodified lines | ||
| 56 | 56 | enum { |
| 57 | 57 | INTERP_ALGO_DEFAULT, |
| 58 | 58 | |
| 59 | + INTERP_ALGO_NEAREST, | |
| 59 | 60 | INTERP_ALGO_BILINEAR, |
| 60 | 61 | INTERP_ALGO_BICUBIC, |
| 61 | 62 | |
| @@ -273,6 +274,12 @@ static av_cold int cudascale_config_props(AVFilterLink *outlink) · 211 unmodified lines | ||
| 273 | 274 | extern char vf_scale_cuda_bicubic_ptx[]; |
| 274 | 275 | |
| 275 | 276 | switch(s->interp_algo) { |
| 277 | + case INTERP_ALGO_NEAREST: | |
| 278 | + scaler_ptx = vf_scale_cuda_ptx; | |
| 279 | + function_infix = "_Nearest"; | |
| 280 | + s->interp_use_linear = 0; | |
| 281 | + s->interp_as_integer = 1; | |
| 282 | + break; | |
| 276 | 283 | case INTERP_ALGO_BILINEAR: |
| 277 | 284 | scaler_ptx = vf_scale_cuda_ptx; |
| 278 | 285 | function_infix = "_Bilinear"; |
| @@ -591,6 +598,7 @@ static const AVOption options[] = { · 312 unmodified lines | ||
| 591 | 598 | { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, { .str = "iw" }, .flags = FLAGS }, |
| 592 | 599 | { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, { .str = "ih" }, .flags = FLAGS }, |
| 593 | 600 | { "interp_algo", "Interpolation algorithm used for resizing", OFFSET(interp_algo), AV_OPT_TYPE_INT, { .i64 = INTERP_ALGO_DEFAULT }, 0, INTERP_ALGO_COUNT - 1, FLAGS, "interp_algo" }, |
| 601 | + { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_NEAREST }, 0, 0, FLAGS, "interp_algo" }, | |
| 594 | 602 | { "bilinear", "bilinear", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_BILINEAR }, 0, 0, FLAGS, "interp_algo" }, |
| 595 | 603 | { "bicubic", "bicubic", 0, AV_OPT_TYPE_CONST, { .i64 = INTERP_ALGO_BICUBIC }, 0, 0, FLAGS, "interp_algo" }, |
| 596 | 604 | { "passthrough", "Do not process frames at all if parameters match", OFFSET(passthrough), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, |
| @@ -22,6 +22,27 @@ · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | #include "cuda/vector_helpers.cuh" |
| 24 | 24 | |
| 25 | +template<typename T> | |
| 26 | +__device__ inline void Subsample_Nearest(cudaTextureObject_t tex, | |
| 27 | + T *dst, | |
| 28 | + int dst_width, int dst_height, int dst_pitch, | |
| 29 | + int src_width, int src_height, | |
| 30 | + int bit_depth) | |
| 31 | +{ | |
| 32 | + int xo = blockIdx.x * blockDim.x + threadIdx.x; | |
| 33 | + int yo = blockIdx.y * blockDim.y + threadIdx.y; | |
| 34 | + | |
| 35 | + if (yo < dst_height && xo < dst_width) | |
| 36 | + { | |
| 37 | + float hscale = (float)src_width / (float)dst_width; | |
| 38 | + float vscale = (float)src_height / (float)dst_height; | |
| 39 | + float xi = (xo + 0.5f) * hscale; | |
| 40 | + float yi = (yo + 0.5f) * vscale; | |
| 41 | + | |
| 42 | + dst[yo*dst_pitch+xo] = tex2D<T>(tex, xi, yi); | |
| 43 | + } | |
| 44 | +} | |
| 45 | + | |
| 25 | 46 | template<typename T> |
| 26 | 47 | __device__ inline void Subsample_Bilinear(cudaTextureObject_t tex, |
| 27 | 48 | T *dst, |
| @@ -57,6 +78,27 @@ __device__ inline void Subsample_Bilinear(cudaTextureObject_t tex, · 29 unmodified lines | ||
| 57 | 78 | |
| 58 | 79 | extern "C" { |
| 59 | 80 | |
| 81 | +#define NEAREST_KERNEL(T) \ | |
| 82 | + __global__ void Subsample_Nearest_ ## T(cudaTextureObject_t src_tex, \ | |
| 83 | + T *dst, \ | |
| 84 | + int dst_width, int dst_height, int dst_pitch, \ | |
| 85 | + int src_width, int src_height, \ | |
| 86 | + int bit_depth) \ | |
| 87 | + { \ | |
| 88 | + Subsample_Nearest<T>(src_tex, dst, \ | |
| 89 | + dst_width, dst_height, dst_pitch, \ | |
| 90 | + src_width, src_height, \ | |
| 91 | + bit_depth); \ | |
| 92 | + } | |
| 93 | + | |
| 94 | +NEAREST_KERNEL(uchar) | |
| 95 | +NEAREST_KERNEL(uchar2) | |
| 96 | +NEAREST_KERNEL(uchar4) | |
| 97 | + | |
| 98 | +NEAREST_KERNEL(ushort) | |
| 99 | +NEAREST_KERNEL(ushort2) | |
| 100 | +NEAREST_KERNEL(ushort4) | |
| 101 | + | |
| 60 | 102 | #define BILINEAR_KERNEL(T) \ |
| 61 | 103 | __global__ void Subsample_Bilinear_ ## T(cudaTextureObject_t src_tex, \ |
| 62 | 104 | T *dst, \ |