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
57#define DECL_DETECT_RANGE_IMPL(TYPE, NAME) \
58static inline int NAME(const uint8_t* data, ptrdiff_t stride, \
59 ptrdiff_t width, ptrdiff_t height, \
60 int mpeg_min, int mpeg_max) \
61{ \
62 const TYPE min = mpeg_min; \
63 const TYPE max = mpeg_max; \
64 av_assume(min == mpeg_min); \
65 av_assume(max == mpeg_max); \
66 \
67 while (height--) { \
68 const TYPE *row = (const TYPE *) data; \
69 uint8_t cond = 0; \
70 for (int x = 0; x < width; x++) { \
71 const TYPE val = row[x]; \
72 cond |= val < min || val > max; \
73 } \
74 if (cond) \
75 return 1; \
76 data += stride; \
77 } \
78 \
79 return 0; \
80}
81
82DECL_DETECT_RANGE_IMPL(uint8_t, ff_detect_range_c)
83DECL_DETECT_RANGE_IMPL(uint16_t, ff_detect_range16_c)
84
85#define DECL_DETECT_ALPHA_FULL_IMPL(TYPE, INTER, NAME) \
86static inline int NAME(const uint8_t* color, ptrdiff_t color_stride, \
87 const uint8_t* alpha, ptrdiff_t alpha_stride, \
88 ptrdiff_t width, ptrdiff_t height, int alpha_max, \
89 int mpeg_range, int offset) \
90{ \
91 const TYPE max = alpha_max; \
92 const INTER off = offset; \
93 av_assume(max == alpha_max); \
94 av_assume(off == offset); \
95 (void) mpeg_range; \
96 \
97 uint8_t transparent = 0; \
98 while (height--) { \
99 const TYPE *col = (const TYPE *) color; \
100 const TYPE *alp = (const TYPE *) alpha; \
101 uint8_t straight = 0; \
102 for (int x = 0; x < width; x++) { \
103 straight |= col[x] > alp[x] + off; \
104 transparent |= alp[x] != max; \
105 } \
106 if (straight) \
107 return FF_ALPHA_STRAIGHT; \
108 color += color_stride; \
109 alpha += alpha_stride; \
110 } \
111 return transparent ? FF_ALPHA_TRANSPARENT : 0; \
112}
113
114DECL_DETECT_ALPHA_FULL_IMPL(uint8_t, uint16_t, ff_detect_alpha_full_c)
115DECL_DETECT_ALPHA_FULL_IMPL(uint16_t, uint32_t, ff_detect_alpha16_full_c)
116
117#define DECL_DETECT_ALPHA_LIMITED_IMPL(TYPE, INTER, NAME) \
118static inline int NAME(const uint8_t* color, ptrdiff_t color_stride, \
119 const uint8_t* alpha, ptrdiff_t alpha_stride, \
120 ptrdiff_t width, ptrdiff_t height, int alpha_max, \
121 int mpeg_range, int offset) \
122{ \
123 const TYPE max = alpha_max; \
124 const INTER off = offset; \
125 const INTER range = mpeg_range; \
126 av_assume(max == alpha_max); \
127 av_assume(off == offset); \
128 av_assume(range == mpeg_range); \
129 \
130 uint8_t transparent = 0; \
131 while (height--) { \
132 const TYPE *col = (const TYPE *) color; \
133 const TYPE *alp = (const TYPE *) alpha; \
134 uint8_t straight = 0; \
135 for (int x = 0; x < width; x++) { \
136 straight |= (INTER) max * col[x] - off > range * alp[x]; \
137 transparent |= alp[x] != max; \
138 } \
139 if (straight) \
140 return FF_ALPHA_STRAIGHT; \
141 color += color_stride; \
142 alpha += alpha_stride; \
143 } \
144 return transparent ? FF_ALPHA_TRANSPARENT : 0; \
145}
146
147DECL_DETECT_ALPHA_LIMITED_IMPL(uint8_t, int32_t, ff_detect_alpha_limited_c)
148DECL_DETECT_ALPHA_LIMITED_IMPL(uint16_t, int64_t, ff_detect_alpha16_limited_c)
149
150static av_cold inline void
153{
154 dsp->detect_range = depth > 8 ? ff_detect_range16_c : ff_detect_range_c;
156 dsp->detect_alpha = depth > 8 ? ff_detect_alpha16_full_c : ff_detect_alpha_full_c;
157 } else {
158 dsp->detect_alpha = depth > 8 ? ff_detect_alpha16_limited_c : ff_detect_alpha_limited_c;
159 }
160
161#if ARCH_AARCH64
163#elif ARCH_X86 && HAVE_X86ASM
165#endif
166}
167
168#endif /* AVFILTER_COLORDETECTDSP_H */
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
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
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
#define DECL_DETECT_ALPHA_LIMITED_IMPL(TYPE, INTER, NAME)
#define DECL_DETECT_RANGE_IMPL(TYPE, NAME)
FFAlphaDetect
@ FF_ALPHA_TRANSPARENT
alpha < alpha_max
@ FF_ALPHA_STRAIGHT
alpha < pixel
@ FF_ALPHA_UNDETERMINED
@ FF_ALPHA_NONE
void ff_color_detect_dsp_init_x86(FFColorDetectDSPContext *dsp, int depth, int offset, enum AVColorRange color_range)
void ff_color_detect_dsp_init_aarch64(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
#define DECL_DETECT_ALPHA_FULL_IMPL(TYPE, INTER, NAME)
static av_cold void ff_color_detect_dsp_init(FFColorDetectDSPContext *dsp, int depth, int offset, enum AVColorRange color_range)
color_range