hwaccel: OS X Video Decoder Acceleration (VDA) support.
[libav.git] / libavutil / pixdesc.c
1 /*
2 * pixel format descriptor
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of Libav.
6 *
7 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include "pixfmt.h"
25 #include "pixdesc.h"
26
27 #include "intreadwrite.h"
28
29 void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
30 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
31 {
32 AVComponentDescriptor comp= desc->comp[c];
33 int plane= comp.plane;
34 int depth= comp.depth_minus1+1;
35 int mask = (1<<depth)-1;
36 int shift= comp.shift;
37 int step = comp.step_minus1+1;
38 int flags= desc->flags;
39
40 if (flags & PIX_FMT_BITSTREAM){
41 int skip = x*step + comp.offset_plus1-1;
42 const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
43 int shift = 8 - depth - (skip&7);
44
45 while(w--){
46 int val = (*p >> shift) & mask;
47 if(read_pal_component)
48 val= data[1][4*val + c];
49 shift -= step;
50 p -= shift>>3;
51 shift &= 7;
52 *dst++= val;
53 }
54 } else {
55 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
56 int is_8bit = shift + depth <= 8;
57
58 if (is_8bit)
59 p += !!(flags & PIX_FMT_BE);
60
61 while(w--){
62 int val = is_8bit ? *p :
63 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
64 val = (val>>shift) & mask;
65 if(read_pal_component)
66 val= data[1][4*val + c];
67 p+= step;
68 *dst++= val;
69 }
70 }
71 }
72
73 void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
74 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
75 {
76 AVComponentDescriptor comp = desc->comp[c];
77 int plane = comp.plane;
78 int depth = comp.depth_minus1+1;
79 int step = comp.step_minus1+1;
80 int flags = desc->flags;
81
82 if (flags & PIX_FMT_BITSTREAM) {
83 int skip = x*step + comp.offset_plus1-1;
84 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
85 int shift = 8 - depth - (skip&7);
86
87 while (w--) {
88 *p |= *src++ << shift;
89 shift -= step;
90 p -= shift>>3;
91 shift &= 7;
92 }
93 } else {
94 int shift = comp.shift;
95 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
96
97 if (shift + depth <= 8) {
98 p += !!(flags & PIX_FMT_BE);
99 while (w--) {
100 *p |= (*src++<<shift);
101 p += step;
102 }
103 } else {
104 while (w--) {
105 if (flags & PIX_FMT_BE) {
106 uint16_t val = AV_RB16(p) | (*src++<<shift);
107 AV_WB16(p, val);
108 } else {
109 uint16_t val = AV_RL16(p) | (*src++<<shift);
110 AV_WL16(p, val);
111 }
112 p+= step;
113 }
114 }
115 }
116 }
117
118 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
119 [PIX_FMT_YUV420P] = {
120 .name = "yuv420p",
121 .nb_components= 3,
122 .log2_chroma_w= 1,
123 .log2_chroma_h= 1,
124 .comp = {
125 {0,0,1,0,7}, /* Y */
126 {1,0,1,0,7}, /* U */
127 {2,0,1,0,7}, /* V */
128 },
129 },
130 [PIX_FMT_YUYV422] = {
131 .name = "yuyv422",
132 .nb_components= 3,
133 .log2_chroma_w= 1,
134 .log2_chroma_h= 0,
135 .comp = {
136 {0,1,1,0,7}, /* Y */
137 {0,3,2,0,7}, /* U */
138 {0,3,4,0,7}, /* V */
139 },
140 },
141 [PIX_FMT_RGB24] = {
142 .name = "rgb24",
143 .nb_components= 3,
144 .log2_chroma_w= 0,
145 .log2_chroma_h= 0,
146 .comp = {
147 {0,2,1,0,7}, /* R */
148 {0,2,2,0,7}, /* G */
149 {0,2,3,0,7}, /* B */
150 },
151 },
152 [PIX_FMT_BGR24] = {
153 .name = "bgr24",
154 .nb_components= 3,
155 .log2_chroma_w= 0,
156 .log2_chroma_h= 0,
157 .comp = {
158 {0,2,1,0,7}, /* B */
159 {0,2,2,0,7}, /* G */
160 {0,2,3,0,7}, /* R */
161 },
162 },
163 [PIX_FMT_YUV422P] = {
164 .name = "yuv422p",
165 .nb_components= 3,
166 .log2_chroma_w= 1,
167 .log2_chroma_h= 0,
168 .comp = {
169 {0,0,1,0,7}, /* Y */
170 {1,0,1,0,7}, /* U */
171 {2,0,1,0,7}, /* V */
172 },
173 },
174 [PIX_FMT_YUV444P] = {
175 .name = "yuv444p",
176 .nb_components= 3,
177 .log2_chroma_w= 0,
178 .log2_chroma_h= 0,
179 .comp = {
180 {0,0,1,0,7}, /* Y */
181 {1,0,1,0,7}, /* U */
182 {2,0,1,0,7}, /* V */
183 },
184 },
185 [PIX_FMT_YUV410P] = {
186 .name = "yuv410p",
187 .nb_components= 3,
188 .log2_chroma_w= 2,
189 .log2_chroma_h= 2,
190 .comp = {
191 {0,0,1,0,7}, /* Y */
192 {1,0,1,0,7}, /* U */
193 {2,0,1,0,7}, /* V */
194 },
195 },
196 [PIX_FMT_YUV411P] = {
197 .name = "yuv411p",
198 .nb_components= 3,
199 .log2_chroma_w= 2,
200 .log2_chroma_h= 0,
201 .comp = {
202 {0,0,1,0,7}, /* Y */
203 {1,0,1,0,7}, /* U */
204 {2,0,1,0,7}, /* V */
205 },
206 },
207 [PIX_FMT_GRAY8] = {
208 .name = "gray",
209 .nb_components= 1,
210 .log2_chroma_w= 0,
211 .log2_chroma_h= 0,
212 .comp = {
213 {0,0,1,0,7}, /* Y */
214 },
215 .flags = PIX_FMT_PAL,
216 },
217 [PIX_FMT_MONOWHITE] = {
218 .name = "monow",
219 .nb_components= 1,
220 .log2_chroma_w= 0,
221 .log2_chroma_h= 0,
222 .comp = {
223 {0,0,1,0,0}, /* Y */
224 },
225 .flags = PIX_FMT_BITSTREAM,
226 },
227 [PIX_FMT_MONOBLACK] = {
228 .name = "monob",
229 .nb_components= 1,
230 .log2_chroma_w= 0,
231 .log2_chroma_h= 0,
232 .comp = {
233 {0,0,1,7,0}, /* Y */
234 },
235 .flags = PIX_FMT_BITSTREAM,
236 },
237 [PIX_FMT_PAL8] = {
238 .name = "pal8",
239 .nb_components= 1,
240 .log2_chroma_w= 0,
241 .log2_chroma_h= 0,
242 .comp = {
243 {0,0,1,0,7},
244 },
245 .flags = PIX_FMT_PAL,
246 },
247 [PIX_FMT_YUVJ420P] = {
248 .name = "yuvj420p",
249 .nb_components= 3,
250 .log2_chroma_w= 1,
251 .log2_chroma_h= 1,
252 .comp = {
253 {0,0,1,0,7}, /* Y */
254 {1,0,1,0,7}, /* U */
255 {2,0,1,0,7}, /* V */
256 },
257 },
258 [PIX_FMT_YUVJ422P] = {
259 .name = "yuvj422p",
260 .nb_components= 3,
261 .log2_chroma_w= 1,
262 .log2_chroma_h= 0,
263 .comp = {
264 {0,0,1,0,7}, /* Y */
265 {1,0,1,0,7}, /* U */
266 {2,0,1,0,7}, /* V */
267 },
268 },
269 [PIX_FMT_YUVJ444P] = {
270 .name = "yuvj444p",
271 .nb_components= 3,
272 .log2_chroma_w= 0,
273 .log2_chroma_h= 0,
274 .comp = {
275 {0,0,1,0,7}, /* Y */
276 {1,0,1,0,7}, /* U */
277 {2,0,1,0,7}, /* V */
278 },
279 },
280 [PIX_FMT_XVMC_MPEG2_MC] = {
281 .name = "xvmcmc",
282 .flags = PIX_FMT_HWACCEL,
283 },
284 [PIX_FMT_XVMC_MPEG2_IDCT] = {
285 .name = "xvmcidct",
286 .flags = PIX_FMT_HWACCEL,
287 },
288 [PIX_FMT_UYVY422] = {
289 .name = "uyvy422",
290 .nb_components= 3,
291 .log2_chroma_w= 1,
292 .log2_chroma_h= 0,
293 .comp = {
294 {0,1,2,0,7}, /* Y */
295 {0,3,1,0,7}, /* U */
296 {0,3,3,0,7}, /* V */
297 },
298 },
299 [PIX_FMT_UYYVYY411] = {
300 .name = "uyyvyy411",
301 .nb_components= 3,
302 .log2_chroma_w= 2,
303 .log2_chroma_h= 0,
304 .comp = {
305 {0,3,2,0,7}, /* Y */
306 {0,5,1,0,7}, /* U */
307 {0,5,4,0,7}, /* V */
308 },
309 },
310 [PIX_FMT_BGR8] = {
311 .name = "bgr8",
312 .nb_components= 3,
313 .log2_chroma_w= 0,
314 .log2_chroma_h= 0,
315 .comp = {
316 {0,0,1,6,1}, /* B */
317 {0,0,1,3,2}, /* G */
318 {0,0,1,0,2}, /* R */
319 },
320 .flags = PIX_FMT_PAL,
321 },
322 [PIX_FMT_BGR4] = {
323 .name = "bgr4",
324 .nb_components= 3,
325 .log2_chroma_w= 0,
326 .log2_chroma_h= 0,
327 .comp = {
328 {0,3,1,0,0}, /* B */
329 {0,3,2,0,1}, /* G */
330 {0,3,4,0,0}, /* R */
331 },
332 .flags = PIX_FMT_BITSTREAM,
333 },
334 [PIX_FMT_BGR4_BYTE] = {
335 .name = "bgr4_byte",
336 .nb_components= 3,
337 .log2_chroma_w= 0,
338 .log2_chroma_h= 0,
339 .comp = {
340 {0,0,1,3,0}, /* B */
341 {0,0,1,1,1}, /* G */
342 {0,0,1,0,0}, /* R */
343 },
344 .flags = PIX_FMT_PAL,
345 },
346 [PIX_FMT_RGB8] = {
347 .name = "rgb8",
348 .nb_components= 3,
349 .log2_chroma_w= 0,
350 .log2_chroma_h= 0,
351 .comp = {
352 {0,0,1,6,1}, /* R */
353 {0,0,1,3,2}, /* G */
354 {0,0,1,0,2}, /* B */
355 },
356 .flags = PIX_FMT_PAL,
357 },
358 [PIX_FMT_RGB4] = {
359 .name = "rgb4",
360 .nb_components= 3,
361 .log2_chroma_w= 0,
362 .log2_chroma_h= 0,
363 .comp = {
364 {0,3,1,0,0}, /* R */
365 {0,3,2,0,1}, /* G */
366 {0,3,4,0,0}, /* B */
367 },
368 .flags = PIX_FMT_BITSTREAM,
369 },
370 [PIX_FMT_RGB4_BYTE] = {
371 .name = "rgb4_byte",
372 .nb_components= 3,
373 .log2_chroma_w= 0,
374 .log2_chroma_h= 0,
375 .comp = {
376 {0,0,1,3,0}, /* R */
377 {0,0,1,1,1}, /* G */
378 {0,0,1,0,0}, /* B */
379 },
380 .flags = PIX_FMT_PAL,
381 },
382 [PIX_FMT_NV12] = {
383 .name = "nv12",
384 .nb_components= 3,
385 .log2_chroma_w= 1,
386 .log2_chroma_h= 1,
387 .comp = {
388 {0,0,1,0,7}, /* Y */
389 {1,1,1,0,7}, /* U */
390 {1,1,2,0,7}, /* V */
391 },
392 },
393 [PIX_FMT_NV21] = {
394 .name = "nv21",
395 .nb_components= 3,
396 .log2_chroma_w= 1,
397 .log2_chroma_h= 1,
398 .comp = {
399 {0,0,1,0,7}, /* Y */
400 {1,1,1,0,7}, /* V */
401 {1,1,2,0,7}, /* U */
402 },
403 },
404 [PIX_FMT_ARGB] = {
405 .name = "argb",
406 .nb_components= 4,
407 .log2_chroma_w= 0,
408 .log2_chroma_h= 0,
409 .comp = {
410 {0,3,1,0,7}, /* A */
411 {0,3,2,0,7}, /* R */
412 {0,3,3,0,7}, /* G */
413 {0,3,4,0,7}, /* B */
414 },
415 },
416 [PIX_FMT_RGBA] = {
417 .name = "rgba",
418 .nb_components= 4,
419 .log2_chroma_w= 0,
420 .log2_chroma_h= 0,
421 .comp = {
422 {0,3,1,0,7}, /* R */
423 {0,3,2,0,7}, /* G */
424 {0,3,3,0,7}, /* B */
425 {0,3,4,0,7}, /* A */
426 },
427 },
428 [PIX_FMT_ABGR] = {
429 .name = "abgr",
430 .nb_components= 4,
431 .log2_chroma_w= 0,
432 .log2_chroma_h= 0,
433 .comp = {
434 {0,3,1,0,7}, /* A */
435 {0,3,2,0,7}, /* B */
436 {0,3,3,0,7}, /* G */
437 {0,3,4,0,7}, /* R */
438 },
439 },
440 [PIX_FMT_BGRA] = {
441 .name = "bgra",
442 .nb_components= 4,
443 .log2_chroma_w= 0,
444 .log2_chroma_h= 0,
445 .comp = {
446 {0,3,1,0,7}, /* B */
447 {0,3,2,0,7}, /* G */
448 {0,3,3,0,7}, /* R */
449 {0,3,4,0,7}, /* A */
450 },
451 },
452 [PIX_FMT_GRAY16BE] = {
453 .name = "gray16be",
454 .nb_components= 1,
455 .log2_chroma_w= 0,
456 .log2_chroma_h= 0,
457 .comp = {
458 {0,1,1,0,15}, /* Y */
459 },
460 .flags = PIX_FMT_BE,
461 },
462 [PIX_FMT_GRAY16LE] = {
463 .name = "gray16le",
464 .nb_components= 1,
465 .log2_chroma_w= 0,
466 .log2_chroma_h= 0,
467 .comp = {
468 {0,1,1,0,15}, /* Y */
469 },
470 },
471 [PIX_FMT_YUV440P] = {
472 .name = "yuv440p",
473 .nb_components= 3,
474 .log2_chroma_w= 0,
475 .log2_chroma_h= 1,
476 .comp = {
477 {0,0,1,0,7}, /* Y */
478 {1,0,1,0,7}, /* U */
479 {2,0,1,0,7}, /* V */
480 },
481 },
482 [PIX_FMT_YUVJ440P] = {
483 .name = "yuvj440p",
484 .nb_components= 3,
485 .log2_chroma_w= 0,
486 .log2_chroma_h= 1,
487 .comp = {
488 {0,0,1,0,7}, /* Y */
489 {1,0,1,0,7}, /* U */
490 {2,0,1,0,7}, /* V */
491 },
492 },
493 [PIX_FMT_YUVA420P] = {
494 .name = "yuva420p",
495 .nb_components= 4,
496 .log2_chroma_w= 1,
497 .log2_chroma_h= 1,
498 .comp = {
499 {0,0,1,0,7}, /* Y */
500 {1,0,1,0,7}, /* U */
501 {2,0,1,0,7}, /* V */
502 {3,0,1,0,7}, /* A */
503 },
504 },
505 [PIX_FMT_VDPAU_H264] = {
506 .name = "vdpau_h264",
507 .log2_chroma_w = 1,
508 .log2_chroma_h = 1,
509 .flags = PIX_FMT_HWACCEL,
510 },
511 [PIX_FMT_VDPAU_MPEG1] = {
512 .name = "vdpau_mpeg1",
513 .log2_chroma_w = 1,
514 .log2_chroma_h = 1,
515 .flags = PIX_FMT_HWACCEL,
516 },
517 [PIX_FMT_VDPAU_MPEG2] = {
518 .name = "vdpau_mpeg2",
519 .log2_chroma_w = 1,
520 .log2_chroma_h = 1,
521 .flags = PIX_FMT_HWACCEL,
522 },
523 [PIX_FMT_VDPAU_WMV3] = {
524 .name = "vdpau_wmv3",
525 .log2_chroma_w = 1,
526 .log2_chroma_h = 1,
527 .flags = PIX_FMT_HWACCEL,
528 },
529 [PIX_FMT_VDPAU_VC1] = {
530 .name = "vdpau_vc1",
531 .log2_chroma_w = 1,
532 .log2_chroma_h = 1,
533 .flags = PIX_FMT_HWACCEL,
534 },
535 [PIX_FMT_VDPAU_MPEG4] = {
536 .name = "vdpau_mpeg4",
537 .log2_chroma_w = 1,
538 .log2_chroma_h = 1,
539 .flags = PIX_FMT_HWACCEL,
540 },
541 [PIX_FMT_RGB48BE] = {
542 .name = "rgb48be",
543 .nb_components= 3,
544 .log2_chroma_w= 0,
545 .log2_chroma_h= 0,
546 .comp = {
547 {0,5,1,0,15}, /* R */
548 {0,5,3,0,15}, /* G */
549 {0,5,5,0,15}, /* B */
550 },
551 .flags = PIX_FMT_BE,
552 },
553 [PIX_FMT_RGB48LE] = {
554 .name = "rgb48le",
555 .nb_components= 3,
556 .log2_chroma_w= 0,
557 .log2_chroma_h= 0,
558 .comp = {
559 {0,5,1,0,15}, /* R */
560 {0,5,3,0,15}, /* G */
561 {0,5,5,0,15}, /* B */
562 },
563 },
564 [PIX_FMT_RGB565BE] = {
565 .name = "rgb565be",
566 .nb_components= 3,
567 .log2_chroma_w= 0,
568 .log2_chroma_h= 0,
569 .comp = {
570 {0,1,0,3,4}, /* R */
571 {0,1,1,5,5}, /* G */
572 {0,1,1,0,4}, /* B */
573 },
574 .flags = PIX_FMT_BE,
575 },
576 [PIX_FMT_RGB565LE] = {
577 .name = "rgb565le",
578 .nb_components= 3,
579 .log2_chroma_w= 0,
580 .log2_chroma_h= 0,
581 .comp = {
582 {0,1,2,3,4}, /* R */
583 {0,1,1,5,5}, /* G */
584 {0,1,1,0,4}, /* B */
585 },
586 },
587 [PIX_FMT_RGB555BE] = {
588 .name = "rgb555be",
589 .nb_components= 3,
590 .log2_chroma_w= 0,
591 .log2_chroma_h= 0,
592 .comp = {
593 {0,1,0,2,4}, /* R */
594 {0,1,1,5,4}, /* G */
595 {0,1,1,0,4}, /* B */
596 },
597 .flags = PIX_FMT_BE,
598 },
599 [PIX_FMT_RGB555LE] = {
600 .name = "rgb555le",
601 .nb_components= 3,
602 .log2_chroma_w= 0,
603 .log2_chroma_h= 0,
604 .comp = {
605 {0,1,2,2,4}, /* R */
606 {0,1,1,5,4}, /* G */
607 {0,1,1,0,4}, /* B */
608 },
609 },
610 [PIX_FMT_RGB444BE] = {
611 .name = "rgb444be",
612 .nb_components= 3,
613 .log2_chroma_w= 0,
614 .log2_chroma_h= 0,
615 .comp = {
616 {0,1,0,0,3}, /* R */
617 {0,1,1,4,3}, /* G */
618 {0,1,1,0,3}, /* B */
619 },
620 .flags = PIX_FMT_BE,
621 },
622 [PIX_FMT_RGB444LE] = {
623 .name = "rgb444le",
624 .nb_components= 3,
625 .log2_chroma_w= 0,
626 .log2_chroma_h= 0,
627 .comp = {
628 {0,1,2,0,3}, /* R */
629 {0,1,1,4,3}, /* G */
630 {0,1,1,0,3}, /* B */
631 },
632 },
633 [PIX_FMT_BGR48BE] = {
634 .name = "bgr48be",
635 .nb_components= 3,
636 .log2_chroma_w= 0,
637 .log2_chroma_h= 0,
638 .comp = {
639 {0,5,1,0,15}, /* B */
640 {0,5,3,0,15}, /* G */
641 {0,5,5,0,15}, /* R */
642 },
643 .flags = PIX_FMT_BE,
644 },
645 [PIX_FMT_BGR48LE] = {
646 .name = "bgr48le",
647 .nb_components= 3,
648 .log2_chroma_w= 0,
649 .log2_chroma_h= 0,
650 .comp = {
651 {0,5,1,0,15}, /* B */
652 {0,5,3,0,15}, /* G */
653 {0,5,5,0,15}, /* R */
654 },
655 },
656 [PIX_FMT_BGR565BE] = {
657 .name = "bgr565be",
658 .nb_components= 3,
659 .log2_chroma_w= 0,
660 .log2_chroma_h= 0,
661 .comp = {
662 {0,1,0,3,4}, /* B */
663 {0,1,1,5,5}, /* G */
664 {0,1,1,0,4}, /* R */
665 },
666 .flags = PIX_FMT_BE,
667 },
668 [PIX_FMT_BGR565LE] = {
669 .name = "bgr565le",
670 .nb_components= 3,
671 .log2_chroma_w= 0,
672 .log2_chroma_h= 0,
673 .comp = {
674 {0,1,2,3,4}, /* B */
675 {0,1,1,5,5}, /* G */
676 {0,1,1,0,4}, /* R */
677 },
678 },
679 [PIX_FMT_BGR555BE] = {
680 .name = "bgr555be",
681 .nb_components= 3,
682 .log2_chroma_w= 0,
683 .log2_chroma_h= 0,
684 .comp = {
685 {0,1,0,2,4}, /* B */
686 {0,1,1,5,4}, /* G */
687 {0,1,1,0,4}, /* R */
688 },
689 .flags = PIX_FMT_BE,
690 },
691 [PIX_FMT_BGR555LE] = {
692 .name = "bgr555le",
693 .nb_components= 3,
694 .log2_chroma_w= 0,
695 .log2_chroma_h= 0,
696 .comp = {
697 {0,1,2,2,4}, /* B */
698 {0,1,1,5,4}, /* G */
699 {0,1,1,0,4}, /* R */
700 },
701 },
702 [PIX_FMT_BGR444BE] = {
703 .name = "bgr444be",
704 .nb_components= 3,
705 .log2_chroma_w= 0,
706 .log2_chroma_h= 0,
707 .comp = {
708 {0,1,0,0,3}, /* B */
709 {0,1,1,4,3}, /* G */
710 {0,1,1,0,3}, /* R */
711 },
712 .flags = PIX_FMT_BE,
713 },
714 [PIX_FMT_BGR444LE] = {
715 .name = "bgr444le",
716 .nb_components= 3,
717 .log2_chroma_w= 0,
718 .log2_chroma_h= 0,
719 .comp = {
720 {0,1,2,0,3}, /* B */
721 {0,1,1,4,3}, /* G */
722 {0,1,1,0,3}, /* R */
723 },
724 },
725 [PIX_FMT_VAAPI_MOCO] = {
726 .name = "vaapi_moco",
727 .log2_chroma_w = 1,
728 .log2_chroma_h = 1,
729 .flags = PIX_FMT_HWACCEL,
730 },
731 [PIX_FMT_VAAPI_IDCT] = {
732 .name = "vaapi_idct",
733 .log2_chroma_w = 1,
734 .log2_chroma_h = 1,
735 .flags = PIX_FMT_HWACCEL,
736 },
737 [PIX_FMT_VAAPI_VLD] = {
738 .name = "vaapi_vld",
739 .log2_chroma_w = 1,
740 .log2_chroma_h = 1,
741 .flags = PIX_FMT_HWACCEL,
742 },
743 [PIX_FMT_VDA_VLD] = {
744 .name = "vda_vld",
745 .log2_chroma_w = 1,
746 .log2_chroma_h = 1,
747 .flags = PIX_FMT_HWACCEL,
748 },
749 [PIX_FMT_YUV420P9LE] = {
750 .name = "yuv420p9le",
751 .nb_components= 3,
752 .log2_chroma_w= 1,
753 .log2_chroma_h= 1,
754 .comp = {
755 {0,1,1,0,8}, /* Y */
756 {1,1,1,0,8}, /* U */
757 {2,1,1,0,8}, /* V */
758 },
759 },
760 [PIX_FMT_YUV420P9BE] = {
761 .name = "yuv420p9be",
762 .nb_components= 3,
763 .log2_chroma_w= 1,
764 .log2_chroma_h= 1,
765 .comp = {
766 {0,1,1,0,8}, /* Y */
767 {1,1,1,0,8}, /* U */
768 {2,1,1,0,8}, /* V */
769 },
770 .flags = PIX_FMT_BE,
771 },
772 [PIX_FMT_YUV420P10LE] = {
773 .name = "yuv420p10le",
774 .nb_components= 3,
775 .log2_chroma_w= 1,
776 .log2_chroma_h= 1,
777 .comp = {
778 {0,1,1,0,9}, /* Y */
779 {1,1,1,0,9}, /* U */
780 {2,1,1,0,9}, /* V */
781 },
782 },
783 [PIX_FMT_YUV420P10BE] = {
784 .name = "yuv420p10be",
785 .nb_components= 3,
786 .log2_chroma_w= 1,
787 .log2_chroma_h= 1,
788 .comp = {
789 {0,1,1,0,9}, /* Y */
790 {1,1,1,0,9}, /* U */
791 {2,1,1,0,9}, /* V */
792 },
793 .flags = PIX_FMT_BE,
794 },
795 [PIX_FMT_YUV420P16LE] = {
796 .name = "yuv420p16le",
797 .nb_components= 3,
798 .log2_chroma_w= 1,
799 .log2_chroma_h= 1,
800 .comp = {
801 {0,1,1,0,15}, /* Y */
802 {1,1,1,0,15}, /* U */
803 {2,1,1,0,15}, /* V */
804 },
805 },
806 [PIX_FMT_YUV420P16BE] = {
807 .name = "yuv420p16be",
808 .nb_components= 3,
809 .log2_chroma_w= 1,
810 .log2_chroma_h= 1,
811 .comp = {
812 {0,1,1,0,15}, /* Y */
813 {1,1,1,0,15}, /* U */
814 {2,1,1,0,15}, /* V */
815 },
816 .flags = PIX_FMT_BE,
817 },
818 [PIX_FMT_YUV422P9LE] = {
819 .name = "yuv422p9le",
820 .nb_components= 3,
821 .log2_chroma_w= 1,
822 .log2_chroma_h= 0,
823 .comp = {
824 {0,1,1,0,8}, /* Y */
825 {1,1,1,0,8}, /* U */
826 {2,1,1,0,8}, /* V */
827 },
828 },
829 [PIX_FMT_YUV422P9BE] = {
830 .name = "yuv422p9be",
831 .nb_components= 3,
832 .log2_chroma_w= 1,
833 .log2_chroma_h= 0,
834 .comp = {
835 {0,1,1,0,8}, /* Y */
836 {1,1,1,0,8}, /* U */
837 {2,1,1,0,8}, /* V */
838 },
839 .flags = PIX_FMT_BE,
840 },
841 [PIX_FMT_YUV422P10LE] = {
842 .name = "yuv422p10le",
843 .nb_components= 3,
844 .log2_chroma_w= 1,
845 .log2_chroma_h= 0,
846 .comp = {
847 {0,1,1,0,9}, /* Y */
848 {1,1,1,0,9}, /* U */
849 {2,1,1,0,9}, /* V */
850 },
851 },
852 [PIX_FMT_YUV422P10BE] = {
853 .name = "yuv422p10be",
854 .nb_components= 3,
855 .log2_chroma_w= 1,
856 .log2_chroma_h= 0,
857 .comp = {
858 {0,1,1,0,9}, /* Y */
859 {1,1,1,0,9}, /* U */
860 {2,1,1,0,9}, /* V */
861 },
862 .flags = PIX_FMT_BE,
863 },
864 [PIX_FMT_YUV422P16LE] = {
865 .name = "yuv422p16le",
866 .nb_components= 3,
867 .log2_chroma_w= 1,
868 .log2_chroma_h= 0,
869 .comp = {
870 {0,1,1,0,15}, /* Y */
871 {1,1,1,0,15}, /* U */
872 {2,1,1,0,15}, /* V */
873 },
874 },
875 [PIX_FMT_YUV422P16BE] = {
876 .name = "yuv422p16be",
877 .nb_components= 3,
878 .log2_chroma_w= 1,
879 .log2_chroma_h= 0,
880 .comp = {
881 {0,1,1,0,15}, /* Y */
882 {1,1,1,0,15}, /* U */
883 {2,1,1,0,15}, /* V */
884 },
885 .flags = PIX_FMT_BE,
886 },
887 [PIX_FMT_YUV444P16LE] = {
888 .name = "yuv444p16le",
889 .nb_components= 3,
890 .log2_chroma_w= 0,
891 .log2_chroma_h= 0,
892 .comp = {
893 {0,1,1,0,15}, /* Y */
894 {1,1,1,0,15}, /* U */
895 {2,1,1,0,15}, /* V */
896 },
897 },
898 [PIX_FMT_YUV444P16BE] = {
899 .name = "yuv444p16be",
900 .nb_components= 3,
901 .log2_chroma_w= 0,
902 .log2_chroma_h= 0,
903 .comp = {
904 {0,1,1,0,15}, /* Y */
905 {1,1,1,0,15}, /* U */
906 {2,1,1,0,15}, /* V */
907 },
908 .flags = PIX_FMT_BE,
909 },
910 [PIX_FMT_YUV444P10LE] = {
911 .name = "yuv444p10le",
912 .nb_components= 3,
913 .log2_chroma_w= 0,
914 .log2_chroma_h= 0,
915 .comp = {
916 {0,1,1,0,9}, /* Y */
917 {1,1,1,0,9}, /* U */
918 {2,1,1,0,9}, /* V */
919 },
920 },
921 [PIX_FMT_YUV444P10BE] = {
922 .name = "yuv444p10be",
923 .nb_components= 3,
924 .log2_chroma_w= 0,
925 .log2_chroma_h= 0,
926 .comp = {
927 {0,1,1,0,9}, /* Y */
928 {1,1,1,0,9}, /* U */
929 {2,1,1,0,9}, /* V */
930 },
931 .flags = PIX_FMT_BE,
932 },
933 [PIX_FMT_YUV444P9LE] = {
934 .name = "yuv444p9le",
935 .nb_components= 3,
936 .log2_chroma_w= 0,
937 .log2_chroma_h= 0,
938 .comp = {
939 {0,1,1,0,8}, /* Y */
940 {1,1,1,0,8}, /* U */
941 {2,1,1,0,8}, /* V */
942 },
943 },
944 [PIX_FMT_YUV444P9BE] = {
945 .name = "yuv444p9be",
946 .nb_components= 3,
947 .log2_chroma_w= 0,
948 .log2_chroma_h= 0,
949 .comp = {
950 {0,1,1,0,8}, /* Y */
951 {1,1,1,0,8}, /* U */
952 {2,1,1,0,8}, /* V */
953 },
954 .flags = PIX_FMT_BE,
955 },
956 [PIX_FMT_DXVA2_VLD] = {
957 .name = "dxva2_vld",
958 .log2_chroma_w = 1,
959 .log2_chroma_h = 1,
960 .flags = PIX_FMT_HWACCEL,
961 },
962 [PIX_FMT_Y400A] = {
963 .name = "y400a",
964 .nb_components= 2,
965 .comp = {
966 {0,1,1,0,7}, /* Y */
967 {0,1,2,0,7}, /* A */
968 },
969 },
970 };
971
972 static enum PixelFormat get_pix_fmt_internal(const char *name)
973 {
974 enum PixelFormat pix_fmt;
975
976 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
977 if (av_pix_fmt_descriptors[pix_fmt].name &&
978 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
979 return pix_fmt;
980
981 return PIX_FMT_NONE;
982 }
983
984 const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
985 {
986 return (unsigned)pix_fmt < PIX_FMT_NB ?
987 av_pix_fmt_descriptors[pix_fmt].name : NULL;
988 }
989
990 #if HAVE_BIGENDIAN
991 # define X_NE(be, le) be
992 #else
993 # define X_NE(be, le) le
994 #endif
995
996 enum PixelFormat av_get_pix_fmt(const char *name)
997 {
998 enum PixelFormat pix_fmt;
999
1000 if (!strcmp(name, "rgb32"))
1001 name = X_NE("argb", "bgra");
1002 else if (!strcmp(name, "bgr32"))
1003 name = X_NE("abgr", "rgba");
1004
1005 pix_fmt = get_pix_fmt_internal(name);
1006 if (pix_fmt == PIX_FMT_NONE) {
1007 char name2[32];
1008
1009 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
1010 pix_fmt = get_pix_fmt_internal(name2);
1011 }
1012 return pix_fmt;
1013 }
1014
1015 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
1016 {
1017 int c, bits = 0;
1018 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
1019
1020 for (c = 0; c < pixdesc->nb_components; c++) {
1021 int s = c==1 || c==2 ? 0 : log2_pixels;
1022 bits += (pixdesc->comp[c].depth_minus1+1) << s;
1023 }
1024
1025 return bits >> log2_pixels;
1026 }
1027
1028 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
1029 {
1030 /* print header */
1031 if (pix_fmt < 0) {
1032 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
1033 } else {
1034 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
1035 snprintf(buf, buf_size, "%-11s %7d %10d",
1036 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
1037 }
1038
1039 return buf;
1040 }