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_VDA_VLD] = {
797 .flags = PIX_FMT_HWACCEL,
799 [PIX_FMT_YUV420P9LE] = {
800 .name = "yuv420p9le",
810 [PIX_FMT_YUV420P9BE] = {
811 .name = "yuv420p9be",
822 [PIX_FMT_YUV420P10LE] = {
823 .name = "yuv420p10le",
833 [PIX_FMT_YUV420P10BE] = {
834 .name = "yuv420p10be",
845 [PIX_FMT_YUV420P16LE] = {
846 .name = "yuv420p16le",
851 {0,1,1,0,15}, /* Y */
852 {1,1,1,0,15}, /* U */
853 {2,1,1,0,15}, /* V */
856 [PIX_FMT_YUV420P16BE] = {
857 .name = "yuv420p16be",
862 {0,1,1,0,15}, /* Y */
863 {1,1,1,0,15}, /* U */
864 {2,1,1,0,15}, /* V */
868 [PIX_FMT_YUV422P9LE] = {
869 .name = "yuv422p9le",
879 [PIX_FMT_YUV422P9BE] = {
880 .name = "yuv422p9be",
891 [PIX_FMT_YUV422P10LE] = {
892 .name = "yuv422p10le",
902 [PIX_FMT_YUV422P10BE] = {
903 .name = "yuv422p10be",
914 [PIX_FMT_YUV422P16LE] = {
915 .name = "yuv422p16le",
920 {0,1,1,0,15}, /* Y */
921 {1,1,1,0,15}, /* U */
922 {2,1,1,0,15}, /* V */
925 [PIX_FMT_YUV422P16BE] = {
926 .name = "yuv422p16be",
931 {0,1,1,0,15}, /* Y */
932 {1,1,1,0,15}, /* U */
933 {2,1,1,0,15}, /* V */
937 [PIX_FMT_YUV444P16LE] = {
938 .name = "yuv444p16le",
943 {0,1,1,0,15}, /* Y */
944 {1,1,1,0,15}, /* U */
945 {2,1,1,0,15}, /* V */
948 [PIX_FMT_YUV444P16BE] = {
949 .name = "yuv444p16be",
954 {0,1,1,0,15}, /* Y */
955 {1,1,1,0,15}, /* U */
956 {2,1,1,0,15}, /* V */
960 [PIX_FMT_YUV444P10LE] = {
961 .name = "yuv444p10le",
971 [PIX_FMT_YUV444P10BE] = {
972 .name = "yuv444p10be",
983 [PIX_FMT_YUV444P9LE] = {
984 .name = "yuv444p9le",
994 [PIX_FMT_YUV444P9BE] = {
995 .name = "yuv444p9be",
1000 {0,1,1,0,8}, /* Y */
1001 {1,1,1,0,8}, /* U */
1002 {2,1,1,0,8}, /* V */
1004 .flags = PIX_FMT_BE,
1006 [PIX_FMT_DXVA2_VLD] = {
1007 .name = "dxva2_vld",
1010 .flags = PIX_FMT_HWACCEL,
1012 [PIX_FMT_VDA_VLD] = {
1016 .flags = PIX_FMT_HWACCEL,
1018 [PIX_FMT_GRAY8A] = {
1022 {0,1,1,0,7}, /* Y */
1023 {0,1,2,0,7}, /* A */
1026 [PIX_FMT_GBR24P] = {
1030 {1,0,1,0,7}, /* B */
1031 {0,0,1,0,7}, /* G */
1032 {2,0,1,0,7}, /* R */
1037 static enum PixelFormat get_pix_fmt_internal(const char *name)
1039 enum PixelFormat pix_fmt;
1041 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
1042 if (av_pix_fmt_descriptors[pix_fmt].name &&
1043 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
1046 return PIX_FMT_NONE;
1049 const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt)
1051 return (unsigned)pix_fmt < PIX_FMT_NB ?
1052 av_pix_fmt_descriptors[pix_fmt].name : NULL;
1056 # define X_NE(be, le) be
1058 # define X_NE(be, le) le
1061 enum PixelFormat av_get_pix_fmt(const char *name)
1063 enum PixelFormat pix_fmt;
1065 if (!strcmp(name, "rgb32"))
1066 name = X_NE("argb", "bgra");
1067 else if (!strcmp(name, "bgr32"))
1068 name = X_NE("abgr", "rgba");
1070 pix_fmt = get_pix_fmt_internal(name);
1071 if (pix_fmt == PIX_FMT_NONE) {
1074 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
1075 pix_fmt = get_pix_fmt_internal(name2);
1080 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
1083 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
1085 for (c = 0; c < pixdesc->nb_components; c++) {
1086 int s = c==1 || c==2 ? 0 : log2_pixels;
1087 bits += (pixdesc->comp[c].depth_minus1+1) << s;
1090 return bits >> log2_pixels;
1093 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
1097 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
1099 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
1100 snprintf(buf, buf_size, "%-11s %7d %10d",
1101 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));