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