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;
58 if (shift + depth <= 8) {
59 p += !!(flags & PIX_FMT_BE);
63 int val = is_8bit ? *p :
64 flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p);
65 val = (val>>shift) & mask;
66 if(read_pal_component)
67 val= data[1][4*val + c];
74 void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4],
75 const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
77 AVComponentDescriptor comp = desc->comp[c];
78 int plane = comp.plane;
79 int depth = comp.depth_minus1+1;
80 int step = comp.step_minus1+1;
81 int flags = desc->flags;
83 if (flags & PIX_FMT_BITSTREAM) {
84 int skip = x*step + comp.offset_plus1-1;
85 uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3);
86 int shift = 8 - depth - (skip&7);
89 *p |= *src++ << shift;
95 int shift = comp.shift;
96 uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1;
98 if (shift + depth <= 8) {
99 p += !!(flags & PIX_FMT_BE);
101 *p |= (*src++<<shift);
106 if (flags & PIX_FMT_BE) {
107 uint16_t val = AV_RB16(p) | (*src++<<shift);
110 uint16_t val = AV_RL16(p) | (*src++<<shift);
119 const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = {
120 [PIX_FMT_YUV420P] = {
131 [PIX_FMT_YUYV422] = {
164 [PIX_FMT_YUV422P] = {
175 [PIX_FMT_YUV444P] = {
186 [PIX_FMT_YUV410P] = {
197 [PIX_FMT_YUV411P] = {
216 .flags = PIX_FMT_PAL,
218 [PIX_FMT_MONOWHITE] = {
226 .flags = PIX_FMT_BITSTREAM,
228 [PIX_FMT_MONOBLACK] = {
236 .flags = PIX_FMT_BITSTREAM,
246 .flags = PIX_FMT_PAL,
248 [PIX_FMT_YUVJ420P] = {
259 [PIX_FMT_YUVJ422P] = {
270 [PIX_FMT_YUVJ444P] = {
281 [PIX_FMT_XVMC_MPEG2_MC] = {
283 .flags = PIX_FMT_HWACCEL,
285 [PIX_FMT_XVMC_MPEG2_IDCT] = {
287 .flags = PIX_FMT_HWACCEL,
289 [PIX_FMT_UYVY422] = {
300 [PIX_FMT_UYYVYY411] = {
321 .flags = PIX_FMT_PAL,
333 .flags = PIX_FMT_BITSTREAM,
335 [PIX_FMT_BGR4_BYTE] = {
345 .flags = PIX_FMT_PAL,
357 .flags = PIX_FMT_PAL,
369 .flags = PIX_FMT_BITSTREAM,
371 [PIX_FMT_RGB4_BYTE] = {
381 .flags = PIX_FMT_PAL,
453 [PIX_FMT_GRAY16BE] = {
459 {0,1,1,0,15}, /* Y */
463 [PIX_FMT_GRAY16LE] = {
469 {0,1,1,0,15}, /* Y */
472 [PIX_FMT_YUV440P] = {
483 [PIX_FMT_YUVJ440P] = {
494 [PIX_FMT_YUVA420P] = {
506 [PIX_FMT_VDPAU_H264] = {
507 .name = "vdpau_h264",
510 .flags = PIX_FMT_HWACCEL,
512 [PIX_FMT_VDPAU_MPEG1] = {
513 .name = "vdpau_mpeg1",
516 .flags = PIX_FMT_HWACCEL,
518 [PIX_FMT_VDPAU_MPEG2] = {
519 .name = "vdpau_mpeg2",
522 .flags = PIX_FMT_HWACCEL,
524 [PIX_FMT_VDPAU_WMV3] = {
525 .name = "vdpau_wmv3",
528 .flags = PIX_FMT_HWACCEL,
530 [PIX_FMT_VDPAU_VC1] = {
534 .flags = PIX_FMT_HWACCEL,
536 [PIX_FMT_VDPAU_MPEG4] = {
537 .name = "vdpau_mpeg4",
540 .flags = PIX_FMT_HWACCEL,
542 [PIX_FMT_RGB48BE] = {
548 {0,5,1,0,15}, /* R */
549 {0,5,3,0,15}, /* G */
550 {0,5,5,0,15}, /* B */
554 [PIX_FMT_RGB48LE] = {
560 {0,5,1,0,15}, /* R */
561 {0,5,3,0,15}, /* G */
562 {0,5,5,0,15}, /* B */
565 [PIX_FMT_RGB565BE] = {
577 [PIX_FMT_RGB565LE] = {
588 [PIX_FMT_RGB555BE] = {
600 [PIX_FMT_RGB555LE] = {
611 [PIX_FMT_RGB444BE] = {
623 [PIX_FMT_RGB444LE] = {
634 [PIX_FMT_BGR565BE] = {
646 [PIX_FMT_BGR565LE] = {
657 [PIX_FMT_BGR555BE] = {
669 [PIX_FMT_BGR555LE] = {
680 [PIX_FMT_BGR444BE] = {
692 [PIX_FMT_BGR444LE] = {
703 [PIX_FMT_VAAPI_MOCO] = {
704 .name = "vaapi_moco",
707 .flags = PIX_FMT_HWACCEL,
709 [PIX_FMT_VAAPI_IDCT] = {
710 .name = "vaapi_idct",
713 .flags = PIX_FMT_HWACCEL,
715 [PIX_FMT_VAAPI_VLD] = {
719 .flags = PIX_FMT_HWACCEL,
721 [PIX_FMT_YUV420P16LE] = {
722 .name = "yuv420p16le",
727 {0,1,1,0,15}, /* Y */
728 {1,1,1,0,15}, /* U */
729 {2,1,1,0,15}, /* V */
732 [PIX_FMT_YUV420P16BE] = {
733 .name = "yuv420p16be",
738 {0,1,1,0,15}, /* Y */
739 {1,1,1,0,15}, /* U */
740 {2,1,1,0,15}, /* V */
744 [PIX_FMT_YUV422P16LE] = {
745 .name = "yuv422p16le",
750 {0,1,1,0,15}, /* Y */
751 {1,1,1,0,15}, /* U */
752 {2,1,1,0,15}, /* V */
755 [PIX_FMT_YUV422P16BE] = {
756 .name = "yuv422p16be",
761 {0,1,1,0,15}, /* Y */
762 {1,1,1,0,15}, /* U */
763 {2,1,1,0,15}, /* V */
767 [PIX_FMT_YUV444P16LE] = {
768 .name = "yuv444p16le",
773 {0,1,1,0,15}, /* Y */
774 {1,1,1,0,15}, /* U */
775 {2,1,1,0,15}, /* V */
778 [PIX_FMT_YUV444P16BE] = {
779 .name = "yuv444p16be",
784 {0,1,1,0,15}, /* Y */
785 {1,1,1,0,15}, /* U */
786 {2,1,1,0,15}, /* V */
790 [PIX_FMT_DXVA2_VLD] = {
794 .flags = PIX_FMT_HWACCEL,
806 static enum PixelFormat get_pix_fmt_internal(const char *name)
808 enum PixelFormat pix_fmt;
810 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
811 if (av_pix_fmt_descriptors[pix_fmt].name &&
812 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
819 # define X_NE(be, le) be
821 # define X_NE(be, le) le
824 enum PixelFormat av_get_pix_fmt(const char *name)
826 enum PixelFormat pix_fmt;
828 if (!strcmp(name, "rgb32"))
829 name = X_NE("argb", "bgra");
830 else if (!strcmp(name, "bgr32"))
831 name = X_NE("abgr", "rgba");
833 pix_fmt = get_pix_fmt_internal(name);
834 if (pix_fmt == PIX_FMT_NONE) {
837 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
838 pix_fmt = get_pix_fmt_internal(name2);
843 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
846 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
848 for (c = 0; c < pixdesc->nb_components; c++) {
849 int s = c==1 || c==2 ? 0 : log2_pixels;
850 bits += (pixdesc->comp[c].depth_minus1+1) << s;
853 return bits >> log2_pixels;