tiff: add support for inverted FillOrder for uncompressed data
[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 },
42239ced
OA
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 },
35f6c154
LT
789 [PIX_FMT_YUV420P16LE] = {
790 .name = "yuv420p16le",
b8873c2a 791 .nb_components= 3,
75801da5
SS
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 },
35f6c154
LT
800 [PIX_FMT_YUV420P16BE] = {
801 .name = "yuv420p16be",
b8873c2a 802 .nb_components= 3,
75801da5
SS
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 },
35f6c154
LT
812 [PIX_FMT_YUV422P16LE] = {
813 .name = "yuv422p16le",
b8873c2a 814 .nb_components= 3,
75801da5
SS
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 },
35f6c154
LT
823 [PIX_FMT_YUV422P16BE] = {
824 .name = "yuv422p16be",
b8873c2a 825 .nb_components= 3,
75801da5
SS
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 },
35f6c154
LT
835 [PIX_FMT_YUV444P16LE] = {
836 .name = "yuv444p16le",
b8873c2a 837 .nb_components= 3,
75801da5
SS
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 },
35f6c154
LT
846 [PIX_FMT_YUV444P16BE] = {
847 .name = "yuv444p16be",
b8873c2a 848 .nb_components= 3,
75801da5
SS
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 },
92c6a099
LA
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 },
4744f896
864 [PIX_FMT_Y400A] = {
865 .name = "y400a",
866 .nb_components= 2,
867 .comp = {
868 {0,1,1,0,7}, /* Y */
869 {0,1,2,0,7}, /* A */
870 },
871 },
9b61d838 872};
5efccce2 873
80a07f6e
SS
874static 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
892enum 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
5efccce2
SS
911int 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
b8873c2a 916 for (c = 0; c < pixdesc->nb_components; c++) {
5efccce2
SS
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}
bb4afa13
SS
923
924char *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}