FFmpeg
vf_colordetect.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_COLORDETECT_H
20 #define AVFILTER_COLORDETECT_H
21 
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 #include <libavutil/macros.h>
26 #include <libavutil/pixfmt.h>
27 
28 typedef struct FFColorDetectDSPContext {
29  /* Returns 1 if an out-of-range value was detected, 0 otherwise */
30  int (*detect_range)(const uint8_t *data, ptrdiff_t stride,
31  ptrdiff_t width, ptrdiff_t height,
32  int mpeg_min, int mpeg_max);
33 
34  /* Returns 1 if the color value exceeds the alpha value, 0 otherwise */
35  int (*detect_alpha)(const uint8_t *color, ptrdiff_t color_stride,
36  const uint8_t *alpha, ptrdiff_t alpha_stride,
37  ptrdiff_t width, ptrdiff_t height,
38  int p, int q, int k);
40 
43 
46 
47 static inline int ff_detect_range_c(const uint8_t *data, ptrdiff_t stride,
48  ptrdiff_t width, ptrdiff_t height,
49  int mpeg_min, int mpeg_max)
50 {
51  while (height--) {
52  for (int x = 0; x < width; x++) {
53  const uint8_t val = data[x];
54  if (val < mpeg_min || val > mpeg_max)
55  return 1;
56  }
57  data += stride;
58  }
59 
60  return 0;
61 }
62 
63 static inline int ff_detect_range16_c(const uint8_t *data, ptrdiff_t stride,
64  ptrdiff_t width, ptrdiff_t height,
65  int mpeg_min, int mpeg_max)
66 {
67  while (height--) {
68  const uint16_t *data16 = (const uint16_t *) data;
69  for (int x = 0; x < width; x++) {
70  const uint16_t val = data16[x];
71  if (val < mpeg_min || val > mpeg_max)
72  return 1;
73  }
74  data += stride;
75  }
76 
77  return 0;
78 }
79 
80 static inline int
81 ff_detect_alpha_full_c(const uint8_t *color, ptrdiff_t color_stride,
82  const uint8_t *alpha, ptrdiff_t alpha_stride,
83  ptrdiff_t width, ptrdiff_t height,
84  int p, int q, int k)
85 {
86  while (height--) {
87  for (int x = 0; x < width; x++) {
88  if (color[x] > alpha[x])
89  return 1;
90  }
91  color += color_stride;
92  alpha += alpha_stride;
93  }
94  return 0;
95 }
96 
97 static inline int
98 ff_detect_alpha_limited_c(const uint8_t *color, ptrdiff_t color_stride,
99  const uint8_t *alpha, ptrdiff_t alpha_stride,
100  ptrdiff_t width, ptrdiff_t height,
101  int p, int q, int k)
102 {
103  while (height--) {
104  for (int x = 0; x < width; x++) {
105  if (p * color[x] - k > q * alpha[x])
106  return 1;
107  }
108  color += color_stride;
109  alpha += alpha_stride;
110  }
111  return 0;
112 }
113 
114 static inline int
115 ff_detect_alpha16_full_c(const uint8_t *color, ptrdiff_t color_stride,
116  const uint8_t *alpha, ptrdiff_t alpha_stride,
117  ptrdiff_t width, ptrdiff_t height,
118  int p, int q, int k)
119 {
120  while (height--) {
121  const uint16_t *color16 = (const uint16_t *) color;
122  const uint16_t *alpha16 = (const uint16_t *) alpha;
123  for (int x = 0; x < width; x++) {
124  if (color16[x] > alpha16[x])
125  return 1;
126  }
127  color += color_stride;
128  alpha += alpha_stride;
129  }
130  return 0;
131 }
132 
133 static inline int
134 ff_detect_alpha16_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 p, int q, int k)
138 {
139  while (height--) {
140  const uint16_t *color16 = (const uint16_t *) color;
141  const uint16_t *alpha16 = (const uint16_t *) alpha;
142  for (int x = 0; x < width; x++) {
143  if ((int64_t) p * color16[x] - k > (int64_t) q * alpha16[x])
144  return 1;
145  }
146  color += color_stride;
147  alpha += alpha_stride;
148  }
149  return 0;
150 }
151 
152 #endif /* AVFILTER_COLORDETECT_H */
color
Definition: vf_paletteuse.c:513
int64_t
long long int64_t
Definition: coverity.c:34
data
const char data[16]
Definition: mxf.c:149
macros.h
val
static double val(void *priv, double ch)
Definition: aeval.c:77
color16
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)
Definition: vf_waveform.c:1743
color_range
color_range
Definition: vf_selectivecolor.c:43
ff_color_detect_dsp_init_x86
void ff_color_detect_dsp_init_x86(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
Definition: vf_colordetect_init.c:79
ff_detect_range16_c
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)
Definition: vf_colordetect.h:63
ff_detect_alpha_limited_c
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 p, int q, int k)
Definition: vf_colordetect.h:98
ff_detect_alpha_full_c
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 p, int q, int k)
Definition: vf_colordetect.h:81
height
#define height
Definition: dsp.h:89
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:97
ff_detect_alpha16_full_c
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 p, int q, int k)
Definition: vf_colordetect.h:115
ff_color_detect_dsp_init
void ff_color_detect_dsp_init(FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
Definition: vf_colordetect.c:232
FFColorDetectDSPContext::detect_range
int(* detect_range)(const uint8_t *data, ptrdiff_t stride, ptrdiff_t width, ptrdiff_t height, int mpeg_min, int mpeg_max)
Definition: vf_colordetect.h:30
ff_detect_alpha16_limited_c
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 p, int q, int k)
Definition: vf_colordetect.h:134
stride
#define stride
Definition: h264pred_template.c:536
pixfmt.h
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
FFColorDetectDSPContext
Definition: vf_colordetect.h:28
FFColorDetectDSPContext::detect_alpha
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 p, int q, int k)
Definition: vf_colordetect.h:35
width
#define width
Definition: dsp.h:89
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:732
ff_detect_range_c
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)
Definition: vf_colordetect.h:47