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
27 #include "intreadwrite.h"
29 void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4],
30 const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
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;
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);
46 int val = (*p >> shift) & mask;
47 if(read_pal_component)
48 val= data[1][4*val + c];
55 const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
56 int is_8bit = shift + depth <= 8;
59 p += !!(flags & PIX_FMT_BE);
62 int val = is_8bit ? *p :
63 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
64 val = (val>>shift) & mask;
65 if(read_pal_component)
66 val= data[1][4*val + c];
73 void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
74 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
76 AVComponentDescriptor comp = desc->comp[c];
77 int plane = comp.plane;
78 int depth = comp.depth_minus1+1;
79 int step = comp.step_minus1+1;
80 int flags = desc->flags;
82 if (flags & PIX_FMT_BITSTREAM) {
83 int skip = x*step + comp.offset_plus1-1;
84 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
85 int shift = 8 - depth - (skip&7);
88 *p |= *src++ << shift;
94 int shift = comp.shift;
95 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
97 if (shift + depth <= 8) {
98 p += !!(flags & PIX_FMT_BE);
100 *p |= (*src++<<shift);
105 if (flags & PIX_FMT_BE) {
106 uint16_t val = AV_RB16(p) | (*src++<<shift);
109 uint16_t val = AV_RL16(p) | (*src++<<shift);
118 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
119 [PIX_FMT_YUV420P] = {
130 [PIX_FMT_YUYV422] = {
163 [PIX_FMT_YUV422P] = {
174 [PIX_FMT_YUV444P] = {
185 [PIX_FMT_YUV410P] = {
196 [PIX_FMT_YUV411P] = {
215 .flags = PIX_FMT_PAL,
217 [PIX_FMT_MONOWHITE] = {
225 .flags = PIX_FMT_BITSTREAM,
227 [PIX_FMT_MONOBLACK] = {
235 .flags = PIX_FMT_BITSTREAM,
245 .flags = PIX_FMT_PAL,
247 [PIX_FMT_YUVJ420P] = {
258 [PIX_FMT_YUVJ422P] = {
269 [PIX_FMT_YUVJ444P] = {
280 [PIX_FMT_XVMC_MPEG2_MC] = {
282 .flags = PIX_FMT_HWACCEL,
284 [PIX_FMT_XVMC_MPEG2_IDCT] = {
286 .flags = PIX_FMT_HWACCEL,
288 [PIX_FMT_UYVY422] = {
299 [PIX_FMT_UYYVYY411] = {
320 .flags = PIX_FMT_PAL,
332 .flags = PIX_FMT_BITSTREAM,
334 [PIX_FMT_BGR4_BYTE] = {
344 .flags = PIX_FMT_PAL,
356 .flags = PIX_FMT_PAL,
368 .flags = PIX_FMT_BITSTREAM,
370 [PIX_FMT_RGB4_BYTE] = {
380 .flags = PIX_FMT_PAL,
452 [PIX_FMT_GRAY16BE] = {
458 {0,1,1,0,15}, /* Y */
462 [PIX_FMT_GRAY16LE] = {
468 {0,1,1,0,15}, /* Y */
471 [PIX_FMT_YUV440P] = {
482 [PIX_FMT_YUVJ440P] = {
493 [PIX_FMT_YUVA420P] = {
505 [PIX_FMT_VDPAU_H264] = {
506 .name = "vdpau_h264",
509 .flags = PIX_FMT_HWACCEL,
511 [PIX_FMT_VDPAU_MPEG1] = {
512 .name = "vdpau_mpeg1",
515 .flags = PIX_FMT_HWACCEL,
517 [PIX_FMT_VDPAU_MPEG2] = {
518 .name = "vdpau_mpeg2",
521 .flags = PIX_FMT_HWACCEL,
523 [PIX_FMT_VDPAU_WMV3] = {
524 .name = "vdpau_wmv3",
527 .flags = PIX_FMT_HWACCEL,
529 [PIX_FMT_VDPAU_VC1] = {
533 .flags = PIX_FMT_HWACCEL,
535 [PIX_FMT_VDPAU_MPEG4] = {
536 .name = "vdpau_mpeg4",
539 .flags = PIX_FMT_HWACCEL,
541 [PIX_FMT_RGB48BE] = {
547 {0,5,1,0,15}, /* R */
548 {0,5,3,0,15}, /* G */
549 {0,5,5,0,15}, /* B */
553 [PIX_FMT_RGB48LE] = {
559 {0,5,1,0,15}, /* R */
560 {0,5,3,0,15}, /* G */
561 {0,5,5,0,15}, /* B */
564 [PIX_FMT_RGBA64BE] = {
570 {0,5,1,0,15}, /* R */
571 {0,5,3,0,15}, /* G */
572 {0,5,5,0,15}, /* B */
573 {0,5,7,0,15}, /* A */
577 [PIX_FMT_RGBA64LE] = {
583 {0,5,1,0,15}, /* R */
584 {0,5,3,0,15}, /* G */
585 {0,5,5,0,15}, /* B */
586 {0,5,7,0,15}, /* B */
589 [PIX_FMT_RGB565BE] = {
601 [PIX_FMT_RGB565LE] = {
612 [PIX_FMT_RGB555BE] = {
624 [PIX_FMT_RGB555LE] = {
635 [PIX_FMT_RGB444BE] = {
647 [PIX_FMT_RGB444LE] = {
658 [PIX_FMT_BGR48BE] = {
664 {0,5,1,0,15}, /* B */
665 {0,5,3,0,15}, /* G */
666 {0,5,5,0,15}, /* R */
670 [PIX_FMT_BGR48LE] = {
676 {0,5,1,0,15}, /* B */
677 {0,5,3,0,15}, /* G */
678 {0,5,5,0,15}, /* R */
681 [PIX_FMT_BGRA64BE] = {
687 {0,5,1,0,15}, /* B */
688 {0,5,3,0,15}, /* G */
689 {0,5,5,0,15}, /* R */
690 {0,5,7,0,15}, /* A */
694 [PIX_FMT_BGRA64LE] = {
700 {0,5,1,0,15}, /* B */
701 {0,5,3,0,15}, /* G */
702 {0,5,5,0,15}, /* R */
703 {0,5,7,0,15}, /* A */
706 [PIX_FMT_BGR565BE] = {
718 [PIX_FMT_BGR565LE] = {
729 [PIX_FMT_BGR555BE] = {
741 [PIX_FMT_BGR555LE] = {
752 [PIX_FMT_BGR444BE] = {
764 [PIX_FMT_BGR444LE] = {
775 [PIX_FMT_VAAPI_MOCO] = {
776 .name = "vaapi_moco",
779 .flags = PIX_FMT_HWACCEL,
781 [PIX_FMT_VAAPI_IDCT] = {
782 .name = "vaapi_idct",
785 .flags = PIX_FMT_HWACCEL,
787 [PIX_FMT_VAAPI_VLD] = {
791 .flags = PIX_FMT_HWACCEL,
793 [PIX_FMT_YUV420P9LE] = {
794 .name = "yuv420p9le",
804 [PIX_FMT_YUV420P9BE] = {
805 .name = "yuv420p9be",
816 [PIX_FMT_YUV420P10LE] = {
817 .name = "yuv420p10le",
827 [PIX_FMT_YUV420P10BE] = {
828 .name = "yuv420p10be",
839 [PIX_FMT_YUV420P16LE] = {
840 .name = "yuv420p16le",
845 {0,1,1,0,15}, /* Y */
846 {1,1,1,0,15}, /* U */
847 {2,1,1,0,15}, /* V */
850 [PIX_FMT_YUV420P16BE] = {
851 .name = "yuv420p16be",
856 {0,1,1,0,15}, /* Y */
857 {1,1,1,0,15}, /* U */
858 {2,1,1,0,15}, /* V */
862 [PIX_FMT_YUV422P9LE] = {
863 .name = "yuv422p9le",
873 [PIX_FMT_YUV422P9BE] = {
874 .name = "yuv422p9be",
885 [PIX_FMT_YUV422P10LE] = {
886 .name = "yuv422p10le",
896 [PIX_FMT_YUV422P10BE] = {
897 .name = "yuv422p10be",
908 [PIX_FMT_YUV422P16LE] = {
909 .name = "yuv422p16le",
914 {0,1,1,0,15}, /* Y */
915 {1,1,1,0,15}, /* U */
916 {2,1,1,0,15}, /* V */
919 [PIX_FMT_YUV422P16BE] = {
920 .name = "yuv422p16be",
925 {0,1,1,0,15}, /* Y */
926 {1,1,1,0,15}, /* U */
927 {2,1,1,0,15}, /* V */
931 [PIX_FMT_YUV444P16LE] = {
932 .name = "yuv444p16le",
937 {0,1,1,0,15}, /* Y */
938 {1,1,1,0,15}, /* U */
939 {2,1,1,0,15}, /* V */
942 [PIX_FMT_YUV444P16BE] = {
943 .name = "yuv444p16be",
948 {0,1,1,0,15}, /* Y */
949 {1,1,1,0,15}, /* U */
950 {2,1,1,0,15}, /* V */
954 [PIX_FMT_YUV444P10LE] = {
955 .name = "yuv444p10le",
965 [PIX_FMT_YUV444P10BE] = {
966 .name = "yuv444p10be",
977 [PIX_FMT_YUV444P9LE] = {
978 .name = "yuv444p9le",
988 [PIX_FMT_YUV444P9BE] = {
989 .name = "yuv444p9be",
1000 [PIX_FMT_DXVA2_VLD] = {
1001 .name = "dxva2_vld",
1004 .flags = PIX_FMT_HWACCEL,
1006 [PIX_FMT_VDA_VLD] = {
1010 .flags = PIX_FMT_HWACCEL,
1012 [PIX_FMT_GRAY8A] = {
1016 {0,1,1,0,7}, /* Y */
1017 {0,1,2,0,7}, /* A */
1020 [PIX_FMT_GBR24P] = {
1024 {1,0,1,0,7}, /* B */
1025 {0,0,1,0,7}, /* G */
1026 {2,0,1,0,7}, /* R */
1031 static enum PixelFormat get_pix_fmt_internal(const char *name)
1033 enum PixelFormat pix_fmt;
1035 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
1036 if (av_pix_fmt_descriptors[pix_fmt].name &&
1037 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
1040 return PIX_FMT_NONE;
1043 const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
1045 return (unsigned)pix_fmt < PIX_FMT_NB ?
1046 av_pix_fmt_descriptors[pix_fmt].name : NULL;
1050 # define X_NE(be, le) be
1052 # define X_NE(be, le) le
1055 enum PixelFormat av_get_pix_fmt(const char *name)
1057 enum PixelFormat pix_fmt;
1059 if (!strcmp(name, "rgb32"))
1060 name = X_NE("argb", "bgra");
1061 else if (!strcmp(name, "bgr32"))
1062 name = X_NE("abgr", "rgba");
1064 pix_fmt = get_pix_fmt_internal(name);
1065 if (pix_fmt == PIX_FMT_NONE) {
1068 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
1069 pix_fmt = get_pix_fmt_internal(name2);
1074 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
1077 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
1079 for (c = 0; c < pixdesc->nb_components; c++) {
1080 int s = c==1 || c==2 ? 0 : log2_pixels;
1081 bits += (pixdesc->comp[c].depth_minus1+1) << s;
1084 return bits >> log2_pixels;
1087 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
1091 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
1093 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
1094 snprintf(buf, buf_size, "%-11s %7d %10d",
1095 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));