pixfmt: add planar RGB formats.
[libav.git] / libavutil / pixdesc.c
CommitLineData
9b61d838 1/*
e0cffbe7 2 * pixel format descriptor
9b61d838
MN
3 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
4 *
2912e87a 5 * This file is part of Libav.
9b61d838 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
9b61d838
MN
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
9b61d838
MN
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
9b61d838
MN
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
47bfd50a
MR
22#include <stdio.h>
23#include <string.h>
51135d1d 24#include "pixfmt.h"
9b61d838
MN
25#include "pixdesc.h"
26
f47a7cb7
SS
27#include "intreadwrite.h"
28
ce1cd1cb 29void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
ee435580 30 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
f47a7cb7
SS
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;
4660143a 56 int is_8bit = shift + depth <= 8;
f47a7cb7 57
4660143a 58 if (is_8bit)
9525243f 59 p += !!(flags & PIX_FMT_BE);
4660143a 60
f47a7cb7 61 while(w--){
9525243f
MR
62 int val = is_8bit ? *p :
63 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
f47a7cb7
SS
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
ce1cd1cb 73void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
ee435580 74 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
f47a7cb7
SS
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
9525243f
MR
97 if (shift + depth <= 8) {
98 p += !!(flags & PIX_FMT_BE);
99 while (w--) {
100 *p |= (*src++<<shift);
101 p += step;
102 }
103 } else {
78b19cf0
MR
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;
f47a7cb7 113 }
9525243f 114 }
f47a7cb7
SS
115 }
116}
117
d2863e72 118const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
bcbd9a14
SS
119 [PIX_FMT_YUV420P] = {
120 .name = "yuv420p",
b8873c2a 121 .nb_components= 3,
9b61d838 122 .log2_chroma_w= 1,
bcbd9a14 123 .log2_chroma_h= 1,
9b61d838 124 .comp = {
eb39fb51
SS
125 {0,0,1,0,7}, /* Y */
126 {1,0,1,0,7}, /* U */
127 {2,0,1,0,7}, /* V */
9b61d838
MN
128 },
129 },
bcbd9a14
SS
130 [PIX_FMT_YUYV422] = {
131 .name = "yuyv422",
b8873c2a 132 .nb_components= 3,
9b61d838 133 .log2_chroma_w= 1,
bcbd9a14
SS
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",
b8873c2a 143 .nb_components= 3,
bcbd9a14
SS
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 },
10151b13
SS
152 [PIX_FMT_BGR24] = {
153 .name = "bgr24",
b8873c2a 154 .nb_components= 3,
10151b13
SS
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 },
bcbd9a14
SS
163 [PIX_FMT_YUV422P] = {
164 .name = "yuv422p",
b8873c2a 165 .nb_components= 3,
bcbd9a14
SS
166 .log2_chroma_w= 1,
167 .log2_chroma_h= 0,
9b61d838 168 .comp = {
eb39fb51
SS
169 {0,0,1,0,7}, /* Y */
170 {1,0,1,0,7}, /* U */
171 {2,0,1,0,7}, /* V */
9b61d838
MN
172 },
173 },
10151b13
SS
174 [PIX_FMT_YUV444P] = {
175 .name = "yuv444p",
b8873c2a 176 .nb_components= 3,
10151b13
SS
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 },
9b61d838 185 [PIX_FMT_YUV410P] = {
1e896640 186 .name = "yuv410p",
b8873c2a 187 .nb_components= 3,
9b61d838
MN
188 .log2_chroma_w= 2,
189 .log2_chroma_h= 2,
190 .comp = {
eb39fb51
SS
191 {0,0,1,0,7}, /* Y */
192 {1,0,1,0,7}, /* U */
193 {2,0,1,0,7}, /* V */
9b61d838
MN
194 },
195 },
10151b13
SS
196 [PIX_FMT_YUV411P] = {
197 .name = "yuv411p",
b8873c2a 198 .nb_components= 3,
10151b13
SS
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] = {
382cb115 208 .name = "gray",
b8873c2a 209 .nb_components= 1,
10151b13
SS
210 .log2_chroma_w= 0,
211 .log2_chroma_h= 0,
212 .comp = {
213 {0,0,1,0,7}, /* Y */
214 },
ce7c7179 215 .flags = PIX_FMT_PAL,
10151b13
SS
216 },
217 [PIX_FMT_MONOWHITE] = {
382cb115 218 .name = "monow",
b8873c2a 219 .nb_components= 1,
10151b13
SS
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 },
bcbd9a14 227 [PIX_FMT_MONOBLACK] = {
382cb115 228 .name = "monob",
b8873c2a 229 .nb_components= 1,
bcbd9a14
SS
230 .log2_chroma_w= 0,
231 .log2_chroma_h= 0,
9b61d838 232 .comp = {
bcbd9a14 233 {0,0,1,7,0}, /* Y */
9b61d838 234 },
bcbd9a14 235 .flags = PIX_FMT_BITSTREAM,
9b61d838 236 },
bcbd9a14
SS
237 [PIX_FMT_PAL8] = {
238 .name = "pal8",
b8873c2a 239 .nb_components= 1,
bcbd9a14 240 .log2_chroma_w= 0,
9b61d838
MN
241 .log2_chroma_h= 0,
242 .comp = {
bcbd9a14 243 {0,0,1,0,7},
9b61d838 244 },
bcbd9a14 245 .flags = PIX_FMT_PAL,
9b61d838 246 },
10151b13
SS
247 [PIX_FMT_YUVJ420P] = {
248 .name = "yuvj420p",
b8873c2a 249 .nb_components= 3,
10151b13
SS
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",
b8873c2a 260 .nb_components= 3,
10151b13
SS
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",
b8873c2a 271 .nb_components= 3,
10151b13
SS
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 },
3fa70a3b 280 [PIX_FMT_XVMC_MPEG2_MC] = {
382cb115 281 .name = "xvmcmc",
3fa70a3b
SS
282 .flags = PIX_FMT_HWACCEL,
283 },
284 [PIX_FMT_XVMC_MPEG2_IDCT] = {
382cb115 285 .name = "xvmcidct",
3fa70a3b
SS
286 .flags = PIX_FMT_HWACCEL,
287 },
9b61d838 288 [PIX_FMT_UYVY422] = {
1e896640 289 .name = "uyvy422",
b8873c2a 290 .nb_components= 3,
9b61d838
MN
291 .log2_chroma_w= 1,
292 .log2_chroma_h= 0,
293 .comp = {
eb39fb51
SS
294 {0,1,2,0,7}, /* Y */
295 {0,3,1,0,7}, /* U */
296 {0,3,3,0,7}, /* V */
9b61d838
MN
297 },
298 },
10151b13
SS
299 [PIX_FMT_UYYVYY411] = {
300 .name = "uyyvyy411",
b8873c2a 301 .nb_components= 3,
10151b13
SS
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",
b8873c2a 312 .nb_components= 3,
10151b13
SS
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 },
d71ad089 320 .flags = PIX_FMT_PAL,
10151b13
SS
321 },
322 [PIX_FMT_BGR4] = {
323 .name = "bgr4",
b8873c2a 324 .nb_components= 3,
10151b13
SS
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",
b8873c2a 336 .nb_components= 3,
10151b13
SS
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 },
d71ad089 344 .flags = PIX_FMT_PAL,
10151b13
SS
345 },
346 [PIX_FMT_RGB8] = {
347 .name = "rgb8",
b8873c2a 348 .nb_components= 3,
10151b13
SS
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 },
d71ad089 356 .flags = PIX_FMT_PAL,
10151b13
SS
357 },
358 [PIX_FMT_RGB4] = {
359 .name = "rgb4",
b8873c2a 360 .nb_components= 3,
10151b13
SS
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",
b8873c2a 372 .nb_components= 3,
10151b13
SS
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 },
d71ad089 380 .flags = PIX_FMT_PAL,
10151b13 381 },
bcbd9a14
SS
382 [PIX_FMT_NV12] = {
383 .name = "nv12",
b8873c2a 384 .nb_components= 3,
bcbd9a14
SS
385 .log2_chroma_w= 1,
386 .log2_chroma_h= 1,
9b61d838 387 .comp = {
bcbd9a14
SS
388 {0,0,1,0,7}, /* Y */
389 {1,1,1,0,7}, /* U */
390 {1,1,2,0,7}, /* V */
9b61d838
MN
391 },
392 },
10151b13
SS
393 [PIX_FMT_NV21] = {
394 .name = "nv21",
b8873c2a 395 .nb_components= 3,
10151b13
SS
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",
b8873c2a 406 .nb_components= 4,
10151b13
SS
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 },
9b61d838 416 [PIX_FMT_RGBA] = {
1e896640 417 .name = "rgba",
b8873c2a 418 .nb_components= 4,
9b61d838
MN
419 .log2_chroma_w= 0,
420 .log2_chroma_h= 0,
421 .comp = {
eb39fb51
SS
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 */
9b61d838
MN
426 },
427 },
10151b13
SS
428 [PIX_FMT_ABGR] = {
429 .name = "abgr",
b8873c2a 430 .nb_components= 4,
10151b13
SS
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",
b8873c2a 442 .nb_components= 4,
10151b13
SS
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 },
bcbd9a14
SS
452 [PIX_FMT_GRAY16BE] = {
453 .name = "gray16be",
b8873c2a 454 .nb_components= 1,
9b61d838
MN
455 .log2_chroma_w= 0,
456 .log2_chroma_h= 0,
457 .comp = {
bcbd9a14
SS
458 {0,1,1,0,15}, /* Y */
459 },
460 .flags = PIX_FMT_BE,
461 },
462 [PIX_FMT_GRAY16LE] = {
463 .name = "gray16le",
b8873c2a 464 .nb_components= 1,
bcbd9a14
SS
465 .log2_chroma_w= 0,
466 .log2_chroma_h= 0,
467 .comp = {
468 {0,1,1,0,15}, /* Y */
9b61d838
MN
469 },
470 },
10151b13
SS
471 [PIX_FMT_YUV440P] = {
472 .name = "yuv440p",
b8873c2a 473 .nb_components= 3,
10151b13
SS
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",
b8873c2a 484 .nb_components= 3,
10151b13
SS
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",
b8873c2a 495 .nb_components= 4,
10151b13
SS
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 },
3fa70a3b
SS
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 },
dd6308ad
CEH
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 },
9b61d838 541 [PIX_FMT_RGB48BE] = {
1e896640 542 .name = "rgb48be",
b8873c2a 543 .nb_components= 3,
9b61d838
MN
544 .log2_chroma_w= 0,
545 .log2_chroma_h= 0,
546 .comp = {
eb39fb51
SS
547 {0,5,1,0,15}, /* R */
548 {0,5,3,0,15}, /* G */
549 {0,5,5,0,15}, /* B */
9b61d838
MN
550 },
551 .flags = PIX_FMT_BE,
552 },
bcbd9a14
SS
553 [PIX_FMT_RGB48LE] = {
554 .name = "rgb48le",
b8873c2a 555 .nb_components= 3,
9b61d838
MN
556 .log2_chroma_w= 0,
557 .log2_chroma_h= 0,
558 .comp = {
bcbd9a14
SS
559 {0,5,1,0,15}, /* R */
560 {0,5,3,0,15}, /* G */
561 {0,5,5,0,15}, /* B */
9b61d838
MN
562 },
563 },
e5681ba0 564 [PIX_FMT_RGB565BE] = {
1e896640 565 .name = "rgb565be",
b8873c2a 566 .nb_components= 3,
9b61d838
MN
567 .log2_chroma_w= 0,
568 .log2_chroma_h= 0,
569 .comp = {
eb39fb51 570 {0,1,0,3,4}, /* R */
f938cbf9
SS
571 {0,1,1,5,5}, /* G */
572 {0,1,1,0,4}, /* B */
9b61d838
MN
573 },
574 .flags = PIX_FMT_BE,
575 },
bcbd9a14
SS
576 [PIX_FMT_RGB565LE] = {
577 .name = "rgb565le",
b8873c2a 578 .nb_components= 3,
9b61d838
MN
579 .log2_chroma_w= 0,
580 .log2_chroma_h= 0,
581 .comp = {
bcbd9a14
SS
582 {0,1,2,3,4}, /* R */
583 {0,1,1,5,5}, /* G */
584 {0,1,1,0,4}, /* B */
9b61d838 585 },
9b61d838 586 },
10151b13
SS
587 [PIX_FMT_RGB555BE] = {
588 .name = "rgb555be",
b8873c2a 589 .nb_components= 3,
10151b13
SS
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",
b8873c2a 601 .nb_components= 3,
10151b13
SS
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 },
2b7cf167
JK
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 },
73389754
PR
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 },
10151b13
SS
656 [PIX_FMT_BGR565BE] = {
657 .name = "bgr565be",
b8873c2a 658 .nb_components= 3,
10151b13
SS
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",
b8873c2a 670 .nb_components= 3,
10151b13
SS
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",
b8873c2a 681 .nb_components= 3,
10151b13
SS
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",
b8873c2a 693 .nb_components= 3,
10151b13
SS
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 },
2b7cf167
JK
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 },
3fa70a3b
SS
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 },
ac3dbb4d
SZ
743 [PIX_FMT_VDA_VLD] = {
744 .name = "vda_vld",
745 .log2_chroma_w = 1,
746 .log2_chroma_h = 1,
747 .flags = PIX_FMT_HWACCEL,
748 },
42239ced
OA
749 [PIX_FMT_YUV420P9LE] = {
750 .name = "yuv420p9le",
751 .nb_components= 3,
752 .log2_chroma_w= 1,
753 .log2_chroma_h= 1,
754 .comp = {
755 {0,1,1,0,8}, /* Y */
756 {1,1,1,0,8}, /* U */
757 {2,1,1,0,8}, /* V */
758 },
759 },
760 [PIX_FMT_YUV420P9BE] = {
761 .name = "yuv420p9be",
762 .nb_components= 3,
763 .log2_chroma_w= 1,
764 .log2_chroma_h= 1,
765 .comp = {
766 {0,1,1,0,8}, /* Y */
767 {1,1,1,0,8}, /* U */
768 {2,1,1,0,8}, /* V */
769 },
770 .flags = PIX_FMT_BE,
771 },
772 [PIX_FMT_YUV420P10LE] = {
773 .name = "yuv420p10le",
774 .nb_components= 3,
775 .log2_chroma_w= 1,
776 .log2_chroma_h= 1,
777 .comp = {
778 {0,1,1,0,9}, /* Y */
779 {1,1,1,0,9}, /* U */
780 {2,1,1,0,9}, /* V */
781 },
782 },
783 [PIX_FMT_YUV420P10BE] = {
784 .name = "yuv420p10be",
785 .nb_components= 3,
786 .log2_chroma_w= 1,
787 .log2_chroma_h= 1,
788 .comp = {
789 {0,1,1,0,9}, /* Y */
790 {1,1,1,0,9}, /* U */
791 {2,1,1,0,9}, /* V */
792 },
793 .flags = PIX_FMT_BE,
794 },
35f6c154
LT
795 [PIX_FMT_YUV420P16LE] = {
796 .name = "yuv420p16le",
b8873c2a 797 .nb_components= 3,
75801da5
SS
798 .log2_chroma_w= 1,
799 .log2_chroma_h= 1,
800 .comp = {
801 {0,1,1,0,15}, /* Y */
802 {1,1,1,0,15}, /* U */
803 {2,1,1,0,15}, /* V */
804 },
805 },
35f6c154
LT
806 [PIX_FMT_YUV420P16BE] = {
807 .name = "yuv420p16be",
b8873c2a 808 .nb_components= 3,
75801da5
SS
809 .log2_chroma_w= 1,
810 .log2_chroma_h= 1,
811 .comp = {
812 {0,1,1,0,15}, /* Y */
813 {1,1,1,0,15}, /* U */
814 {2,1,1,0,15}, /* V */
815 },
816 .flags = PIX_FMT_BE,
817 },
dc49bf12
RB
818 [PIX_FMT_YUV422P9LE] = {
819 .name = "yuv422p9le",
820 .nb_components= 3,
821 .log2_chroma_w= 1,
822 .log2_chroma_h= 0,
823 .comp = {
824 {0,1,1,0,8}, /* Y */
825 {1,1,1,0,8}, /* U */
826 {2,1,1,0,8}, /* V */
827 },
828 },
829 [PIX_FMT_YUV422P9BE] = {
830 .name = "yuv422p9be",
831 .nb_components= 3,
832 .log2_chroma_w= 1,
833 .log2_chroma_h= 0,
834 .comp = {
835 {0,1,1,0,8}, /* Y */
836 {1,1,1,0,8}, /* U */
837 {2,1,1,0,8}, /* V */
838 },
839 .flags = PIX_FMT_BE,
840 },
5c511ad4
BC
841 [PIX_FMT_YUV422P10LE] = {
842 .name = "yuv422p10le",
843 .nb_components= 3,
844 .log2_chroma_w= 1,
845 .log2_chroma_h= 0,
846 .comp = {
847 {0,1,1,0,9}, /* Y */
848 {1,1,1,0,9}, /* U */
849 {2,1,1,0,9}, /* V */
850 },
851 },
852 [PIX_FMT_YUV422P10BE] = {
853 .name = "yuv422p10be",
854 .nb_components= 3,
855 .log2_chroma_w= 1,
856 .log2_chroma_h= 0,
857 .comp = {
858 {0,1,1,0,9}, /* Y */
859 {1,1,1,0,9}, /* U */
860 {2,1,1,0,9}, /* V */
861 },
862 .flags = PIX_FMT_BE,
863 },
35f6c154
LT
864 [PIX_FMT_YUV422P16LE] = {
865 .name = "yuv422p16le",
b8873c2a 866 .nb_components= 3,
75801da5
SS
867 .log2_chroma_w= 1,
868 .log2_chroma_h= 0,
869 .comp = {
870 {0,1,1,0,15}, /* Y */
871 {1,1,1,0,15}, /* U */
872 {2,1,1,0,15}, /* V */
873 },
874 },
35f6c154
LT
875 [PIX_FMT_YUV422P16BE] = {
876 .name = "yuv422p16be",
b8873c2a 877 .nb_components= 3,
75801da5
SS
878 .log2_chroma_w= 1,
879 .log2_chroma_h= 0,
880 .comp = {
881 {0,1,1,0,15}, /* Y */
882 {1,1,1,0,15}, /* U */
883 {2,1,1,0,15}, /* V */
884 },
885 .flags = PIX_FMT_BE,
886 },
35f6c154
LT
887 [PIX_FMT_YUV444P16LE] = {
888 .name = "yuv444p16le",
b8873c2a 889 .nb_components= 3,
75801da5
SS
890 .log2_chroma_w= 0,
891 .log2_chroma_h= 0,
892 .comp = {
893 {0,1,1,0,15}, /* Y */
894 {1,1,1,0,15}, /* U */
895 {2,1,1,0,15}, /* V */
896 },
897 },
35f6c154
LT
898 [PIX_FMT_YUV444P16BE] = {
899 .name = "yuv444p16be",
b8873c2a 900 .nb_components= 3,
75801da5
SS
901 .log2_chroma_w= 0,
902 .log2_chroma_h= 0,
903 .comp = {
904 {0,1,1,0,15}, /* Y */
905 {1,1,1,0,15}, /* U */
906 {2,1,1,0,15}, /* V */
907 },
908 .flags = PIX_FMT_BE,
909 },
103278f7
RB
910 [PIX_FMT_YUV444P10LE] = {
911 .name = "yuv444p10le",
912 .nb_components= 3,
913 .log2_chroma_w= 0,
914 .log2_chroma_h= 0,
915 .comp = {
916 {0,1,1,0,9}, /* Y */
917 {1,1,1,0,9}, /* U */
918 {2,1,1,0,9}, /* V */
919 },
920 },
921 [PIX_FMT_YUV444P10BE] = {
922 .name = "yuv444p10be",
923 .nb_components= 3,
924 .log2_chroma_w= 0,
925 .log2_chroma_h= 0,
926 .comp = {
927 {0,1,1,0,9}, /* Y */
928 {1,1,1,0,9}, /* U */
929 {2,1,1,0,9}, /* V */
930 },
931 .flags = PIX_FMT_BE,
932 },
933 [PIX_FMT_YUV444P9LE] = {
934 .name = "yuv444p9le",
935 .nb_components= 3,
936 .log2_chroma_w= 0,
937 .log2_chroma_h= 0,
938 .comp = {
939 {0,1,1,0,8}, /* Y */
940 {1,1,1,0,8}, /* U */
941 {2,1,1,0,8}, /* V */
942 },
943 },
944 [PIX_FMT_YUV444P9BE] = {
945 .name = "yuv444p9be",
946 .nb_components= 3,
947 .log2_chroma_w= 0,
948 .log2_chroma_h= 0,
949 .comp = {
e59d6b4d
OA
950 {0,1,1,0,8}, /* Y */
951 {1,1,1,0,8}, /* U */
952 {2,1,1,0,8}, /* V */
103278f7
RB
953 },
954 .flags = PIX_FMT_BE,
955 },
92c6a099
LA
956 [PIX_FMT_DXVA2_VLD] = {
957 .name = "dxva2_vld",
958 .log2_chroma_w = 1,
959 .log2_chroma_h = 1,
960 .flags = PIX_FMT_HWACCEL,
961 },
4744f896
962 [PIX_FMT_Y400A] = {
963 .name = "y400a",
964 .nb_components= 2,
965 .comp = {
966 {0,1,1,0,7}, /* Y */
967 {0,1,2,0,7}, /* A */
968 },
969 },
bd97b2e1
RB
970 [PIX_FMT_GBRP] = {
971 .name = "gbrp",
972 .nb_components= 3,
973 .log2_chroma_w= 0,
974 .log2_chroma_h= 0,
975 .comp = {
976 {0,0,1,0,7}, /* G */
977 {1,0,1,0,7}, /* B */
978 {2,0,1,0,7}, /* R */
979 },
980 },
981 [PIX_FMT_GBRP9LE] = {
982 .name = "gbrp9le",
983 .nb_components= 3,
984 .log2_chroma_w= 0,
985 .log2_chroma_h= 0,
986 .comp = {
987 {0,1,1,0,8}, /* G */
988 {1,1,1,0,8}, /* B */
989 {2,1,1,0,8}, /* R */
990 },
991 },
992 [PIX_FMT_GBRP9BE] = {
993 .name = "gbrp9be",
994 .nb_components= 3,
995 .log2_chroma_w= 0,
996 .log2_chroma_h= 0,
997 .comp = {
998 {0,1,1,0,8}, /* G */
999 {1,1,1,0,8}, /* B */
1000 {2,1,1,0,8}, /* R */
1001 },
1002 .flags = PIX_FMT_BE,
1003 },
1004 [PIX_FMT_GBRP10LE] = {
1005 .name = "gbrp10le",
1006 .nb_components= 3,
1007 .log2_chroma_w= 0,
1008 .log2_chroma_h= 0,
1009 .comp = {
1010 {0,1,1,0,9}, /* G */
1011 {1,1,1,0,9}, /* B */
1012 {2,1,1,0,9}, /* R */
1013 },
1014 },
1015 [PIX_FMT_GBRP10BE] = {
1016 .name = "gbrp10be",
1017 .nb_components= 3,
1018 .log2_chroma_w= 0,
1019 .log2_chroma_h= 0,
1020 .comp = {
1021 {0,1,1,0,9}, /* G */
1022 {1,1,1,0,9}, /* B */
1023 {2,1,1,0,9}, /* R */
1024 },
1025 .flags = PIX_FMT_BE,
1026 },
1027 [PIX_FMT_GBRP16LE] = {
1028 .name = "gbrp16le",
1029 .nb_components= 3,
1030 .log2_chroma_w= 0,
1031 .log2_chroma_h= 0,
1032 .comp = {
1033 {0,1,1,0,15}, /* G */
1034 {1,1,1,0,15}, /* B */
1035 {2,1,1,0,15}, /* R */
1036 },
1037 },
1038 [PIX_FMT_GBRP16BE] = {
1039 .name = "gbrp16be",
1040 .nb_components= 3,
1041 .log2_chroma_w= 0,
1042 .log2_chroma_h= 0,
1043 .comp = {
1044 {0,1,1,0,15}, /* G */
1045 {1,1,1,0,15}, /* B */
1046 {2,1,1,0,15}, /* R */
1047 },
1048 .flags = PIX_FMT_BE,
1049 },
9b61d838 1050};
5efccce2 1051
80a07f6e
SS
1052static enum PixelFormat get_pix_fmt_internal(const char *name)
1053{
1054 enum PixelFormat pix_fmt;
1055
1056 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
1057 if (av_pix_fmt_descriptors[pix_fmt].name &&
1058 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
1059 return pix_fmt;
1060
1061 return PIX_FMT_NONE;
1062}
1063
8f653e28
SS
1064const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
1065{
1066 return (unsigned)pix_fmt < PIX_FMT_NB ?
1067 av_pix_fmt_descriptors[pix_fmt].name : NULL;
1068}
1069
80a07f6e
SS
1070#if HAVE_BIGENDIAN
1071# define X_NE(be, le) be
1072#else
1073# define X_NE(be, le) le
1074#endif
1075
1076enum PixelFormat av_get_pix_fmt(const char *name)
1077{
1078 enum PixelFormat pix_fmt;
1079
1080 if (!strcmp(name, "rgb32"))
1081 name = X_NE("argb", "bgra");
1082 else if (!strcmp(name, "bgr32"))
1083 name = X_NE("abgr", "rgba");
1084
1085 pix_fmt = get_pix_fmt_internal(name);
1086 if (pix_fmt == PIX_FMT_NONE) {
1087 char name2[32];
1088
1089 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
1090 pix_fmt = get_pix_fmt_internal(name2);
1091 }
1092 return pix_fmt;
1093}
1094
5efccce2
SS
1095int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
1096{
1097 int c, bits = 0;
1098 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
1099
b8873c2a 1100 for (c = 0; c < pixdesc->nb_components; c++) {
5efccce2
SS
1101 int s = c==1 || c==2 ? 0 : log2_pixels;
1102 bits += (pixdesc->comp[c].depth_minus1+1) << s;
1103 }
1104
1105 return bits >> log2_pixels;
1106}
bb4afa13
SS
1107
1108char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
1109{
1110 /* print header */
1111 if (pix_fmt < 0) {
1112 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
1113 } else {
1114 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
1115 snprintf(buf, buf_size, "%-11s %7d %10d",
1116 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
1117 }
1118
1119 return buf;
1120}