Rename y400a to gray8a.
[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 = 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_YUV420P9LE] = {
744         .name = "yuv420p9le",
745         .nb_components= 3,
746         .log2_chroma_w= 1,
747         .log2_chroma_h= 1,
748         .comp = {
749             {0,1,1,0,8},        /* Y */
750             {1,1,1,0,8},        /* U */
751             {2,1,1,0,8},        /* V */
752         },
753     },
754     [PIX_FMT_YUV420P9BE] = {
755         .name = "yuv420p9be",
756         .nb_components= 3,
757         .log2_chroma_w= 1,
758         .log2_chroma_h= 1,
759         .comp = {
760             {0,1,1,0,8},        /* Y */
761             {1,1,1,0,8},        /* U */
762             {2,1,1,0,8},        /* V */
763         },
764         .flags = PIX_FMT_BE,
765     },
766     [PIX_FMT_YUV420P10LE] = {
767         .name = "yuv420p10le",
768         .nb_components= 3,
769         .log2_chroma_w= 1,
770         .log2_chroma_h= 1,
771         .comp = {
772             {0,1,1,0,9},        /* Y */
773             {1,1,1,0,9},        /* U */
774             {2,1,1,0,9},        /* V */
775         },
776     },
777     [PIX_FMT_YUV420P10BE] = {
778         .name = "yuv420p10be",
779         .nb_components= 3,
780         .log2_chroma_w= 1,
781         .log2_chroma_h= 1,
782         .comp = {
783             {0,1,1,0,9},        /* Y */
784             {1,1,1,0,9},        /* U */
785             {2,1,1,0,9},        /* V */
786         },
787         .flags = PIX_FMT_BE,
788     },
789     [PIX_FMT_YUV420P16LE] = {
790         .name = "yuv420p16le",
791         .nb_components= 3,
792         .log2_chroma_w= 1,
793         .log2_chroma_h= 1,
794         .comp = {
795             {0,1,1,0,15},        /* Y */
796             {1,1,1,0,15},        /* U */
797             {2,1,1,0,15},        /* V */
798         },
799     },
800     [PIX_FMT_YUV420P16BE] = {
801         .name = "yuv420p16be",
802         .nb_components= 3,
803         .log2_chroma_w= 1,
804         .log2_chroma_h= 1,
805         .comp = {
806             {0,1,1,0,15},        /* Y */
807             {1,1,1,0,15},        /* U */
808             {2,1,1,0,15},        /* V */
809         },
810         .flags = PIX_FMT_BE,
811     },
812     [PIX_FMT_YUV422P16LE] = {
813         .name = "yuv422p16le",
814         .nb_components= 3,
815         .log2_chroma_w= 1,
816         .log2_chroma_h= 0,
817         .comp = {
818             {0,1,1,0,15},        /* Y */
819             {1,1,1,0,15},        /* U */
820             {2,1,1,0,15},        /* V */
821         },
822     },
823     [PIX_FMT_YUV422P16BE] = {
824         .name = "yuv422p16be",
825         .nb_components= 3,
826         .log2_chroma_w= 1,
827         .log2_chroma_h= 0,
828         .comp = {
829             {0,1,1,0,15},        /* Y */
830             {1,1,1,0,15},        /* U */
831             {2,1,1,0,15},        /* V */
832         },
833         .flags = PIX_FMT_BE,
834     },
835     [PIX_FMT_YUV444P16LE] = {
836         .name = "yuv444p16le",
837         .nb_components= 3,
838         .log2_chroma_w= 0,
839         .log2_chroma_h= 0,
840         .comp = {
841             {0,1,1,0,15},        /* Y */
842             {1,1,1,0,15},        /* U */
843             {2,1,1,0,15},        /* V */
844         },
845     },
846     [PIX_FMT_YUV444P16BE] = {
847         .name = "yuv444p16be",
848         .nb_components= 3,
849         .log2_chroma_w= 0,
850         .log2_chroma_h= 0,
851         .comp = {
852             {0,1,1,0,15},        /* Y */
853             {1,1,1,0,15},        /* U */
854             {2,1,1,0,15},        /* V */
855         },
856         .flags = PIX_FMT_BE,
857     },
858     [PIX_FMT_DXVA2_VLD] = {
859         .name = "dxva2_vld",
860         .log2_chroma_w = 1,
861         .log2_chroma_h = 1,
862         .flags = PIX_FMT_HWACCEL,
863     },
864     [PIX_FMT_GRAY8A] = {
865         .name = "gray8a",
866         .nb_components= 2,
867         .comp = {
868             {0,1,1,0,7},        /* Y */
869             {0,1,2,0,7},        /* A */
870         },
871     },
872 };
873
874 static enum PixelFormat get_pix_fmt_internal(const char *name)
875 {
876     enum PixelFormat pix_fmt;
877
878     for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
879         if (av_pix_fmt_descriptors[pix_fmt].name &&
880             !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
881             return pix_fmt;
882
883     return PIX_FMT_NONE;
884 }
885
886 #if HAVE_BIGENDIAN
887 #   define X_NE(be, le) be
888 #else
889 #   define X_NE(be, le) le
890 #endif
891
892 enum PixelFormat av_get_pix_fmt(const char *name)
893 {
894     enum PixelFormat pix_fmt;
895
896     if (!strcmp(name, "rgb32"))
897         name = X_NE("argb", "bgra");
898     else if (!strcmp(name, "bgr32"))
899         name = X_NE("abgr", "rgba");
900
901     pix_fmt = get_pix_fmt_internal(name);
902     if (pix_fmt == PIX_FMT_NONE) {
903         char name2[32];
904
905         snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
906         pix_fmt = get_pix_fmt_internal(name2);
907     }
908     return pix_fmt;
909 }
910
911 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
912 {
913     int c, bits = 0;
914     int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
915
916     for (c = 0; c < pixdesc->nb_components; c++) {
917         int s = c==1 || c==2 ? 0 : log2_pixels;
918         bits += (pixdesc->comp[c].depth_minus1+1) << s;
919     }
920
921     return bits >> log2_pixels;
922 }
923
924 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
925 {
926     /* print header */
927     if (pix_fmt < 0) {
928         snprintf (buf, buf_size, "name      " " nb_components" " nb_bits");
929     } else {
930         const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
931         snprintf(buf, buf_size, "%-11s %7d %10d",
932                  pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
933     }
934
935     return buf;
936 }