Statistics
| Branch: | Revision:

ffmpeg / libavutil / pixdesc.c @ 1fc81e73

History | View | Annotate | Download (22.2 KB)

1 9b61d838 Michael Niedermayer
/*
2 e0cffbe7 Diego Biurrun
 * pixel format descriptor
3 9b61d838 Michael Niedermayer
 * 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 47bfd50a Måns Rullgård
#include <stdio.h>
23
#include <string.h>
24 51135d1d Stefano Sabatini
#include "pixfmt.h"
25 9b61d838 Michael Niedermayer
#include "pixdesc.h"
26
27 f47a7cb7 Stefano Sabatini
#include "intreadwrite.h"
28
29 ce1cd1cb Stefano Sabatini
void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
30 ee435580 Stefano Sabatini
                        const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
31 f47a7cb7 Stefano Sabatini
{
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;
56
57
        while(w--){
58
            int val;
59
            if(flags & PIX_FMT_BE) val= AV_RB16(p);
60
            else                   val= AV_RL16(p);
61
            val = (val>>shift) & mask;
62
            if(read_pal_component)
63
                val= data[1][4*val + c];
64
            p+= step;
65
            *dst++= val;
66
        }
67
    }
68
}
69
70 ce1cd1cb Stefano Sabatini
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
71 ee435580 Stefano Sabatini
                         const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
72 f47a7cb7 Stefano Sabatini
{
73
    AVComponentDescriptor comp = desc->comp[c];
74
    int plane = comp.plane;
75
    int depth = comp.depth_minus1+1;
76
    int step  = comp.step_minus1+1;
77
    int flags = desc->flags;
78
79
    if (flags & PIX_FMT_BITSTREAM) {
80
        int skip = x*step + comp.offset_plus1-1;
81
        uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
82
        int shift = 8 - depth - (skip&7);
83
84
        while (w--) {
85
            *p |= *src++ << shift;
86
            shift -= step;
87
            p -= shift>>3;
88
            shift &= 7;
89
        }
90
    } else {
91
        int shift = comp.shift;
92
        uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
93
94
        while (w--) {
95
            if (flags & PIX_FMT_BE) {
96
                uint16_t val = AV_RB16(p) | (*src++<<shift);
97
                AV_WB16(p, val);
98
            } else {
99
                uint16_t val = AV_RL16(p) | (*src++<<shift);
100
                AV_WL16(p, val);
101
            }
102
            p+= step;
103
        }
104
    }
105
}
106
107 d2863e72 Stefano Sabatini
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
108 bcbd9a14 Stefano Sabatini
    [PIX_FMT_YUV420P] = {
109
        .name = "yuv420p",
110 b8873c2a Stefano Sabatini
        .nb_components= 3,
111 9b61d838 Michael Niedermayer
        .log2_chroma_w= 1,
112 bcbd9a14 Stefano Sabatini
        .log2_chroma_h= 1,
113 9b61d838 Michael Niedermayer
        .comp = {
114 eb39fb51 Stefano Sabatini
            {0,0,1,0,7},        /* Y */
115
            {1,0,1,0,7},        /* U */
116
            {2,0,1,0,7},        /* V */
117 9b61d838 Michael Niedermayer
        },
118
    },
119 bcbd9a14 Stefano Sabatini
    [PIX_FMT_YUYV422] = {
120
        .name = "yuyv422",
121 b8873c2a Stefano Sabatini
        .nb_components= 3,
122 9b61d838 Michael Niedermayer
        .log2_chroma_w= 1,
123 bcbd9a14 Stefano Sabatini
        .log2_chroma_h= 0,
124
        .comp = {
125
            {0,1,1,0,7},        /* Y */
126
            {0,3,2,0,7},        /* U */
127
            {0,3,4,0,7},        /* V */
128
        },
129
    },
130
    [PIX_FMT_RGB24] = {
131
        .name = "rgb24",
132 b8873c2a Stefano Sabatini
        .nb_components= 3,
133 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 0,
134
        .log2_chroma_h= 0,
135
        .comp = {
136
            {0,2,1,0,7},        /* R */
137
            {0,2,2,0,7},        /* G */
138
            {0,2,3,0,7},        /* B */
139
        },
140
    },
141 10151b13 Stefano Sabatini
    [PIX_FMT_BGR24] = {
142
        .name = "bgr24",
143 b8873c2a Stefano Sabatini
        .nb_components= 3,
144 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
145
        .log2_chroma_h= 0,
146
        .comp = {
147
            {0,2,1,0,7},        /* B */
148
            {0,2,2,0,7},        /* G */
149
            {0,2,3,0,7},        /* R */
150
        },
151
    },
152 bcbd9a14 Stefano Sabatini
    [PIX_FMT_YUV422P] = {
153
        .name = "yuv422p",
154 b8873c2a Stefano Sabatini
        .nb_components= 3,
155 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 1,
156
        .log2_chroma_h= 0,
157 9b61d838 Michael Niedermayer
        .comp = {
158 eb39fb51 Stefano Sabatini
            {0,0,1,0,7},        /* Y */
159
            {1,0,1,0,7},        /* U */
160
            {2,0,1,0,7},        /* V */
161 9b61d838 Michael Niedermayer
        },
162
    },
163 10151b13 Stefano Sabatini
    [PIX_FMT_YUV444P] = {
164
        .name = "yuv444p",
165 b8873c2a Stefano Sabatini
        .nb_components= 3,
166 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
167
        .log2_chroma_h= 0,
168
        .comp = {
169
            {0,0,1,0,7},        /* Y */
170
            {1,0,1,0,7},        /* U */
171
            {2,0,1,0,7},        /* V */
172
        },
173
    },
174 9b61d838 Michael Niedermayer
    [PIX_FMT_YUV410P] = {
175 1e896640 Stefano Sabatini
        .name = "yuv410p",
176 b8873c2a Stefano Sabatini
        .nb_components= 3,
177 9b61d838 Michael Niedermayer
        .log2_chroma_w= 2,
178
        .log2_chroma_h= 2,
179
        .comp = {
180 eb39fb51 Stefano Sabatini
            {0,0,1,0,7},        /* Y */
181
            {1,0,1,0,7},        /* U */
182
            {2,0,1,0,7},        /* V */
183 9b61d838 Michael Niedermayer
        },
184
    },
185 10151b13 Stefano Sabatini
    [PIX_FMT_YUV411P] = {
186
        .name = "yuv411p",
187 b8873c2a Stefano Sabatini
        .nb_components= 3,
188 10151b13 Stefano Sabatini
        .log2_chroma_w= 2,
189
        .log2_chroma_h= 0,
190
        .comp = {
191
            {0,0,1,0,7},        /* Y */
192
            {1,0,1,0,7},        /* U */
193
            {2,0,1,0,7},        /* V */
194
        },
195
    },
196
    [PIX_FMT_GRAY8] = {
197 382cb115 Stefano Sabatini
        .name = "gray",
198 b8873c2a Stefano Sabatini
        .nb_components= 1,
199 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
200
        .log2_chroma_h= 0,
201
        .comp = {
202
            {0,0,1,0,7},        /* Y */
203
        },
204 ce7c7179 Stefano Sabatini
        .flags = PIX_FMT_PAL,
205 10151b13 Stefano Sabatini
    },
206
    [PIX_FMT_MONOWHITE] = {
207 382cb115 Stefano Sabatini
        .name = "monow",
208 b8873c2a Stefano Sabatini
        .nb_components= 1,
209 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
210
        .log2_chroma_h= 0,
211
        .comp = {
212
            {0,0,1,0,0},        /* Y */
213
        },
214
        .flags = PIX_FMT_BITSTREAM,
215
    },
216 bcbd9a14 Stefano Sabatini
    [PIX_FMT_MONOBLACK] = {
217 382cb115 Stefano Sabatini
        .name = "monob",
218 b8873c2a Stefano Sabatini
        .nb_components= 1,
219 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 0,
220
        .log2_chroma_h= 0,
221 9b61d838 Michael Niedermayer
        .comp = {
222 bcbd9a14 Stefano Sabatini
            {0,0,1,7,0},        /* Y */
223 9b61d838 Michael Niedermayer
        },
224 bcbd9a14 Stefano Sabatini
        .flags = PIX_FMT_BITSTREAM,
225 9b61d838 Michael Niedermayer
    },
226 bcbd9a14 Stefano Sabatini
    [PIX_FMT_PAL8] = {
227
        .name = "pal8",
228 b8873c2a Stefano Sabatini
        .nb_components= 1,
229 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 0,
230 9b61d838 Michael Niedermayer
        .log2_chroma_h= 0,
231
        .comp = {
232 bcbd9a14 Stefano Sabatini
            {0,0,1,0,7},
233 9b61d838 Michael Niedermayer
        },
234 bcbd9a14 Stefano Sabatini
        .flags = PIX_FMT_PAL,
235 9b61d838 Michael Niedermayer
    },
236 10151b13 Stefano Sabatini
    [PIX_FMT_YUVJ420P] = {
237
        .name = "yuvj420p",
238 b8873c2a Stefano Sabatini
        .nb_components= 3,
239 10151b13 Stefano Sabatini
        .log2_chroma_w= 1,
240
        .log2_chroma_h= 1,
241
        .comp = {
242
            {0,0,1,0,7},        /* Y */
243
            {1,0,1,0,7},        /* U */
244
            {2,0,1,0,7},        /* V */
245
        },
246
    },
247
    [PIX_FMT_YUVJ422P] = {
248
        .name = "yuvj422p",
249 b8873c2a Stefano Sabatini
        .nb_components= 3,
250 10151b13 Stefano Sabatini
        .log2_chroma_w= 1,
251
        .log2_chroma_h= 0,
252
        .comp = {
253
            {0,0,1,0,7},        /* Y */
254
            {1,0,1,0,7},        /* U */
255
            {2,0,1,0,7},        /* V */
256
        },
257
    },
258
    [PIX_FMT_YUVJ444P] = {
259
        .name = "yuvj444p",
260 b8873c2a Stefano Sabatini
        .nb_components= 3,
261 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
262
        .log2_chroma_h= 0,
263
        .comp = {
264
            {0,0,1,0,7},        /* Y */
265
            {1,0,1,0,7},        /* U */
266
            {2,0,1,0,7},        /* V */
267
        },
268
    },
269 3fa70a3b Stefano Sabatini
    [PIX_FMT_XVMC_MPEG2_MC] = {
270 382cb115 Stefano Sabatini
        .name = "xvmcmc",
271 3fa70a3b Stefano Sabatini
        .flags = PIX_FMT_HWACCEL,
272
    },
273
    [PIX_FMT_XVMC_MPEG2_IDCT] = {
274 382cb115 Stefano Sabatini
        .name = "xvmcidct",
275 3fa70a3b Stefano Sabatini
        .flags = PIX_FMT_HWACCEL,
276
    },
277 9b61d838 Michael Niedermayer
    [PIX_FMT_UYVY422] = {
278 1e896640 Stefano Sabatini
        .name = "uyvy422",
279 b8873c2a Stefano Sabatini
        .nb_components= 3,
280 9b61d838 Michael Niedermayer
        .log2_chroma_w= 1,
281
        .log2_chroma_h= 0,
282
        .comp = {
283 eb39fb51 Stefano Sabatini
            {0,1,2,0,7},        /* Y */
284
            {0,3,1,0,7},        /* U */
285
            {0,3,3,0,7},        /* V */
286 9b61d838 Michael Niedermayer
        },
287
    },
288 10151b13 Stefano Sabatini
    [PIX_FMT_UYYVYY411] = {
289
        .name = "uyyvyy411",
290 b8873c2a Stefano Sabatini
        .nb_components= 3,
291 10151b13 Stefano Sabatini
        .log2_chroma_w= 2,
292
        .log2_chroma_h= 0,
293
        .comp = {
294
            {0,3,2,0,7},        /* Y */
295
            {0,5,1,0,7},        /* U */
296
            {0,5,4,0,7},        /* V */
297
        },
298
    },
299
    [PIX_FMT_BGR8] = {
300
        .name = "bgr8",
301 b8873c2a Stefano Sabatini
        .nb_components= 3,
302 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
303
        .log2_chroma_h= 0,
304
        .comp = {
305
            {0,0,1,6,1},        /* B */
306
            {0,0,1,3,2},        /* G */
307
            {0,0,1,0,2},        /* R */
308
        },
309 d71ad089 Stefano Sabatini
        .flags = PIX_FMT_PAL,
310 10151b13 Stefano Sabatini
    },
311
    [PIX_FMT_BGR4] = {
312
        .name = "bgr4",
313 b8873c2a Stefano Sabatini
        .nb_components= 3,
314 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
315
        .log2_chroma_h= 0,
316
        .comp = {
317
            {0,3,1,0,0},        /* B */
318
            {0,3,2,0,1},        /* G */
319
            {0,3,4,0,0},        /* R */
320
        },
321
        .flags = PIX_FMT_BITSTREAM,
322
    },
323
    [PIX_FMT_BGR4_BYTE] = {
324
        .name = "bgr4_byte",
325 b8873c2a Stefano Sabatini
        .nb_components= 3,
326 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
327
        .log2_chroma_h= 0,
328
        .comp = {
329
            {0,0,1,3,0},        /* B */
330
            {0,0,1,1,1},        /* G */
331
            {0,0,1,0,0},        /* R */
332
        },
333 d71ad089 Stefano Sabatini
        .flags = PIX_FMT_PAL,
334 10151b13 Stefano Sabatini
    },
335
    [PIX_FMT_RGB8] = {
336
        .name = "rgb8",
337 b8873c2a Stefano Sabatini
        .nb_components= 3,
338 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
339
        .log2_chroma_h= 0,
340
        .comp = {
341
            {0,0,1,6,1},        /* R */
342
            {0,0,1,3,2},        /* G */
343
            {0,0,1,0,2},        /* B */
344
        },
345 d71ad089 Stefano Sabatini
        .flags = PIX_FMT_PAL,
346 10151b13 Stefano Sabatini
    },
347
    [PIX_FMT_RGB4] = {
348
        .name = "rgb4",
349 b8873c2a Stefano Sabatini
        .nb_components= 3,
350 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
351
        .log2_chroma_h= 0,
352
        .comp = {
353
            {0,3,1,0,0},       /* R */
354
            {0,3,2,0,1},       /* G */
355
            {0,3,4,0,0},       /* B */
356
        },
357
        .flags = PIX_FMT_BITSTREAM,
358
    },
359
    [PIX_FMT_RGB4_BYTE] = {
360
        .name = "rgb4_byte",
361 b8873c2a Stefano Sabatini
        .nb_components= 3,
362 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
363
        .log2_chroma_h= 0,
364
        .comp = {
365
            {0,0,1,3,0},        /* R */
366
            {0,0,1,1,1},        /* G */
367
            {0,0,1,0,0},        /* B */
368
        },
369 d71ad089 Stefano Sabatini
        .flags = PIX_FMT_PAL,
370 10151b13 Stefano Sabatini
    },
371 bcbd9a14 Stefano Sabatini
    [PIX_FMT_NV12] = {
372
        .name = "nv12",
373 b8873c2a Stefano Sabatini
        .nb_components= 3,
374 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 1,
375
        .log2_chroma_h= 1,
376 9b61d838 Michael Niedermayer
        .comp = {
377 bcbd9a14 Stefano Sabatini
            {0,0,1,0,7},        /* Y */
378
            {1,1,1,0,7},        /* U */
379
            {1,1,2,0,7},        /* V */
380 9b61d838 Michael Niedermayer
        },
381
    },
382 10151b13 Stefano Sabatini
    [PIX_FMT_NV21] = {
383
        .name = "nv21",
384 b8873c2a Stefano Sabatini
        .nb_components= 3,
385 10151b13 Stefano Sabatini
        .log2_chroma_w= 1,
386
        .log2_chroma_h= 1,
387
        .comp = {
388
            {0,0,1,0,7},        /* Y */
389
            {1,1,1,0,7},        /* V */
390
            {1,1,2,0,7},        /* U */
391
        },
392
    },
393
    [PIX_FMT_ARGB] = {
394
        .name = "argb",
395 b8873c2a Stefano Sabatini
        .nb_components= 4,
396 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
397
        .log2_chroma_h= 0,
398
        .comp = {
399
            {0,3,1,0,7},        /* A */
400
            {0,3,2,0,7},        /* R */
401
            {0,3,3,0,7},        /* G */
402
            {0,3,4,0,7},        /* B */
403
        },
404
    },
405 9b61d838 Michael Niedermayer
    [PIX_FMT_RGBA] = {
406 1e896640 Stefano Sabatini
        .name = "rgba",
407 b8873c2a Stefano Sabatini
        .nb_components= 4,
408 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
409
        .log2_chroma_h= 0,
410
        .comp = {
411 eb39fb51 Stefano Sabatini
            {0,3,1,0,7},        /* R */
412
            {0,3,2,0,7},        /* G */
413
            {0,3,3,0,7},        /* B */
414
            {0,3,4,0,7},        /* A */
415 9b61d838 Michael Niedermayer
        },
416
    },
417 10151b13 Stefano Sabatini
    [PIX_FMT_ABGR] = {
418
        .name = "abgr",
419 b8873c2a Stefano Sabatini
        .nb_components= 4,
420 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
421
        .log2_chroma_h= 0,
422
        .comp = {
423
            {0,3,1,0,7},        /* A */
424
            {0,3,2,0,7},        /* B */
425
            {0,3,3,0,7},        /* G */
426
            {0,3,4,0,7},        /* R */
427
        },
428
    },
429
    [PIX_FMT_BGRA] = {
430
        .name = "bgra",
431 b8873c2a Stefano Sabatini
        .nb_components= 4,
432 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
433
        .log2_chroma_h= 0,
434
        .comp = {
435
            {0,3,1,0,7},        /* B */
436
            {0,3,2,0,7},        /* G */
437
            {0,3,3,0,7},        /* R */
438
            {0,3,4,0,7},        /* A */
439
        },
440
    },
441 bcbd9a14 Stefano Sabatini
    [PIX_FMT_GRAY16BE] = {
442
        .name = "gray16be",
443 b8873c2a Stefano Sabatini
        .nb_components= 1,
444 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
445
        .log2_chroma_h= 0,
446
        .comp = {
447 bcbd9a14 Stefano Sabatini
            {0,1,1,0,15},       /* Y */
448
        },
449
        .flags = PIX_FMT_BE,
450
    },
451
    [PIX_FMT_GRAY16LE] = {
452
        .name = "gray16le",
453 b8873c2a Stefano Sabatini
        .nb_components= 1,
454 bcbd9a14 Stefano Sabatini
        .log2_chroma_w= 0,
455
        .log2_chroma_h= 0,
456
        .comp = {
457
            {0,1,1,0,15},       /* Y */
458 9b61d838 Michael Niedermayer
        },
459
    },
460 10151b13 Stefano Sabatini
    [PIX_FMT_YUV440P] = {
461
        .name = "yuv440p",
462 b8873c2a Stefano Sabatini
        .nb_components= 3,
463 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
464
        .log2_chroma_h= 1,
465
        .comp = {
466
            {0,0,1,0,7},        /* Y */
467
            {1,0,1,0,7},        /* U */
468
            {2,0,1,0,7},        /* V */
469
        },
470
    },
471
    [PIX_FMT_YUVJ440P] = {
472
        .name = "yuvj440p",
473 b8873c2a Stefano Sabatini
        .nb_components= 3,
474 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
475
        .log2_chroma_h= 1,
476
        .comp = {
477
            {0,0,1,0,7},        /* Y */
478
            {1,0,1,0,7},        /* U */
479
            {2,0,1,0,7},        /* V */
480
        },
481
    },
482
    [PIX_FMT_YUVA420P] = {
483
        .name = "yuva420p",
484 b8873c2a Stefano Sabatini
        .nb_components= 4,
485 10151b13 Stefano Sabatini
        .log2_chroma_w= 1,
486
        .log2_chroma_h= 1,
487
        .comp = {
488
            {0,0,1,0,7},        /* Y */
489
            {1,0,1,0,7},        /* U */
490
            {2,0,1,0,7},        /* V */
491
            {3,0,1,0,7},        /* A */
492
        },
493
    },
494 3fa70a3b Stefano Sabatini
    [PIX_FMT_VDPAU_H264] = {
495
        .name = "vdpau_h264",
496
        .log2_chroma_w = 1,
497
        .log2_chroma_h = 1,
498
        .flags = PIX_FMT_HWACCEL,
499
    },
500
    [PIX_FMT_VDPAU_MPEG1] = {
501
        .name = "vdpau_mpeg1",
502
        .log2_chroma_w = 1,
503
        .log2_chroma_h = 1,
504
        .flags = PIX_FMT_HWACCEL,
505
    },
506
    [PIX_FMT_VDPAU_MPEG2] = {
507
        .name = "vdpau_mpeg2",
508
        .log2_chroma_w = 1,
509
        .log2_chroma_h = 1,
510
        .flags = PIX_FMT_HWACCEL,
511
    },
512
    [PIX_FMT_VDPAU_WMV3] = {
513
        .name = "vdpau_wmv3",
514
        .log2_chroma_w = 1,
515
        .log2_chroma_h = 1,
516
        .flags = PIX_FMT_HWACCEL,
517
    },
518
    [PIX_FMT_VDPAU_VC1] = {
519
        .name = "vdpau_vc1",
520
        .log2_chroma_w = 1,
521
        .log2_chroma_h = 1,
522
        .flags = PIX_FMT_HWACCEL,
523
    },
524 dd6308ad Carl Eugen Hoyos
    [PIX_FMT_VDPAU_MPEG4] = {
525
        .name = "vdpau_mpeg4",
526
        .log2_chroma_w = 1,
527
        .log2_chroma_h = 1,
528
        .flags = PIX_FMT_HWACCEL,
529
    },
530 9b61d838 Michael Niedermayer
    [PIX_FMT_RGB48BE] = {
531 1e896640 Stefano Sabatini
        .name = "rgb48be",
532 b8873c2a Stefano Sabatini
        .nb_components= 3,
533 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
534
        .log2_chroma_h= 0,
535
        .comp = {
536 eb39fb51 Stefano Sabatini
            {0,5,1,0,15},       /* R */
537
            {0,5,3,0,15},       /* G */
538
            {0,5,5,0,15},       /* B */
539 9b61d838 Michael Niedermayer
        },
540
        .flags = PIX_FMT_BE,
541
    },
542 bcbd9a14 Stefano Sabatini
    [PIX_FMT_RGB48LE] = {
543
        .name = "rgb48le",
544 b8873c2a Stefano Sabatini
        .nb_components= 3,
545 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
546
        .log2_chroma_h= 0,
547
        .comp = {
548 bcbd9a14 Stefano Sabatini
            {0,5,1,0,15},       /* R */
549
            {0,5,3,0,15},       /* G */
550
            {0,5,5,0,15},       /* B */
551 9b61d838 Michael Niedermayer
        },
552
    },
553 e5681ba0 Stefano Sabatini
    [PIX_FMT_RGB565BE] = {
554 1e896640 Stefano Sabatini
        .name = "rgb565be",
555 b8873c2a Stefano Sabatini
        .nb_components= 3,
556 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
557
        .log2_chroma_h= 0,
558
        .comp = {
559 eb39fb51 Stefano Sabatini
            {0,1,0,3,4},        /* R */
560 f938cbf9 Stefano Sabatini
            {0,1,1,5,5},        /* G */
561
            {0,1,1,0,4},        /* B */
562 9b61d838 Michael Niedermayer
        },
563
        .flags = PIX_FMT_BE,
564
    },
565 bcbd9a14 Stefano Sabatini
    [PIX_FMT_RGB565LE] = {
566
        .name = "rgb565le",
567 b8873c2a Stefano Sabatini
        .nb_components= 3,
568 9b61d838 Michael Niedermayer
        .log2_chroma_w= 0,
569
        .log2_chroma_h= 0,
570
        .comp = {
571 bcbd9a14 Stefano Sabatini
            {0,1,2,3,4},        /* R */
572
            {0,1,1,5,5},        /* G */
573
            {0,1,1,0,4},        /* B */
574 9b61d838 Michael Niedermayer
        },
575
    },
576 10151b13 Stefano Sabatini
    [PIX_FMT_RGB555BE] = {
577
        .name = "rgb555be",
578 b8873c2a Stefano Sabatini
        .nb_components= 3,
579 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
580
        .log2_chroma_h= 0,
581
        .comp = {
582
            {0,1,0,2,4},        /* R */
583
            {0,1,1,5,4},        /* G */
584
            {0,1,1,0,4},        /* B */
585
        },
586
        .flags = PIX_FMT_BE,
587
    },
588
    [PIX_FMT_RGB555LE] = {
589
        .name = "rgb555le",
590 b8873c2a Stefano Sabatini
        .nb_components= 3,
591 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
592
        .log2_chroma_h= 0,
593
        .comp = {
594
            {0,1,2,2,4},        /* R */
595
            {0,1,1,5,4},        /* G */
596
            {0,1,1,0,4},        /* B */
597
        },
598
    },
599 2b7cf167 Janusz Krzysztofik
    [PIX_FMT_RGB444BE] = {
600
        .name = "rgb444be",
601
        .nb_components= 3,
602
        .log2_chroma_w= 0,
603
        .log2_chroma_h= 0,
604
        .comp = {
605
            {0,1,0,0,3},        /* R */
606
            {0,1,1,4,3},        /* G */
607
            {0,1,1,0,3},        /* B */
608
        },
609
        .flags = PIX_FMT_BE,
610
    },
611
    [PIX_FMT_RGB444LE] = {
612
        .name = "rgb444le",
613
        .nb_components= 3,
614
        .log2_chroma_w= 0,
615
        .log2_chroma_h= 0,
616
        .comp = {
617
            {0,1,2,0,3},        /* R */
618
            {0,1,1,4,3},        /* G */
619
            {0,1,1,0,3},        /* B */
620
        },
621
    },
622 10151b13 Stefano Sabatini
    [PIX_FMT_BGR565BE] = {
623
        .name = "bgr565be",
624 b8873c2a Stefano Sabatini
        .nb_components= 3,
625 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
626
        .log2_chroma_h= 0,
627
        .comp = {
628
            {0,1,0,3,4},        /* B */
629
            {0,1,1,5,5},        /* G */
630
            {0,1,1,0,4},        /* R */
631
        },
632
        .flags = PIX_FMT_BE,
633
    },
634
    [PIX_FMT_BGR565LE] = {
635
        .name = "bgr565le",
636 b8873c2a Stefano Sabatini
        .nb_components= 3,
637 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
638
        .log2_chroma_h= 0,
639
        .comp = {
640
            {0,1,2,3,4},        /* B */
641
            {0,1,1,5,5},        /* G */
642
            {0,1,1,0,4},        /* R */
643
        },
644
    },
645
    [PIX_FMT_BGR555BE] = {
646
        .name = "bgr555be",
647 b8873c2a Stefano Sabatini
        .nb_components= 3,
648 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
649
        .log2_chroma_h= 0,
650
        .comp = {
651
            {0,1,0,2,4},       /* B */
652
            {0,1,1,5,4},       /* G */
653
            {0,1,1,0,4},       /* R */
654
        },
655
        .flags = PIX_FMT_BE,
656
     },
657
    [PIX_FMT_BGR555LE] = {
658
        .name = "bgr555le",
659 b8873c2a Stefano Sabatini
        .nb_components= 3,
660 10151b13 Stefano Sabatini
        .log2_chroma_w= 0,
661
        .log2_chroma_h= 0,
662
        .comp = {
663
            {0,1,2,2,4},        /* B */
664
            {0,1,1,5,4},        /* G */
665
            {0,1,1,0,4},        /* R */
666
        },
667
    },
668 2b7cf167 Janusz Krzysztofik
    [PIX_FMT_BGR444BE] = {
669
        .name = "bgr444be",
670
        .nb_components= 3,
671
        .log2_chroma_w= 0,
672
        .log2_chroma_h= 0,
673
        .comp = {
674
            {0,1,0,0,3},       /* B */
675
            {0,1,1,4,3},       /* G */
676
            {0,1,1,0,3},       /* R */
677
        },
678
        .flags = PIX_FMT_BE,
679
     },
680
    [PIX_FMT_BGR444LE] = {
681
        .name = "bgr444le",
682
        .nb_components= 3,
683
        .log2_chroma_w= 0,
684
        .log2_chroma_h= 0,
685
        .comp = {
686
            {0,1,2,0,3},        /* B */
687
            {0,1,1,4,3},        /* G */
688
            {0,1,1,0,3},        /* R */
689
        },
690
    },
691 3fa70a3b Stefano Sabatini
    [PIX_FMT_VAAPI_MOCO] = {
692
        .name = "vaapi_moco",
693
        .log2_chroma_w = 1,
694
        .log2_chroma_h = 1,
695
        .flags = PIX_FMT_HWACCEL,
696
    },
697
    [PIX_FMT_VAAPI_IDCT] = {
698
        .name = "vaapi_idct",
699
        .log2_chroma_w = 1,
700
        .log2_chroma_h = 1,
701
        .flags = PIX_FMT_HWACCEL,
702
    },
703
    [PIX_FMT_VAAPI_VLD] = {
704
        .name = "vaapi_vld",
705
        .log2_chroma_w = 1,
706
        .log2_chroma_h = 1,
707
        .flags = PIX_FMT_HWACCEL,
708
    },
709 35f6c154 Lars Täuber
    [PIX_FMT_YUV420P16LE] = {
710
        .name = "yuv420p16le",
711 b8873c2a Stefano Sabatini
        .nb_components= 3,
712 75801da5 Stefano Sabatini
        .log2_chroma_w= 1,
713
        .log2_chroma_h= 1,
714
        .comp = {
715
            {0,1,1,0,15},        /* Y */
716
            {1,1,1,0,15},        /* U */
717
            {2,1,1,0,15},        /* V */
718
        },
719
    },
720 35f6c154 Lars Täuber
    [PIX_FMT_YUV420P16BE] = {
721
        .name = "yuv420p16be",
722 b8873c2a Stefano Sabatini
        .nb_components= 3,
723 75801da5 Stefano Sabatini
        .log2_chroma_w= 1,
724
        .log2_chroma_h= 1,
725
        .comp = {
726
            {0,1,1,0,15},        /* Y */
727
            {1,1,1,0,15},        /* U */
728
            {2,1,1,0,15},        /* V */
729
        },
730
        .flags = PIX_FMT_BE,
731
    },
732 35f6c154 Lars Täuber
    [PIX_FMT_YUV422P16LE] = {
733
        .name = "yuv422p16le",
734 b8873c2a Stefano Sabatini
        .nb_components= 3,
735 75801da5 Stefano Sabatini
        .log2_chroma_w= 1,
736
        .log2_chroma_h= 0,
737
        .comp = {
738
            {0,1,1,0,15},        /* Y */
739
            {1,1,1,0,15},        /* U */
740
            {2,1,1,0,15},        /* V */
741
        },
742
    },
743 35f6c154 Lars Täuber
    [PIX_FMT_YUV422P16BE] = {
744
        .name = "yuv422p16be",
745 b8873c2a Stefano Sabatini
        .nb_components= 3,
746 75801da5 Stefano Sabatini
        .log2_chroma_w= 1,
747
        .log2_chroma_h= 0,
748
        .comp = {
749
            {0,1,1,0,15},        /* Y */
750
            {1,1,1,0,15},        /* U */
751
            {2,1,1,0,15},        /* V */
752
        },
753
        .flags = PIX_FMT_BE,
754
    },
755 35f6c154 Lars Täuber
    [PIX_FMT_YUV444P16LE] = {
756
        .name = "yuv444p16le",
757 b8873c2a Stefano Sabatini
        .nb_components= 3,
758 75801da5 Stefano Sabatini
        .log2_chroma_w= 0,
759
        .log2_chroma_h= 0,
760
        .comp = {
761
            {0,1,1,0,15},        /* Y */
762
            {1,1,1,0,15},        /* U */
763
            {2,1,1,0,15},        /* V */
764
        },
765
    },
766 35f6c154 Lars Täuber
    [PIX_FMT_YUV444P16BE] = {
767
        .name = "yuv444p16be",
768 b8873c2a Stefano Sabatini
        .nb_components= 3,
769 75801da5 Stefano Sabatini
        .log2_chroma_w= 0,
770
        .log2_chroma_h= 0,
771
        .comp = {
772
            {0,1,1,0,15},        /* Y */
773
            {1,1,1,0,15},        /* U */
774
            {2,1,1,0,15},        /* V */
775
        },
776
        .flags = PIX_FMT_BE,
777
    },
778 92c6a099 Laurent Aimar
    [PIX_FMT_DXVA2_VLD] = {
779
        .name = "dxva2_vld",
780
        .log2_chroma_w = 1,
781
        .log2_chroma_h = 1,
782
        .flags = PIX_FMT_HWACCEL,
783
    },
784 4744f896 Andreas Öman
    [PIX_FMT_Y400A] = {
785
        .name = "y400a",
786
        .nb_components= 2,
787
        .comp = {
788
            {0,1,1,0,7},        /* Y */
789
            {0,1,2,0,7},        /* A */
790
        },
791
    },
792 9b61d838 Michael Niedermayer
};
793 5efccce2 Stefano Sabatini
794 80a07f6e Stefano Sabatini
static enum PixelFormat get_pix_fmt_internal(const char *name)
795
{
796
    enum PixelFormat pix_fmt;
797
798
    for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
799
        if (av_pix_fmt_descriptors[pix_fmt].name &&
800
            !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
801
            return pix_fmt;
802
803
    return PIX_FMT_NONE;
804
}
805
806
#if HAVE_BIGENDIAN
807
#   define X_NE(be, le) be
808
#else
809
#   define X_NE(be, le) le
810
#endif
811
812
enum PixelFormat av_get_pix_fmt(const char *name)
813
{
814
    enum PixelFormat pix_fmt;
815
816
    if (!strcmp(name, "rgb32"))
817
        name = X_NE("argb", "bgra");
818
    else if (!strcmp(name, "bgr32"))
819
        name = X_NE("abgr", "rgba");
820
821
    pix_fmt = get_pix_fmt_internal(name);
822
    if (pix_fmt == PIX_FMT_NONE) {
823
        char name2[32];
824
825
        snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
826
        pix_fmt = get_pix_fmt_internal(name2);
827
    }
828
    return pix_fmt;
829
}
830
831 5efccce2 Stefano Sabatini
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
832
{
833
    int c, bits = 0;
834
    int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
835
836 b8873c2a Stefano Sabatini
    for (c = 0; c < pixdesc->nb_components; c++) {
837 5efccce2 Stefano Sabatini
        int s = c==1 || c==2 ? 0 : log2_pixels;
838
        bits += (pixdesc->comp[c].depth_minus1+1) << s;
839
    }
840
841
    return bits >> log2_pixels;
842
}