zmbv.c: coding style clean-up.
[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 128 },
6b0768e2 129 .flags = PIX_FMT_PLANAR,
9b61d838 130 },
bcbd9a14
SS
131 [PIX_FMT_YUYV422] = {
132 .name = "yuyv422",
b8873c2a 133 .nb_components= 3,
9b61d838 134 .log2_chroma_w= 1,
bcbd9a14
SS
135 .log2_chroma_h= 0,
136 .comp = {
137 {0,1,1,0,7}, /* Y */
138 {0,3,2,0,7}, /* U */
139 {0,3,4,0,7}, /* V */
140 },
141 },
142 [PIX_FMT_RGB24] = {
143 .name = "rgb24",
b8873c2a 144 .nb_components= 3,
bcbd9a14
SS
145 .log2_chroma_w= 0,
146 .log2_chroma_h= 0,
147 .comp = {
148 {0,2,1,0,7}, /* R */
149 {0,2,2,0,7}, /* G */
150 {0,2,3,0,7}, /* B */
151 },
6b0768e2 152 .flags = PIX_FMT_RGB,
bcbd9a14 153 },
10151b13
SS
154 [PIX_FMT_BGR24] = {
155 .name = "bgr24",
b8873c2a 156 .nb_components= 3,
10151b13
SS
157 .log2_chroma_w= 0,
158 .log2_chroma_h= 0,
159 .comp = {
160 {0,2,1,0,7}, /* B */
161 {0,2,2,0,7}, /* G */
162 {0,2,3,0,7}, /* R */
163 },
6b0768e2 164 .flags = PIX_FMT_RGB,
10151b13 165 },
bcbd9a14
SS
166 [PIX_FMT_YUV422P] = {
167 .name = "yuv422p",
b8873c2a 168 .nb_components= 3,
bcbd9a14
SS
169 .log2_chroma_w= 1,
170 .log2_chroma_h= 0,
9b61d838 171 .comp = {
eb39fb51
SS
172 {0,0,1,0,7}, /* Y */
173 {1,0,1,0,7}, /* U */
174 {2,0,1,0,7}, /* V */
9b61d838 175 },
6b0768e2 176 .flags = PIX_FMT_PLANAR,
9b61d838 177 },
10151b13
SS
178 [PIX_FMT_YUV444P] = {
179 .name = "yuv444p",
b8873c2a 180 .nb_components= 3,
10151b13
SS
181 .log2_chroma_w= 0,
182 .log2_chroma_h= 0,
183 .comp = {
184 {0,0,1,0,7}, /* Y */
185 {1,0,1,0,7}, /* U */
186 {2,0,1,0,7}, /* V */
187 },
6b0768e2 188 .flags = PIX_FMT_PLANAR,
10151b13 189 },
9b61d838 190 [PIX_FMT_YUV410P] = {
1e896640 191 .name = "yuv410p",
b8873c2a 192 .nb_components= 3,
9b61d838
MN
193 .log2_chroma_w= 2,
194 .log2_chroma_h= 2,
195 .comp = {
eb39fb51
SS
196 {0,0,1,0,7}, /* Y */
197 {1,0,1,0,7}, /* U */
198 {2,0,1,0,7}, /* V */
9b61d838 199 },
6b0768e2 200 .flags = PIX_FMT_PLANAR,
9b61d838 201 },
10151b13
SS
202 [PIX_FMT_YUV411P] = {
203 .name = "yuv411p",
b8873c2a 204 .nb_components= 3,
10151b13
SS
205 .log2_chroma_w= 2,
206 .log2_chroma_h= 0,
207 .comp = {
208 {0,0,1,0,7}, /* Y */
209 {1,0,1,0,7}, /* U */
210 {2,0,1,0,7}, /* V */
211 },
6b0768e2 212 .flags = PIX_FMT_PLANAR,
10151b13
SS
213 },
214 [PIX_FMT_GRAY8] = {
382cb115 215 .name = "gray",
b8873c2a 216 .nb_components= 1,
10151b13
SS
217 .log2_chroma_w= 0,
218 .log2_chroma_h= 0,
219 .comp = {
220 {0,0,1,0,7}, /* Y */
221 },
222 },
223 [PIX_FMT_MONOWHITE] = {
382cb115 224 .name = "monow",
b8873c2a 225 .nb_components= 1,
10151b13
SS
226 .log2_chroma_w= 0,
227 .log2_chroma_h= 0,
228 .comp = {
229 {0,0,1,0,0}, /* Y */
230 },
231 .flags = PIX_FMT_BITSTREAM,
232 },
bcbd9a14 233 [PIX_FMT_MONOBLACK] = {
382cb115 234 .name = "monob",
b8873c2a 235 .nb_components= 1,
bcbd9a14
SS
236 .log2_chroma_w= 0,
237 .log2_chroma_h= 0,
9b61d838 238 .comp = {
bcbd9a14 239 {0,0,1,7,0}, /* Y */
9b61d838 240 },
bcbd9a14 241 .flags = PIX_FMT_BITSTREAM,
9b61d838 242 },
bcbd9a14
SS
243 [PIX_FMT_PAL8] = {
244 .name = "pal8",
b8873c2a 245 .nb_components= 1,
bcbd9a14 246 .log2_chroma_w= 0,
9b61d838
MN
247 .log2_chroma_h= 0,
248 .comp = {
bcbd9a14 249 {0,0,1,0,7},
9b61d838 250 },
bcbd9a14 251 .flags = PIX_FMT_PAL,
9b61d838 252 },
10151b13
SS
253 [PIX_FMT_YUVJ420P] = {
254 .name = "yuvj420p",
b8873c2a 255 .nb_components= 3,
10151b13
SS
256 .log2_chroma_w= 1,
257 .log2_chroma_h= 1,
258 .comp = {
259 {0,0,1,0,7}, /* Y */
260 {1,0,1,0,7}, /* U */
261 {2,0,1,0,7}, /* V */
262 },
6b0768e2 263 .flags = PIX_FMT_PLANAR,
10151b13
SS
264 },
265 [PIX_FMT_YUVJ422P] = {
266 .name = "yuvj422p",
b8873c2a 267 .nb_components= 3,
10151b13
SS
268 .log2_chroma_w= 1,
269 .log2_chroma_h= 0,
270 .comp = {
271 {0,0,1,0,7}, /* Y */
272 {1,0,1,0,7}, /* U */
273 {2,0,1,0,7}, /* V */
274 },
6b0768e2 275 .flags = PIX_FMT_PLANAR,
10151b13
SS
276 },
277 [PIX_FMT_YUVJ444P] = {
278 .name = "yuvj444p",
b8873c2a 279 .nb_components= 3,
10151b13
SS
280 .log2_chroma_w= 0,
281 .log2_chroma_h= 0,
282 .comp = {
283 {0,0,1,0,7}, /* Y */
284 {1,0,1,0,7}, /* U */
285 {2,0,1,0,7}, /* V */
286 },
6b0768e2 287 .flags = PIX_FMT_PLANAR,
10151b13 288 },
3fa70a3b 289 [PIX_FMT_XVMC_MPEG2_MC] = {
382cb115 290 .name = "xvmcmc",
3fa70a3b
SS
291 .flags = PIX_FMT_HWACCEL,
292 },
293 [PIX_FMT_XVMC_MPEG2_IDCT] = {
382cb115 294 .name = "xvmcidct",
3fa70a3b
SS
295 .flags = PIX_FMT_HWACCEL,
296 },
9b61d838 297 [PIX_FMT_UYVY422] = {
1e896640 298 .name = "uyvy422",
b8873c2a 299 .nb_components= 3,
9b61d838
MN
300 .log2_chroma_w= 1,
301 .log2_chroma_h= 0,
302 .comp = {
eb39fb51
SS
303 {0,1,2,0,7}, /* Y */
304 {0,3,1,0,7}, /* U */
305 {0,3,3,0,7}, /* V */
9b61d838
MN
306 },
307 },
10151b13
SS
308 [PIX_FMT_UYYVYY411] = {
309 .name = "uyyvyy411",
b8873c2a 310 .nb_components= 3,
10151b13
SS
311 .log2_chroma_w= 2,
312 .log2_chroma_h= 0,
313 .comp = {
314 {0,3,2,0,7}, /* Y */
315 {0,5,1,0,7}, /* U */
316 {0,5,4,0,7}, /* V */
317 },
318 },
319 [PIX_FMT_BGR8] = {
320 .name = "bgr8",
b8873c2a 321 .nb_components= 3,
10151b13
SS
322 .log2_chroma_w= 0,
323 .log2_chroma_h= 0,
324 .comp = {
325 {0,0,1,6,1}, /* B */
326 {0,0,1,3,2}, /* G */
327 {0,0,1,0,2}, /* R */
328 },
6b0768e2 329 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
10151b13
SS
330 },
331 [PIX_FMT_BGR4] = {
332 .name = "bgr4",
b8873c2a 333 .nb_components= 3,
10151b13
SS
334 .log2_chroma_w= 0,
335 .log2_chroma_h= 0,
336 .comp = {
337 {0,3,1,0,0}, /* B */
338 {0,3,2,0,1}, /* G */
339 {0,3,4,0,0}, /* R */
340 },
6b0768e2 341 .flags = PIX_FMT_BITSTREAM | PIX_FMT_RGB,
10151b13
SS
342 },
343 [PIX_FMT_BGR4_BYTE] = {
344 .name = "bgr4_byte",
b8873c2a 345 .nb_components= 3,
10151b13
SS
346 .log2_chroma_w= 0,
347 .log2_chroma_h= 0,
348 .comp = {
349 {0,0,1,3,0}, /* B */
350 {0,0,1,1,1}, /* G */
351 {0,0,1,0,0}, /* R */
352 },
6b0768e2 353 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
10151b13
SS
354 },
355 [PIX_FMT_RGB8] = {
356 .name = "rgb8",
b8873c2a 357 .nb_components= 3,
10151b13
SS
358 .log2_chroma_w= 0,
359 .log2_chroma_h= 0,
360 .comp = {
361 {0,0,1,6,1}, /* R */
362 {0,0,1,3,2}, /* G */
363 {0,0,1,0,2}, /* B */
364 },
6b0768e2 365 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
10151b13
SS
366 },
367 [PIX_FMT_RGB4] = {
368 .name = "rgb4",
b8873c2a 369 .nb_components= 3,
10151b13
SS
370 .log2_chroma_w= 0,
371 .log2_chroma_h= 0,
372 .comp = {
373 {0,3,1,0,0}, /* R */
374 {0,3,2,0,1}, /* G */
375 {0,3,4,0,0}, /* B */
376 },
6b0768e2 377 .flags = PIX_FMT_BITSTREAM | PIX_FMT_RGB,
10151b13
SS
378 },
379 [PIX_FMT_RGB4_BYTE] = {
380 .name = "rgb4_byte",
b8873c2a 381 .nb_components= 3,
10151b13
SS
382 .log2_chroma_w= 0,
383 .log2_chroma_h= 0,
384 .comp = {
385 {0,0,1,3,0}, /* R */
386 {0,0,1,1,1}, /* G */
387 {0,0,1,0,0}, /* B */
388 },
6b0768e2 389 .flags = PIX_FMT_PAL | PIX_FMT_RGB,
10151b13 390 },
bcbd9a14
SS
391 [PIX_FMT_NV12] = {
392 .name = "nv12",
b8873c2a 393 .nb_components= 3,
bcbd9a14
SS
394 .log2_chroma_w= 1,
395 .log2_chroma_h= 1,
9b61d838 396 .comp = {
bcbd9a14
SS
397 {0,0,1,0,7}, /* Y */
398 {1,1,1,0,7}, /* U */
399 {1,1,2,0,7}, /* V */
9b61d838 400 },
6b0768e2 401 .flags = PIX_FMT_PLANAR,
9b61d838 402 },
10151b13
SS
403 [PIX_FMT_NV21] = {
404 .name = "nv21",
b8873c2a 405 .nb_components= 3,
10151b13
SS
406 .log2_chroma_w= 1,
407 .log2_chroma_h= 1,
408 .comp = {
409 {0,0,1,0,7}, /* Y */
410 {1,1,1,0,7}, /* V */
411 {1,1,2,0,7}, /* U */
412 },
6b0768e2 413 .flags = PIX_FMT_PLANAR,
10151b13
SS
414 },
415 [PIX_FMT_ARGB] = {
416 .name = "argb",
b8873c2a 417 .nb_components= 4,
10151b13
SS
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}, /* R */
423 {0,3,3,0,7}, /* G */
424 {0,3,4,0,7}, /* B */
425 },
6b0768e2 426 .flags = PIX_FMT_RGB,
10151b13 427 },
9b61d838 428 [PIX_FMT_RGBA] = {
1e896640 429 .name = "rgba",
b8873c2a 430 .nb_components= 4,
9b61d838
MN
431 .log2_chroma_w= 0,
432 .log2_chroma_h= 0,
433 .comp = {
eb39fb51
SS
434 {0,3,1,0,7}, /* R */
435 {0,3,2,0,7}, /* G */
436 {0,3,3,0,7}, /* B */
437 {0,3,4,0,7}, /* A */
9b61d838 438 },
6b0768e2 439 .flags = PIX_FMT_RGB,
9b61d838 440 },
10151b13
SS
441 [PIX_FMT_ABGR] = {
442 .name = "abgr",
b8873c2a 443 .nb_components= 4,
10151b13
SS
444 .log2_chroma_w= 0,
445 .log2_chroma_h= 0,
446 .comp = {
447 {0,3,1,0,7}, /* A */
448 {0,3,2,0,7}, /* B */
449 {0,3,3,0,7}, /* G */
450 {0,3,4,0,7}, /* R */
451 },
6b0768e2 452 .flags = PIX_FMT_RGB,
10151b13
SS
453 },
454 [PIX_FMT_BGRA] = {
455 .name = "bgra",
b8873c2a 456 .nb_components= 4,
10151b13
SS
457 .log2_chroma_w= 0,
458 .log2_chroma_h= 0,
459 .comp = {
460 {0,3,1,0,7}, /* B */
461 {0,3,2,0,7}, /* G */
462 {0,3,3,0,7}, /* R */
463 {0,3,4,0,7}, /* A */
464 },
6b0768e2 465 .flags = PIX_FMT_RGB,
10151b13 466 },
bcbd9a14
SS
467 [PIX_FMT_GRAY16BE] = {
468 .name = "gray16be",
b8873c2a 469 .nb_components= 1,
9b61d838
MN
470 .log2_chroma_w= 0,
471 .log2_chroma_h= 0,
472 .comp = {
bcbd9a14
SS
473 {0,1,1,0,15}, /* Y */
474 },
475 .flags = PIX_FMT_BE,
476 },
477 [PIX_FMT_GRAY16LE] = {
478 .name = "gray16le",
b8873c2a 479 .nb_components= 1,
bcbd9a14
SS
480 .log2_chroma_w= 0,
481 .log2_chroma_h= 0,
482 .comp = {
483 {0,1,1,0,15}, /* Y */
9b61d838
MN
484 },
485 },
10151b13
SS
486 [PIX_FMT_YUV440P] = {
487 .name = "yuv440p",
b8873c2a 488 .nb_components= 3,
10151b13
SS
489 .log2_chroma_w= 0,
490 .log2_chroma_h= 1,
491 .comp = {
492 {0,0,1,0,7}, /* Y */
493 {1,0,1,0,7}, /* U */
494 {2,0,1,0,7}, /* V */
495 },
6b0768e2 496 .flags = PIX_FMT_PLANAR,
10151b13
SS
497 },
498 [PIX_FMT_YUVJ440P] = {
499 .name = "yuvj440p",
b8873c2a 500 .nb_components= 3,
10151b13
SS
501 .log2_chroma_w= 0,
502 .log2_chroma_h= 1,
503 .comp = {
504 {0,0,1,0,7}, /* Y */
505 {1,0,1,0,7}, /* U */
506 {2,0,1,0,7}, /* V */
507 },
6b0768e2 508 .flags = PIX_FMT_PLANAR,
10151b13
SS
509 },
510 [PIX_FMT_YUVA420P] = {
511 .name = "yuva420p",
b8873c2a 512 .nb_components= 4,
10151b13
SS
513 .log2_chroma_w= 1,
514 .log2_chroma_h= 1,
515 .comp = {
516 {0,0,1,0,7}, /* Y */
517 {1,0,1,0,7}, /* U */
518 {2,0,1,0,7}, /* V */
519 {3,0,1,0,7}, /* A */
520 },
6b0768e2 521 .flags = PIX_FMT_PLANAR,
10151b13 522 },
3fa70a3b
SS
523 [PIX_FMT_VDPAU_H264] = {
524 .name = "vdpau_h264",
525 .log2_chroma_w = 1,
526 .log2_chroma_h = 1,
527 .flags = PIX_FMT_HWACCEL,
528 },
529 [PIX_FMT_VDPAU_MPEG1] = {
530 .name = "vdpau_mpeg1",
531 .log2_chroma_w = 1,
532 .log2_chroma_h = 1,
533 .flags = PIX_FMT_HWACCEL,
534 },
535 [PIX_FMT_VDPAU_MPEG2] = {
536 .name = "vdpau_mpeg2",
537 .log2_chroma_w = 1,
538 .log2_chroma_h = 1,
539 .flags = PIX_FMT_HWACCEL,
540 },
541 [PIX_FMT_VDPAU_WMV3] = {
542 .name = "vdpau_wmv3",
543 .log2_chroma_w = 1,
544 .log2_chroma_h = 1,
545 .flags = PIX_FMT_HWACCEL,
546 },
547 [PIX_FMT_VDPAU_VC1] = {
548 .name = "vdpau_vc1",
549 .log2_chroma_w = 1,
550 .log2_chroma_h = 1,
551 .flags = PIX_FMT_HWACCEL,
552 },
dd6308ad
CEH
553 [PIX_FMT_VDPAU_MPEG4] = {
554 .name = "vdpau_mpeg4",
555 .log2_chroma_w = 1,
556 .log2_chroma_h = 1,
557 .flags = PIX_FMT_HWACCEL,
558 },
9b61d838 559 [PIX_FMT_RGB48BE] = {
1e896640 560 .name = "rgb48be",
b8873c2a 561 .nb_components= 3,
9b61d838
MN
562 .log2_chroma_w= 0,
563 .log2_chroma_h= 0,
564 .comp = {
eb39fb51
SS
565 {0,5,1,0,15}, /* R */
566 {0,5,3,0,15}, /* G */
567 {0,5,5,0,15}, /* B */
9b61d838 568 },
f7f18352 569 .flags = PIX_FMT_RGB | PIX_FMT_BE,
9b61d838 570 },
bcbd9a14
SS
571 [PIX_FMT_RGB48LE] = {
572 .name = "rgb48le",
b8873c2a 573 .nb_components= 3,
9b61d838
MN
574 .log2_chroma_w= 0,
575 .log2_chroma_h= 0,
576 .comp = {
bcbd9a14
SS
577 {0,5,1,0,15}, /* R */
578 {0,5,3,0,15}, /* G */
579 {0,5,5,0,15}, /* B */
9b61d838 580 },
6b0768e2 581 .flags = PIX_FMT_RGB,
9b61d838 582 },
e5681ba0 583 [PIX_FMT_RGB565BE] = {
1e896640 584 .name = "rgb565be",
b8873c2a 585 .nb_components= 3,
9b61d838
MN
586 .log2_chroma_w= 0,
587 .log2_chroma_h= 0,
588 .comp = {
eb39fb51 589 {0,1,0,3,4}, /* R */
f938cbf9
SS
590 {0,1,1,5,5}, /* G */
591 {0,1,1,0,4}, /* B */
9b61d838 592 },
6b0768e2 593 .flags = PIX_FMT_BE | PIX_FMT_RGB,
9b61d838 594 },
bcbd9a14
SS
595 [PIX_FMT_RGB565LE] = {
596 .name = "rgb565le",
b8873c2a 597 .nb_components= 3,
9b61d838
MN
598 .log2_chroma_w= 0,
599 .log2_chroma_h= 0,
600 .comp = {
bcbd9a14
SS
601 {0,1,2,3,4}, /* R */
602 {0,1,1,5,5}, /* G */
603 {0,1,1,0,4}, /* B */
9b61d838 604 },
6b0768e2 605 .flags = PIX_FMT_RGB,
9b61d838 606 },
10151b13
SS
607 [PIX_FMT_RGB555BE] = {
608 .name = "rgb555be",
b8873c2a 609 .nb_components= 3,
10151b13
SS
610 .log2_chroma_w= 0,
611 .log2_chroma_h= 0,
612 .comp = {
613 {0,1,0,2,4}, /* R */
614 {0,1,1,5,4}, /* G */
615 {0,1,1,0,4}, /* B */
616 },
6b0768e2 617 .flags = PIX_FMT_BE | PIX_FMT_RGB,
10151b13
SS
618 },
619 [PIX_FMT_RGB555LE] = {
620 .name = "rgb555le",
b8873c2a 621 .nb_components= 3,
10151b13
SS
622 .log2_chroma_w= 0,
623 .log2_chroma_h= 0,
624 .comp = {
625 {0,1,2,2,4}, /* R */
626 {0,1,1,5,4}, /* G */
627 {0,1,1,0,4}, /* B */
628 },
6b0768e2 629 .flags = PIX_FMT_RGB,
10151b13 630 },
2b7cf167
JK
631 [PIX_FMT_RGB444BE] = {
632 .name = "rgb444be",
633 .nb_components= 3,
634 .log2_chroma_w= 0,
635 .log2_chroma_h= 0,
636 .comp = {
637 {0,1,0,0,3}, /* R */
638 {0,1,1,4,3}, /* G */
639 {0,1,1,0,3}, /* B */
640 },
6b0768e2 641 .flags = PIX_FMT_BE | PIX_FMT_RGB,
2b7cf167
JK
642 },
643 [PIX_FMT_RGB444LE] = {
644 .name = "rgb444le",
645 .nb_components= 3,
646 .log2_chroma_w= 0,
647 .log2_chroma_h= 0,
648 .comp = {
649 {0,1,2,0,3}, /* R */
650 {0,1,1,4,3}, /* G */
651 {0,1,1,0,3}, /* B */
652 },
6b0768e2 653 .flags = PIX_FMT_RGB,
2b7cf167 654 },
73389754
PR
655 [PIX_FMT_BGR48BE] = {
656 .name = "bgr48be",
657 .nb_components= 3,
658 .log2_chroma_w= 0,
659 .log2_chroma_h= 0,
660 .comp = {
661 {0,5,1,0,15}, /* B */
662 {0,5,3,0,15}, /* G */
663 {0,5,5,0,15}, /* R */
664 },
6b0768e2 665 .flags = PIX_FMT_BE | PIX_FMT_RGB,
73389754
PR
666 },
667 [PIX_FMT_BGR48LE] = {
668 .name = "bgr48le",
669 .nb_components= 3,
670 .log2_chroma_w= 0,
671 .log2_chroma_h= 0,
672 .comp = {
673 {0,5,1,0,15}, /* B */
674 {0,5,3,0,15}, /* G */
675 {0,5,5,0,15}, /* R */
676 },
6b0768e2 677 .flags = PIX_FMT_RGB,
73389754 678 },
10151b13
SS
679 [PIX_FMT_BGR565BE] = {
680 .name = "bgr565be",
b8873c2a 681 .nb_components= 3,
10151b13
SS
682 .log2_chroma_w= 0,
683 .log2_chroma_h= 0,
684 .comp = {
685 {0,1,0,3,4}, /* B */
686 {0,1,1,5,5}, /* G */
687 {0,1,1,0,4}, /* R */
688 },
6b0768e2 689 .flags = PIX_FMT_BE | PIX_FMT_RGB,
10151b13
SS
690 },
691 [PIX_FMT_BGR565LE] = {
692 .name = "bgr565le",
b8873c2a 693 .nb_components= 3,
10151b13
SS
694 .log2_chroma_w= 0,
695 .log2_chroma_h= 0,
696 .comp = {
697 {0,1,2,3,4}, /* B */
698 {0,1,1,5,5}, /* G */
699 {0,1,1,0,4}, /* R */
700 },
6b0768e2 701 .flags = PIX_FMT_RGB,
10151b13
SS
702 },
703 [PIX_FMT_BGR555BE] = {
704 .name = "bgr555be",
b8873c2a 705 .nb_components= 3,
10151b13
SS
706 .log2_chroma_w= 0,
707 .log2_chroma_h= 0,
708 .comp = {
709 {0,1,0,2,4}, /* B */
710 {0,1,1,5,4}, /* G */
711 {0,1,1,0,4}, /* R */
712 },
6b0768e2 713 .flags = PIX_FMT_BE | PIX_FMT_RGB,
10151b13
SS
714 },
715 [PIX_FMT_BGR555LE] = {
716 .name = "bgr555le",
b8873c2a 717 .nb_components= 3,
10151b13
SS
718 .log2_chroma_w= 0,
719 .log2_chroma_h= 0,
720 .comp = {
721 {0,1,2,2,4}, /* B */
722 {0,1,1,5,4}, /* G */
723 {0,1,1,0,4}, /* R */
724 },
6b0768e2 725 .flags = PIX_FMT_RGB,
10151b13 726 },
2b7cf167
JK
727 [PIX_FMT_BGR444BE] = {
728 .name = "bgr444be",
729 .nb_components= 3,
730 .log2_chroma_w= 0,
731 .log2_chroma_h= 0,
732 .comp = {
733 {0,1,0,0,3}, /* B */
734 {0,1,1,4,3}, /* G */
735 {0,1,1,0,3}, /* R */
736 },
6b0768e2 737 .flags = PIX_FMT_BE | PIX_FMT_RGB,
2b7cf167
JK
738 },
739 [PIX_FMT_BGR444LE] = {
740 .name = "bgr444le",
741 .nb_components= 3,
742 .log2_chroma_w= 0,
743 .log2_chroma_h= 0,
744 .comp = {
745 {0,1,2,0,3}, /* B */
746 {0,1,1,4,3}, /* G */
747 {0,1,1,0,3}, /* R */
748 },
6b0768e2 749 .flags = PIX_FMT_RGB,
2b7cf167 750 },
3fa70a3b
SS
751 [PIX_FMT_VAAPI_MOCO] = {
752 .name = "vaapi_moco",
753 .log2_chroma_w = 1,
754 .log2_chroma_h = 1,
755 .flags = PIX_FMT_HWACCEL,
756 },
757 [PIX_FMT_VAAPI_IDCT] = {
758 .name = "vaapi_idct",
759 .log2_chroma_w = 1,
760 .log2_chroma_h = 1,
761 .flags = PIX_FMT_HWACCEL,
762 },
763 [PIX_FMT_VAAPI_VLD] = {
764 .name = "vaapi_vld",
765 .log2_chroma_w = 1,
766 .log2_chroma_h = 1,
767 .flags = PIX_FMT_HWACCEL,
768 },
ac3dbb4d
SZ
769 [PIX_FMT_VDA_VLD] = {
770 .name = "vda_vld",
771 .log2_chroma_w = 1,
772 .log2_chroma_h = 1,
773 .flags = PIX_FMT_HWACCEL,
774 },
42239ced
OA
775 [PIX_FMT_YUV420P9LE] = {
776 .name = "yuv420p9le",
777 .nb_components= 3,
778 .log2_chroma_w= 1,
779 .log2_chroma_h= 1,
780 .comp = {
781 {0,1,1,0,8}, /* Y */
782 {1,1,1,0,8}, /* U */
783 {2,1,1,0,8}, /* V */
784 },
6b0768e2 785 .flags = PIX_FMT_PLANAR,
42239ced
OA
786 },
787 [PIX_FMT_YUV420P9BE] = {
788 .name = "yuv420p9be",
789 .nb_components= 3,
790 .log2_chroma_w= 1,
791 .log2_chroma_h= 1,
792 .comp = {
793 {0,1,1,0,8}, /* Y */
794 {1,1,1,0,8}, /* U */
795 {2,1,1,0,8}, /* V */
796 },
6b0768e2 797 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
42239ced
OA
798 },
799 [PIX_FMT_YUV420P10LE] = {
800 .name = "yuv420p10le",
801 .nb_components= 3,
802 .log2_chroma_w= 1,
803 .log2_chroma_h= 1,
804 .comp = {
805 {0,1,1,0,9}, /* Y */
806 {1,1,1,0,9}, /* U */
807 {2,1,1,0,9}, /* V */
808 },
6b0768e2 809 .flags = PIX_FMT_PLANAR,
42239ced
OA
810 },
811 [PIX_FMT_YUV420P10BE] = {
812 .name = "yuv420p10be",
813 .nb_components= 3,
814 .log2_chroma_w= 1,
815 .log2_chroma_h= 1,
816 .comp = {
817 {0,1,1,0,9}, /* Y */
818 {1,1,1,0,9}, /* U */
819 {2,1,1,0,9}, /* V */
820 },
6b0768e2 821 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
42239ced 822 },
35f6c154
LT
823 [PIX_FMT_YUV420P16LE] = {
824 .name = "yuv420p16le",
b8873c2a 825 .nb_components= 3,
75801da5
SS
826 .log2_chroma_w= 1,
827 .log2_chroma_h= 1,
828 .comp = {
829 {0,1,1,0,15}, /* Y */
830 {1,1,1,0,15}, /* U */
831 {2,1,1,0,15}, /* V */
832 },
6b0768e2 833 .flags = PIX_FMT_PLANAR,
75801da5 834 },
35f6c154
LT
835 [PIX_FMT_YUV420P16BE] = {
836 .name = "yuv420p16be",
b8873c2a 837 .nb_components= 3,
75801da5
SS
838 .log2_chroma_w= 1,
839 .log2_chroma_h= 1,
840 .comp = {
841 {0,1,1,0,15}, /* Y */
842 {1,1,1,0,15}, /* U */
843 {2,1,1,0,15}, /* V */
844 },
6b0768e2 845 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
75801da5 846 },
dc49bf12
RB
847 [PIX_FMT_YUV422P9LE] = {
848 .name = "yuv422p9le",
849 .nb_components= 3,
850 .log2_chroma_w= 1,
851 .log2_chroma_h= 0,
852 .comp = {
853 {0,1,1,0,8}, /* Y */
854 {1,1,1,0,8}, /* U */
855 {2,1,1,0,8}, /* V */
856 },
6b0768e2 857 .flags = PIX_FMT_PLANAR,
dc49bf12
RB
858 },
859 [PIX_FMT_YUV422P9BE] = {
860 .name = "yuv422p9be",
861 .nb_components= 3,
862 .log2_chroma_w= 1,
863 .log2_chroma_h= 0,
864 .comp = {
865 {0,1,1,0,8}, /* Y */
866 {1,1,1,0,8}, /* U */
867 {2,1,1,0,8}, /* V */
868 },
6b0768e2 869 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
dc49bf12 870 },
5c511ad4
BC
871 [PIX_FMT_YUV422P10LE] = {
872 .name = "yuv422p10le",
873 .nb_components= 3,
874 .log2_chroma_w= 1,
875 .log2_chroma_h= 0,
876 .comp = {
877 {0,1,1,0,9}, /* Y */
878 {1,1,1,0,9}, /* U */
879 {2,1,1,0,9}, /* V */
880 },
6b0768e2 881 .flags = PIX_FMT_PLANAR,
5c511ad4
BC
882 },
883 [PIX_FMT_YUV422P10BE] = {
884 .name = "yuv422p10be",
885 .nb_components= 3,
886 .log2_chroma_w= 1,
887 .log2_chroma_h= 0,
888 .comp = {
889 {0,1,1,0,9}, /* Y */
890 {1,1,1,0,9}, /* U */
891 {2,1,1,0,9}, /* V */
892 },
6b0768e2 893 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
5c511ad4 894 },
35f6c154
LT
895 [PIX_FMT_YUV422P16LE] = {
896 .name = "yuv422p16le",
b8873c2a 897 .nb_components= 3,
75801da5
SS
898 .log2_chroma_w= 1,
899 .log2_chroma_h= 0,
900 .comp = {
901 {0,1,1,0,15}, /* Y */
902 {1,1,1,0,15}, /* U */
903 {2,1,1,0,15}, /* V */
904 },
6b0768e2 905 .flags = PIX_FMT_PLANAR,
75801da5 906 },
35f6c154
LT
907 [PIX_FMT_YUV422P16BE] = {
908 .name = "yuv422p16be",
b8873c2a 909 .nb_components= 3,
75801da5
SS
910 .log2_chroma_w= 1,
911 .log2_chroma_h= 0,
912 .comp = {
913 {0,1,1,0,15}, /* Y */
914 {1,1,1,0,15}, /* U */
915 {2,1,1,0,15}, /* V */
916 },
6b0768e2 917 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
75801da5 918 },
35f6c154
LT
919 [PIX_FMT_YUV444P16LE] = {
920 .name = "yuv444p16le",
b8873c2a 921 .nb_components= 3,
75801da5
SS
922 .log2_chroma_w= 0,
923 .log2_chroma_h= 0,
924 .comp = {
925 {0,1,1,0,15}, /* Y */
926 {1,1,1,0,15}, /* U */
927 {2,1,1,0,15}, /* V */
928 },
6b0768e2 929 .flags = PIX_FMT_PLANAR,
75801da5 930 },
35f6c154
LT
931 [PIX_FMT_YUV444P16BE] = {
932 .name = "yuv444p16be",
b8873c2a 933 .nb_components= 3,
75801da5
SS
934 .log2_chroma_w= 0,
935 .log2_chroma_h= 0,
936 .comp = {
937 {0,1,1,0,15}, /* Y */
938 {1,1,1,0,15}, /* U */
939 {2,1,1,0,15}, /* V */
940 },
6b0768e2 941 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
75801da5 942 },
103278f7
RB
943 [PIX_FMT_YUV444P10LE] = {
944 .name = "yuv444p10le",
945 .nb_components= 3,
946 .log2_chroma_w= 0,
947 .log2_chroma_h= 0,
948 .comp = {
949 {0,1,1,0,9}, /* Y */
950 {1,1,1,0,9}, /* U */
951 {2,1,1,0,9}, /* V */
952 },
6b0768e2 953 .flags = PIX_FMT_PLANAR,
103278f7
RB
954 },
955 [PIX_FMT_YUV444P10BE] = {
956 .name = "yuv444p10be",
957 .nb_components= 3,
958 .log2_chroma_w= 0,
959 .log2_chroma_h= 0,
960 .comp = {
961 {0,1,1,0,9}, /* Y */
962 {1,1,1,0,9}, /* U */
963 {2,1,1,0,9}, /* V */
964 },
6b0768e2 965 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
103278f7
RB
966 },
967 [PIX_FMT_YUV444P9LE] = {
968 .name = "yuv444p9le",
969 .nb_components= 3,
970 .log2_chroma_w= 0,
971 .log2_chroma_h= 0,
972 .comp = {
973 {0,1,1,0,8}, /* Y */
974 {1,1,1,0,8}, /* U */
975 {2,1,1,0,8}, /* V */
976 },
6b0768e2 977 .flags = PIX_FMT_PLANAR,
103278f7
RB
978 },
979 [PIX_FMT_YUV444P9BE] = {
980 .name = "yuv444p9be",
981 .nb_components= 3,
982 .log2_chroma_w= 0,
983 .log2_chroma_h= 0,
984 .comp = {
e59d6b4d
OA
985 {0,1,1,0,8}, /* Y */
986 {1,1,1,0,8}, /* U */
987 {2,1,1,0,8}, /* V */
103278f7 988 },
6b0768e2 989 .flags = PIX_FMT_BE | PIX_FMT_PLANAR,
103278f7 990 },
92c6a099
LA
991 [PIX_FMT_DXVA2_VLD] = {
992 .name = "dxva2_vld",
993 .log2_chroma_w = 1,
994 .log2_chroma_h = 1,
995 .flags = PIX_FMT_HWACCEL,
996 },
4744f896
997 [PIX_FMT_Y400A] = {
998 .name = "y400a",
999 .nb_components= 2,
1000 .comp = {
1001 {0,1,1,0,7}, /* Y */
1002 {0,1,2,0,7}, /* A */
1003 },
1004 },
bd97b2e1
RB
1005 [PIX_FMT_GBRP] = {
1006 .name = "gbrp",
1007 .nb_components= 3,
1008 .log2_chroma_w= 0,
1009 .log2_chroma_h= 0,
1010 .comp = {
1011 {0,0,1,0,7}, /* G */
1012 {1,0,1,0,7}, /* B */
1013 {2,0,1,0,7}, /* R */
1014 },
6b0768e2 1015 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1016 },
1017 [PIX_FMT_GBRP9LE] = {
1018 .name = "gbrp9le",
1019 .nb_components= 3,
1020 .log2_chroma_w= 0,
1021 .log2_chroma_h= 0,
1022 .comp = {
1023 {0,1,1,0,8}, /* G */
1024 {1,1,1,0,8}, /* B */
1025 {2,1,1,0,8}, /* R */
1026 },
6b0768e2 1027 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1028 },
1029 [PIX_FMT_GBRP9BE] = {
1030 .name = "gbrp9be",
1031 .nb_components= 3,
1032 .log2_chroma_w= 0,
1033 .log2_chroma_h= 0,
1034 .comp = {
1035 {0,1,1,0,8}, /* G */
1036 {1,1,1,0,8}, /* B */
1037 {2,1,1,0,8}, /* R */
1038 },
6b0768e2 1039 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1040 },
1041 [PIX_FMT_GBRP10LE] = {
1042 .name = "gbrp10le",
1043 .nb_components= 3,
1044 .log2_chroma_w= 0,
1045 .log2_chroma_h= 0,
1046 .comp = {
1047 {0,1,1,0,9}, /* G */
1048 {1,1,1,0,9}, /* B */
1049 {2,1,1,0,9}, /* R */
1050 },
6b0768e2 1051 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1052 },
1053 [PIX_FMT_GBRP10BE] = {
1054 .name = "gbrp10be",
1055 .nb_components= 3,
1056 .log2_chroma_w= 0,
1057 .log2_chroma_h= 0,
1058 .comp = {
1059 {0,1,1,0,9}, /* G */
1060 {1,1,1,0,9}, /* B */
1061 {2,1,1,0,9}, /* R */
1062 },
6b0768e2 1063 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1064 },
1065 [PIX_FMT_GBRP16LE] = {
1066 .name = "gbrp16le",
1067 .nb_components= 3,
1068 .log2_chroma_w= 0,
1069 .log2_chroma_h= 0,
1070 .comp = {
1071 {0,1,1,0,15}, /* G */
1072 {1,1,1,0,15}, /* B */
1073 {2,1,1,0,15}, /* R */
1074 },
6b0768e2 1075 .flags = PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1
RB
1076 },
1077 [PIX_FMT_GBRP16BE] = {
1078 .name = "gbrp16be",
1079 .nb_components= 3,
1080 .log2_chroma_w= 0,
1081 .log2_chroma_h= 0,
1082 .comp = {
1083 {0,1,1,0,15}, /* G */
1084 {1,1,1,0,15}, /* B */
1085 {2,1,1,0,15}, /* R */
1086 },
6b0768e2 1087 .flags = PIX_FMT_BE | PIX_FMT_PLANAR | PIX_FMT_RGB,
bd97b2e1 1088 },
9b61d838 1089};
5efccce2 1090
80a07f6e
SS
1091static enum PixelFormat get_pix_fmt_internal(const char *name)
1092{
1093 enum PixelFormat pix_fmt;
1094
1095 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
1096 if (av_pix_fmt_descriptors[pix_fmt].name &&
1097 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
1098 return pix_fmt;
1099
1100 return PIX_FMT_NONE;
1101}
1102
8f653e28
SS
1103const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
1104{
1105 return (unsigned)pix_fmt < PIX_FMT_NB ?
1106 av_pix_fmt_descriptors[pix_fmt].name : NULL;
1107}
1108
80a07f6e
SS
1109#if HAVE_BIGENDIAN
1110# define X_NE(be, le) be
1111#else
1112# define X_NE(be, le) le
1113#endif
1114
1115enum PixelFormat av_get_pix_fmt(const char *name)
1116{
1117 enum PixelFormat pix_fmt;
1118
1119 if (!strcmp(name, "rgb32"))
1120 name = X_NE("argb", "bgra");
1121 else if (!strcmp(name, "bgr32"))
1122 name = X_NE("abgr", "rgba");
1123
1124 pix_fmt = get_pix_fmt_internal(name);
1125 if (pix_fmt == PIX_FMT_NONE) {
1126 char name2[32];
1127
1128 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
1129 pix_fmt = get_pix_fmt_internal(name2);
1130 }
1131 return pix_fmt;
1132}
1133
5efccce2
SS
1134int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
1135{
1136 int c, bits = 0;
1137 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
1138
b8873c2a 1139 for (c = 0; c < pixdesc->nb_components; c++) {
5efccce2
SS
1140 int s = c==1 || c==2 ? 0 : log2_pixels;
1141 bits += (pixdesc->comp[c].depth_minus1+1) << s;
1142 }
1143
1144 return bits >> log2_pixels;
1145}
bb4afa13
SS
1146
1147char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
1148{
1149 /* print header */
1150 if (pix_fmt < 0) {
1151 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
1152 } else {
1153 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
1154 snprintf(buf, buf_size, "%-11s %7d %10d",
1155 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
1156 }
1157
1158 return buf;
1159}