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_RGB565BE] = {
576 [PIX_FMT_RGB565LE] = {
587 [PIX_FMT_RGB555BE] = {
599 [PIX_FMT_RGB555LE] = {
610 [PIX_FMT_RGB444BE] = {
622 [PIX_FMT_RGB444LE] = {
633 [PIX_FMT_BGR565BE] = {
645 [PIX_FMT_BGR565LE] = {
656 [PIX_FMT_BGR555BE] = {
668 [PIX_FMT_BGR555LE] = {
679 [PIX_FMT_BGR444BE] = {
691 [PIX_FMT_BGR444LE] = {
702 [PIX_FMT_VAAPI_MOCO] = {
703 .name = "vaapi_moco",
706 .flags = PIX_FMT_HWACCEL,
708 [PIX_FMT_VAAPI_IDCT] = {
709 .name = "vaapi_idct",
712 .flags = PIX_FMT_HWACCEL,
714 [PIX_FMT_VAAPI_VLD] = {
718 .flags = PIX_FMT_HWACCEL,
720 [PIX_FMT_YUV420P16LE] = {
721 .name = "yuv420p16le",
726 {0,1,1,0,15}, /* Y */
727 {1,1,1,0,15}, /* U */
728 {2,1,1,0,15}, /* V */
731 [PIX_FMT_YUV420P16BE] = {
732 .name = "yuv420p16be",
737 {0,1,1,0,15}, /* Y */
738 {1,1,1,0,15}, /* U */
739 {2,1,1,0,15}, /* V */
743 [PIX_FMT_YUV422P16LE] = {
744 .name = "yuv422p16le",
749 {0,1,1,0,15}, /* Y */
750 {1,1,1,0,15}, /* U */
751 {2,1,1,0,15}, /* V */
754 [PIX_FMT_YUV422P16BE] = {
755 .name = "yuv422p16be",
760 {0,1,1,0,15}, /* Y */
761 {1,1,1,0,15}, /* U */
762 {2,1,1,0,15}, /* V */
766 [PIX_FMT_YUV444P16LE] = {
767 .name = "yuv444p16le",
772 {0,1,1,0,15}, /* Y */
773 {1,1,1,0,15}, /* U */
774 {2,1,1,0,15}, /* V */
777 [PIX_FMT_YUV444P16BE] = {
778 .name = "yuv444p16be",
783 {0,1,1,0,15}, /* Y */
784 {1,1,1,0,15}, /* U */
785 {2,1,1,0,15}, /* V */
789 [PIX_FMT_DXVA2_VLD] = {
793 .flags = PIX_FMT_HWACCEL,
805 static enum PixelFormat get_pix_fmt_internal(const char *name)
807 enum PixelFormat pix_fmt;
809 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
810 if (av_pix_fmt_descriptors[pix_fmt].name &&
811 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
818 # define X_NE(be, le) be
820 # define X_NE(be, le) le
823 enum PixelFormat av_get_pix_fmt(const char *name)
825 enum PixelFormat pix_fmt;
827 if (!strcmp(name, "rgb32"))
828 name = X_NE("argb", "bgra");
829 else if (!strcmp(name, "bgr32"))
830 name = X_NE("abgr", "rgba");
832 pix_fmt = get_pix_fmt_internal(name);
833 if (pix_fmt == PIX_FMT_NONE) {
836 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
837 pix_fmt = get_pix_fmt_internal(name2);
842 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
845 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
847 for (c = 0; c < pixdesc->nb_components; c++) {
848 int s = c==1 || c==2 ? 0 : log2_pixels;
849 bits += (pixdesc->comp[c].depth_minus1+1) << s;
852 return bits >> log2_pixels;
855 char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt)
859 snprintf (buf, buf_size, "name " " nb_components" " nb_bits");
861 const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt];
862 snprintf(buf, buf_size, "%-11s %7d %10d",
863 pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc));