6d618f33029db14bf97d5665c661adb0abb7aa38
[ffmpeg.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 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
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 = 0;
57
58         if (shift + depth <= 8) {
59             p += !!(flags & PIX_FMT_BE);
60             is_8bit = 1;
61         }
62         while(w--){
63             int val = is_8bit ? *p :
64                 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
65             val = (val>>shift) & mask;
66             if(read_pal_component)
67                 val= data[1][4*val + c];
68             p+= step;
69             *dst++= val;
70         }
71     }
72 }
73
74 void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
75                          const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
76 {
77     AVComponentDescriptor comp = desc->comp[c];
78     int plane = comp.plane;
79     int depth = comp.depth_minus1+1;
80     int step  = comp.step_minus1+1;
81     int flags = desc->flags;
82
83     if (flags & PIX_FMT_BITSTREAM) {
84         int skip = x*step + comp.offset_plus1-1;
85         uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
86         int shift = 8 - depth - (skip&7);
87
88         while (w--) {
89             *p |= *src++ << shift;
90             shift -= step;
91             p -= shift>>3;
92             shift &= 7;
93         }
94     } else {
95         int shift = comp.shift;
96         uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
97
98         if (shift + depth <= 8) {
99             p += !!(flags & PIX_FMT_BE);
100             while (w--) {
101                 *p |= (*src++<<shift);
102                 p += step;
103             }
104         } else {
105         while (w--) {
106             if (flags & PIX_FMT_BE) {
107                 uint16_t val = AV_RB16(p) | (*src++<<shift);
108                 AV_WB16(p, val);
109             } else {
110                 uint16_t val = AV_RL16(p) | (*src++<<shift);
111                 AV_WL16(p, val);
112             }
113             p+= step;
114         }
115         }
116     }
117 }
118
119 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
120     [PIX_FMT_YUV420P] = {
121         .name = "yuv420p",
122         .nb_components= 3,
123         .log2_chroma_w= 1,
124         .log2_chroma_h= 1,
125         .comp = {
126             {0,0,1,0,7},        /* Y */
127             {1,0,1,0,7},        /* U */
128             {2,0,1,0,7},        /* V */
129         },
130     },
131     [PIX_FMT_YUYV422] = {
132         .name = "yuyv422",
133         .nb_components= 3,
134         .log2_chroma_w= 1,
135         .log2_chroma_h= 0,
136         .comp = {
137             {0,1,1,0,7},        /* Y */
138             {0,3,2,0,7},        /* U */
139             {0,3,4,0,7},        /* V */
140         },
141     },
142     [PIX_FMT_RGB24] = {
143         .name = "rgb24",
144         .nb_components= 3,
145         .log2_chroma_w= 0,
146         .log2_chroma_h= 0,
147         .comp = {
148             {0,2,1,0,7},        /* R */
149             {0,2,2,0,7},        /* G */
150             {0,2,3,0,7},        /* B */
151         },
152     },
153     [PIX_FMT_BGR24] = {
154         .name = "bgr24",
155         .nb_components= 3,
156         .log2_chroma_w= 0,
157         .log2_chroma_h= 0,
158         .comp = {
159             {0,2,1,0,7},        /* B */
160             {0,2,2,0,7},        /* G */
161             {0,2,3,0,7},        /* R */
162         },
163     },
164     [PIX_FMT_YUV422P] = {
165         .name = "yuv422p",
166         .nb_components= 3,
167         .log2_chroma_w= 1,
168         .log2_chroma_h= 0,
169         .comp = {
170             {0,0,1,0,7},        /* Y */
171             {1,0,1,0,7},        /* U */
172             {2,0,1,0,7},        /* V */
173         },
174     },
175     [PIX_FMT_YUV444P] = {
176         .name = "yuv444p",
177         .nb_components= 3,
178         .log2_chroma_w= 0,
179         .log2_chroma_h= 0,
180         .comp = {
181             {0,0,1,0,7},        /* Y */
182             {1,0,1,0,7},        /* U */
183             {2,0,1,0,7},        /* V */
184         },
185     },
186     [PIX_FMT_YUV410P] = {
187         .name = "yuv410p",
188         .nb_components= 3,
189         .log2_chroma_w= 2,
190         .log2_chroma_h= 2,
191         .comp = {
192             {0,0,1,0,7},        /* Y */
193             {1,0,1,0,7},        /* U */
194             {2,0,1,0,7},        /* V */
195         },
196     },
197     [PIX_FMT_YUV411P] = {
198         .name = "yuv411p",
199         .nb_components= 3,
200         .log2_chroma_w= 2,
201         .log2_chroma_h= 0,
202         .comp = {
203             {0,0,1,0,7},        /* Y */
204             {1,0,1,0,7},        /* U */
205             {2,0,1,0,7},        /* V */
206         },
207     },
208     [PIX_FMT_GRAY8] = {
209         .name = "gray",
210         .nb_components= 1,
211         .log2_chroma_w= 0,
212         .log2_chroma_h= 0,
213         .comp = {
214             {0,0,1,0,7},        /* Y */
215         },
216         .flags = PIX_FMT_PAL,
217     },
218     [PIX_FMT_MONOWHITE] = {
219         .name = "monow",
220         .nb_components= 1,
221         .log2_chroma_w= 0,
222         .log2_chroma_h= 0,
223         .comp = {
224             {0,0,1,0,0},        /* Y */
225         },
226         .flags = PIX_FMT_BITSTREAM,
227     },
228     [PIX_FMT_MONOBLACK] = {
229         .name = "monob",
230         .nb_components= 1,
231         .log2_chroma_w= 0,
232         .log2_chroma_h= 0,
233         .comp = {
234             {0,0,1,7,0},        /* Y */
235         },
236         .flags = PIX_FMT_BITSTREAM,
237     },
238     [PIX_FMT_PAL8] = {
239         .name = "pal8",
240         .nb_components= 1,
241         .log2_chroma_w= 0,
242         .log2_chroma_h= 0,
243         .comp = {
244             {0,0,1,0,7},
245         },
246         .flags = PIX_FMT_PAL,
247     },
248     [PIX_FMT_YUVJ420P] = {
249         .name = "yuvj420p",
250         .nb_components= 3,
251         .log2_chroma_w= 1,
252         .log2_chroma_h= 1,
253         .comp = {
254             {0,0,1,0,7},        /* Y */
255             {1,0,1,0,7},        /* U */
256             {2,0,1,0,7},        /* V */
257         },
258     },
259     [PIX_FMT_YUVJ422P] = {
260         .name = "yuvj422p",
261         .nb_components= 3,
262         .log2_chroma_w= 1,
263         .log2_chroma_h= 0,
264         .comp = {
265             {0,0,1,0,7},        /* Y */
266             {1,0,1,0,7},        /* U */
267             {2,0,1,0,7},        /* V */
268         },
269     },
270     [PIX_FMT_YUVJ444P] = {
271         .name = "yuvj444p",
272         .nb_components= 3,
273         .log2_chroma_w= 0,
274         .log2_chroma_h= 0,
275         .comp = {
276             {0,0,1,0,7},        /* Y */
277             {1,0,1,0,7},        /* U */
278             {2,0,1,0,7},        /* V */
279         },
280     },
281     [PIX_FMT_XVMC_MPEG2_MC] = {
282         .name = "xvmcmc",
283         .flags = PIX_FMT_HWACCEL,
284     },
285     [PIX_FMT_XVMC_MPEG2_IDCT] = {
286         .name = "xvmcidct",
287         .flags = PIX_FMT_HWACCEL,
288     },
289     [PIX_FMT_UYVY422] = {
290         .name = "uyvy422",
291         .nb_components= 3,
292         .log2_chroma_w= 1,
293         .log2_chroma_h= 0,
294         .comp = {
295             {0,1,2,0,7},        /* Y */
296             {0,3,1,0,7},        /* U */
297             {0,3,3,0,7},        /* V */
298         },
299     },
300     [PIX_FMT_UYYVYY411] = {
301         .name = "uyyvyy411",
302         .nb_components= 3,
303         .log2_chroma_w= 2,
304         .log2_chroma_h= 0,
305         .comp = {
306             {0,3,2,0,7},        /* Y */
307             {0,5,1,0,7},        /* U */
308             {0,5,4,0,7},        /* V */
309         },
310     },
311     [PIX_FMT_BGR8] = {
312         .name = "bgr8",
313         .nb_components= 3,
314         .log2_chroma_w= 0,
315         .log2_chroma_h= 0,
316         .comp = {
317             {0,0,1,6,1},        /* B */
318             {0,0,1,3,2},        /* G */
319             {0,0,1,0,2},        /* R */
320         },
321         .flags = PIX_FMT_PAL,
322     },
323     [PIX_FMT_BGR4] = {
324         .name = "bgr4",
325         .nb_components= 3,
326         .log2_chroma_w= 0,
327         .log2_chroma_h= 0,
328         .comp = {
329             {0,3,1,0,0},        /* B */
330             {0,3,2,0,1},        /* G */
331             {0,3,4,0,0},        /* R */
332         },
333         .flags = PIX_FMT_BITSTREAM,
334     },
335     [PIX_FMT_BGR4_BYTE] = {
336         .name = "bgr4_byte",
337         .nb_components= 3,
338         .log2_chroma_w= 0,
339         .log2_chroma_h= 0,
340         .comp = {
341             {0,0,1,3,0},        /* B */
342             {0,0,1,1,1},        /* G */
343             {0,0,1,0,0},        /* R */
344         },
345         .flags = PIX_FMT_PAL,
346     },
347     [PIX_FMT_RGB8] = {
348         .name = "rgb8",
349         .nb_components= 3,
350         .log2_chroma_w= 0,
351         .log2_chroma_h= 0,
352         .comp = {
353             {0,0,1,6,1},        /* R */
354             {0,0,1,3,2},        /* G */
355             {0,0,1,0,2},        /* B */
356         },
357         .flags = PIX_FMT_PAL,
358     },
359     [PIX_FMT_RGB4] = {
360         .name = "rgb4",
361         .nb_components= 3,
362         .log2_chroma_w= 0,
363         .log2_chroma_h= 0,
364         .comp = {
365             {0,3,1,0,0},       /* R */
366             {0,3,2,0,1},       /* G */
367             {0,3,4,0,0},       /* B */
368         },
369         .flags = PIX_FMT_BITSTREAM,
370     },
371     [PIX_FMT_RGB4_BYTE] = {
372         .name = "rgb4_byte",
373         .nb_components= 3,
374         .log2_chroma_w= 0,
375         .log2_chroma_h= 0,
376         .comp = {
377             {0,0,1,3,0},        /* R */
378             {0,0,1,1,1},        /* G */
379             {0,0,1,0,0},        /* B */
380         },
381         .flags = PIX_FMT_PAL,
382     },
383     [PIX_FMT_NV12] = {
384         .name = "nv12",
385         .nb_components= 3,
386         .log2_chroma_w= 1,
387         .log2_chroma_h= 1,
388         .comp = {
389             {0,0,1,0,7},        /* Y */
390             {1,1,1,0,7},        /* U */
391             {1,1,2,0,7},        /* V */
392         },
393     },
394     [PIX_FMT_NV21] = {
395         .name = "nv21",
396         .nb_components= 3,
397         .log2_chroma_w= 1,
398         .log2_chroma_h= 1,
399         .comp = {
400             {0,0,1,0,7},        /* Y */
401             {1,1,1,0,7},        /* V */
402             {1,1,2,0,7},        /* U */
403         },
404     },
405     [PIX_FMT_ARGB] = {
406         .name = "argb",
407         .nb_components= 4,
408         .log2_chroma_w= 0,
409         .log2_chroma_h= 0,
410         .comp = {
411             {0,3,1,0,7},        /* A */
412             {0,3,2,0,7},        /* R */
413             {0,3,3,0,7},        /* G */
414             {0,3,4,0,7},        /* B */
415         },
416     },
417     [PIX_FMT_RGBA] = {
418         .name = "rgba",
419         .nb_components= 4,
420         .log2_chroma_w= 0,
421         .log2_chroma_h= 0,
422         .comp = {
423             {0,3,1,0,7},        /* R */
424             {0,3,2,0,7},        /* G */
425             {0,3,3,0,7},        /* B */
426             {0,3,4,0,7},        /* A */
427         },
428     },
429     [PIX_FMT_ABGR] = {
430         .name = "abgr",
431         .nb_components= 4,
432         .log2_chroma_w= 0,
433         .log2_chroma_h= 0,
434         .comp = {
435             {0,3,1,0,7},        /* A */
436             {0,3,2,0,7},        /* B */
437             {0,3,3,0,7},        /* G */
438             {0,3,4,0,7},        /* R */
439         },
440     },
441     [PIX_FMT_BGRA] = {
442         .name = "bgra",
443         .nb_components= 4,
444         .log2_chroma_w= 0,
445         .log2_chroma_h= 0,
446         .comp = {
447             {0,3,1,0,7},        /* B */
448             {0,3,2,0,7},        /* G */
449             {0,3,3,0,7},        /* R */
450             {0,3,4,0,7},        /* A */
451         },
452     },
453     [PIX_FMT_GRAY16BE] = {
454         .name = "gray16be",
455         .nb_components= 1,
456         .log2_chroma_w= 0,
457         .log2_chroma_h= 0,
458         .comp = {
459             {0,1,1,0,15},       /* Y */
460         },
461         .flags = PIX_FMT_BE,
462     },
463     [PIX_FMT_GRAY16LE] = {
464         .name = "gray16le",
465         .nb_components= 1,
466         .log2_chroma_w= 0,
467         .log2_chroma_h= 0,
468         .comp = {
469             {0,1,1,0,15},       /* Y */
470         },
471     },
472     [PIX_FMT_YUV440P] = {
473         .name = "yuv440p",
474         .nb_components= 3,
475         .log2_chroma_w= 0,
476         .log2_chroma_h= 1,
477         .comp = {
478             {0,0,1,0,7},        /* Y */
479             {1,0,1,0,7},        /* U */
480             {2,0,1,0,7},        /* V */
481         },
482     },
483     [PIX_FMT_YUVJ440P] = {
484         .name = "yuvj440p",
485         .nb_components= 3,
486         .log2_chroma_w= 0,
487         .log2_chroma_h= 1,
488         .comp = {
489             {0,0,1,0,7},        /* Y */
490             {1,0,1,0,7},        /* U */
491             {2,0,1,0,7},        /* V */
492         },
493     },
494     [PIX_FMT_YUVA420P] = {
495         .name = "yuva420p",
496         .nb_components= 4,
497         .log2_chroma_w= 1,
498         .log2_chroma_h= 1,
499         .comp = {
500             {0,0,1,0,7},        /* Y */
501             {1,0,1,0,7},        /* U */
502             {2,0,1,0,7},        /* V */
503             {3,0,1,0,7},        /* A */
504         },
505     },
506     [PIX_FMT_VDPAU_H264] = {
507         .name = "vdpau_h264",
508         .log2_chroma_w = 1,
509         .log2_chroma_h = 1,
510         .flags = PIX_FMT_HWACCEL,
511     },
512     [PIX_FMT_VDPAU_MPEG1] = {
513         .name = "vdpau_mpeg1",
514         .log2_chroma_w = 1,
515         .log2_chroma_h = 1,
516         .flags = PIX_FMT_HWACCEL,
517     },
518     [PIX_FMT_VDPAU_MPEG2] = {
519         .name = "vdpau_mpeg2",
520         .log2_chroma_w = 1,
521         .log2_chroma_h = 1,
522         .flags = PIX_FMT_HWACCEL,
523     },
524     [PIX_FMT_VDPAU_WMV3] = {
525         .name = "vdpau_wmv3",
526         .log2_chroma_w = 1,
527         .log2_chroma_h = 1,
528         .flags = PIX_FMT_HWACCEL,
529     },
530     [PIX_FMT_VDPAU_VC1] = {
531         .name = "vdpau_vc1",
532         .log2_chroma_w = 1,
533         .log2_chroma_h = 1,
534         .flags = PIX_FMT_HWACCEL,
535     },
536     [PIX_FMT_VDPAU_MPEG4] = {
537         .name = "vdpau_mpeg4",
538         .log2_chroma_w = 1,
539         .log2_chroma_h = 1,
540         .flags = PIX_FMT_HWACCEL,
541     },
542     [PIX_FMT_RGB48BE] = {
543         .name = "rgb48be",
544         .nb_components= 3,
545         .log2_chroma_w= 0,
546         .log2_chroma_h= 0,
547         .comp = {
548             {0,5,1,0,15},       /* R */
549             {0,5,3,0,15},       /* G */
550             {0,5,5,0,15},       /* B */
551         },
552         .flags = PIX_FMT_BE,
553     },
554     [PIX_FMT_RGB48LE] = {
555         .name = "rgb48le",
556         .nb_components= 3,
557         .log2_chroma_w= 0,
558         .log2_chroma_h= 0,
559         .comp = {
560             {0,5,1,0,15},       /* R */
561             {0,5,3,0,15},       /* G */
562             {0,5,5,0,15},       /* B */
563         },
564     },
565     [PIX_FMT_RGB565BE] = {
566         .name = "rgb565be",
567         .nb_components= 3,
568         .log2_chroma_w= 0,
569         .log2_chroma_h= 0,
570         .comp = {
571             {0,1,0,3,4},        /* R */
572             {0,1,1,5,5},        /* G */
573             {0,1,1,0,4},        /* B */
574         },
575         .flags = PIX_FMT_BE,
576     },
577     [PIX_FMT_RGB565LE] = {
578         .name = "rgb565le",
579         .nb_components= 3,
580         .log2_chroma_w= 0,
581         .log2_chroma_h= 0,
582         .comp = {
583             {0,1,2,3,4},        /* R */
584             {0,1,1,5,5},        /* G */
585             {0,1,1,0,4},        /* B */
586         },
587     },
588     [PIX_FMT_RGB555BE] = {
589         .name = "rgb555be",
590         .nb_components= 3,
591         .log2_chroma_w= 0,
592         .log2_chroma_h= 0,
593         .comp = {
594             {0,1,0,2,4},        /* R */
595             {0,1,1,5,4},        /* G */
596             {0,1,1,0,4},        /* B */
597         },
598         .flags = PIX_FMT_BE,
599     },
600     [PIX_FMT_RGB555LE] = {
601         .name = "rgb555le",
602         .nb_components= 3,
603         .log2_chroma_w= 0,
604         .log2_chroma_h= 0,
605         .comp = {
606             {0,1,2,2,4},        /* R */
607             {0,1,1,5,4},        /* G */
608             {0,1,1,0,4},        /* B */
609         },
610     },
611     [PIX_FMT_RGB444BE] = {
612         .name = "rgb444be",
613         .nb_components= 3,
614         .log2_chroma_w= 0,
615         .log2_chroma_h= 0,
616         .comp = {
617             {0,1,0,0,3},        /* R */
618             {0,1,1,4,3},        /* G */
619             {0,1,1,0,3},        /* B */
620         },
621         .flags = PIX_FMT_BE,
622     },
623     [PIX_FMT_RGB444LE] = {
624         .name = "rgb444le",
625         .nb_components= 3,
626         .log2_chroma_w= 0,
627         .log2_chroma_h= 0,
628         .comp = {
629             {0,1,2,0,3},        /* R */
630             {0,1,1,4,3},        /* G */
631             {0,1,1,0,3},        /* B */
632         },
633     },
634     [PIX_FMT_BGR565BE] = {
635         .name = "bgr565be",
636         .nb_components= 3,
637         .log2_chroma_w= 0,
638         .log2_chroma_h= 0,
639         .comp = {
640             {0,1,0,3,4},        /* B */
641             {0,1,1,5,5},        /* G */
642             {0,1,1,0,4},        /* R */
643         },
644         .flags = PIX_FMT_BE,
645     },
646     [PIX_FMT_BGR565LE] = {
647         .name = "bgr565le",
648         .nb_components= 3,
649         .log2_chroma_w= 0,
650         .log2_chroma_h= 0,
651         .comp = {
652             {0,1,2,3,4},        /* B */
653             {0,1,1,5,5},        /* G */
654             {0,1,1,0,4},        /* R */
655         },
656     },
657     [PIX_FMT_BGR555BE] = {
658         .name = "bgr555be",
659         .nb_components= 3,
660         .log2_chroma_w= 0,
661         .log2_chroma_h= 0,
662         .comp = {
663             {0,1,0,2,4},       /* B */
664             {0,1,1,5,4},       /* G */
665             {0,1,1,0,4},       /* R */
666         },
667         .flags = PIX_FMT_BE,
668      },
669     [PIX_FMT_BGR555LE] = {
670         .name = "bgr555le",
671         .nb_components= 3,
672         .log2_chroma_w= 0,
673         .log2_chroma_h= 0,
674         .comp = {
675             {0,1,2,2,4},        /* B */
676             {0,1,1,5,4},        /* G */
677             {0,1,1,0,4},        /* R */
678         },
679     },
680     [PIX_FMT_BGR444BE] = {
681         .name = "bgr444be",
682         .nb_components= 3,
683         .log2_chroma_w= 0,
684         .log2_chroma_h= 0,
685         .comp = {
686             {0,1,0,0,3},       /* B */
687             {0,1,1,4,3},       /* G */
688             {0,1,1,0,3},       /* R */
689         },
690         .flags = PIX_FMT_BE,
691      },
692     [PIX_FMT_BGR444LE] = {
693         .name = "bgr444le",
694         .nb_components= 3,
695         .log2_chroma_w= 0,
696         .log2_chroma_h= 0,
697         .comp = {
698             {0,1,2,0,3},        /* B */
699             {0,1,1,4,3},        /* G */
700             {0,1,1,0,3},        /* R */
701         },
702     },
703     [PIX_FMT_VAAPI_MOCO] = {
704         .name = "vaapi_moco",
705         .log2_chroma_w = 1,
706         .log2_chroma_h = 1,
707         .flags = PIX_FMT_HWACCEL,
708     },
709     [PIX_FMT_VAAPI_IDCT] = {
710         .name = "vaapi_idct",
711         .log2_chroma_w = 1,
712         .log2_chroma_h = 1,
713         .flags = PIX_FMT_HWACCEL,
714     },
715     [PIX_FMT_VAAPI_VLD] = {
716         .name = "vaapi_vld",
717         .log2_chroma_w = 1,
718         .log2_chroma_h = 1,
719         .flags = PIX_FMT_HWACCEL,
720     },
721     [PIX_FMT_YUV420P16LE] = {
722         .name = "yuv420p16le",
723         .nb_components= 3,
724         .log2_chroma_w= 1,
725         .log2_chroma_h= 1,
726         .comp = {
727             {0,1,1,0,15},        /* Y */
728             {1,1,1,0,15},        /* U */
729             {2,1,1,0,15},        /* V */
730         },
731     },
732     [PIX_FMT_YUV420P16BE] = {
733         .name = "yuv420p16be",
734         .nb_components= 3,
735         .log2_chroma_w= 1,
736         .log2_chroma_h= 1,
737         .comp = {
738             {0,1,1,0,15},        /* Y */
739             {1,1,1,0,15},        /* U */
740             {2,1,1,0,15},        /* V */
741         },
742         .flags = PIX_FMT_BE,
743     },
744     [PIX_FMT_YUV422P16LE] = {
745         .name = "yuv422p16le",
746         .nb_components= 3,
747         .log2_chroma_w= 1,
748         .log2_chroma_h= 0,
749         .comp = {
750             {0,1,1,0,15},        /* Y */
751             {1,1,1,0,15},        /* U */
752             {2,1,1,0,15},        /* V */
753         },
754     },
755     [PIX_FMT_YUV422P16BE] = {
756         .name = "yuv422p16be",
757         .nb_components= 3,
758         .log2_chroma_w= 1,
759         .log2_chroma_h= 0,
760         .comp = {
761             {0,1,1,0,15},        /* Y */
762             {1,1,1,0,15},        /* U */
763             {2,1,1,0,15},        /* V */
764         },
765         .flags = PIX_FMT_BE,
766     },
767     [PIX_FMT_YUV444P16LE] = {
768         .name = "yuv444p16le",
769         .nb_components= 3,
770         .log2_chroma_w= 0,
771         .log2_chroma_h= 0,
772         .comp = {
773             {0,1,1,0,15},        /* Y */
774             {1,1,1,0,15},        /* U */
775             {2,1,1,0,15},        /* V */
776         },
777     },
778     [PIX_FMT_YUV444P16BE] = {
779         .name = "yuv444p16be",
780         .nb_components= 3,
781         .log2_chroma_w= 0,
782         .log2_chroma_h= 0,
783         .comp = {
784             {0,1,1,0,15},        /* Y */
785             {1,1,1,0,15},        /* U */
786             {2,1,1,0,15},        /* V */
787         },
788         .flags = PIX_FMT_BE,
789     },
790     [PIX_FMT_DXVA2_VLD] = {
791         .name = "dxva2_vld",
792         .log2_chroma_w = 1,
793         .log2_chroma_h = 1,
794         .flags = PIX_FMT_HWACCEL,
795     },
796     [PIX_FMT_Y400A] = {
797         .name = "y400a",
798         .nb_components= 2,
799         .comp = {
800             {0,1,1,0,7},        /* Y */
801             {0,1,2,0,7},        /* A */
802         },
803     },
804 };
805
806 static enum PixelFormat get_pix_fmt_internal(const char *name)
807 {
808     enum PixelFormat pix_fmt;
809
810     for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
811         if (av_pix_fmt_descriptors[pix_fmt].name &&
812             !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
813             return pix_fmt;
814
815     return PIX_FMT_NONE;
816 }
817
818 #if HAVE_BIGENDIAN
819 #   define X_NE(be, le) be
820 #else
821 #   define X_NE(be, le) le
822 #endif
823
824 enum PixelFormat av_get_pix_fmt(const char *name)
825 {
826     enum PixelFormat pix_fmt;
827
828     if (!strcmp(name, "rgb32"))
829         name = X_NE("argb", "bgra");
830     else if (!strcmp(name, "bgr32"))
831         name = X_NE("abgr", "rgba");
832
833     pix_fmt = get_pix_fmt_internal(name);
834     if (pix_fmt == PIX_FMT_NONE) {
835         char name2[32];
836
837         snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
838         pix_fmt = get_pix_fmt_internal(name2);
839     }
840     return pix_fmt;
841 }
842
843 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
844 {
845     int c, bits = 0;
846     int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
847
848     for (c = 0; c < pixdesc->nb_components; c++) {
849         int s = c==1 || c==2 ? 0 : log2_pixels;
850         bits += (pixdesc->comp[c].depth_minus1+1) << s;
851     }
852
853     return bits >> log2_pixels;
854 }