2
* pixel format descriptor
3
* Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at>
5
* This file is part of FFmpeg.
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.
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.
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
25
#include "intreadwrite.h"
27
void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
28
const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
30
AVComponentDescriptor comp= desc->comp[c];
31
int plane= comp.plane;
32
int depth= comp.depth_minus1+1;
33
int mask = (1<<depth)-1;
34
int shift= comp.shift;
35
int step = comp.step_minus1+1;
36
int flags= desc->flags;
38
if (flags & PIX_FMT_BITSTREAM){
39
int skip = x*step + comp.offset_plus1-1;
40
const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
41
int shift = 8 - depth - (skip&7);
44
int val = (*p >> shift) & mask;
45
if(read_pal_component)
46
val= data[1][4*val + c];
53
const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
57
if(flags & PIX_FMT_BE) val= AV_RB16(p);
59
val = (val>>shift) & mask;
60
if(read_pal_component)
61
val= data[1][4*val + c];
68
void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
69
const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
71
AVComponentDescriptor comp = desc->comp[c];
72
int plane = comp.plane;
73
int depth = comp.depth_minus1+1;
74
int step = comp.step_minus1+1;
75
int flags = desc->flags;
77
if (flags & PIX_FMT_BITSTREAM) {
78
int skip = x*step + comp.offset_plus1-1;
79
uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
80
int shift = 8 - depth - (skip&7);
83
*p |= *src++ << shift;
89
int shift = comp.shift;
90
uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
93
if (flags & PIX_FMT_BE) {
94
uint16_t val = AV_RB16(p) | (*src++<<shift);
97
uint16_t val = AV_RL16(p) | (*src++<<shift);
105
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
106
[PIX_FMT_YUV420P] = {
117
[PIX_FMT_YUYV422] = {
150
[PIX_FMT_YUV422P] = {
161
[PIX_FMT_YUV444P] = {
172
[PIX_FMT_YUV410P] = {
183
[PIX_FMT_YUV411P] = {
202
.flags = PIX_FMT_PAL,
204
[PIX_FMT_MONOWHITE] = {
212
.flags = PIX_FMT_BITSTREAM,
214
[PIX_FMT_MONOBLACK] = {
222
.flags = PIX_FMT_BITSTREAM,
232
.flags = PIX_FMT_PAL,
234
[PIX_FMT_YUVJ420P] = {
245
[PIX_FMT_YUVJ422P] = {
256
[PIX_FMT_YUVJ444P] = {
267
[PIX_FMT_XVMC_MPEG2_MC] = {
269
.flags = PIX_FMT_HWACCEL,
271
[PIX_FMT_XVMC_MPEG2_IDCT] = {
273
.flags = PIX_FMT_HWACCEL,
275
[PIX_FMT_UYVY422] = {
286
[PIX_FMT_UYYVYY411] = {
307
.flags = PIX_FMT_PAL,
319
.flags = PIX_FMT_BITSTREAM,
321
[PIX_FMT_BGR4_BYTE] = {
331
.flags = PIX_FMT_PAL,
343
.flags = PIX_FMT_PAL,
355
.flags = PIX_FMT_BITSTREAM,
357
[PIX_FMT_RGB4_BYTE] = {
367
.flags = PIX_FMT_PAL,
439
[PIX_FMT_GRAY16BE] = {
445
{0,1,1,0,15}, /* Y */
449
[PIX_FMT_GRAY16LE] = {
455
{0,1,1,0,15}, /* Y */
458
[PIX_FMT_YUV440P] = {
469
[PIX_FMT_YUVJ440P] = {
480
[PIX_FMT_YUVA420P] = {
492
[PIX_FMT_VDPAU_H264] = {
493
.name = "vdpau_h264",
496
.flags = PIX_FMT_HWACCEL,
498
[PIX_FMT_VDPAU_MPEG1] = {
499
.name = "vdpau_mpeg1",
502
.flags = PIX_FMT_HWACCEL,
504
[PIX_FMT_VDPAU_MPEG2] = {
505
.name = "vdpau_mpeg2",
508
.flags = PIX_FMT_HWACCEL,
510
[PIX_FMT_VDPAU_WMV3] = {
511
.name = "vdpau_wmv3",
514
.flags = PIX_FMT_HWACCEL,
516
[PIX_FMT_VDPAU_VC1] = {
520
.flags = PIX_FMT_HWACCEL,
522
[PIX_FMT_VDPAU_MPEG4] = {
523
.name = "vdpau_mpeg4",
526
.flags = PIX_FMT_HWACCEL,
528
[PIX_FMT_RGB48BE] = {
534
{0,5,1,0,15}, /* R */
535
{0,5,3,0,15}, /* G */
536
{0,5,5,0,15}, /* B */
540
[PIX_FMT_RGB48LE] = {
546
{0,5,1,0,15}, /* R */
547
{0,5,3,0,15}, /* G */
548
{0,5,5,0,15}, /* B */
551
[PIX_FMT_RGB565BE] = {
563
[PIX_FMT_RGB565LE] = {
574
[PIX_FMT_RGB555BE] = {
586
[PIX_FMT_RGB555LE] = {
597
[PIX_FMT_RGB444BE] = {
609
[PIX_FMT_RGB444LE] = {
620
[PIX_FMT_BGR565BE] = {
632
[PIX_FMT_BGR565LE] = {
643
[PIX_FMT_BGR555BE] = {
655
[PIX_FMT_BGR555LE] = {
666
[PIX_FMT_BGR444BE] = {
678
[PIX_FMT_BGR444LE] = {
689
[PIX_FMT_VAAPI_MOCO] = {
690
.name = "vaapi_moco",
693
.flags = PIX_FMT_HWACCEL,
695
[PIX_FMT_VAAPI_IDCT] = {
696
.name = "vaapi_idct",
699
.flags = PIX_FMT_HWACCEL,
701
[PIX_FMT_VAAPI_VLD] = {
705
.flags = PIX_FMT_HWACCEL,
707
[PIX_FMT_YUV420P16LE] = {
708
.name = "yuv420p16le",
713
{0,1,1,0,15}, /* Y */
714
{1,1,1,0,15}, /* U */
715
{2,1,1,0,15}, /* V */
718
[PIX_FMT_YUV420P16BE] = {
719
.name = "yuv420p16be",
724
{0,1,1,0,15}, /* Y */
725
{1,1,1,0,15}, /* U */
726
{2,1,1,0,15}, /* V */
730
[PIX_FMT_YUV422P16LE] = {
731
.name = "yuv422p16le",
736
{0,1,1,0,15}, /* Y */
737
{1,1,1,0,15}, /* U */
738
{2,1,1,0,15}, /* V */
741
[PIX_FMT_YUV422P16BE] = {
742
.name = "yuv422p16be",
747
{0,1,1,0,15}, /* Y */
748
{1,1,1,0,15}, /* U */
749
{2,1,1,0,15}, /* V */
753
[PIX_FMT_YUV444P16LE] = {
754
.name = "yuv444p16le",
759
{0,1,1,0,15}, /* Y */
760
{1,1,1,0,15}, /* U */
761
{2,1,1,0,15}, /* V */
764
[PIX_FMT_YUV444P16BE] = {
765
.name = "yuv444p16be",
770
{0,1,1,0,15}, /* Y */
771
{1,1,1,0,15}, /* U */
772
{2,1,1,0,15}, /* V */
776
[PIX_FMT_DXVA2_VLD] = {
780
.flags = PIX_FMT_HWACCEL,
792
static enum PixelFormat get_pix_fmt_internal(const char *name)
794
enum PixelFormat pix_fmt;
796
for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
797
if (av_pix_fmt_descriptors[pix_fmt].name &&
798
!strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
805
# define X_NE(be, le) be
807
# define X_NE(be, le) le
810
enum PixelFormat av_get_pix_fmt(const char *name)
812
enum PixelFormat pix_fmt;
814
if (!strcmp(name, "rgb32"))
815
name = X_NE("argb", "bgra");
816
else if (!strcmp(name, "bgr32"))
817
name = X_NE("abgr", "rgba");
819
pix_fmt = get_pix_fmt_internal(name);
820
if (pix_fmt == PIX_FMT_NONE) {
823
snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
824
pix_fmt = get_pix_fmt_internal(name2);
829
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
832
int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
834
for (c = 0; c < pixdesc->nb_components; c++) {
835
int s = c==1 || c==2 ? 0 : log2_pixels;
836
bits += (pixdesc->comp[c].depth_minus1+1) << s;
839
return bits >> log2_pixels;