Statistics
| Branch: | Revision:

ffmpeg / libavutil / pixdesc.c @ d71ad089

History | View | Annotate | Download (15.7 KB)

1
/*
2
 * pixel format descriptor
3
 * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
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
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
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
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
#include "pixfmt.h"
23
#include "pixdesc.h"
24

    
25
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
26
    [PIX_FMT_YUV420P] = {
27
        .name = "yuv420p",
28
        .nb_channels  = 3,
29
        .log2_chroma_w= 1,
30
        .log2_chroma_h= 1,
31
        .comp = {
32
            {0,0,1,0,7},        /* Y */
33
            {1,0,1,0,7},        /* U */
34
            {2,0,1,0,7},        /* V */
35
        },
36
    },
37
    [PIX_FMT_YUYV422] = {
38
        .name = "yuyv422",
39
        .nb_channels  = 3,
40
        .log2_chroma_w= 1,
41
        .log2_chroma_h= 0,
42
        .comp = {
43
            {0,1,1,0,7},        /* Y */
44
            {0,3,2,0,7},        /* U */
45
            {0,3,4,0,7},        /* V */
46
        },
47
    },
48
    [PIX_FMT_RGB24] = {
49
        .name = "rgb24",
50
        .nb_channels  = 3,
51
        .log2_chroma_w= 0,
52
        .log2_chroma_h= 0,
53
        .comp = {
54
            {0,2,1,0,7},        /* R */
55
            {0,2,2,0,7},        /* G */
56
            {0,2,3,0,7},        /* B */
57
        },
58
    },
59
    [PIX_FMT_BGR24] = {
60
        .name = "bgr24",
61
        .nb_channels  = 3,
62
        .log2_chroma_w= 0,
63
        .log2_chroma_h= 0,
64
        .comp = {
65
            {0,2,1,0,7},        /* B */
66
            {0,2,2,0,7},        /* G */
67
            {0,2,3,0,7},        /* R */
68
        },
69
    },
70
    [PIX_FMT_YUV422P] = {
71
        .name = "yuv422p",
72
        .nb_channels  = 3,
73
        .log2_chroma_w= 1,
74
        .log2_chroma_h= 0,
75
        .comp = {
76
            {0,0,1,0,7},        /* Y */
77
            {1,0,1,0,7},        /* U */
78
            {2,0,1,0,7},        /* V */
79
        },
80
    },
81
    [PIX_FMT_YUV444P] = {
82
        .name = "yuv444p",
83
        .nb_channels  = 3,
84
        .log2_chroma_w= 0,
85
        .log2_chroma_h= 0,
86
        .comp = {
87
            {0,0,1,0,7},        /* Y */
88
            {1,0,1,0,7},        /* U */
89
            {2,0,1,0,7},        /* V */
90
        },
91
    },
92
    [PIX_FMT_YUV410P] = {
93
        .name = "yuv410p",
94
        .nb_channels  = 3,
95
        .log2_chroma_w= 2,
96
        .log2_chroma_h= 2,
97
        .comp = {
98
            {0,0,1,0,7},        /* Y */
99
            {1,0,1,0,7},        /* U */
100
            {2,0,1,0,7},        /* V */
101
        },
102
    },
103
    [PIX_FMT_YUV411P] = {
104
        .name = "yuv411p",
105
        .nb_channels  = 3,
106
        .log2_chroma_w= 2,
107
        .log2_chroma_h= 0,
108
        .comp = {
109
            {0,0,1,0,7},        /* Y */
110
            {1,0,1,0,7},        /* U */
111
            {2,0,1,0,7},        /* V */
112
        },
113
    },
114
    [PIX_FMT_GRAY8] = {
115
        .name = "gray8",
116
        .nb_channels  = 1,
117
        .log2_chroma_w= 0,
118
        .log2_chroma_h= 0,
119
        .comp = {
120
            {0,0,1,0,7},        /* Y */
121
        },
122
    },
123
    [PIX_FMT_MONOWHITE] = {
124
        .name = "monowhite",
125
        .nb_channels  = 1,
126
        .log2_chroma_w= 0,
127
        .log2_chroma_h= 0,
128
        .comp = {
129
            {0,0,1,0,0},        /* Y */
130
        },
131
        .flags = PIX_FMT_BITSTREAM,
132
    },
133
    [PIX_FMT_MONOBLACK] = {
134
        .name = "monoblack",
135
        .nb_channels  = 1,
136
        .log2_chroma_w= 0,
137
        .log2_chroma_h= 0,
138
        .comp = {
139
            {0,0,1,7,0},        /* Y */
140
        },
141
        .flags = PIX_FMT_BITSTREAM,
142
    },
143
    [PIX_FMT_PAL8] = {
144
        .name = "pal8",
145
        .nb_channels  = 1,
146
        .log2_chroma_w= 0,
147
        .log2_chroma_h= 0,
148
        .comp = {
149
            {0,0,1,0,7},
150
        },
151
        .flags = PIX_FMT_PAL,
152
    },
153
    [PIX_FMT_YUVJ420P] = {
154
        .name = "yuvj420p",
155
        .nb_channels  = 3,
156
        .log2_chroma_w= 1,
157
        .log2_chroma_h= 1,
158
        .comp = {
159
            {0,0,1,0,7},        /* Y */
160
            {1,0,1,0,7},        /* U */
161
            {2,0,1,0,7},        /* V */
162
        },
163
    },
164
    [PIX_FMT_YUVJ422P] = {
165
        .name = "yuvj422p",
166
        .nb_channels  = 3,
167
        .log2_chroma_w= 1,
168
        .log2_chroma_h= 0,
169
        .comp = {
170
            {0,0,1,0,7},        /* Y */
171
            {1,0,1,0,7},        /* U */
172
            {2,0,1,0,7},        /* V */
173
        },
174
    },
175
    [PIX_FMT_YUVJ444P] = {
176
        .name = "yuvj444p",
177
        .nb_channels  = 3,
178
        .log2_chroma_w= 0,
179
        .log2_chroma_h= 0,
180
        .comp = {
181
            {0,0,1,0,7},        /* Y */
182
            {1,0,1,0,7},        /* U */
183
            {2,0,1,0,7},        /* V */
184
        },
185
    },
186
    [PIX_FMT_UYVY422] = {
187
        .name = "uyvy422",
188
        .nb_channels  = 3,
189
        .log2_chroma_w= 1,
190
        .log2_chroma_h= 0,
191
        .comp = {
192
            {0,1,2,0,7},        /* Y */
193
            {0,3,1,0,7},        /* U */
194
            {0,3,3,0,7},        /* V */
195
        },
196
    },
197
    [PIX_FMT_UYYVYY411] = {
198
        .name = "uyyvyy411",
199
        .nb_channels  = 3,
200
        .log2_chroma_w= 2,
201
        .log2_chroma_h= 0,
202
        .comp = {
203
            {0,3,2,0,7},        /* Y */
204
            {0,5,1,0,7},        /* U */
205
            {0,5,4,0,7},        /* V */
206
        },
207
    },
208
    [PIX_FMT_BGR8] = {
209
        .name = "bgr8",
210
        .nb_channels  = 3,
211
        .log2_chroma_w= 0,
212
        .log2_chroma_h= 0,
213
        .comp = {
214
            {0,0,1,6,1},        /* B */
215
            {0,0,1,3,2},        /* G */
216
            {0,0,1,0,2},        /* R */
217
        },
218
        .flags = PIX_FMT_PAL,
219
    },
220
    [PIX_FMT_BGR4] = {
221
        .name = "bgr4",
222
        .nb_channels  = 3,
223
        .log2_chroma_w= 0,
224
        .log2_chroma_h= 0,
225
        .comp = {
226
            {0,3,1,0,0},        /* B */
227
            {0,3,2,0,1},        /* G */
228
            {0,3,4,0,0},        /* R */
229
        },
230
        .flags = PIX_FMT_BITSTREAM,
231
    },
232
    [PIX_FMT_BGR4_BYTE] = {
233
        .name = "bgr4_byte",
234
        .nb_channels  = 3,
235
        .log2_chroma_w= 0,
236
        .log2_chroma_h= 0,
237
        .comp = {
238
            {0,0,1,3,0},        /* B */
239
            {0,0,1,1,1},        /* G */
240
            {0,0,1,0,0},        /* R */
241
        },
242
        .flags = PIX_FMT_PAL,
243
    },
244
    [PIX_FMT_RGB8] = {
245
        .name = "rgb8",
246
        .nb_channels  = 3,
247
        .log2_chroma_w= 0,
248
        .log2_chroma_h= 0,
249
        .comp = {
250
            {0,0,1,6,1},        /* R */
251
            {0,0,1,3,2},        /* G */
252
            {0,0,1,0,2},        /* B */
253
        },
254
        .flags = PIX_FMT_PAL,
255
    },
256
    [PIX_FMT_RGB4] = {
257
        .name = "rgb4",
258
        .nb_channels  = 3,
259
        .log2_chroma_w= 0,
260
        .log2_chroma_h= 0,
261
        .comp = {
262
            {0,3,1,0,0},       /* R */
263
            {0,3,2,0,1},       /* G */
264
            {0,3,4,0,0},       /* B */
265
        },
266
        .flags = PIX_FMT_BITSTREAM,
267
    },
268
    [PIX_FMT_RGB4_BYTE] = {
269
        .name = "rgb4_byte",
270
        .nb_channels  = 3,
271
        .log2_chroma_w= 0,
272
        .log2_chroma_h= 0,
273
        .comp = {
274
            {0,0,1,3,0},        /* R */
275
            {0,0,1,1,1},        /* G */
276
            {0,0,1,0,0},        /* B */
277
        },
278
        .flags = PIX_FMT_PAL,
279
    },
280
    [PIX_FMT_NV12] = {
281
        .name = "nv12",
282
        .nb_channels  = 3,
283
        .log2_chroma_w= 1,
284
        .log2_chroma_h= 1,
285
        .comp = {
286
            {0,0,1,0,7},        /* Y */
287
            {1,1,1,0,7},        /* U */
288
            {1,1,2,0,7},        /* V */
289
        },
290
    },
291
    [PIX_FMT_NV21] = {
292
        .name = "nv21",
293
        .nb_channels  = 3,
294
        .log2_chroma_w= 1,
295
        .log2_chroma_h= 1,
296
        .comp = {
297
            {0,0,1,0,7},        /* Y */
298
            {1,1,1,0,7},        /* V */
299
            {1,1,2,0,7},        /* U */
300
        },
301
    },
302
    [PIX_FMT_ARGB] = {
303
        .name = "argb",
304
        .nb_channels  = 4,
305
        .log2_chroma_w= 0,
306
        .log2_chroma_h= 0,
307
        .comp = {
308
            {0,3,1,0,7},        /* A */
309
            {0,3,2,0,7},        /* R */
310
            {0,3,3,0,7},        /* G */
311
            {0,3,4,0,7},        /* B */
312
        },
313
    },
314
    [PIX_FMT_RGBA] = {
315
        .name = "rgba",
316
        .nb_channels  = 4,
317
        .log2_chroma_w= 0,
318
        .log2_chroma_h= 0,
319
        .comp = {
320
            {0,3,1,0,7},        /* R */
321
            {0,3,2,0,7},        /* G */
322
            {0,3,3,0,7},        /* B */
323
            {0,3,4,0,7},        /* A */
324
        },
325
    },
326
    [PIX_FMT_ABGR] = {
327
        .name = "abgr",
328
        .nb_channels  = 4,
329
        .log2_chroma_w= 0,
330
        .log2_chroma_h= 0,
331
        .comp = {
332
            {0,3,1,0,7},        /* A */
333
            {0,3,2,0,7},        /* B */
334
            {0,3,3,0,7},        /* G */
335
            {0,3,4,0,7},        /* R */
336
        },
337
    },
338
    [PIX_FMT_BGRA] = {
339
        .name = "bgra",
340
        .nb_channels  = 4,
341
        .log2_chroma_w= 0,
342
        .log2_chroma_h= 0,
343
        .comp = {
344
            {0,3,1,0,7},        /* B */
345
            {0,3,2,0,7},        /* G */
346
            {0,3,3,0,7},        /* R */
347
            {0,3,4,0,7},        /* A */
348
        },
349
    },
350
    [PIX_FMT_GRAY16BE] = {
351
        .name = "gray16be",
352
        .nb_channels  = 1,
353
        .log2_chroma_w= 0,
354
        .log2_chroma_h= 0,
355
        .comp = {
356
            {0,1,1,0,15},       /* Y */
357
        },
358
        .flags = PIX_FMT_BE,
359
    },
360
    [PIX_FMT_GRAY16LE] = {
361
        .name = "gray16le",
362
        .nb_channels  = 1,
363
        .log2_chroma_w= 0,
364
        .log2_chroma_h= 0,
365
        .comp = {
366
            {0,1,1,0,15},       /* Y */
367
        },
368
    },
369
    [PIX_FMT_YUV440P] = {
370
        .name = "yuv440p",
371
        .nb_channels  = 3,
372
        .log2_chroma_w= 0,
373
        .log2_chroma_h= 1,
374
        .comp = {
375
            {0,0,1,0,7},        /* Y */
376
            {1,0,1,0,7},        /* U */
377
            {2,0,1,0,7},        /* V */
378
        },
379
    },
380
    [PIX_FMT_YUVJ440P] = {
381
        .name = "yuvj440p",
382
        .nb_channels  = 3,
383
        .log2_chroma_w= 0,
384
        .log2_chroma_h= 1,
385
        .comp = {
386
            {0,0,1,0,7},        /* Y */
387
            {1,0,1,0,7},        /* U */
388
            {2,0,1,0,7},        /* V */
389
        },
390
    },
391
    [PIX_FMT_YUVA420P] = {
392
        .name = "yuva420p",
393
        .nb_channels  = 4,
394
        .log2_chroma_w= 1,
395
        .log2_chroma_h= 1,
396
        .comp = {
397
            {0,0,1,0,7},        /* Y */
398
            {1,0,1,0,7},        /* U */
399
            {2,0,1,0,7},        /* V */
400
            {3,0,1,0,7},        /* A */
401
        },
402
    },
403
    [PIX_FMT_RGB48BE] = {
404
        .name = "rgb48be",
405
        .nb_channels  = 3,
406
        .log2_chroma_w= 0,
407
        .log2_chroma_h= 0,
408
        .comp = {
409
            {0,5,1,0,15},       /* R */
410
            {0,5,3,0,15},       /* G */
411
            {0,5,5,0,15},       /* B */
412
        },
413
        .flags = PIX_FMT_BE,
414
    },
415
    [PIX_FMT_RGB48LE] = {
416
        .name = "rgb48le",
417
        .nb_channels  = 3,
418
        .log2_chroma_w= 0,
419
        .log2_chroma_h= 0,
420
        .comp = {
421
            {0,5,1,0,15},       /* R */
422
            {0,5,3,0,15},       /* G */
423
            {0,5,5,0,15},       /* B */
424
        },
425
    },
426
    [PIX_FMT_RGB565BE] = {
427
        .name = "rgb565be",
428
        .nb_channels  = 3,
429
        .log2_chroma_w= 0,
430
        .log2_chroma_h= 0,
431
        .comp = {
432
            {0,1,0,3,4},        /* R */
433
            {0,1,1,5,5},        /* G */
434
            {0,1,1,0,4},        /* B */
435
        },
436
        .flags = PIX_FMT_BE,
437
    },
438
    [PIX_FMT_RGB565LE] = {
439
        .name = "rgb565le",
440
        .nb_channels  = 3,
441
        .log2_chroma_w= 0,
442
        .log2_chroma_h= 0,
443
        .comp = {
444
            {0,1,2,3,4},        /* R */
445
            {0,1,1,5,5},        /* G */
446
            {0,1,1,0,4},        /* B */
447
        },
448
    },
449
    [PIX_FMT_RGB555BE] = {
450
        .name = "rgb555be",
451
        .nb_channels  = 3,
452
        .log2_chroma_w= 0,
453
        .log2_chroma_h= 0,
454
        .comp = {
455
            {0,1,0,2,4},        /* R */
456
            {0,1,1,5,4},        /* G */
457
            {0,1,1,0,4},        /* B */
458
        },
459
        .flags = PIX_FMT_BE,
460
    },
461
    [PIX_FMT_RGB555LE] = {
462
        .name = "rgb555le",
463
        .nb_channels  = 3,
464
        .log2_chroma_w= 0,
465
        .log2_chroma_h= 0,
466
        .comp = {
467
            {0,1,2,2,4},        /* R */
468
            {0,1,1,5,4},        /* G */
469
            {0,1,1,0,4},        /* B */
470
        },
471
    },
472
    [PIX_FMT_BGR565BE] = {
473
        .name = "bgr565be",
474
        .nb_channels  = 3,
475
        .log2_chroma_w= 0,
476
        .log2_chroma_h= 0,
477
        .comp = {
478
            {0,1,0,3,4},        /* B */
479
            {0,1,1,5,5},        /* G */
480
            {0,1,1,0,4},        /* R */
481
        },
482
        .flags = PIX_FMT_BE,
483
    },
484
    [PIX_FMT_BGR565LE] = {
485
        .name = "bgr565le",
486
        .nb_channels  = 3,
487
        .log2_chroma_w= 0,
488
        .log2_chroma_h= 0,
489
        .comp = {
490
            {0,1,2,3,4},        /* B */
491
            {0,1,1,5,5},        /* G */
492
            {0,1,1,0,4},        /* R */
493
        },
494
    },
495
    [PIX_FMT_BGR555BE] = {
496
        .name = "bgr555be",
497
        .nb_channels  = 3,
498
        .log2_chroma_w= 0,
499
        .log2_chroma_h= 0,
500
        .comp = {
501
            {0,1,0,2,4},       /* B */
502
            {0,1,1,5,4},       /* G */
503
            {0,1,1,0,4},       /* R */
504
        },
505
        .flags = PIX_FMT_BE,
506
     },
507
    [PIX_FMT_BGR555LE] = {
508
        .name = "bgr555le",
509
        .nb_channels  = 3,
510
        .log2_chroma_w= 0,
511
        .log2_chroma_h= 0,
512
        .comp = {
513
            {0,1,2,2,4},        /* B */
514
            {0,1,1,5,4},        /* G */
515
            {0,1,1,0,4},        /* R */
516
        },
517
    },
518
    [PIX_FMT_YUV420P16LE] = {
519
        .name = "yuv420p16le",
520
        .nb_channels  = 3,
521
        .log2_chroma_w= 1,
522
        .log2_chroma_h= 1,
523
        .comp = {
524
            {0,1,1,0,15},        /* Y */
525
            {1,1,1,0,15},        /* U */
526
            {2,1,1,0,15},        /* V */
527
        },
528
    },
529
    [PIX_FMT_YUV420P16BE] = {
530
        .name = "yuv420p16be",
531
        .nb_channels  = 3,
532
        .log2_chroma_w= 1,
533
        .log2_chroma_h= 1,
534
        .comp = {
535
            {0,1,1,0,15},        /* Y */
536
            {1,1,1,0,15},        /* U */
537
            {2,1,1,0,15},        /* V */
538
        },
539
        .flags = PIX_FMT_BE,
540
    },
541
    [PIX_FMT_YUV422P16LE] = {
542
        .name = "yuv422p16le",
543
        .nb_channels  = 3,
544
        .log2_chroma_w= 1,
545
        .log2_chroma_h= 0,
546
        .comp = {
547
            {0,1,1,0,15},        /* Y */
548
            {1,1,1,0,15},        /* U */
549
            {2,1,1,0,15},        /* V */
550
        },
551
    },
552
    [PIX_FMT_YUV422P16BE] = {
553
        .name = "yuv422p16be",
554
        .nb_channels  = 3,
555
        .log2_chroma_w= 1,
556
        .log2_chroma_h= 0,
557
        .comp = {
558
            {0,1,1,0,15},        /* Y */
559
            {1,1,1,0,15},        /* U */
560
            {2,1,1,0,15},        /* V */
561
        },
562
        .flags = PIX_FMT_BE,
563
    },
564
    [PIX_FMT_YUV444P16LE] = {
565
        .name = "yuv444p16le",
566
        .nb_channels  = 3,
567
        .log2_chroma_w= 0,
568
        .log2_chroma_h= 0,
569
        .comp = {
570
            {0,1,1,0,15},        /* Y */
571
            {1,1,1,0,15},        /* U */
572
            {2,1,1,0,15},        /* V */
573
        },
574
    },
575
    [PIX_FMT_YUV444P16BE] = {
576
        .name = "yuv444p16be",
577
        .nb_channels  = 3,
578
        .log2_chroma_w= 0,
579
        .log2_chroma_h= 0,
580
        .comp = {
581
            {0,1,1,0,15},        /* Y */
582
            {1,1,1,0,15},        /* U */
583
            {2,1,1,0,15},        /* V */
584
        },
585
        .flags = PIX_FMT_BE,
586
    },
587
};
588

    
589
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
590
{
591
    int c, bits = 0;
592
    int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
593

    
594
    for (c = 0; c < pixdesc->nb_channels; c++) {
595
        int s = c==1 || c==2 ? 0 : log2_pixels;
596
        bits += (pixdesc->comp[c].depth_minus1+1) << s;
597
    }
598

    
599
    return bits >> log2_pixels;
600
}