pixdesc.c 22.1 KB
Newer Older
1
/*
2
 * pixel format descriptor
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

22 23
#include <stdio.h>
#include <string.h>
24
#include "pixfmt.h"
25 26
#include "pixdesc.h"

27 28
#include "intreadwrite.h"

29
void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
Stefano Sabatini's avatar
Stefano Sabatini committed
30
                        const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
{
    AVComponentDescriptor comp= desc->comp[c];
    int plane= comp.plane;
    int depth= comp.depth_minus1+1;
    int mask = (1<<depth)-1;
    int shift= comp.shift;
    int step = comp.step_minus1+1;
    int flags= desc->flags;

    if (flags & PIX_FMT_BITSTREAM){
        int skip = x*step + comp.offset_plus1-1;
        const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
        int shift = 8 - depth - (skip&7);

        while(w--){
            int val = (*p >> shift) & mask;
            if(read_pal_component)
                val= data[1][4*val + c];
            shift -= step;
            p -= shift>>3;
            shift &= 7;
            *dst++= val;
        }
    } else {
        const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;

        while(w--){
58
            int val = flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
59 60 61 62 63 64 65 66 67
            val = (val>>shift) & mask;
            if(read_pal_component)
                val= data[1][4*val + c];
            p+= step;
            *dst++= val;
        }
    }
}

68
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
Stefano Sabatini's avatar
Stefano Sabatini committed
69
                         const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
{
    AVComponentDescriptor comp = desc->comp[c];
    int plane = comp.plane;
    int depth = comp.depth_minus1+1;
    int step  = comp.step_minus1+1;
    int flags = desc->flags;

    if (flags & PIX_FMT_BITSTREAM) {
        int skip = x*step + comp.offset_plus1-1;
        uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
        int shift = 8 - depth - (skip&7);

        while (w--) {
            *p |= *src++ << shift;
            shift -= step;
            p -= shift>>3;
            shift &= 7;
        }
    } else {
        int shift = comp.shift;
        uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;

        while (w--) {
            if (flags & PIX_FMT_BE) {
                uint16_t val = AV_RB16(p) | (*src++<<shift);
                AV_WB16(p, val);
            } else {
                uint16_t val = AV_RL16(p) | (*src++<<shift);
                AV_WL16(p, val);
            }
            p+= step;
        }
    }
}

105
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
106 107
    [PIX_FMT_YUV420P] = {
        .name = "yuv420p",
108
        .nb_components= 3,
109
        .log2_chroma_w= 1,
110
        .log2_chroma_h= 1,
111
        .comp = {
112 113 114
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
115 116
        },
    },
117 118
    [PIX_FMT_YUYV422] = {
        .name = "yuyv422",
119
        .nb_components= 3,
120
        .log2_chroma_w= 1,
121 122 123 124 125 126 127 128 129
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,7},        /* Y */
            {0,3,2,0,7},        /* U */
            {0,3,4,0,7},        /* V */
        },
    },
    [PIX_FMT_RGB24] = {
        .name = "rgb24",
130
        .nb_components= 3,
131 132 133 134 135 136 137 138
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,2,1,0,7},        /* R */
            {0,2,2,0,7},        /* G */
            {0,2,3,0,7},        /* B */
        },
    },
139 140
    [PIX_FMT_BGR24] = {
        .name = "bgr24",
141
        .nb_components= 3,
142 143 144 145 146 147 148 149
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,2,1,0,7},        /* B */
            {0,2,2,0,7},        /* G */
            {0,2,3,0,7},        /* R */
        },
    },
150 151
    [PIX_FMT_YUV422P] = {
        .name = "yuv422p",
152
        .nb_components= 3,
153 154
        .log2_chroma_w= 1,
        .log2_chroma_h= 0,
155
        .comp = {
156 157 158
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
159 160
        },
    },
161 162
    [PIX_FMT_YUV444P] = {
        .name = "yuv444p",
163
        .nb_components= 3,
164 165 166 167 168 169 170 171
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
172
    [PIX_FMT_YUV410P] = {
173
        .name = "yuv410p",
174
        .nb_components= 3,
175 176 177
        .log2_chroma_w= 2,
        .log2_chroma_h= 2,
        .comp = {
178 179 180
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
181 182
        },
    },
183 184
    [PIX_FMT_YUV411P] = {
        .name = "yuv411p",
185
        .nb_components= 3,
186 187 188 189 190 191 192 193 194
        .log2_chroma_w= 2,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
    [PIX_FMT_GRAY8] = {
195
        .name = "gray",
196
        .nb_components= 1,
197 198 199 200 201
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,7},        /* Y */
        },
202
        .flags = PIX_FMT_PAL,
203 204
    },
    [PIX_FMT_MONOWHITE] = {
205
        .name = "monow",
206
        .nb_components= 1,
207 208 209 210 211 212 213
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,0},        /* Y */
        },
        .flags = PIX_FMT_BITSTREAM,
    },
214
    [PIX_FMT_MONOBLACK] = {
215
        .name = "monob",
216
        .nb_components= 1,
217 218
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
219
        .comp = {
220
            {0,0,1,7,0},        /* Y */
221
        },
222
        .flags = PIX_FMT_BITSTREAM,
223
    },
224 225
    [PIX_FMT_PAL8] = {
        .name = "pal8",
226
        .nb_components= 1,
227
        .log2_chroma_w= 0,
228 229
        .log2_chroma_h= 0,
        .comp = {
230
            {0,0,1,0,7},
231
        },
232
        .flags = PIX_FMT_PAL,
233
    },
234 235
    [PIX_FMT_YUVJ420P] = {
        .name = "yuvj420p",
236
        .nb_components= 3,
237 238 239 240 241 242 243 244 245 246
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
    [PIX_FMT_YUVJ422P] = {
        .name = "yuvj422p",
247
        .nb_components= 3,
248 249 250 251 252 253 254 255 256 257
        .log2_chroma_w= 1,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
    [PIX_FMT_YUVJ444P] = {
        .name = "yuvj444p",
258
        .nb_components= 3,
259 260 261 262 263 264 265 266
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
267
    [PIX_FMT_XVMC_MPEG2_MC] = {
268
        .name = "xvmcmc",
269 270 271
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_XVMC_MPEG2_IDCT] = {
272
        .name = "xvmcidct",
273 274
        .flags = PIX_FMT_HWACCEL,
    },
275
    [PIX_FMT_UYVY422] = {
276
        .name = "uyvy422",
277
        .nb_components= 3,
278 279 280
        .log2_chroma_w= 1,
        .log2_chroma_h= 0,
        .comp = {
281 282 283
            {0,1,2,0,7},        /* Y */
            {0,3,1,0,7},        /* U */
            {0,3,3,0,7},        /* V */
284 285
        },
    },
286 287
    [PIX_FMT_UYYVYY411] = {
        .name = "uyyvyy411",
288
        .nb_components= 3,
289 290 291 292 293 294 295 296 297 298
        .log2_chroma_w= 2,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,2,0,7},        /* Y */
            {0,5,1,0,7},        /* U */
            {0,5,4,0,7},        /* V */
        },
    },
    [PIX_FMT_BGR8] = {
        .name = "bgr8",
299
        .nb_components= 3,
300 301 302 303 304 305 306
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,6,1},        /* B */
            {0,0,1,3,2},        /* G */
            {0,0,1,0,2},        /* R */
        },
307
        .flags = PIX_FMT_PAL,
308 309 310
    },
    [PIX_FMT_BGR4] = {
        .name = "bgr4",
311
        .nb_components= 3,
312 313 314 315 316 317 318 319 320 321 322
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,1,0,0},        /* B */
            {0,3,2,0,1},        /* G */
            {0,3,4,0,0},        /* R */
        },
        .flags = PIX_FMT_BITSTREAM,
    },
    [PIX_FMT_BGR4_BYTE] = {
        .name = "bgr4_byte",
323
        .nb_components= 3,
324 325 326 327 328 329 330
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,3,0},        /* B */
            {0,0,1,1,1},        /* G */
            {0,0,1,0,0},        /* R */
        },
331
        .flags = PIX_FMT_PAL,
332 333 334
    },
    [PIX_FMT_RGB8] = {
        .name = "rgb8",
335
        .nb_components= 3,
336 337 338 339 340 341 342
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,6,1},        /* R */
            {0,0,1,3,2},        /* G */
            {0,0,1,0,2},        /* B */
        },
343
        .flags = PIX_FMT_PAL,
344 345 346
    },
    [PIX_FMT_RGB4] = {
        .name = "rgb4",
347
        .nb_components= 3,
348 349 350 351 352 353 354 355 356 357 358
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,1,0,0},       /* R */
            {0,3,2,0,1},       /* G */
            {0,3,4,0,0},       /* B */
        },
        .flags = PIX_FMT_BITSTREAM,
    },
    [PIX_FMT_RGB4_BYTE] = {
        .name = "rgb4_byte",
359
        .nb_components= 3,
360 361 362 363 364 365 366
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,0,1,3,0},        /* R */
            {0,0,1,1,1},        /* G */
            {0,0,1,0,0},        /* B */
        },
367
        .flags = PIX_FMT_PAL,
368
    },
369 370
    [PIX_FMT_NV12] = {
        .name = "nv12",
371
        .nb_components= 3,
372 373
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
374
        .comp = {
375 376 377
            {0,0,1,0,7},        /* Y */
            {1,1,1,0,7},        /* U */
            {1,1,2,0,7},        /* V */
378 379
        },
    },
380 381
    [PIX_FMT_NV21] = {
        .name = "nv21",
382
        .nb_components= 3,
383 384 385 386 387 388 389 390 391 392
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,1,1,0,7},        /* V */
            {1,1,2,0,7},        /* U */
        },
    },
    [PIX_FMT_ARGB] = {
        .name = "argb",
393
        .nb_components= 4,
394 395 396 397 398 399 400 401 402
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,1,0,7},        /* A */
            {0,3,2,0,7},        /* R */
            {0,3,3,0,7},        /* G */
            {0,3,4,0,7},        /* B */
        },
    },
403
    [PIX_FMT_RGBA] = {
404
        .name = "rgba",
405
        .nb_components= 4,
406 407 408
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
409 410 411 412
            {0,3,1,0,7},        /* R */
            {0,3,2,0,7},        /* G */
            {0,3,3,0,7},        /* B */
            {0,3,4,0,7},        /* A */
413 414
        },
    },
415 416
    [PIX_FMT_ABGR] = {
        .name = "abgr",
417
        .nb_components= 4,
418 419 420 421 422 423 424 425 426 427 428
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,1,0,7},        /* A */
            {0,3,2,0,7},        /* B */
            {0,3,3,0,7},        /* G */
            {0,3,4,0,7},        /* R */
        },
    },
    [PIX_FMT_BGRA] = {
        .name = "bgra",
429
        .nb_components= 4,
430 431 432 433 434 435 436 437 438
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,3,1,0,7},        /* B */
            {0,3,2,0,7},        /* G */
            {0,3,3,0,7},        /* R */
            {0,3,4,0,7},        /* A */
        },
    },
439 440
    [PIX_FMT_GRAY16BE] = {
        .name = "gray16be",
441
        .nb_components= 1,
442 443 444
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
445 446 447 448 449 450
            {0,1,1,0,15},       /* Y */
        },
        .flags = PIX_FMT_BE,
    },
    [PIX_FMT_GRAY16LE] = {
        .name = "gray16le",
451
        .nb_components= 1,
452 453 454 455
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,15},       /* Y */
456 457
        },
    },
458 459
    [PIX_FMT_YUV440P] = {
        .name = "yuv440p",
460
        .nb_components= 3,
461 462 463 464 465 466 467 468 469 470
        .log2_chroma_w= 0,
        .log2_chroma_h= 1,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
    [PIX_FMT_YUVJ440P] = {
        .name = "yuvj440p",
471
        .nb_components= 3,
472 473 474 475 476 477 478 479 480 481
        .log2_chroma_w= 0,
        .log2_chroma_h= 1,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
        },
    },
    [PIX_FMT_YUVA420P] = {
        .name = "yuva420p",
482
        .nb_components= 4,
483 484 485 486 487 488 489 490 491
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
        .comp = {
            {0,0,1,0,7},        /* Y */
            {1,0,1,0,7},        /* U */
            {2,0,1,0,7},        /* V */
            {3,0,1,0,7},        /* A */
        },
    },
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
    [PIX_FMT_VDPAU_H264] = {
        .name = "vdpau_h264",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VDPAU_MPEG1] = {
        .name = "vdpau_mpeg1",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VDPAU_MPEG2] = {
        .name = "vdpau_mpeg2",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VDPAU_WMV3] = {
        .name = "vdpau_wmv3",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VDPAU_VC1] = {
        .name = "vdpau_vc1",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
522 523 524 525 526 527
    [PIX_FMT_VDPAU_MPEG4] = {
        .name = "vdpau_mpeg4",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
528
    [PIX_FMT_RGB48BE] = {
529
        .name = "rgb48be",
530
        .nb_components= 3,
531 532 533
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
534 535 536
            {0,5,1,0,15},       /* R */
            {0,5,3,0,15},       /* G */
            {0,5,5,0,15},       /* B */
537 538 539
        },
        .flags = PIX_FMT_BE,
    },
540 541
    [PIX_FMT_RGB48LE] = {
        .name = "rgb48le",
542
        .nb_components= 3,
543 544 545
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
546 547 548
            {0,5,1,0,15},       /* R */
            {0,5,3,0,15},       /* G */
            {0,5,5,0,15},       /* B */
549 550
        },
    },
551
    [PIX_FMT_RGB565BE] = {
552
        .name = "rgb565be",
553
        .nb_components= 3,
554 555 556
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
557
            {0,1,0,3,4},        /* R */
558 559
            {0,1,1,5,5},        /* G */
            {0,1,1,0,4},        /* B */
560 561 562
        },
        .flags = PIX_FMT_BE,
    },
563 564
    [PIX_FMT_RGB565LE] = {
        .name = "rgb565le",
565
        .nb_components= 3,
566 567 568
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
569 570 571
            {0,1,2,3,4},        /* R */
            {0,1,1,5,5},        /* G */
            {0,1,1,0,4},        /* B */
572 573
        },
    },
574 575
    [PIX_FMT_RGB555BE] = {
        .name = "rgb555be",
576
        .nb_components= 3,
577 578 579 580 581 582 583 584 585 586 587
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,0,2,4},        /* R */
            {0,1,1,5,4},        /* G */
            {0,1,1,0,4},        /* B */
        },
        .flags = PIX_FMT_BE,
    },
    [PIX_FMT_RGB555LE] = {
        .name = "rgb555le",
588
        .nb_components= 3,
589 590 591 592 593 594 595 596
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,2,2,4},        /* R */
            {0,1,1,5,4},        /* G */
            {0,1,1,0,4},        /* B */
        },
    },
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
    [PIX_FMT_RGB444BE] = {
        .name = "rgb444be",
        .nb_components= 3,
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,0,0,3},        /* R */
            {0,1,1,4,3},        /* G */
            {0,1,1,0,3},        /* B */
        },
        .flags = PIX_FMT_BE,
    },
    [PIX_FMT_RGB444LE] = {
        .name = "rgb444le",
        .nb_components= 3,
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,2,0,3},        /* R */
            {0,1,1,4,3},        /* G */
            {0,1,1,0,3},        /* B */
        },
    },
620 621
    [PIX_FMT_BGR565BE] = {
        .name = "bgr565be",
622
        .nb_components= 3,
623 624 625 626 627 628 629 630 631 632 633
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,0,3,4},        /* B */
            {0,1,1,5,5},        /* G */
            {0,1,1,0,4},        /* R */
        },
        .flags = PIX_FMT_BE,
    },
    [PIX_FMT_BGR565LE] = {
        .name = "bgr565le",
634
        .nb_components= 3,
635 636 637 638 639 640 641 642 643 644
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,2,3,4},        /* B */
            {0,1,1,5,5},        /* G */
            {0,1,1,0,4},        /* R */
        },
    },
    [PIX_FMT_BGR555BE] = {
        .name = "bgr555be",
645
        .nb_components= 3,
646 647 648 649 650 651 652 653 654 655 656
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,0,2,4},       /* B */
            {0,1,1,5,4},       /* G */
            {0,1,1,0,4},       /* R */
        },
        .flags = PIX_FMT_BE,
     },
    [PIX_FMT_BGR555LE] = {
        .name = "bgr555le",
657
        .nb_components= 3,
658 659 660 661 662 663 664 665
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,2,2,4},        /* B */
            {0,1,1,5,4},        /* G */
            {0,1,1,0,4},        /* R */
        },
    },
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
    [PIX_FMT_BGR444BE] = {
        .name = "bgr444be",
        .nb_components= 3,
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,0,0,3},       /* B */
            {0,1,1,4,3},       /* G */
            {0,1,1,0,3},       /* R */
        },
        .flags = PIX_FMT_BE,
     },
    [PIX_FMT_BGR444LE] = {
        .name = "bgr444le",
        .nb_components= 3,
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,2,0,3},        /* B */
            {0,1,1,4,3},        /* G */
            {0,1,1,0,3},        /* R */
        },
    },
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
    [PIX_FMT_VAAPI_MOCO] = {
        .name = "vaapi_moco",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VAAPI_IDCT] = {
        .name = "vaapi_idct",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
    [PIX_FMT_VAAPI_VLD] = {
        .name = "vaapi_vld",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
707 708
    [PIX_FMT_YUV420P16LE] = {
        .name = "yuv420p16le",
709
        .nb_components= 3,
710 711 712 713 714 715 716 717
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
    },
718 719
    [PIX_FMT_YUV420P16BE] = {
        .name = "yuv420p16be",
720
        .nb_components= 3,
721 722 723 724 725 726 727 728 729
        .log2_chroma_w= 1,
        .log2_chroma_h= 1,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
        .flags = PIX_FMT_BE,
    },
730 731
    [PIX_FMT_YUV422P16LE] = {
        .name = "yuv422p16le",
732
        .nb_components= 3,
733 734 735 736 737 738 739 740
        .log2_chroma_w= 1,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
    },
741 742
    [PIX_FMT_YUV422P16BE] = {
        .name = "yuv422p16be",
743
        .nb_components= 3,
744 745 746 747 748 749 750 751 752
        .log2_chroma_w= 1,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
        .flags = PIX_FMT_BE,
    },
753 754
    [PIX_FMT_YUV444P16LE] = {
        .name = "yuv444p16le",
755
        .nb_components= 3,
756 757 758 759 760 761 762 763
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
    },
764 765
    [PIX_FMT_YUV444P16BE] = {
        .name = "yuv444p16be",
766
        .nb_components= 3,
767 768 769 770 771 772 773 774 775
        .log2_chroma_w= 0,
        .log2_chroma_h= 0,
        .comp = {
            {0,1,1,0,15},        /* Y */
            {1,1,1,0,15},        /* U */
            {2,1,1,0,15},        /* V */
        },
        .flags = PIX_FMT_BE,
    },
Laurent Aimar's avatar
Laurent Aimar committed
776 777 778 779 780 781
    [PIX_FMT_DXVA2_VLD] = {
        .name = "dxva2_vld",
        .log2_chroma_w = 1,
        .log2_chroma_h = 1,
        .flags = PIX_FMT_HWACCEL,
    },
782 783 784 785 786 787 788 789
    [PIX_FMT_Y400A] = {
        .name = "y400a",
        .nb_components= 2,
        .comp = {
            {0,1,1,0,7},        /* Y */
            {0,1,2,0,7},        /* A */
        },
    },
790
};
791

792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
static enum PixelFormat get_pix_fmt_internal(const char *name)
{
    enum PixelFormat pix_fmt;

    for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
        if (av_pix_fmt_descriptors[pix_fmt].name &&
            !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
            return pix_fmt;

    return PIX_FMT_NONE;
}

#if HAVE_BIGENDIAN
#   define X_NE(be, le) be
#else
#   define X_NE(be, le) le
#endif

enum PixelFormat av_get_pix_fmt(const char *name)
{
    enum PixelFormat pix_fmt;

    if (!strcmp(name, "rgb32"))
        name = X_NE("argb", "bgra");
    else if (!strcmp(name, "bgr32"))
        name = X_NE("abgr", "rgba");

    pix_fmt = get_pix_fmt_internal(name);
    if (pix_fmt == PIX_FMT_NONE) {
        char name2[32];

        snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
        pix_fmt = get_pix_fmt_internal(name2);
    }
    return pix_fmt;
}

829 830 831 832 833
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
{
    int c, bits = 0;
    int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;

834
    for (c = 0; c < pixdesc->nb_components; c++) {
835 836 837 838 839 840
        int s = c==1 || c==2 ? 0 : log2_pixels;
        bits += (pixdesc->comp[c].depth_minus1+1) << s;
    }

    return bits >> log2_pixels;
}