pixdesc.c 23 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
{
    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;
56
        int is_8bit = shift + depth <= 8;
57

58
        if (is_8bit)
59
            p += !!(flags & PIX_FMT_BE);
60

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

73
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
Stefano Sabatini's avatar
Stefano Sabatini committed
74
                         const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
    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;

97
98
99
100
101
102
103
        if (shift + depth <= 8) {
            p += !!(flags & PIX_FMT_BE);
            while (w--) {
                *p |= (*src++<<shift);
                p += step;
            }
        } else {
Måns Rullgård's avatar
Måns Rullgård committed
104
105
106
107
108
109
110
111
112
            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;
113
            }
114
        }
115
116
117
    }
}

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

842
843
844
845
846
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
{
    int c, bits = 0;
    int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;

847
    for (c = 0; c < pixdesc->nb_components; c++) {
848
849
850
851
852
853
        int s = c==1 || c==2 ? 0 : log2_pixels;
        bits += (pixdesc->comp[c].depth_minus1+1) << s;
    }

    return bits >> log2_pixels;
}
854
855
856
857
858
859
860
861
862
863
864
865
866
867

char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
{
    /* print header */
    if (pix_fmt < 0) {
        snprintf (buf, buf_size, "name      " " nb_components" " nb_bits");
    } else {
        const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
        snprintf(buf, buf_size, "%-11s %7d %10d",
                 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));
    }

    return buf;
}