Return from rtp_read when select returns an error
[libav.git] / libavutil / pixdesc.c
CommitLineData
9b61d838 1/*
e0cffbe7 2 * pixel format descriptor
9b61d838
MN
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
51135d1d 22#include "pixfmt.h"
9b61d838
MN
23#include "pixdesc.h"
24
f47a7cb7
SS
25#include "intreadwrite.h"
26
27void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
28 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
29{
30 AVComponentDescriptor comp= desc->comp[c];
31 int plane= comp.plane;
32 int depth= comp.depth_minus1+1;
33 int mask = (1<<depth)-1;
34 int shift= comp.shift;
35 int step = comp.step_minus1+1;
36 int flags= desc->flags;
37
38 if (flags & PIX_FMT_BITSTREAM){
39 int skip = x*step + comp.offset_plus1-1;
40 const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
41 int shift = 8 - depth - (skip&7);
42
43 while(w--){
44 int val = (*p >> shift) & mask;
45 if(read_pal_component)
46 val= data[1][4*val + c];
47 shift -= step;
48 p -= shift>>3;
49 shift &= 7;
50 *dst++= val;
51 }
52 } else {
53 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
54
55 while(w--){
56 int val;
57 if(flags & PIX_FMT_BE) val= AV_RB16(p);
58 else val= AV_RL16(p);
59 val = (val>>shift) & mask;
60 if(read_pal_component)
61 val= data[1][4*val + c];
62 p+= step;
63 *dst++= val;
64 }
65 }
66}
67
68void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
69 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
70{
71 AVComponentDescriptor comp = desc->comp[c];
72 int plane = comp.plane;
73 int depth = comp.depth_minus1+1;
74 int step = comp.step_minus1+1;
75 int flags = desc->flags;
76
77 if (flags & PIX_FMT_BITSTREAM) {
78 int skip = x*step + comp.offset_plus1-1;
79 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
80 int shift = 8 - depth - (skip&7);
81
82 while (w--) {
83 *p |= *src++ << shift;
84 shift -= step;
85 p -= shift>>3;
86 shift &= 7;
87 }
88 } else {
89 int shift = comp.shift;
90 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
91
92 while (w--) {
93 if (flags & PIX_FMT_BE) {
94 uint16_t val = AV_RB16(p) | (*src++<<shift);
95 AV_WB16(p, val);
96 } else {
97 uint16_t val = AV_RL16(p) | (*src++<<shift);
98 AV_WL16(p, val);
99 }
100 p+= step;
101 }
102 }
103}
104
d2863e72 105const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
bcbd9a14
SS
106 [PIX_FMT_YUV420P] = {
107 .name = "yuv420p",
b8873c2a 108 .nb_components= 3,
9b61d838 109 .log2_chroma_w= 1,
bcbd9a14 110 .log2_chroma_h= 1,
9b61d838 111 .comp = {
eb39fb51
SS
112 {0,0,1,0,7}, /* Y */
113 {1,0,1,0,7}, /* U */
114 {2,0,1,0,7}, /* V */
9b61d838
MN
115 },
116 },
bcbd9a14
SS
117 [PIX_FMT_YUYV422] = {
118 .name = "yuyv422",
b8873c2a 119 .nb_components= 3,
9b61d838 120 .log2_chroma_w= 1,
bcbd9a14
SS
121 .log2_chroma_h= 0,
122 .comp = {
123 {0,1,1,0,7}, /* Y */
124 {0,3,2,0,7}, /* U */
125 {0,3,4,0,7}, /* V */
126 },
127 },
128 [PIX_FMT_RGB24] = {
129 .name = "rgb24",
b8873c2a 130 .nb_components= 3,
bcbd9a14
SS
131 .log2_chroma_w= 0,
132 .log2_chroma_h= 0,
133 .comp = {
134 {0,2,1,0,7}, /* R */
135 {0,2,2,0,7}, /* G */
136 {0,2,3,0,7}, /* B */
137 },
138 },
10151b13
SS
139 [PIX_FMT_BGR24] = {
140 .name = "bgr24",
b8873c2a 141 .nb_components= 3,
10151b13
SS
142 .log2_chroma_w= 0,
143 .log2_chroma_h= 0,
144 .comp = {
145 {0,2,1,0,7}, /* B */
146 {0,2,2,0,7}, /* G */
147 {0,2,3,0,7}, /* R */
148 },
149 },
bcbd9a14
SS
150 [PIX_FMT_YUV422P] = {
151 .name = "yuv422p",
b8873c2a 152 .nb_components= 3,
bcbd9a14
SS
153 .log2_chroma_w= 1,
154 .log2_chroma_h= 0,
9b61d838 155 .comp = {
eb39fb51
SS
156 {0,0,1,0,7}, /* Y */
157 {1,0,1,0,7}, /* U */
158 {2,0,1,0,7}, /* V */
9b61d838
MN
159 },
160 },
10151b13
SS
161 [PIX_FMT_YUV444P] = {
162 .name = "yuv444p",
b8873c2a 163 .nb_components= 3,
10151b13
SS
164 .log2_chroma_w= 0,
165 .log2_chroma_h= 0,
166 .comp = {
167 {0,0,1,0,7}, /* Y */
168 {1,0,1,0,7}, /* U */
169 {2,0,1,0,7}, /* V */
170 },
171 },
9b61d838 172 [PIX_FMT_YUV410P] = {
1e896640 173 .name = "yuv410p",
b8873c2a 174 .nb_components= 3,
9b61d838
MN
175 .log2_chroma_w= 2,
176 .log2_chroma_h= 2,
177 .comp = {
eb39fb51
SS
178 {0,0,1,0,7}, /* Y */
179 {1,0,1,0,7}, /* U */
180 {2,0,1,0,7}, /* V */
9b61d838
MN
181 },
182 },
10151b13
SS
183 [PIX_FMT_YUV411P] = {
184 .name = "yuv411p",
b8873c2a 185 .nb_components= 3,
10151b13
SS
186 .log2_chroma_w= 2,
187 .log2_chroma_h= 0,
188 .comp = {
189 {0,0,1,0,7}, /* Y */
190 {1,0,1,0,7}, /* U */
191 {2,0,1,0,7}, /* V */
192 },
193 },
194 [PIX_FMT_GRAY8] = {
382cb115 195 .name = "gray",
b8873c2a 196 .nb_components= 1,
10151b13
SS
197 .log2_chroma_w= 0,
198 .log2_chroma_h= 0,
199 .comp = {
200 {0,0,1,0,7}, /* Y */
201 },
ce7c7179 202 .flags = PIX_FMT_PAL,
10151b13
SS
203 },
204 [PIX_FMT_MONOWHITE] = {
382cb115 205 .name = "monow",
b8873c2a 206 .nb_components= 1,
10151b13
SS
207 .log2_chroma_w= 0,
208 .log2_chroma_h= 0,
209 .comp = {
210 {0,0,1,0,0}, /* Y */
211 },
212 .flags = PIX_FMT_BITSTREAM,
213 },
bcbd9a14 214 [PIX_FMT_MONOBLACK] = {
382cb115 215 .name = "monob",
b8873c2a 216 .nb_components= 1,
bcbd9a14
SS
217 .log2_chroma_w= 0,
218 .log2_chroma_h= 0,
9b61d838 219 .comp = {
bcbd9a14 220 {0,0,1,7,0}, /* Y */
9b61d838 221 },
bcbd9a14 222 .flags = PIX_FMT_BITSTREAM,
9b61d838 223 },
bcbd9a14
SS
224 [PIX_FMT_PAL8] = {
225 .name = "pal8",
b8873c2a 226 .nb_components= 1,
bcbd9a14 227 .log2_chroma_w= 0,
9b61d838
MN
228 .log2_chroma_h= 0,
229 .comp = {
bcbd9a14 230 {0,0,1,0,7},
9b61d838 231 },
bcbd9a14 232 .flags = PIX_FMT_PAL,
9b61d838 233 },
10151b13
SS
234 [PIX_FMT_YUVJ420P] = {
235 .name = "yuvj420p",
b8873c2a 236 .nb_components= 3,
10151b13
SS
237 .log2_chroma_w= 1,
238 .log2_chroma_h= 1,
239 .comp = {
240 {0,0,1,0,7}, /* Y */
241 {1,0,1,0,7}, /* U */
242 {2,0,1,0,7}, /* V */
243 },
244 },
245 [PIX_FMT_YUVJ422P] = {
246 .name = "yuvj422p",
b8873c2a 247 .nb_components= 3,
10151b13
SS
248 .log2_chroma_w= 1,
249 .log2_chroma_h= 0,
250 .comp = {
251 {0,0,1,0,7}, /* Y */
252 {1,0,1,0,7}, /* U */
253 {2,0,1,0,7}, /* V */
254 },
255 },
256 [PIX_FMT_YUVJ444P] = {
257 .name = "yuvj444p",
b8873c2a 258 .nb_components= 3,
10151b13
SS
259 .log2_chroma_w= 0,
260 .log2_chroma_h= 0,
261 .comp = {
262 {0,0,1,0,7}, /* Y */
263 {1,0,1,0,7}, /* U */
264 {2,0,1,0,7}, /* V */
265 },
266 },
3fa70a3b 267 [PIX_FMT_XVMC_MPEG2_MC] = {
382cb115 268 .name = "xvmcmc",
3fa70a3b
SS
269 .flags = PIX_FMT_HWACCEL,
270 },
271 [PIX_FMT_XVMC_MPEG2_IDCT] = {
382cb115 272 .name = "xvmcidct",
3fa70a3b
SS
273 .flags = PIX_FMT_HWACCEL,
274 },
9b61d838 275 [PIX_FMT_UYVY422] = {
1e896640 276 .name = "uyvy422",
b8873c2a 277 .nb_components= 3,
9b61d838
MN
278 .log2_chroma_w= 1,
279 .log2_chroma_h= 0,
280 .comp = {
eb39fb51
SS
281 {0,1,2,0,7}, /* Y */
282 {0,3,1,0,7}, /* U */
283 {0,3,3,0,7}, /* V */
9b61d838
MN
284 },
285 },
10151b13
SS
286 [PIX_FMT_UYYVYY411] = {
287 .name = "uyyvyy411",
b8873c2a 288 .nb_components= 3,
10151b13
SS
289 .log2_chroma_w= 2,
290 .log2_chroma_h= 0,
291 .comp = {
292 {0,3,2,0,7}, /* Y */
293 {0,5,1,0,7}, /* U */
294 {0,5,4,0,7}, /* V */
295 },
296 },
297 [PIX_FMT_BGR8] = {
298 .name = "bgr8",
b8873c2a 299 .nb_components= 3,
10151b13
SS
300 .log2_chroma_w= 0,
301 .log2_chroma_h= 0,
302 .comp = {
303 {0,0,1,6,1}, /* B */
304 {0,0,1,3,2}, /* G */
305 {0,0,1,0,2}, /* R */
306 },
d71ad089 307 .flags = PIX_FMT_PAL,
10151b13
SS
308 },
309 [PIX_FMT_BGR4] = {
310 .name = "bgr4",
b8873c2a 311 .nb_components= 3,
10151b13
SS
312 .log2_chroma_w= 0,
313 .log2_chroma_h= 0,
314 .comp = {
315 {0,3,1,0,0}, /* B */
316 {0,3,2,0,1}, /* G */
317 {0,3,4,0,0}, /* R */
318 },
319 .flags = PIX_FMT_BITSTREAM,
320 },
321 [PIX_FMT_BGR4_BYTE] = {
322 .name = "bgr4_byte",
b8873c2a 323 .nb_components= 3,
10151b13
SS
324 .log2_chroma_w= 0,
325 .log2_chroma_h= 0,
326 .comp = {
327 {0,0,1,3,0}, /* B */
328 {0,0,1,1,1}, /* G */
329 {0,0,1,0,0}, /* R */
330 },
d71ad089 331 .flags = PIX_FMT_PAL,
10151b13
SS
332 },
333 [PIX_FMT_RGB8] = {
334 .name = "rgb8",
b8873c2a 335 .nb_components= 3,
10151b13
SS
336 .log2_chroma_w= 0,
337 .log2_chroma_h= 0,
338 .comp = {
339 {0,0,1,6,1}, /* R */
340 {0,0,1,3,2}, /* G */
341 {0,0,1,0,2}, /* B */
342 },
d71ad089 343 .flags = PIX_FMT_PAL,
10151b13
SS
344 },
345 [PIX_FMT_RGB4] = {
346 .name = "rgb4",
b8873c2a 347 .nb_components= 3,
10151b13
SS
348 .log2_chroma_w= 0,
349 .log2_chroma_h= 0,
350 .comp = {
351 {0,3,1,0,0}, /* R */
352 {0,3,2,0,1}, /* G */
353 {0,3,4,0,0}, /* B */
354 },
355 .flags = PIX_FMT_BITSTREAM,
356 },
357 [PIX_FMT_RGB4_BYTE] = {
358 .name = "rgb4_byte",
b8873c2a 359 .nb_components= 3,
10151b13
SS
360 .log2_chroma_w= 0,
361 .log2_chroma_h= 0,
362 .comp = {
363 {0,0,1,3,0}, /* R */
364 {0,0,1,1,1}, /* G */
365 {0,0,1,0,0}, /* B */
366 },
d71ad089 367 .flags = PIX_FMT_PAL,
10151b13 368 },
bcbd9a14
SS
369 [PIX_FMT_NV12] = {
370 .name = "nv12",
b8873c2a 371 .nb_components= 3,
bcbd9a14
SS
372 .log2_chroma_w= 1,
373 .log2_chroma_h= 1,
9b61d838 374 .comp = {
bcbd9a14
SS
375 {0,0,1,0,7}, /* Y */
376 {1,1,1,0,7}, /* U */
377 {1,1,2,0,7}, /* V */
9b61d838
MN
378 },
379 },
10151b13
SS
380 [PIX_FMT_NV21] = {
381 .name = "nv21",
b8873c2a 382 .nb_components= 3,
10151b13
SS
383 .log2_chroma_w= 1,
384 .log2_chroma_h= 1,
385 .comp = {
386 {0,0,1,0,7}, /* Y */
387 {1,1,1,0,7}, /* V */
388 {1,1,2,0,7}, /* U */
389 },
390 },
391 [PIX_FMT_ARGB] = {
392 .name = "argb",
b8873c2a 393 .nb_components= 4,
10151b13
SS
394 .log2_chroma_w= 0,
395 .log2_chroma_h= 0,
396 .comp = {
397 {0,3,1,0,7}, /* A */
398 {0,3,2,0,7}, /* R */
399 {0,3,3,0,7}, /* G */
400 {0,3,4,0,7}, /* B */
401 },
402 },
9b61d838 403 [PIX_FMT_RGBA] = {
1e896640 404 .name = "rgba",
b8873c2a 405 .nb_components= 4,
9b61d838
MN
406 .log2_chroma_w= 0,
407 .log2_chroma_h= 0,
408 .comp = {
eb39fb51
SS
409 {0,3,1,0,7}, /* R */
410 {0,3,2,0,7}, /* G */
411 {0,3,3,0,7}, /* B */
412 {0,3,4,0,7}, /* A */
9b61d838
MN
413 },
414 },
10151b13
SS
415 [PIX_FMT_ABGR] = {
416 .name = "abgr",
b8873c2a 417 .nb_components= 4,
10151b13
SS
418 .log2_chroma_w= 0,
419 .log2_chroma_h= 0,
420 .comp = {
421 {0,3,1,0,7}, /* A */
422 {0,3,2,0,7}, /* B */
423 {0,3,3,0,7}, /* G */
424 {0,3,4,0,7}, /* R */
425 },
426 },
427 [PIX_FMT_BGRA] = {
428 .name = "bgra",
b8873c2a 429 .nb_components= 4,
10151b13
SS
430 .log2_chroma_w= 0,
431 .log2_chroma_h= 0,
432 .comp = {
433 {0,3,1,0,7}, /* B */
434 {0,3,2,0,7}, /* G */
435 {0,3,3,0,7}, /* R */
436 {0,3,4,0,7}, /* A */
437 },
438 },
bcbd9a14
SS
439 [PIX_FMT_GRAY16BE] = {
440 .name = "gray16be",
b8873c2a 441 .nb_components= 1,
9b61d838
MN
442 .log2_chroma_w= 0,
443 .log2_chroma_h= 0,
444 .comp = {
bcbd9a14
SS
445 {0,1,1,0,15}, /* Y */
446 },
447 .flags = PIX_FMT_BE,
448 },
449 [PIX_FMT_GRAY16LE] = {
450 .name = "gray16le",
b8873c2a 451 .nb_components= 1,
bcbd9a14
SS
452 .log2_chroma_w= 0,
453 .log2_chroma_h= 0,
454 .comp = {
455 {0,1,1,0,15}, /* Y */
9b61d838
MN
456 },
457 },
10151b13
SS
458 [PIX_FMT_YUV440P] = {
459 .name = "yuv440p",
b8873c2a 460 .nb_components= 3,
10151b13
SS
461 .log2_chroma_w= 0,
462 .log2_chroma_h= 1,
463 .comp = {
464 {0,0,1,0,7}, /* Y */
465 {1,0,1,0,7}, /* U */
466 {2,0,1,0,7}, /* V */
467 },
468 },
469 [PIX_FMT_YUVJ440P] = {
470 .name = "yuvj440p",
b8873c2a 471 .nb_components= 3,
10151b13
SS
472 .log2_chroma_w= 0,
473 .log2_chroma_h= 1,
474 .comp = {
475 {0,0,1,0,7}, /* Y */
476 {1,0,1,0,7}, /* U */
477 {2,0,1,0,7}, /* V */
478 },
479 },
480 [PIX_FMT_YUVA420P] = {
481 .name = "yuva420p",
b8873c2a 482 .nb_components= 4,
10151b13
SS
483 .log2_chroma_w= 1,
484 .log2_chroma_h= 1,
485 .comp = {
486 {0,0,1,0,7}, /* Y */
487 {1,0,1,0,7}, /* U */
488 {2,0,1,0,7}, /* V */
489 {3,0,1,0,7}, /* A */
490 },
491 },
3fa70a3b
SS
492 [PIX_FMT_VDPAU_H264] = {
493 .name = "vdpau_h264",
494 .log2_chroma_w = 1,
495 .log2_chroma_h = 1,
496 .flags = PIX_FMT_HWACCEL,
497 },
498 [PIX_FMT_VDPAU_MPEG1] = {
499 .name = "vdpau_mpeg1",
500 .log2_chroma_w = 1,
501 .log2_chroma_h = 1,
502 .flags = PIX_FMT_HWACCEL,
503 },
504 [PIX_FMT_VDPAU_MPEG2] = {
505 .name = "vdpau_mpeg2",
506 .log2_chroma_w = 1,
507 .log2_chroma_h = 1,
508 .flags = PIX_FMT_HWACCEL,
509 },
510 [PIX_FMT_VDPAU_WMV3] = {
511 .name = "vdpau_wmv3",
512 .log2_chroma_w = 1,
513 .log2_chroma_h = 1,
514 .flags = PIX_FMT_HWACCEL,
515 },
516 [PIX_FMT_VDPAU_VC1] = {
517 .name = "vdpau_vc1",
518 .log2_chroma_w = 1,
519 .log2_chroma_h = 1,
520 .flags = PIX_FMT_HWACCEL,
521 },
dd6308ad
CEH
522 [PIX_FMT_VDPAU_MPEG4] = {
523 .name = "vdpau_mpeg4",
524 .log2_chroma_w = 1,
525 .log2_chroma_h = 1,
526 .flags = PIX_FMT_HWACCEL,
527 },
9b61d838 528 [PIX_FMT_RGB48BE] = {
1e896640 529 .name = "rgb48be",
b8873c2a 530 .nb_components= 3,
9b61d838
MN
531 .log2_chroma_w= 0,
532 .log2_chroma_h= 0,
533 .comp = {
eb39fb51
SS
534 {0,5,1,0,15}, /* R */
535 {0,5,3,0,15}, /* G */
536 {0,5,5,0,15}, /* B */
9b61d838
MN
537 },
538 .flags = PIX_FMT_BE,
539 },
bcbd9a14
SS
540 [PIX_FMT_RGB48LE] = {
541 .name = "rgb48le",
b8873c2a 542 .nb_components= 3,
9b61d838
MN
543 .log2_chroma_w= 0,
544 .log2_chroma_h= 0,
545 .comp = {
bcbd9a14
SS
546 {0,5,1,0,15}, /* R */
547 {0,5,3,0,15}, /* G */
548 {0,5,5,0,15}, /* B */
9b61d838
MN
549 },
550 },
e5681ba0 551 [PIX_FMT_RGB565BE] = {
1e896640 552 .name = "rgb565be",
b8873c2a 553 .nb_components= 3,
9b61d838
MN
554 .log2_chroma_w= 0,
555 .log2_chroma_h= 0,
556 .comp = {
eb39fb51 557 {0,1,0,3,4}, /* R */
f938cbf9
SS
558 {0,1,1,5,5}, /* G */
559 {0,1,1,0,4}, /* B */
9b61d838
MN
560 },
561 .flags = PIX_FMT_BE,
562 },
bcbd9a14
SS
563 [PIX_FMT_RGB565LE] = {
564 .name = "rgb565le",
b8873c2a 565 .nb_components= 3,
9b61d838
MN
566 .log2_chroma_w= 0,
567 .log2_chroma_h= 0,
568 .comp = {
bcbd9a14
SS
569 {0,1,2,3,4}, /* R */
570 {0,1,1,5,5}, /* G */
571 {0,1,1,0,4}, /* B */
9b61d838 572 },
9b61d838 573 },
10151b13
SS
574 [PIX_FMT_RGB555BE] = {
575 .name = "rgb555be",
b8873c2a 576 .nb_components= 3,
10151b13
SS
577 .log2_chroma_w= 0,
578 .log2_chroma_h= 0,
579 .comp = {
580 {0,1,0,2,4}, /* R */
581 {0,1,1,5,4}, /* G */
582 {0,1,1,0,4}, /* B */
583 },
584 .flags = PIX_FMT_BE,
585 },
586 [PIX_FMT_RGB555LE] = {
587 .name = "rgb555le",
b8873c2a 588 .nb_components= 3,
10151b13
SS
589 .log2_chroma_w= 0,
590 .log2_chroma_h= 0,
591 .comp = {
592 {0,1,2,2,4}, /* R */
593 {0,1,1,5,4}, /* G */
594 {0,1,1,0,4}, /* B */
595 },
596 },
597 [PIX_FMT_BGR565BE] = {
598 .name = "bgr565be",
b8873c2a 599 .nb_components= 3,
10151b13
SS
600 .log2_chroma_w= 0,
601 .log2_chroma_h= 0,
602 .comp = {
603 {0,1,0,3,4}, /* B */
604 {0,1,1,5,5}, /* G */
605 {0,1,1,0,4}, /* R */
606 },
607 .flags = PIX_FMT_BE,
608 },
609 [PIX_FMT_BGR565LE] = {
610 .name = "bgr565le",
b8873c2a 611 .nb_components= 3,
10151b13
SS
612 .log2_chroma_w= 0,
613 .log2_chroma_h= 0,
614 .comp = {
615 {0,1,2,3,4}, /* B */
616 {0,1,1,5,5}, /* G */
617 {0,1,1,0,4}, /* R */
618 },
619 },
620 [PIX_FMT_BGR555BE] = {
621 .name = "bgr555be",
b8873c2a 622 .nb_components= 3,
10151b13
SS
623 .log2_chroma_w= 0,
624 .log2_chroma_h= 0,
625 .comp = {
626 {0,1,0,2,4}, /* B */
627 {0,1,1,5,4}, /* G */
628 {0,1,1,0,4}, /* R */
629 },
630 .flags = PIX_FMT_BE,
631 },
632 [PIX_FMT_BGR555LE] = {
633 .name = "bgr555le",
b8873c2a 634 .nb_components= 3,
10151b13
SS
635 .log2_chroma_w= 0,
636 .log2_chroma_h= 0,
637 .comp = {
638 {0,1,2,2,4}, /* B */
639 {0,1,1,5,4}, /* G */
640 {0,1,1,0,4}, /* R */
641 },
642 },
3fa70a3b
SS
643 [PIX_FMT_VAAPI_MOCO] = {
644 .name = "vaapi_moco",
645 .log2_chroma_w = 1,
646 .log2_chroma_h = 1,
647 .flags = PIX_FMT_HWACCEL,
648 },
649 [PIX_FMT_VAAPI_IDCT] = {
650 .name = "vaapi_idct",
651 .log2_chroma_w = 1,
652 .log2_chroma_h = 1,
653 .flags = PIX_FMT_HWACCEL,
654 },
655 [PIX_FMT_VAAPI_VLD] = {
656 .name = "vaapi_vld",
657 .log2_chroma_w = 1,
658 .log2_chroma_h = 1,
659 .flags = PIX_FMT_HWACCEL,
660 },
35f6c154
LT
661 [PIX_FMT_YUV420P16LE] = {
662 .name = "yuv420p16le",
b8873c2a 663 .nb_components= 3,
75801da5
SS
664 .log2_chroma_w= 1,
665 .log2_chroma_h= 1,
666 .comp = {
667 {0,1,1,0,15}, /* Y */
668 {1,1,1,0,15}, /* U */
669 {2,1,1,0,15}, /* V */
670 },
671 },
35f6c154
LT
672 [PIX_FMT_YUV420P16BE] = {
673 .name = "yuv420p16be",
b8873c2a 674 .nb_components= 3,
75801da5
SS
675 .log2_chroma_w= 1,
676 .log2_chroma_h= 1,
677 .comp = {
678 {0,1,1,0,15}, /* Y */
679 {1,1,1,0,15}, /* U */
680 {2,1,1,0,15}, /* V */
681 },
682 .flags = PIX_FMT_BE,
683 },
35f6c154
LT
684 [PIX_FMT_YUV422P16LE] = {
685 .name = "yuv422p16le",
b8873c2a 686 .nb_components= 3,
75801da5
SS
687 .log2_chroma_w= 1,
688 .log2_chroma_h= 0,
689 .comp = {
690 {0,1,1,0,15}, /* Y */
691 {1,1,1,0,15}, /* U */
692 {2,1,1,0,15}, /* V */
693 },
694 },
35f6c154
LT
695 [PIX_FMT_YUV422P16BE] = {
696 .name = "yuv422p16be",
b8873c2a 697 .nb_components= 3,
75801da5
SS
698 .log2_chroma_w= 1,
699 .log2_chroma_h= 0,
700 .comp = {
701 {0,1,1,0,15}, /* Y */
702 {1,1,1,0,15}, /* U */
703 {2,1,1,0,15}, /* V */
704 },
705 .flags = PIX_FMT_BE,
706 },
35f6c154
LT
707 [PIX_FMT_YUV444P16LE] = {
708 .name = "yuv444p16le",
b8873c2a 709 .nb_components= 3,
75801da5
SS
710 .log2_chroma_w= 0,
711 .log2_chroma_h= 0,
712 .comp = {
713 {0,1,1,0,15}, /* Y */
714 {1,1,1,0,15}, /* U */
715 {2,1,1,0,15}, /* V */
716 },
717 },
35f6c154
LT
718 [PIX_FMT_YUV444P16BE] = {
719 .name = "yuv444p16be",
b8873c2a 720 .nb_components= 3,
75801da5
SS
721 .log2_chroma_w= 0,
722 .log2_chroma_h= 0,
723 .comp = {
724 {0,1,1,0,15}, /* Y */
725 {1,1,1,0,15}, /* U */
726 {2,1,1,0,15}, /* V */
727 },
728 .flags = PIX_FMT_BE,
729 },
92c6a099
LA
730 [PIX_FMT_DXVA2_VLD] = {
731 .name = "dxva2_vld",
732 .log2_chroma_w = 1,
733 .log2_chroma_h = 1,
734 .flags = PIX_FMT_HWACCEL,
735 },
9b61d838 736};
5efccce2 737
80a07f6e
SS
738static enum PixelFormat get_pix_fmt_internal(const char *name)
739{
740 enum PixelFormat pix_fmt;
741
742 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
743 if (av_pix_fmt_descriptors[pix_fmt].name &&
744 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
745 return pix_fmt;
746
747 return PIX_FMT_NONE;
748}
749
750#if HAVE_BIGENDIAN
751# define X_NE(be, le) be
752#else
753# define X_NE(be, le) le
754#endif
755
756enum PixelFormat av_get_pix_fmt(const char *name)
757{
758 enum PixelFormat pix_fmt;
759
760 if (!strcmp(name, "rgb32"))
761 name = X_NE("argb", "bgra");
762 else if (!strcmp(name, "bgr32"))
763 name = X_NE("abgr", "rgba");
764
765 pix_fmt = get_pix_fmt_internal(name);
766 if (pix_fmt == PIX_FMT_NONE) {
767 char name2[32];
768
769 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
770 pix_fmt = get_pix_fmt_internal(name2);
771 }
772 return pix_fmt;
773}
774
5efccce2
SS
775int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
776{
777 int c, bits = 0;
778 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
779
b8873c2a 780 for (c = 0; c < pixdesc->nb_components; c++) {
5efccce2
SS
781 int s = c==1 || c==2 ? 0 : log2_pixels;
782 bits += (pixdesc->comp[c].depth_minus1+1) << s;
783 }
784
785 return bits >> log2_pixels;
786}