FFmpeg
Loading...
Searching...
No Matches
vf_colordetectdsp.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVFILTER_COLORDETECTDSP_H
20#define AVFILTER_COLORDETECTDSP_H
21
22#include <stddef.h>
23#include <stdint.h>
24
25#include "config.h"
26
28#include "libavutil/avassert.h"
29#include "libavutil/pixfmt.h"
30
34 FF_ALPHA_TRANSPARENT = 1 << 0, ///< alpha < alpha_max
35 FF_ALPHA_STRAIGHT = (1 << 1) | FF_ALPHA_TRANSPARENT, ///< alpha < pixel
36 /* No way to positively identify premultiplied alpha */
37};
38
40 /* Returns 1 if an out-of-range value was detected, 0 otherwise */
41 int (*detect_range)(const uint8_t *data, ptrdiff_t stride,
42 ptrdiff_t width, ptrdiff_t height,
43 int mpeg_min, int mpeg_max);
44
45 /* Returns an FFAlphaDetect enum value */
46 int (*detect_alpha)(const uint8_t *color, ptrdiff_t color_stride,
47 const uint8_t *alpha, ptrdiff_t alpha_stride,
48 ptrdiff_t width, ptrdiff_t height,
49 int alpha_max, int mpeg_range, int offset);
51
56
57static inline int ff_detect_range_impl_c(const uint8_t *data, ptrdiff_t stride,
58 ptrdiff_t width, ptrdiff_t height,
59 uint8_t mpeg_min, uint8_t mpeg_max)
60{
61 while (height--) {
62 uint8_t cond = 0;
63 for (int x = 0; x < width; x++) {
64 const uint8_t val = data[x];
65 cond |= val < mpeg_min || val > mpeg_max;
66 }
67 if (cond)
68 return 1;
69 data += stride;
70 }
71
72 return 0;
73}
74
75static inline int ff_detect_range_c(const uint8_t *data, ptrdiff_t stride,
76 ptrdiff_t width, ptrdiff_t height,
77 int mpeg_min, int mpeg_max)
78{
79 av_assume(mpeg_min >= 0 && mpeg_min <= UINT8_MAX);
80 av_assume(mpeg_max >= 0 && mpeg_max <= UINT8_MAX);
81 return ff_detect_range_impl_c(data, stride, width, height, mpeg_min, mpeg_max);
82}
83
84static inline int ff_detect_range16_impl_c(const uint8_t *data, ptrdiff_t stride,
85 ptrdiff_t width, ptrdiff_t height,
86 uint16_t mpeg_min, uint16_t mpeg_max)
87{
88 while (height--) {
89 const uint16_t *data16 = (const uint16_t *) data;
90 uint8_t cond = 0;
91 for (int x = 0; x < width; x++) {
92 const uint16_t val = data16[x];
93 cond |= val < mpeg_min || val > mpeg_max;
94 }
95 if (cond)
96 return 1;
97 data += stride;
98 }
99
100 return 0;
101}
102
103static inline int ff_detect_range16_c(const uint8_t *data, ptrdiff_t stride,
104 ptrdiff_t width, ptrdiff_t height,
105 int mpeg_min, int mpeg_max)
106{
107 av_assume(mpeg_min >= 0 && mpeg_min <= UINT16_MAX);
108 av_assume(mpeg_max >= 0 && mpeg_max <= UINT16_MAX);
109 return ff_detect_range16_impl_c(data, stride, width, height, mpeg_min, mpeg_max);
110}
111
112static inline int
113ff_detect_alpha_full_c(const uint8_t *color, ptrdiff_t color_stride,
114 const uint8_t *alpha, ptrdiff_t alpha_stride,
115 ptrdiff_t width, ptrdiff_t height,
116 int alpha_max, int mpeg_range, int offset)
117{
118 uint8_t transparent = 0;
119 while (height--) {
120 uint8_t straight = 0;
121 for (int x = 0; x < width; x++) {
122 straight |= color[x] > alpha[x];
123 transparent |= alpha[x] != alpha_max;
124 }
125 if (straight)
126 return FF_ALPHA_STRAIGHT;
127 color += color_stride;
128 alpha += alpha_stride;
129 }
130 return transparent ? FF_ALPHA_TRANSPARENT : 0;
131}
132
133static inline int
134ff_detect_alpha_limited_c(const uint8_t *color, ptrdiff_t color_stride,
135 const uint8_t *alpha, ptrdiff_t alpha_stride,
136 ptrdiff_t width, ptrdiff_t height,
137 int alpha_max, int mpeg_range, int offset)
138{
139 uint8_t transparent = 0;
140 while (height--) {
141 uint8_t straight = 0;
142 for (int x = 0; x < width; x++) {
143 straight |= alpha_max * color[x] - offset > mpeg_range * alpha[x];
144 transparent |= alpha[x] != alpha_max;
145 }
146 if (straight)
147 return FF_ALPHA_STRAIGHT;
148 color += color_stride;
149 alpha += alpha_stride;
150 }
151 return transparent ? FF_ALPHA_TRANSPARENT : 0;
152}
153
154static inline int
155ff_detect_alpha16_full_c(const uint8_t *color, ptrdiff_t color_stride,
156 const uint8_t *alpha, ptrdiff_t alpha_stride,
157 ptrdiff_t width, ptrdiff_t height,
158 int alpha_max, int mpeg_range, int offset)
159{
160 uint8_t transparent = 0;
161 while (height--) {
162 const uint16_t *color16 = (const uint16_t *) color;
163 const uint16_t *alpha16 = (const uint16_t *) alpha;
164 uint8_t straight = 0;
165 for (int x = 0; x < width; x++) {
166 straight |= color16[x] > alpha16[x];
167 transparent |= alpha16[x] != alpha_max;
168 }
169 if (straight)
170 return FF_ALPHA_STRAIGHT;
171 color += color_stride;
172 alpha += alpha_stride;
173 }
174 return transparent ? FF_ALPHA_TRANSPARENT : 0;
175}
176
177static inline int
178ff_detect_alpha16_limited_c(const uint8_t *color, ptrdiff_t color_stride,
179 const uint8_t *alpha, ptrdiff_t alpha_stride,
180 ptrdiff_t width, ptrdiff_t height,
181 int alpha_max, int mpeg_range, int offset)
182{
183 uint8_t transparent = 0;
184 while (height--) {
185 const uint16_t *color16 = (const uint16_t *) color;
186 const uint16_t *alpha16 = (const uint16_t *) alpha;
187 for (int x = 0; x < width; x++) {
188 if ((int64_t) alpha_max * color16[x] - offset > (int64_t) mpeg_range * alpha16[x])
189 return FF_ALPHA_STRAIGHT;
190 transparent |= alpha16[x] != alpha_max;
191 }
192 color += color_stride;
193 alpha += alpha_stride;
194 }
195 return transparent ? FF_ALPHA_TRANSPARENT : 0;
196}
197
198static av_cold inline void
201{
205 } else {
207 }
208
209#if ARCH_AARCH64
211#elif ARCH_X86 && HAVE_X86ASM
213#endif
214}
215
216#endif /* AVFILTER_COLORDETECTDSP_H */
static double val(void *priv, double ch)
Definition aeval.c:77
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assume(cond)
Definition avassert.h:119
long long int64_t
Definition coverity.c:34
static const int16_t alpha[]
Definition ilbcdata.h:55
unsigned offset
Definition libaomenc.c:763
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
const char data[16]
Definition mxf.c:149
int(* cond)(enum AVPixelFormat pix_fmt)
pixel format definitions
AVColorRange
Visual content value range.
Definition pixfmt.h:748
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
int(* detect_range)(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int mpeg_min, int mpeg_max)
int(* detect_alpha)(const uint8_t *color, ptrdiff_t color_stride, const uint8_t *alpha, ptrdiff_t alpha_stride, ptrdiff_t width, ptrdiff_t height, int alpha_max, int mpeg_range, int offset)
#define stride
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
FFAlphaDetect
@ FF_ALPHA_TRANSPARENT
alpha < alpha_max
@ FF_ALPHA_STRAIGHT
alpha < pixel
@ FF_ALPHA_UNDETERMINED
@ FF_ALPHA_NONE
static int ff_detect_range_impl_c(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, uint8_t mpeg_min, uint8_t mpeg_max)
void ff_color_detect_dsp_init_aarch64(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
static av_cold void ff_color_detect_dsp_init(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
static int ff_detect_alpha16_full_c(const uint8_t *color, ptrdiff_t color_stride, const uint8_t *alpha, ptrdiff_t alpha_stride, ptrdiff_t width, ptrdiff_t height, int alpha_max, int mpeg_range, int offset)
static int ff_detect_range_c(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int mpeg_min, int mpeg_max)
static int ff_detect_range16_impl_c(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, uint16_t mpeg_min, uint16_t mpeg_max)
static int ff_detect_alpha16_limited_c(const uint8_t *color, ptrdiff_t color_stride, const uint8_t *alpha, ptrdiff_t alpha_stride, ptrdiff_t width, ptrdiff_t height, int alpha_max, int mpeg_range, int offset)
static int ff_detect_alpha_full_c(const uint8_t *color, ptrdiff_t color_stride, const uint8_t *alpha, ptrdiff_t alpha_stride, ptrdiff_t width, ptrdiff_t height, int alpha_max, int mpeg_range, int offset)
static int ff_detect_alpha_limited_c(const uint8_t *color, ptrdiff_t color_stride, const uint8_t *alpha, ptrdiff_t alpha_stride, ptrdiff_t width, ptrdiff_t height, int alpha_max, int mpeg_range, int offset)
void ff_color_detect_dsp_init_x86(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
static int ff_detect_range16_c(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int mpeg_min, int mpeg_max)
color_range
static av_always_inline void color16(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)