FFmpeg
Loading...
Searching...
No Matches
vf_threshold_init.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Paul B Mahol
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdint.h>
22
24#include "libavutil/cpu.h"
25#include "libavutil/x86/cpu.h"
27
28#define THRESHOLD_FUNC(depth, opt) \
29void ff_threshold##depth##_##opt(const uint8_t *in, const uint8_t *threshold,\
30 const uint8_t *min, const uint8_t *max, \
31 uint8_t *out, \
32 ptrdiff_t ilinesize, ptrdiff_t tlinesize, \
33 ptrdiff_t flinesize, ptrdiff_t slinesize, \
34 ptrdiff_t olinesize, \
35 int w, int h);
36
37THRESHOLD_FUNC(8, sse4)
38THRESHOLD_FUNC(8, avx2)
39THRESHOLD_FUNC(16, sse4)
40THRESHOLD_FUNC(16, avx2)
41
42static void threshold8_tail(const uint8_t *in, const uint8_t *threshold,
43 const uint8_t *min, const uint8_t *max,
44 uint8_t *out,
45 ptrdiff_t ilinesize, ptrdiff_t tlinesize,
46 ptrdiff_t flinesize, ptrdiff_t slinesize,
47 ptrdiff_t olinesize,
48 int start, int end, int h)
49{
50 for (int y = 0; y < h; y++) {
51 for (int x = start; x < end; x++)
52 out[x] = in[x] <= threshold[x] ? min[x] : max[x];
53 in += ilinesize;
54 threshold += tlinesize;
55 min += flinesize;
56 max += slinesize;
57 out += olinesize;
58 }
59}
60
61static void threshold16_tail(const uint8_t *iin, const uint8_t *tthreshold,
62 const uint8_t *ffirst, const uint8_t *ssecond,
63 uint8_t *oout,
64 ptrdiff_t ilinesize, ptrdiff_t tlinesize,
65 ptrdiff_t flinesize, ptrdiff_t slinesize,
66 ptrdiff_t olinesize,
67 int start, int end, int h)
68{
69 const uint16_t *in = (const uint16_t *)iin;
70 const uint16_t *threshold = (const uint16_t *)tthreshold;
71 const uint16_t *min = (const uint16_t *)ffirst;
72 const uint16_t *max = (const uint16_t *)ssecond;
73 uint16_t *out = (uint16_t *)oout;
74
75 for (int y = 0; y < h; y++) {
76 for (int x = start; x < end; x++)
77 out[x] = in[x] <= threshold[x] ? min[x] : max[x];
78 in += ilinesize / 2;
79 threshold += tlinesize / 2;
80 min += flinesize / 2;
81 max += slinesize / 2;
82 out += olinesize / 2;
83 }
84}
85
86#define THRESHOLD_X86(depth, opt, vec_elements) \
87static void threshold##depth##_##opt##_x86(const uint8_t *in, const uint8_t *threshold, \
88 const uint8_t *min, const uint8_t *max, \
89 uint8_t *out, \
90 ptrdiff_t ilinesize, ptrdiff_t tlinesize, \
91 ptrdiff_t flinesize, ptrdiff_t slinesize, \
92 ptrdiff_t olinesize, \
93 int w, int h) \
94{ \
95 int aligned_w = w & ~((vec_elements) - 1); \
96 if (aligned_w > 0) \
97 ff_threshold##depth##_##opt(in, threshold, min, max, out, \
98 ilinesize, tlinesize, flinesize, slinesize, olinesize, \
99 aligned_w, h); \
100 if (aligned_w < w) \
101 threshold##depth##_tail(in, threshold, min, max, out, \
102 ilinesize, tlinesize, flinesize, slinesize, olinesize, \
103 aligned_w, w, h); \
104}
105
106THRESHOLD_X86(8, sse4, 16)
107THRESHOLD_X86(8, avx2, 32)
108THRESHOLD_X86(16, sse4, 8)
109THRESHOLD_X86(16, avx2, 16)
110
112{
114
115 if (s->depth == 8) {
117 s->threshold = threshold8_sse4_x86;
118 }
120 s->threshold = threshold8_avx2_x86;
121 }
122 } else if (s->depth == 16) {
124 s->threshold = threshold16_sse4_x86;
125 }
127 s->threshold = threshold16_avx2_x86;
128 }
129 }
130}
static FILE * out
#define s(width, name)
Definition cbs_vp9.c:198
#define min(a, b)
#define max(a, b)
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
static atomic_int cpu_flags
Definition cpu.c:56
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define EXTERNAL_AVX2_FAST(flags)
Definition cpu.h:74
#define EXTERNAL_SSE4(flags)
Definition cpu.h:63
void ff_threshold_init_x86(ThresholdContext *s)
#define THRESHOLD_FUNC(depth, opt)
#define THRESHOLD_X86(depth, opt, vec_elements)
static void threshold16_tail(const uint8_t *iin, const uint8_t *tthreshold, const uint8_t *ffirst, const uint8_t *ssecond, uint8_t *oout, ptrdiff_t ilinesize, ptrdiff_t tlinesize, ptrdiff_t flinesize, ptrdiff_t slinesize, ptrdiff_t olinesize, int start, int end, int h)
static void threshold8_tail(const uint8_t *in, const uint8_t *threshold, const uint8_t *min, const uint8_t *max, uint8_t *out, ptrdiff_t ilinesize, ptrdiff_t tlinesize, ptrdiff_t flinesize, ptrdiff_t slinesize, ptrdiff_t olinesize, int start, int end, int h)