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