59
50
#define deinterlace_line deinterlace_line_c
62
typedef struct PixFmtInfo {
63
uint8_t nb_channels; /**< number of channels (including alpha) */
64
uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */
65
uint8_t pixel_type; /**< pixel storage type (see FF_PIXEL_xxx constants) */
66
uint8_t is_alpha : 1; /**< true if alpha can be specified */
67
uint8_t depth; /**< bit depth of the color components */
70
/* this table gives more information about formats */
71
static const PixFmtInfo pix_fmt_info[AV_PIX_FMT_NB] = {
73
[AV_PIX_FMT_YUV420P] = {
75
.color_type = FF_COLOR_YUV,
76
.pixel_type = FF_PIXEL_PLANAR,
79
[AV_PIX_FMT_YUV422P] = {
81
.color_type = FF_COLOR_YUV,
82
.pixel_type = FF_PIXEL_PLANAR,
85
[AV_PIX_FMT_YUV444P] = {
87
.color_type = FF_COLOR_YUV,
88
.pixel_type = FF_PIXEL_PLANAR,
91
[AV_PIX_FMT_YUYV422] = {
93
.color_type = FF_COLOR_YUV,
94
.pixel_type = FF_PIXEL_PACKED,
97
[AV_PIX_FMT_UYVY422] = {
99
.color_type = FF_COLOR_YUV,
100
.pixel_type = FF_PIXEL_PACKED,
103
[AV_PIX_FMT_YUV410P] = {
105
.color_type = FF_COLOR_YUV,
106
.pixel_type = FF_PIXEL_PLANAR,
109
[AV_PIX_FMT_YUV411P] = {
111
.color_type = FF_COLOR_YUV,
112
.pixel_type = FF_PIXEL_PLANAR,
115
[AV_PIX_FMT_YUV440P] = {
117
.color_type = FF_COLOR_YUV,
118
.pixel_type = FF_PIXEL_PLANAR,
121
[AV_PIX_FMT_YUV420P16LE] = {
123
.color_type = FF_COLOR_YUV,
124
.pixel_type = FF_PIXEL_PLANAR,
127
[AV_PIX_FMT_YUV422P16LE] = {
129
.color_type = FF_COLOR_YUV,
130
.pixel_type = FF_PIXEL_PLANAR,
133
[AV_PIX_FMT_YUV444P16LE] = {
135
.color_type = FF_COLOR_YUV,
136
.pixel_type = FF_PIXEL_PLANAR,
139
[AV_PIX_FMT_YUV420P16BE] = {
141
.color_type = FF_COLOR_YUV,
142
.pixel_type = FF_PIXEL_PLANAR,
145
[AV_PIX_FMT_YUV422P16BE] = {
147
.color_type = FF_COLOR_YUV,
148
.pixel_type = FF_PIXEL_PLANAR,
151
[AV_PIX_FMT_YUV444P16BE] = {
153
.color_type = FF_COLOR_YUV,
154
.pixel_type = FF_PIXEL_PLANAR,
159
/* YUV formats with alpha plane */
160
[AV_PIX_FMT_YUVA420P] = {
162
.color_type = FF_COLOR_YUV,
163
.pixel_type = FF_PIXEL_PLANAR,
168
[AV_PIX_FMT_YUVJ420P] = {
170
.color_type = FF_COLOR_YUV_JPEG,
171
.pixel_type = FF_PIXEL_PLANAR,
174
[AV_PIX_FMT_YUVJ422P] = {
176
.color_type = FF_COLOR_YUV_JPEG,
177
.pixel_type = FF_PIXEL_PLANAR,
180
[AV_PIX_FMT_YUVJ444P] = {
182
.color_type = FF_COLOR_YUV_JPEG,
183
.pixel_type = FF_PIXEL_PLANAR,
186
[AV_PIX_FMT_YUVJ440P] = {
188
.color_type = FF_COLOR_YUV_JPEG,
189
.pixel_type = FF_PIXEL_PLANAR,
194
[AV_PIX_FMT_RGB24] = {
196
.color_type = FF_COLOR_RGB,
197
.pixel_type = FF_PIXEL_PACKED,
200
[AV_PIX_FMT_BGR24] = {
202
.color_type = FF_COLOR_RGB,
203
.pixel_type = FF_PIXEL_PACKED,
206
[AV_PIX_FMT_ARGB] = {
207
.nb_channels = 4, .is_alpha = 1,
208
.color_type = FF_COLOR_RGB,
209
.pixel_type = FF_PIXEL_PACKED,
212
[AV_PIX_FMT_RGB48BE] = {
214
.color_type = FF_COLOR_RGB,
215
.pixel_type = FF_PIXEL_PACKED,
218
[AV_PIX_FMT_RGB48LE] = {
220
.color_type = FF_COLOR_RGB,
221
.pixel_type = FF_PIXEL_PACKED,
224
[AV_PIX_FMT_RGB565BE] = {
226
.color_type = FF_COLOR_RGB,
227
.pixel_type = FF_PIXEL_PACKED,
230
[AV_PIX_FMT_RGB565LE] = {
232
.color_type = FF_COLOR_RGB,
233
.pixel_type = FF_PIXEL_PACKED,
236
[AV_PIX_FMT_RGB555BE] = {
238
.color_type = FF_COLOR_RGB,
239
.pixel_type = FF_PIXEL_PACKED,
242
[AV_PIX_FMT_RGB555LE] = {
244
.color_type = FF_COLOR_RGB,
245
.pixel_type = FF_PIXEL_PACKED,
248
[AV_PIX_FMT_RGB444BE] = {
250
.color_type = FF_COLOR_RGB,
251
.pixel_type = FF_PIXEL_PACKED,
254
[AV_PIX_FMT_RGB444LE] = {
256
.color_type = FF_COLOR_RGB,
257
.pixel_type = FF_PIXEL_PACKED,
261
/* gray / mono formats */
262
[AV_PIX_FMT_GRAY16BE] = {
264
.color_type = FF_COLOR_GRAY,
265
.pixel_type = FF_PIXEL_PLANAR,
268
[AV_PIX_FMT_GRAY16LE] = {
270
.color_type = FF_COLOR_GRAY,
271
.pixel_type = FF_PIXEL_PLANAR,
274
[AV_PIX_FMT_GRAY8] = {
276
.color_type = FF_COLOR_GRAY,
277
.pixel_type = FF_PIXEL_PLANAR,
280
[AV_PIX_FMT_MONOWHITE] = {
282
.color_type = FF_COLOR_GRAY,
283
.pixel_type = FF_PIXEL_PLANAR,
286
[AV_PIX_FMT_MONOBLACK] = {
288
.color_type = FF_COLOR_GRAY,
289
.pixel_type = FF_PIXEL_PLANAR,
293
/* paletted formats */
294
[AV_PIX_FMT_PAL8] = {
295
.nb_channels = 4, .is_alpha = 1,
296
.color_type = FF_COLOR_RGB,
297
.pixel_type = FF_PIXEL_PALETTE,
300
[AV_PIX_FMT_UYYVYY411] = {
302
.color_type = FF_COLOR_YUV,
303
.pixel_type = FF_PIXEL_PACKED,
306
[AV_PIX_FMT_ABGR] = {
307
.nb_channels = 4, .is_alpha = 1,
308
.color_type = FF_COLOR_RGB,
309
.pixel_type = FF_PIXEL_PACKED,
312
[AV_PIX_FMT_BGR565BE] = {
314
.color_type = FF_COLOR_RGB,
315
.pixel_type = FF_PIXEL_PACKED,
318
[AV_PIX_FMT_BGR565LE] = {
320
.color_type = FF_COLOR_RGB,
321
.pixel_type = FF_PIXEL_PACKED,
324
[AV_PIX_FMT_BGR555BE] = {
326
.color_type = FF_COLOR_RGB,
327
.pixel_type = FF_PIXEL_PACKED,
330
[AV_PIX_FMT_BGR555LE] = {
332
.color_type = FF_COLOR_RGB,
333
.pixel_type = FF_PIXEL_PACKED,
336
[AV_PIX_FMT_BGR444BE] = {
338
.color_type = FF_COLOR_RGB,
339
.pixel_type = FF_PIXEL_PACKED,
342
[AV_PIX_FMT_BGR444LE] = {
344
.color_type = FF_COLOR_RGB,
345
.pixel_type = FF_PIXEL_PACKED,
348
[AV_PIX_FMT_RGB8] = {
350
.color_type = FF_COLOR_RGB,
351
.pixel_type = FF_PIXEL_PACKED,
354
[AV_PIX_FMT_RGB4] = {
356
.color_type = FF_COLOR_RGB,
357
.pixel_type = FF_PIXEL_PACKED,
360
[AV_PIX_FMT_RGB4_BYTE] = {
362
.color_type = FF_COLOR_RGB,
363
.pixel_type = FF_PIXEL_PACKED,
366
[AV_PIX_FMT_BGR8] = {
368
.color_type = FF_COLOR_RGB,
369
.pixel_type = FF_PIXEL_PACKED,
372
[AV_PIX_FMT_BGR4] = {
374
.color_type = FF_COLOR_RGB,
375
.pixel_type = FF_PIXEL_PACKED,
378
[AV_PIX_FMT_BGR4_BYTE] = {
380
.color_type = FF_COLOR_RGB,
381
.pixel_type = FF_PIXEL_PACKED,
384
[AV_PIX_FMT_NV12] = {
386
.color_type = FF_COLOR_YUV,
387
.pixel_type = FF_PIXEL_PLANAR,
390
[AV_PIX_FMT_NV21] = {
392
.color_type = FF_COLOR_YUV,
393
.pixel_type = FF_PIXEL_PLANAR,
397
[AV_PIX_FMT_BGRA] = {
398
.nb_channels = 4, .is_alpha = 1,
399
.color_type = FF_COLOR_RGB,
400
.pixel_type = FF_PIXEL_PACKED,
403
[AV_PIX_FMT_RGBA] = {
404
.nb_channels = 4, .is_alpha = 1,
405
.color_type = FF_COLOR_RGB,
406
.pixel_type = FF_PIXEL_PACKED,
411
53
void avcodec_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
413
55
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
415
57
*v_shift = desc->log2_chroma_h;
418
int ff_is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)
420
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
421
return desc->flags & PIX_FMT_HWACCEL;
424
int avpicture_fill(AVPicture *picture, uint8_t *ptr,
425
enum AVPixelFormat pix_fmt, int width, int height)
429
if ((ret = av_image_check_size(width, height, 0, NULL)) < 0)
432
if ((ret = av_image_fill_linesizes(picture->linesize, pix_fmt, width)) < 0)
435
return av_image_fill_pointers(picture->data, pix_fmt, height, ptr, picture->linesize);
438
int avpicture_layout(const AVPicture* src, enum AVPixelFormat pix_fmt, int width, int height,
439
unsigned char *dest, int dest_size)
441
int i, j, nb_planes = 0, linesizes[4];
442
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
443
int size = avpicture_get_size(pix_fmt, width, height);
445
if (size > dest_size || size < 0)
446
return AVERROR(EINVAL);
448
for (i = 0; i < desc->nb_components; i++)
449
nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
452
av_image_fill_linesizes(linesizes, pix_fmt, width);
453
for (i = 0; i < nb_planes; i++) {
454
int h, shift = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
455
const unsigned char *s = src->data[i];
456
h = (height + (1 << shift) - 1) >> shift;
458
for (j = 0; j < h; j++) {
459
memcpy(dest, s, linesizes[i]);
460
dest += linesizes[i];
461
s += src->linesize[i];
465
if (desc->flags & PIX_FMT_PAL)
466
memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4);
471
int avpicture_get_size(enum AVPixelFormat pix_fmt, int width, int height)
473
AVPicture dummy_pict;
474
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
476
if(av_image_check_size(width, height, 0, NULL))
478
if (desc->flags & PIX_FMT_PSEUDOPAL)
479
// do not include palette for these pseudo-paletted formats
480
return width * height;
481
return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
484
int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt, enum AVPixelFormat src_pix_fmt,
60
static int is_gray(const AVPixFmtDescriptor *desc)
62
return desc->nb_components - (desc->flags & PIX_FMT_ALPHA) == 1;
65
int avcodec_get_pix_fmt_loss(enum AVPixelFormat dst_pix_fmt,
66
enum AVPixelFormat src_pix_fmt,
487
const PixFmtInfo *pf, *ps;
488
69
const AVPixFmtDescriptor *src_desc = av_pix_fmt_desc_get(src_pix_fmt);
489
70
const AVPixFmtDescriptor *dst_desc = av_pix_fmt_desc_get(dst_pix_fmt);
492
ps = &pix_fmt_info[src_pix_fmt];
71
int loss, i, nb_components = FFMIN(src_desc->nb_components,
72
dst_desc->nb_components);
494
74
/* compute loss */
496
pf = &pix_fmt_info[dst_pix_fmt];
497
if (pf->depth < ps->depth ||
498
((dst_pix_fmt == AV_PIX_FMT_RGB555BE || dst_pix_fmt == AV_PIX_FMT_RGB555LE ||
499
dst_pix_fmt == AV_PIX_FMT_BGR555BE || dst_pix_fmt == AV_PIX_FMT_BGR555LE) &&
500
(src_pix_fmt == AV_PIX_FMT_RGB565BE || src_pix_fmt == AV_PIX_FMT_RGB565LE ||
501
src_pix_fmt == AV_PIX_FMT_BGR565BE || src_pix_fmt == AV_PIX_FMT_BGR565LE)))
502
loss |= FF_LOSS_DEPTH;
77
if (dst_pix_fmt == src_pix_fmt)
80
for (i = 0; i < nb_components; i++)
81
if (src_desc->comp[i].depth_minus1 > dst_desc->comp[i].depth_minus1)
82
loss |= FF_LOSS_DEPTH;
503
84
if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w ||
504
85
dst_desc->log2_chroma_h > src_desc->log2_chroma_h)
505
86
loss |= FF_LOSS_RESOLUTION;
506
switch(pf->color_type) {
508
if (ps->color_type != FF_COLOR_RGB &&
509
ps->color_type != FF_COLOR_GRAY)
510
loss |= FF_LOSS_COLORSPACE;
513
if (ps->color_type != FF_COLOR_GRAY)
514
loss |= FF_LOSS_COLORSPACE;
517
if (ps->color_type != FF_COLOR_YUV)
518
loss |= FF_LOSS_COLORSPACE;
520
case FF_COLOR_YUV_JPEG:
521
if (ps->color_type != FF_COLOR_YUV_JPEG &&
522
ps->color_type != FF_COLOR_YUV &&
523
ps->color_type != FF_COLOR_GRAY)
524
loss |= FF_LOSS_COLORSPACE;
528
if (ps->color_type != pf->color_type)
529
loss |= FF_LOSS_COLORSPACE;
532
if (pf->color_type == FF_COLOR_GRAY &&
533
ps->color_type != FF_COLOR_GRAY)
534
loss |= FF_LOSS_CHROMA;
535
if (!pf->is_alpha && (ps->is_alpha && has_alpha))
88
if ((src_desc->flags & PIX_FMT_RGB) != (dst_desc->flags & PIX_FMT_RGB))
89
loss |= FF_LOSS_COLORSPACE;
91
if (has_alpha && !(dst_desc->flags & PIX_FMT_ALPHA) &&
92
(dst_desc->flags & PIX_FMT_ALPHA))
536
93
loss |= FF_LOSS_ALPHA;
537
if (pf->pixel_type == FF_PIXEL_PALETTE &&
538
(ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
539
loss |= FF_LOSS_COLORQUANT;
95
if (dst_pix_fmt == AV_PIX_FMT_PAL8 && !is_gray(src_desc))
96
return loss | FF_LOSS_COLORQUANT;
98
if (src_desc->nb_components > dst_desc->nb_components)
99
if (is_gray(dst_desc))
100
loss |= FF_LOSS_CHROMA;
543
static int avg_bits_per_pixel(enum AVPixelFormat pix_fmt)
546
const PixFmtInfo *pf;
547
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
549
pf = &pix_fmt_info[pix_fmt];
550
switch(pf->pixel_type) {
551
case FF_PIXEL_PACKED:
553
case AV_PIX_FMT_YUYV422:
554
case AV_PIX_FMT_UYVY422:
555
case AV_PIX_FMT_RGB565BE:
556
case AV_PIX_FMT_RGB565LE:
557
case AV_PIX_FMT_RGB555BE:
558
case AV_PIX_FMT_RGB555LE:
559
case AV_PIX_FMT_RGB444BE:
560
case AV_PIX_FMT_RGB444LE:
561
case AV_PIX_FMT_BGR565BE:
562
case AV_PIX_FMT_BGR565LE:
563
case AV_PIX_FMT_BGR555BE:
564
case AV_PIX_FMT_BGR555LE:
565
case AV_PIX_FMT_BGR444BE:
566
case AV_PIX_FMT_BGR444LE:
569
case AV_PIX_FMT_UYYVYY411:
573
bits = pf->depth * pf->nb_channels;
577
case FF_PIXEL_PLANAR:
578
if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
579
bits = pf->depth * pf->nb_channels;
581
bits = pf->depth + ((2 * pf->depth) >>
582
(desc->log2_chroma_w + desc->log2_chroma_h));
585
case FF_PIXEL_PALETTE:
595
105
static enum AVPixelFormat avcodec_find_best_pix_fmt1(enum AVPixelFormat *pix_fmt_list,
596
106
enum AVPixelFormat src_pix_fmt,