Line | Branch | Exec | Source |
---|---|---|---|
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); | ||
39 | } FFColorDetectDSPContext; | ||
40 | |||
41 | void ff_color_detect_dsp_init(FFColorDetectDSPContext *dsp, int depth, | ||
42 | enum AVColorRange color_range); | ||
43 | |||
44 | void ff_color_detect_dsp_init_x86(FFColorDetectDSPContext *dsp, int depth, | ||
45 | enum AVColorRange color_range); | ||
46 | |||
47 | 61 | 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 |
2/2✓ Branch 0 taken 476 times.
✓ Branch 1 taken 48 times.
|
524 | while (height--) { |
52 |
2/2✓ Branch 0 taken 97905 times.
✓ Branch 1 taken 463 times.
|
98368 | for (int x = 0; x < width; x++) { |
53 | 97905 | const uint8_t val = data[x]; | |
54 |
3/4✓ Branch 0 taken 97892 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97892 times.
|
97905 | if (val < mpeg_min || val > mpeg_max) |
55 | 13 | return 1; | |
56 | } | ||
57 | 463 | data += stride; | |
58 | } | ||
59 | |||
60 | 48 | return 0; | |
61 | } | ||
62 | |||
63 | 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 |
2/2✓ Branch 0 taken 498 times.
✓ Branch 1 taken 50 times.
|
548 | while (height--) { |
68 | 498 | const uint16_t *data16 = (const uint16_t *) data; | |
69 |
2/2✓ Branch 0 taken 48165 times.
✓ Branch 1 taken 485 times.
|
48650 | for (int x = 0; x < width; x++) { |
70 | 48165 | const uint16_t val = data16[x]; | |
71 |
3/4✓ Branch 0 taken 48152 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48152 times.
|
48165 | if (val < mpeg_min || val > mpeg_max) |
72 | 13 | return 1; | |
73 | } | ||
74 | 485 | data += stride; | |
75 | } | ||
76 | |||
77 | 50 | return 0; | |
78 | } | ||
79 | |||
80 | static inline int | ||
81 | 57 | 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 |
2/2✓ Branch 0 taken 426 times.
✓ Branch 1 taken 44 times.
|
470 | while (height--) { |
87 |
2/2✓ Branch 0 taken 94833 times.
✓ Branch 1 taken 413 times.
|
95246 | for (int x = 0; x < width; x++) { |
88 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 94820 times.
|
94833 | if (color[x] > alpha[x]) |
89 | 13 | return 1; | |
90 | } | ||
91 | 413 | color += color_stride; | |
92 | 413 | alpha += alpha_stride; | |
93 | } | ||
94 | 44 | return 0; | |
95 | } | ||
96 | |||
97 | static inline int | ||
98 | 61 | 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 |
2/2✓ Branch 0 taken 454 times.
✓ Branch 1 taken 44 times.
|
498 | while (height--) { |
104 |
2/2✓ Branch 0 taken 91446 times.
✓ Branch 1 taken 437 times.
|
91883 | for (int x = 0; x < width; x++) { |
105 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 91429 times.
|
91446 | if (p * color[x] - k > q * alpha[x]) |
106 | 17 | return 1; | |
107 | } | ||
108 | 437 | color += color_stride; | |
109 | 437 | alpha += alpha_stride; | |
110 | } | ||
111 | 44 | return 0; | |
112 | } | ||
113 | |||
114 | static inline int | ||
115 | 58 | 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 |
2/2✓ Branch 0 taken 428 times.
✓ Branch 1 taken 42 times.
|
470 | while (height--) { |
121 | 428 | const uint16_t *color16 = (const uint16_t *) color; | |
122 | 428 | const uint16_t *alpha16 = (const uint16_t *) alpha; | |
123 |
2/2✓ Branch 0 taken 46126 times.
✓ Branch 1 taken 412 times.
|
46538 | for (int x = 0; x < width; x++) { |
124 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 46110 times.
|
46126 | if (color16[x] > alpha16[x]) |
125 | 16 | return 1; | |
126 | } | ||
127 | 412 | color += color_stride; | |
128 | 412 | alpha += alpha_stride; | |
129 | } | ||
130 | 42 | return 0; | |
131 | } | ||
132 | |||
133 | static inline int | ||
134 | 63 | 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 |
2/2✓ Branch 0 taken 486 times.
✓ Branch 1 taken 48 times.
|
534 | while (height--) { |
140 | 486 | const uint16_t *color16 = (const uint16_t *) color; | |
141 | 486 | const uint16_t *alpha16 = (const uint16_t *) alpha; | |
142 |
2/2✓ Branch 0 taken 46595 times.
✓ Branch 1 taken 471 times.
|
47066 | for (int x = 0; x < width; x++) { |
143 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 46580 times.
|
46595 | if ((int64_t) p * color16[x] - k > (int64_t) q * alpha16[x]) |
144 | 15 | return 1; | |
145 | } | ||
146 | 471 | color += color_stride; | |
147 | 471 | alpha += alpha_stride; | |
148 | } | ||
149 | 48 | return 0; | |
150 | } | ||
151 | |||
152 | #endif /* AVFILTER_COLORDETECT_H */ | ||
153 |