Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2024 Niklas Haas | ||
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 "libavutil/avassert.h" | ||
22 | #include "libavutil/hdr_dynamic_metadata.h" | ||
23 | #include "libavutil/mastering_display_metadata.h" | ||
24 | |||
25 | #include "format.h" | ||
26 | |||
27 | typedef struct FormatEntry { | ||
28 | uint8_t is_supported_in :1; | ||
29 | uint8_t is_supported_out :1; | ||
30 | uint8_t is_supported_endianness :1; | ||
31 | } FormatEntry; | ||
32 | |||
33 | /* Format support table for legacy swscale */ | ||
34 | static const FormatEntry format_entries[] = { | ||
35 | [AV_PIX_FMT_YUV420P] = { 1, 1 }, | ||
36 | [AV_PIX_FMT_YUYV422] = { 1, 1 }, | ||
37 | [AV_PIX_FMT_RGB24] = { 1, 1 }, | ||
38 | [AV_PIX_FMT_BGR24] = { 1, 1 }, | ||
39 | [AV_PIX_FMT_YUV422P] = { 1, 1 }, | ||
40 | [AV_PIX_FMT_YUV444P] = { 1, 1 }, | ||
41 | [AV_PIX_FMT_YUV410P] = { 1, 1 }, | ||
42 | [AV_PIX_FMT_YUV411P] = { 1, 1 }, | ||
43 | [AV_PIX_FMT_GRAY8] = { 1, 1 }, | ||
44 | [AV_PIX_FMT_MONOWHITE] = { 1, 1 }, | ||
45 | [AV_PIX_FMT_MONOBLACK] = { 1, 1 }, | ||
46 | [AV_PIX_FMT_PAL8] = { 1, 0 }, | ||
47 | [AV_PIX_FMT_YUVJ420P] = { 1, 1 }, | ||
48 | [AV_PIX_FMT_YUVJ411P] = { 1, 1 }, | ||
49 | [AV_PIX_FMT_YUVJ422P] = { 1, 1 }, | ||
50 | [AV_PIX_FMT_YUVJ444P] = { 1, 1 }, | ||
51 | [AV_PIX_FMT_YVYU422] = { 1, 1 }, | ||
52 | [AV_PIX_FMT_UYVY422] = { 1, 1 }, | ||
53 | [AV_PIX_FMT_UYYVYY411] = { 1, 0 }, | ||
54 | [AV_PIX_FMT_BGR8] = { 1, 1 }, | ||
55 | [AV_PIX_FMT_BGR4] = { 0, 1 }, | ||
56 | [AV_PIX_FMT_BGR4_BYTE] = { 1, 1 }, | ||
57 | [AV_PIX_FMT_RGB8] = { 1, 1 }, | ||
58 | [AV_PIX_FMT_RGB4] = { 0, 1 }, | ||
59 | [AV_PIX_FMT_RGB4_BYTE] = { 1, 1 }, | ||
60 | [AV_PIX_FMT_NV12] = { 1, 1 }, | ||
61 | [AV_PIX_FMT_NV21] = { 1, 1 }, | ||
62 | [AV_PIX_FMT_ARGB] = { 1, 1 }, | ||
63 | [AV_PIX_FMT_RGBA] = { 1, 1 }, | ||
64 | [AV_PIX_FMT_ABGR] = { 1, 1 }, | ||
65 | [AV_PIX_FMT_BGRA] = { 1, 1 }, | ||
66 | [AV_PIX_FMT_0RGB] = { 1, 1 }, | ||
67 | [AV_PIX_FMT_RGB0] = { 1, 1 }, | ||
68 | [AV_PIX_FMT_0BGR] = { 1, 1 }, | ||
69 | [AV_PIX_FMT_BGR0] = { 1, 1 }, | ||
70 | [AV_PIX_FMT_GRAY9BE] = { 1, 1 }, | ||
71 | [AV_PIX_FMT_GRAY9LE] = { 1, 1 }, | ||
72 | [AV_PIX_FMT_GRAY10BE] = { 1, 1 }, | ||
73 | [AV_PIX_FMT_GRAY10LE] = { 1, 1 }, | ||
74 | [AV_PIX_FMT_GRAY12BE] = { 1, 1 }, | ||
75 | [AV_PIX_FMT_GRAY12LE] = { 1, 1 }, | ||
76 | [AV_PIX_FMT_GRAY14BE] = { 1, 1 }, | ||
77 | [AV_PIX_FMT_GRAY14LE] = { 1, 1 }, | ||
78 | [AV_PIX_FMT_GRAY16BE] = { 1, 1 }, | ||
79 | [AV_PIX_FMT_GRAY16LE] = { 1, 1 }, | ||
80 | [AV_PIX_FMT_YUV440P] = { 1, 1 }, | ||
81 | [AV_PIX_FMT_YUVJ440P] = { 1, 1 }, | ||
82 | [AV_PIX_FMT_YUV440P10LE] = { 1, 1 }, | ||
83 | [AV_PIX_FMT_YUV440P10BE] = { 1, 1 }, | ||
84 | [AV_PIX_FMT_YUV440P12LE] = { 1, 1 }, | ||
85 | [AV_PIX_FMT_YUV440P12BE] = { 1, 1 }, | ||
86 | [AV_PIX_FMT_YUVA420P] = { 1, 1 }, | ||
87 | [AV_PIX_FMT_YUVA422P] = { 1, 1 }, | ||
88 | [AV_PIX_FMT_YUVA444P] = { 1, 1 }, | ||
89 | [AV_PIX_FMT_YUVA420P9BE] = { 1, 1 }, | ||
90 | [AV_PIX_FMT_YUVA420P9LE] = { 1, 1 }, | ||
91 | [AV_PIX_FMT_YUVA422P9BE] = { 1, 1 }, | ||
92 | [AV_PIX_FMT_YUVA422P9LE] = { 1, 1 }, | ||
93 | [AV_PIX_FMT_YUVA444P9BE] = { 1, 1 }, | ||
94 | [AV_PIX_FMT_YUVA444P9LE] = { 1, 1 }, | ||
95 | [AV_PIX_FMT_YUVA420P10BE] = { 1, 1 }, | ||
96 | [AV_PIX_FMT_YUVA420P10LE] = { 1, 1 }, | ||
97 | [AV_PIX_FMT_YUVA422P10BE] = { 1, 1 }, | ||
98 | [AV_PIX_FMT_YUVA422P10LE] = { 1, 1 }, | ||
99 | [AV_PIX_FMT_YUVA444P10BE] = { 1, 1 }, | ||
100 | [AV_PIX_FMT_YUVA444P10LE] = { 1, 1 }, | ||
101 | [AV_PIX_FMT_YUVA420P16BE] = { 1, 1 }, | ||
102 | [AV_PIX_FMT_YUVA420P16LE] = { 1, 1 }, | ||
103 | [AV_PIX_FMT_YUVA422P16BE] = { 1, 1 }, | ||
104 | [AV_PIX_FMT_YUVA422P16LE] = { 1, 1 }, | ||
105 | [AV_PIX_FMT_YUVA444P16BE] = { 1, 1 }, | ||
106 | [AV_PIX_FMT_YUVA444P16LE] = { 1, 1 }, | ||
107 | [AV_PIX_FMT_RGB48BE] = { 1, 1 }, | ||
108 | [AV_PIX_FMT_RGB48LE] = { 1, 1 }, | ||
109 | [AV_PIX_FMT_RGBA64BE] = { 1, 1, 1 }, | ||
110 | [AV_PIX_FMT_RGBA64LE] = { 1, 1, 1 }, | ||
111 | [AV_PIX_FMT_RGB565BE] = { 1, 1 }, | ||
112 | [AV_PIX_FMT_RGB565LE] = { 1, 1 }, | ||
113 | [AV_PIX_FMT_RGB555BE] = { 1, 1 }, | ||
114 | [AV_PIX_FMT_RGB555LE] = { 1, 1 }, | ||
115 | [AV_PIX_FMT_BGR565BE] = { 1, 1 }, | ||
116 | [AV_PIX_FMT_BGR565LE] = { 1, 1 }, | ||
117 | [AV_PIX_FMT_BGR555BE] = { 1, 1 }, | ||
118 | [AV_PIX_FMT_BGR555LE] = { 1, 1 }, | ||
119 | [AV_PIX_FMT_YUV420P16LE] = { 1, 1 }, | ||
120 | [AV_PIX_FMT_YUV420P16BE] = { 1, 1 }, | ||
121 | [AV_PIX_FMT_YUV422P16LE] = { 1, 1 }, | ||
122 | [AV_PIX_FMT_YUV422P16BE] = { 1, 1 }, | ||
123 | [AV_PIX_FMT_YUV444P16LE] = { 1, 1 }, | ||
124 | [AV_PIX_FMT_YUV444P16BE] = { 1, 1 }, | ||
125 | [AV_PIX_FMT_RGB444LE] = { 1, 1 }, | ||
126 | [AV_PIX_FMT_RGB444BE] = { 1, 1 }, | ||
127 | [AV_PIX_FMT_BGR444LE] = { 1, 1 }, | ||
128 | [AV_PIX_FMT_BGR444BE] = { 1, 1 }, | ||
129 | [AV_PIX_FMT_YA8] = { 1, 1 }, | ||
130 | [AV_PIX_FMT_YA16BE] = { 1, 1 }, | ||
131 | [AV_PIX_FMT_YA16LE] = { 1, 1 }, | ||
132 | [AV_PIX_FMT_BGR48BE] = { 1, 1 }, | ||
133 | [AV_PIX_FMT_BGR48LE] = { 1, 1 }, | ||
134 | [AV_PIX_FMT_BGRA64BE] = { 1, 1, 1 }, | ||
135 | [AV_PIX_FMT_BGRA64LE] = { 1, 1, 1 }, | ||
136 | [AV_PIX_FMT_YUV420P9BE] = { 1, 1 }, | ||
137 | [AV_PIX_FMT_YUV420P9LE] = { 1, 1 }, | ||
138 | [AV_PIX_FMT_YUV420P10BE] = { 1, 1 }, | ||
139 | [AV_PIX_FMT_YUV420P10LE] = { 1, 1 }, | ||
140 | [AV_PIX_FMT_YUV420P12BE] = { 1, 1 }, | ||
141 | [AV_PIX_FMT_YUV420P12LE] = { 1, 1 }, | ||
142 | [AV_PIX_FMT_YUV420P14BE] = { 1, 1 }, | ||
143 | [AV_PIX_FMT_YUV420P14LE] = { 1, 1 }, | ||
144 | [AV_PIX_FMT_YUV422P9BE] = { 1, 1 }, | ||
145 | [AV_PIX_FMT_YUV422P9LE] = { 1, 1 }, | ||
146 | [AV_PIX_FMT_YUV422P10BE] = { 1, 1 }, | ||
147 | [AV_PIX_FMT_YUV422P10LE] = { 1, 1 }, | ||
148 | [AV_PIX_FMT_YUV422P12BE] = { 1, 1 }, | ||
149 | [AV_PIX_FMT_YUV422P12LE] = { 1, 1 }, | ||
150 | [AV_PIX_FMT_YUV422P14BE] = { 1, 1 }, | ||
151 | [AV_PIX_FMT_YUV422P14LE] = { 1, 1 }, | ||
152 | [AV_PIX_FMT_YUV444P9BE] = { 1, 1 }, | ||
153 | [AV_PIX_FMT_YUV444P9LE] = { 1, 1 }, | ||
154 | [AV_PIX_FMT_YUV444P10BE] = { 1, 1 }, | ||
155 | [AV_PIX_FMT_YUV444P10LE] = { 1, 1 }, | ||
156 | [AV_PIX_FMT_YUV444P12BE] = { 1, 1 }, | ||
157 | [AV_PIX_FMT_YUV444P12LE] = { 1, 1 }, | ||
158 | [AV_PIX_FMT_YUV444P14BE] = { 1, 1 }, | ||
159 | [AV_PIX_FMT_YUV444P14LE] = { 1, 1 }, | ||
160 | [AV_PIX_FMT_GBRP] = { 1, 1 }, | ||
161 | [AV_PIX_FMT_GBRP9LE] = { 1, 1 }, | ||
162 | [AV_PIX_FMT_GBRP9BE] = { 1, 1 }, | ||
163 | [AV_PIX_FMT_GBRP10LE] = { 1, 1 }, | ||
164 | [AV_PIX_FMT_GBRP10BE] = { 1, 1 }, | ||
165 | [AV_PIX_FMT_GBRAP10LE] = { 1, 1 }, | ||
166 | [AV_PIX_FMT_GBRAP10BE] = { 1, 1 }, | ||
167 | [AV_PIX_FMT_GBRP12LE] = { 1, 1 }, | ||
168 | [AV_PIX_FMT_GBRP12BE] = { 1, 1 }, | ||
169 | [AV_PIX_FMT_GBRAP12LE] = { 1, 1 }, | ||
170 | [AV_PIX_FMT_GBRAP12BE] = { 1, 1 }, | ||
171 | [AV_PIX_FMT_GBRP14LE] = { 1, 1 }, | ||
172 | [AV_PIX_FMT_GBRP14BE] = { 1, 1 }, | ||
173 | [AV_PIX_FMT_GBRAP14LE] = { 1, 1 }, | ||
174 | [AV_PIX_FMT_GBRAP14BE] = { 1, 1 }, | ||
175 | [AV_PIX_FMT_GBRP16LE] = { 1, 1 }, | ||
176 | [AV_PIX_FMT_GBRP16BE] = { 1, 1 }, | ||
177 | [AV_PIX_FMT_GBRPF32LE] = { 1, 1 }, | ||
178 | [AV_PIX_FMT_GBRPF32BE] = { 1, 1 }, | ||
179 | [AV_PIX_FMT_GBRAPF32LE] = { 1, 1 }, | ||
180 | [AV_PIX_FMT_GBRAPF32BE] = { 1, 1 }, | ||
181 | [AV_PIX_FMT_GBRPF16LE] = { 1, 0 }, | ||
182 | [AV_PIX_FMT_GBRPF16BE] = { 1, 0 }, | ||
183 | [AV_PIX_FMT_GBRAPF16LE] = { 1, 0 }, | ||
184 | [AV_PIX_FMT_GBRAPF16BE] = { 1, 0 }, | ||
185 | [AV_PIX_FMT_GBRAP] = { 1, 1 }, | ||
186 | [AV_PIX_FMT_GBRAP16LE] = { 1, 1 }, | ||
187 | [AV_PIX_FMT_GBRAP16BE] = { 1, 1 }, | ||
188 | [AV_PIX_FMT_BAYER_BGGR8] = { 1, 0 }, | ||
189 | [AV_PIX_FMT_BAYER_RGGB8] = { 1, 0 }, | ||
190 | [AV_PIX_FMT_BAYER_GBRG8] = { 1, 0 }, | ||
191 | [AV_PIX_FMT_BAYER_GRBG8] = { 1, 0 }, | ||
192 | [AV_PIX_FMT_BAYER_BGGR16LE] = { 1, 0 }, | ||
193 | [AV_PIX_FMT_BAYER_BGGR16BE] = { 1, 0 }, | ||
194 | [AV_PIX_FMT_BAYER_RGGB16LE] = { 1, 0 }, | ||
195 | [AV_PIX_FMT_BAYER_RGGB16BE] = { 1, 0 }, | ||
196 | [AV_PIX_FMT_BAYER_GBRG16LE] = { 1, 0 }, | ||
197 | [AV_PIX_FMT_BAYER_GBRG16BE] = { 1, 0 }, | ||
198 | [AV_PIX_FMT_BAYER_GRBG16LE] = { 1, 0 }, | ||
199 | [AV_PIX_FMT_BAYER_GRBG16BE] = { 1, 0 }, | ||
200 | [AV_PIX_FMT_XYZ12BE] = { 1, 1, 1 }, | ||
201 | [AV_PIX_FMT_XYZ12LE] = { 1, 1, 1 }, | ||
202 | [AV_PIX_FMT_AYUV64LE] = { 1, 1}, | ||
203 | [AV_PIX_FMT_AYUV64BE] = { 1, 1 }, | ||
204 | [AV_PIX_FMT_P010LE] = { 1, 1 }, | ||
205 | [AV_PIX_FMT_P010BE] = { 1, 1 }, | ||
206 | [AV_PIX_FMT_P012LE] = { 1, 1 }, | ||
207 | [AV_PIX_FMT_P012BE] = { 1, 1 }, | ||
208 | [AV_PIX_FMT_P016LE] = { 1, 1 }, | ||
209 | [AV_PIX_FMT_P016BE] = { 1, 1 }, | ||
210 | [AV_PIX_FMT_GRAYF32LE] = { 1, 1 }, | ||
211 | [AV_PIX_FMT_GRAYF32BE] = { 1, 1 }, | ||
212 | [AV_PIX_FMT_GRAYF16LE] = { 1, 0 }, | ||
213 | [AV_PIX_FMT_GRAYF16BE] = { 1, 0 }, | ||
214 | [AV_PIX_FMT_YAF32LE] = { 1, 0 }, | ||
215 | [AV_PIX_FMT_YAF32BE] = { 1, 0 }, | ||
216 | [AV_PIX_FMT_YAF16LE] = { 1, 0 }, | ||
217 | [AV_PIX_FMT_YAF16BE] = { 1, 0 }, | ||
218 | [AV_PIX_FMT_YUVA422P12BE] = { 1, 1 }, | ||
219 | [AV_PIX_FMT_YUVA422P12LE] = { 1, 1 }, | ||
220 | [AV_PIX_FMT_YUVA444P12BE] = { 1, 1 }, | ||
221 | [AV_PIX_FMT_YUVA444P12LE] = { 1, 1 }, | ||
222 | [AV_PIX_FMT_NV24] = { 1, 1 }, | ||
223 | [AV_PIX_FMT_NV42] = { 1, 1 }, | ||
224 | [AV_PIX_FMT_Y210LE] = { 1, 1 }, | ||
225 | [AV_PIX_FMT_Y212LE] = { 1, 1 }, | ||
226 | [AV_PIX_FMT_Y216LE] = { 1, 1 }, | ||
227 | [AV_PIX_FMT_X2RGB10LE] = { 1, 1 }, | ||
228 | [AV_PIX_FMT_X2BGR10LE] = { 1, 1 }, | ||
229 | [AV_PIX_FMT_NV20BE] = { 1, 1 }, | ||
230 | [AV_PIX_FMT_NV20LE] = { 1, 1 }, | ||
231 | [AV_PIX_FMT_P210BE] = { 1, 1 }, | ||
232 | [AV_PIX_FMT_P210LE] = { 1, 1 }, | ||
233 | [AV_PIX_FMT_P212BE] = { 1, 1 }, | ||
234 | [AV_PIX_FMT_P212LE] = { 1, 1 }, | ||
235 | [AV_PIX_FMT_P410BE] = { 1, 1 }, | ||
236 | [AV_PIX_FMT_P410LE] = { 1, 1 }, | ||
237 | [AV_PIX_FMT_P412BE] = { 1, 1 }, | ||
238 | [AV_PIX_FMT_P412LE] = { 1, 1 }, | ||
239 | [AV_PIX_FMT_P216BE] = { 1, 1 }, | ||
240 | [AV_PIX_FMT_P216LE] = { 1, 1 }, | ||
241 | [AV_PIX_FMT_P416BE] = { 1, 1 }, | ||
242 | [AV_PIX_FMT_P416LE] = { 1, 1 }, | ||
243 | [AV_PIX_FMT_NV16] = { 1, 1 }, | ||
244 | [AV_PIX_FMT_VUYA] = { 1, 1 }, | ||
245 | [AV_PIX_FMT_VUYX] = { 1, 1 }, | ||
246 | [AV_PIX_FMT_RGBAF16BE] = { 1, 0 }, | ||
247 | [AV_PIX_FMT_RGBAF16LE] = { 1, 0 }, | ||
248 | [AV_PIX_FMT_RGBF16BE] = { 1, 0 }, | ||
249 | [AV_PIX_FMT_RGBF16LE] = { 1, 0 }, | ||
250 | [AV_PIX_FMT_RGBF32BE] = { 1, 0 }, | ||
251 | [AV_PIX_FMT_RGBF32LE] = { 1, 0 }, | ||
252 | [AV_PIX_FMT_XV30LE] = { 1, 1 }, | ||
253 | [AV_PIX_FMT_XV36LE] = { 1, 1 }, | ||
254 | [AV_PIX_FMT_XV36BE] = { 1, 1 }, | ||
255 | [AV_PIX_FMT_XV48LE] = { 1, 1 }, | ||
256 | [AV_PIX_FMT_XV48BE] = { 1, 1 }, | ||
257 | [AV_PIX_FMT_AYUV] = { 1, 1 }, | ||
258 | [AV_PIX_FMT_UYVA] = { 1, 1 }, | ||
259 | [AV_PIX_FMT_VYU444] = { 1, 1 }, | ||
260 | [AV_PIX_FMT_V30XLE] = { 1, 1 }, | ||
261 | }; | ||
262 | |||
263 | 1780796 | int sws_isSupportedInput(enum AVPixelFormat pix_fmt) | |
264 | { | ||
265 | 1780796 | return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ? | |
266 |
2/2✓ Branch 0 taken 1767998 times.
✓ Branch 1 taken 12798 times.
|
1780796 | format_entries[pix_fmt].is_supported_in : 0; |
267 | } | ||
268 | |||
269 | 1780796 | int sws_isSupportedOutput(enum AVPixelFormat pix_fmt) | |
270 | { | ||
271 | 1780796 | return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ? | |
272 |
2/2✓ Branch 0 taken 1767998 times.
✓ Branch 1 taken 12798 times.
|
1780796 | format_entries[pix_fmt].is_supported_out : 0; |
273 | } | ||
274 | |||
275 | 30400 | int sws_isSupportedEndiannessConversion(enum AVPixelFormat pix_fmt) | |
276 | { | ||
277 | 30400 | return (unsigned)pix_fmt < FF_ARRAY_ELEMS(format_entries) ? | |
278 |
1/2✓ Branch 0 taken 30400 times.
✗ Branch 1 not taken.
|
30400 | format_entries[pix_fmt].is_supported_endianness : 0; |
279 | } | ||
280 | |||
281 | /** | ||
282 | * This function also sanitizes and strips the input data, removing irrelevant | ||
283 | * fields for certain formats. | ||
284 | */ | ||
285 | 403422 | SwsFormat ff_fmt_from_frame(const AVFrame *frame, int field) | |
286 | { | ||
287 | 403422 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
288 | const AVColorPrimariesDesc *primaries; | ||
289 | AVFrameSideData *sd; | ||
290 | |||
291 | 403422 | SwsFormat fmt = { | |
292 | 403422 | .width = frame->width, | |
293 | 403422 | .height = frame->height, | |
294 | 403422 | .format = frame->format, | |
295 | 403422 | .range = frame->color_range, | |
296 | 403422 | .csp = frame->colorspace, | |
297 | 403422 | .loc = frame->chroma_location, | |
298 | .desc = desc, | ||
299 | .color = { | ||
300 | 403422 | .prim = frame->color_primaries, | |
301 | 403422 | .trc = frame->color_trc, | |
302 | }, | ||
303 | }; | ||
304 | |||
305 | av_assert1(fmt.width > 0); | ||
306 | av_assert1(fmt.height > 0); | ||
307 | av_assert1(fmt.format != AV_PIX_FMT_NONE); | ||
308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 403422 times.
|
403422 | av_assert0(desc); |
309 |
2/2✓ Branch 0 taken 121594 times.
✓ Branch 1 taken 281828 times.
|
403422 | if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL | AV_PIX_FMT_FLAG_BAYER)) { |
310 | /* RGB-like family */ | ||
311 | 121594 | fmt.csp = AVCOL_SPC_RGB; | |
312 | 121594 | fmt.range = AVCOL_RANGE_JPEG; | |
313 |
2/2✓ Branch 0 taken 1242 times.
✓ Branch 1 taken 280586 times.
|
281828 | } else if (desc->flags & AV_PIX_FMT_FLAG_XYZ) { |
314 | 1242 | fmt.csp = AVCOL_SPC_UNSPECIFIED; | |
315 | 1242 | fmt.color = (SwsColor) { | |
316 | .prim = AVCOL_PRI_BT709, /* swscale currently hard-codes this XYZ matrix */ | ||
317 | .trc = AVCOL_TRC_SMPTE428, | ||
318 | }; | ||
319 |
2/2✓ Branch 0 taken 14786 times.
✓ Branch 1 taken 265800 times.
|
280586 | } else if (desc->nb_components < 3) { |
320 | /* Grayscale formats */ | ||
321 | 14786 | fmt.color.prim = AVCOL_PRI_UNSPECIFIED; | |
322 | 14786 | fmt.csp = AVCOL_SPC_UNSPECIFIED; | |
323 |
2/2✓ Branch 0 taken 306 times.
✓ Branch 1 taken 14480 times.
|
14786 | if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) |
324 | 306 | fmt.range = AVCOL_RANGE_UNSPECIFIED; | |
325 | else | ||
326 | 14480 | fmt.range = AVCOL_RANGE_JPEG; // FIXME: this restriction should be lifted | |
327 | } | ||
328 | |||
329 |
2/2✓ Branch 0 taken 10958 times.
✓ Branch 1 taken 392464 times.
|
403422 | switch (frame->format) { |
330 | 10958 | case AV_PIX_FMT_YUVJ420P: | |
331 | case AV_PIX_FMT_YUVJ411P: | ||
332 | case AV_PIX_FMT_YUVJ422P: | ||
333 | case AV_PIX_FMT_YUVJ444P: | ||
334 | case AV_PIX_FMT_YUVJ440P: | ||
335 | 10958 | fmt.range = AVCOL_RANGE_JPEG; | |
336 | 10958 | break; | |
337 | } | ||
338 | |||
339 |
4/4✓ Branch 0 taken 246962 times.
✓ Branch 1 taken 156460 times.
✓ Branch 2 taken 239542 times.
✓ Branch 3 taken 7420 times.
|
403422 | if (!desc->log2_chroma_w && !desc->log2_chroma_h) |
340 | 239542 | fmt.loc = AVCHROMA_LOC_UNSPECIFIED; | |
341 | |||
342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 403422 times.
|
403422 | if (frame->flags & AV_FRAME_FLAG_INTERLACED) { |
343 | ✗ | fmt.height = (fmt.height + (field == FIELD_TOP)) >> 1; | |
344 | ✗ | fmt.interlaced = 1; | |
345 | } | ||
346 | |||
347 | /* Set luminance and gamut information */ | ||
348 | 403422 | fmt.color.min_luma = av_make_q(0, 1); | |
349 |
3/3✓ Branch 0 taken 4 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 403360 times.
|
403422 | switch (fmt.color.trc) { |
350 | 4 | case AVCOL_TRC_SMPTE2084: | |
351 | 4 | fmt.color.max_luma = av_make_q(10000, 1); break; | |
352 | 58 | case AVCOL_TRC_ARIB_STD_B67: | |
353 | 58 | fmt.color.max_luma = av_make_q( 1000, 1); break; /* HLG reference display */ | |
354 | 403360 | default: | |
355 | 403360 | fmt.color.max_luma = av_make_q( 203, 1); break; /* SDR reference brightness */ | |
356 | } | ||
357 | |||
358 | 403422 | primaries = av_csp_primaries_desc_from_id(fmt.color.prim); | |
359 |
2/2✓ Branch 0 taken 1990 times.
✓ Branch 1 taken 401432 times.
|
403422 | if (primaries) |
360 | 1990 | fmt.color.gamut = primaries->prim; | |
361 | |||
362 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 403418 times.
|
403422 | if ((sd = av_frame_get_side_data(frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA))) { |
363 | 4 | const AVMasteringDisplayMetadata *mdm = (const AVMasteringDisplayMetadata *) sd->data; | |
364 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (mdm->has_luminance) { |
365 | 4 | fmt.color.min_luma = mdm->min_luminance; | |
366 | 4 | fmt.color.max_luma = mdm->max_luminance; | |
367 | } | ||
368 | |||
369 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (mdm->has_primaries) { |
370 | /* Ignore mastering display white point as it has no bearance on | ||
371 | * the underlying content */ | ||
372 | 4 | fmt.color.gamut.r.x = mdm->display_primaries[0][0]; | |
373 | 4 | fmt.color.gamut.r.y = mdm->display_primaries[0][1]; | |
374 | 4 | fmt.color.gamut.g.x = mdm->display_primaries[1][0]; | |
375 | 4 | fmt.color.gamut.g.y = mdm->display_primaries[1][1]; | |
376 | 4 | fmt.color.gamut.b.x = mdm->display_primaries[2][0]; | |
377 | 4 | fmt.color.gamut.b.y = mdm->display_primaries[2][1]; | |
378 | } | ||
379 | } | ||
380 | |||
381 |
2/2✓ Branch 1 taken 403418 times.
✓ Branch 2 taken 4 times.
|
403422 | if ((sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS))) { |
382 | 4 | const AVDynamicHDRPlus *dhp = (const AVDynamicHDRPlus *) sd->data; | |
383 | 4 | const AVHDRPlusColorTransformParams *pars = &dhp->params[0]; | |
384 | 4 | const AVRational nits = av_make_q(10000, 1); | |
385 | 4 | AVRational maxrgb = pars->maxscl[0]; | |
386 | |||
387 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (!dhp->num_windows || dhp->application_version > 1) |
388 | ✗ | goto skip_hdr10; | |
389 | |||
390 | /* Maximum of MaxSCL components */ | ||
391 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (av_cmp_q(pars->maxscl[1], maxrgb) > 0) |
392 | ✗ | maxrgb = pars->maxscl[1]; | |
393 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (av_cmp_q(pars->maxscl[2], maxrgb) > 0) |
394 | ✗ | maxrgb = pars->maxscl[2]; | |
395 | |||
396 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (maxrgb.num > 0) { |
397 | /* Estimate true luminance from MaxSCL */ | ||
398 | 4 | const AVLumaCoefficients *luma = av_csp_luma_coeffs_from_avcsp(fmt.csp); | |
399 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!luma) |
400 | ✗ | goto skip_hdr10; | |
401 | 4 | fmt.color.frame_peak = av_add_q(av_mul_q(luma->cr, pars->maxscl[0]), | |
402 | av_add_q(av_mul_q(luma->cg, pars->maxscl[1]), | ||
403 | av_mul_q(luma->cb, pars->maxscl[2]))); | ||
404 | /* Scale the scene average brightness by the ratio between the | ||
405 | * maximum luminance and the MaxRGB values */ | ||
406 | 4 | fmt.color.frame_avg = av_mul_q(pars->average_maxrgb, | |
407 | av_div_q(fmt.color.frame_peak, maxrgb)); | ||
408 | } else { | ||
409 | /** | ||
410 | * Calculate largest value from histogram to use as fallback for | ||
411 | * clips with missing MaxSCL information. Note that this may end | ||
412 | * up picking the "reserved" value at the 5% percentile, which in | ||
413 | * practice appears to track the brightest pixel in the scene. | ||
414 | */ | ||
415 | ✗ | for (int i = 0; i < pars->num_distribution_maxrgb_percentiles; i++) { | |
416 | ✗ | const AVRational pct = pars->distribution_maxrgb[i].percentile; | |
417 | ✗ | if (av_cmp_q(pct, maxrgb) > 0) | |
418 | ✗ | maxrgb = pct; | |
419 | ✗ | fmt.color.frame_peak = maxrgb; | |
420 | ✗ | fmt.color.frame_avg = pars->average_maxrgb; | |
421 | } | ||
422 | } | ||
423 | |||
424 | /* Rescale to nits */ | ||
425 | 4 | fmt.color.frame_peak = av_mul_q(nits, fmt.color.frame_peak); | |
426 | 4 | fmt.color.frame_avg = av_mul_q(nits, fmt.color.frame_avg); | |
427 | } | ||
428 | 403418 | skip_hdr10: | |
429 | |||
430 | /* PQ is always scaled down to absolute zero, so ignore mastering metadata */ | ||
431 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 403418 times.
|
403422 | if (fmt.color.trc == AVCOL_TRC_SMPTE2084) |
432 | 4 | fmt.color.min_luma = av_make_q(0, 1); | |
433 | |||
434 | 403422 | return fmt; | |
435 | } | ||
436 | |||
437 | 12240 | static int infer_prim_ref(SwsColor *csp, const SwsColor *ref) | |
438 | { | ||
439 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12096 times.
|
12240 | if (csp->prim != AVCOL_PRI_UNSPECIFIED) |
440 | 144 | return 0; | |
441 | |||
442 | /* Re-use the reference gamut only for "safe", similar primaries */ | ||
443 |
2/2✓ Branch 0 taken 6072 times.
✓ Branch 1 taken 6024 times.
|
12096 | switch (ref->prim) { |
444 | 6072 | case AVCOL_PRI_BT709: | |
445 | case AVCOL_PRI_BT470M: | ||
446 | case AVCOL_PRI_BT470BG: | ||
447 | case AVCOL_PRI_SMPTE170M: | ||
448 | case AVCOL_PRI_SMPTE240M: | ||
449 | 6072 | csp->prim = ref->prim; | |
450 | 6072 | csp->gamut = ref->gamut; | |
451 | 6072 | break; | |
452 | 6024 | default: | |
453 | 6024 | csp->prim = AVCOL_PRI_BT709; | |
454 | 6024 | csp->gamut = av_csp_primaries_desc_from_id(csp->prim)->prim; | |
455 | 6024 | break; | |
456 | } | ||
457 | |||
458 | 12096 | return 1; | |
459 | } | ||
460 | |||
461 | 12240 | static int infer_trc_ref(SwsColor *csp, const SwsColor *ref) | |
462 | { | ||
463 |
2/2✓ Branch 0 taken 294 times.
✓ Branch 1 taken 11946 times.
|
12240 | if (csp->trc != AVCOL_TRC_UNSPECIFIED) |
464 | 294 | return 0; | |
465 | |||
466 | /* Pick a suitable SDR transfer function, to try and minimize conversions */ | ||
467 |
2/2✓ Branch 0 taken 5949 times.
✓ Branch 1 taken 5997 times.
|
11946 | switch (ref->trc) { |
468 | 5949 | case AVCOL_TRC_UNSPECIFIED: | |
469 | /* HDR curves, never default to these */ | ||
470 | case AVCOL_TRC_SMPTE2084: | ||
471 | case AVCOL_TRC_ARIB_STD_B67: | ||
472 | 5949 | csp->trc = AVCOL_TRC_BT709; | |
473 | 5949 | csp->min_luma = av_make_q(0, 1); | |
474 | 5949 | csp->max_luma = av_make_q(203, 1); | |
475 | 5949 | break; | |
476 | 5997 | default: | |
477 | 5997 | csp->trc = ref->trc; | |
478 | 5997 | csp->min_luma = ref->min_luma; | |
479 | 5997 | csp->max_luma = ref->max_luma; | |
480 | 5997 | break; | |
481 | } | ||
482 | |||
483 | 11946 | return 1; | |
484 | } | ||
485 | |||
486 | 6120 | int ff_infer_colors(SwsColor *src, SwsColor *dst) | |
487 | { | ||
488 | 6120 | int incomplete = 0; | |
489 | |||
490 | 6120 | incomplete |= infer_prim_ref(dst, src); | |
491 | 6120 | incomplete |= infer_prim_ref(src, dst); | |
492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
|
6120 | av_assert0(src->prim != AVCOL_PRI_UNSPECIFIED); |
493 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
|
6120 | av_assert0(dst->prim != AVCOL_PRI_UNSPECIFIED); |
494 | |||
495 | 6120 | incomplete |= infer_trc_ref(dst, src); | |
496 | 6120 | incomplete |= infer_trc_ref(src, dst); | |
497 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
|
6120 | av_assert0(src->trc != AVCOL_TRC_UNSPECIFIED); |
498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6120 times.
|
6120 | av_assert0(dst->trc != AVCOL_TRC_UNSPECIFIED); |
499 | |||
500 | 6120 | return incomplete; | |
501 | } | ||
502 | |||
503 | 3498336 | int sws_test_format(enum AVPixelFormat format, int output) | |
504 | { | ||
505 |
2/2✓ Branch 0 taken 1749168 times.
✓ Branch 1 taken 1749168 times.
|
3498336 | return output ? sws_isSupportedOutput(format) : sws_isSupportedInput(format); |
506 | } | ||
507 | |||
508 | 425247 | int sws_test_colorspace(enum AVColorSpace csp, int output) | |
509 | { | ||
510 |
2/2✓ Branch 0 taken 310101 times.
✓ Branch 1 taken 115146 times.
|
425247 | switch (csp) { |
511 | 310101 | case AVCOL_SPC_UNSPECIFIED: | |
512 | case AVCOL_SPC_RGB: | ||
513 | case AVCOL_SPC_BT709: | ||
514 | case AVCOL_SPC_BT470BG: | ||
515 | case AVCOL_SPC_SMPTE170M: | ||
516 | case AVCOL_SPC_FCC: | ||
517 | case AVCOL_SPC_SMPTE240M: | ||
518 | case AVCOL_SPC_BT2020_NCL: | ||
519 | 310101 | return 1; | |
520 | 115146 | default: | |
521 | 115146 | return 0; | |
522 | } | ||
523 | } | ||
524 | |||
525 | 196968 | int sws_test_primaries(enum AVColorPrimaries prim, int output) | |
526 | { | ||
527 |
3/6✓ Branch 0 taken 196968 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 196968 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 196968 times.
✗ Branch 5 not taken.
|
196968 | return prim > AVCOL_PRI_RESERVED0 && prim < AVCOL_PRI_NB && |
528 | prim != AVCOL_PRI_RESERVED; | ||
529 | } | ||
530 | |||
531 | 196968 | int sws_test_transfer(enum AVColorTransferCharacteristic trc, int output) | |
532 | { | ||
533 | 98484 | av_csp_eotf_function eotf = output ? av_csp_itu_eotf_inv(trc) | |
534 |
2/2✓ Branch 0 taken 98484 times.
✓ Branch 1 taken 98484 times.
|
196968 | : av_csp_itu_eotf(trc); |
535 |
3/4✓ Branch 0 taken 1191 times.
✓ Branch 1 taken 195777 times.
✓ Branch 2 taken 1191 times.
✗ Branch 3 not taken.
|
196968 | return trc == AVCOL_TRC_UNSPECIFIED || eotf != NULL; |
536 | } | ||
537 | |||
538 | 196968 | static int test_range(enum AVColorRange range) | |
539 | { | ||
540 | 196968 | return (unsigned)range < AVCOL_RANGE_NB; | |
541 | } | ||
542 | |||
543 | 196968 | static int test_loc(enum AVChromaLocation loc) | |
544 | { | ||
545 | 196968 | return (unsigned)loc < AVCHROMA_LOC_NB; | |
546 | } | ||
547 | |||
548 | 196968 | int ff_test_fmt(const SwsFormat *fmt, int output) | |
549 | { | ||
550 |
2/4✓ Branch 0 taken 196968 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 196968 times.
✗ Branch 3 not taken.
|
393936 | return fmt->width > 0 && fmt->height > 0 && |
551 |
1/2✓ Branch 1 taken 196968 times.
✗ Branch 2 not taken.
|
393936 | sws_test_format (fmt->format, output) && |
552 |
1/2✓ Branch 1 taken 196968 times.
✗ Branch 2 not taken.
|
393936 | sws_test_colorspace(fmt->csp, output) && |
553 |
1/2✓ Branch 1 taken 196968 times.
✗ Branch 2 not taken.
|
393936 | sws_test_primaries (fmt->color.prim, output) && |
554 |
1/2✓ Branch 1 taken 196968 times.
✗ Branch 2 not taken.
|
393936 | sws_test_transfer (fmt->color.trc, output) && |
555 |
2/4✓ Branch 0 taken 196968 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 196968 times.
✗ Branch 4 not taken.
|
590904 | test_range (fmt->range) && |
556 | 196968 | test_loc (fmt->loc); | |
557 | } | ||
558 | |||
559 | ✗ | int sws_test_frame(const AVFrame *frame, int output) | |
560 | { | ||
561 | ✗ | for (int field = 0; field < 2; field++) { | |
562 | ✗ | const SwsFormat fmt = ff_fmt_from_frame(frame, field); | |
563 | ✗ | if (!ff_test_fmt(&fmt, output)) | |
564 | ✗ | return 0; | |
565 | ✗ | if (!fmt.interlaced) | |
566 | ✗ | break; | |
567 | } | ||
568 | |||
569 | ✗ | return 1; | |
570 | } | ||
571 | |||
572 | 103227 | int sws_is_noop(const AVFrame *dst, const AVFrame *src) | |
573 | { | ||
574 |
1/2✓ Branch 0 taken 103227 times.
✗ Branch 1 not taken.
|
103227 | for (int field = 0; field < 2; field++) { |
575 | 103227 | SwsFormat dst_fmt = ff_fmt_from_frame(dst, field); | |
576 | 103227 | SwsFormat src_fmt = ff_fmt_from_frame(src, field); | |
577 |
2/2✓ Branch 1 taken 98484 times.
✓ Branch 2 taken 4743 times.
|
103227 | if (!ff_fmt_equal(&dst_fmt, &src_fmt)) |
578 | 98484 | return 0; | |
579 |
1/2✓ Branch 0 taken 4743 times.
✗ Branch 1 not taken.
|
4743 | if (!dst_fmt.interlaced) |
580 | 4743 | break; | |
581 | } | ||
582 | |||
583 | 4743 | return 1; | |
584 | } | ||
585 |