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] = {
203 [PIX_FMT_MONOWHITE] = {
211 .flags = PIX_FMT_BITSTREAM,
213 [PIX_FMT_MONOBLACK] = {
221 .flags = PIX_FMT_BITSTREAM,
231 .flags = PIX_FMT_PAL,
233 [PIX_FMT_YUVJ420P] = {
244 [PIX_FMT_YUVJ422P] = {
255 [PIX_FMT_YUVJ444P] = {
266 [PIX_FMT_XVMC_MPEG2_MC] = {
268 .flags = PIX_FMT_HWACCEL,
270 [PIX_FMT_XVMC_MPEG2_IDCT] = {
272 .flags = PIX_FMT_HWACCEL,
274 [PIX_FMT_UYVY422] = {
285 [PIX_FMT_UYYVYY411] = {
306 .flags = PIX_FMT_PAL,
318 .flags = PIX_FMT_BITSTREAM,
320 [PIX_FMT_BGR4_BYTE] = {
330 .flags = PIX_FMT_PAL,
342 .flags = PIX_FMT_PAL,
354 .flags = PIX_FMT_BITSTREAM,
356 [PIX_FMT_RGB4_BYTE] = {
366 .flags = PIX_FMT_PAL,
438 [PIX_FMT_GRAY16BE] = {
444 {0,1,1,0,15}, /* Y */
448 [PIX_FMT_GRAY16LE] = {
454 {0,1,1,0,15}, /* Y */
457 [PIX_FMT_YUV440P] = {
468 [PIX_FMT_YUVJ440P] = {
479 [PIX_FMT_YUVA420P] = {
491 [PIX_FMT_VDPAU_H264] = {
492 .name = "vdpau_h264",
495 .flags = PIX_FMT_HWACCEL,
497 [PIX_FMT_VDPAU_MPEG1] = {
498 .name = "vdpau_mpeg1",
501 .flags = PIX_FMT_HWACCEL,
503 [PIX_FMT_VDPAU_MPEG2] = {
504 .name = "vdpau_mpeg2",
507 .flags = PIX_FMT_HWACCEL,
509 [PIX_FMT_VDPAU_WMV3] = {
510 .name = "vdpau_wmv3",
513 .flags = PIX_FMT_HWACCEL,
515 [PIX_FMT_VDPAU_VC1] = {
519 .flags = PIX_FMT_HWACCEL,
521 [PIX_FMT_VDPAU_MPEG4] = {
522 .name = "vdpau_mpeg4",
525 .flags = PIX_FMT_HWACCEL,
527 [PIX_FMT_RGB48BE] = {
533 {0,5,1,0,15}, /* R */
534 {0,5,3,0,15}, /* G */
535 {0,5,5,0,15}, /* B */
539 [PIX_FMT_RGB48LE] = {
545 {0,5,1,0,15}, /* R */
546 {0,5,3,0,15}, /* G */
547 {0,5,5,0,15}, /* B */
550 [PIX_FMT_RGB565BE] = {
562 [PIX_FMT_RGB565LE] = {
573 [PIX_FMT_RGB555BE] = {
585 [PIX_FMT_RGB555LE] = {
596 [PIX_FMT_BGR565BE] = {
608 [PIX_FMT_BGR565LE] = {
619 [PIX_FMT_BGR555BE] = {
631 [PIX_FMT_BGR555LE] = {
642 [PIX_FMT_VAAPI_MOCO] = {
643 .name = "vaapi_moco",
646 .flags = PIX_FMT_HWACCEL,
648 [PIX_FMT_VAAPI_IDCT] = {
649 .name = "vaapi_idct",
652 .flags = PIX_FMT_HWACCEL,
654 [PIX_FMT_VAAPI_VLD] = {
658 .flags = PIX_FMT_HWACCEL,
660 [PIX_FMT_YUV420P16LE] = {
661 .name = "yuv420p16le",
666 {0,1,1,0,15}, /* Y */
667 {1,1,1,0,15}, /* U */
668 {2,1,1,0,15}, /* V */
671 [PIX_FMT_YUV420P16BE] = {
672 .name = "yuv420p16be",
677 {0,1,1,0,15}, /* Y */
678 {1,1,1,0,15}, /* U */
679 {2,1,1,0,15}, /* V */
683 [PIX_FMT_YUV422P16LE] = {
684 .name = "yuv422p16le",
689 {0,1,1,0,15}, /* Y */
690 {1,1,1,0,15}, /* U */
691 {2,1,1,0,15}, /* V */
694 [PIX_FMT_YUV422P16BE] = {
695 .name = "yuv422p16be",
700 {0,1,1,0,15}, /* Y */
701 {1,1,1,0,15}, /* U */
702 {2,1,1,0,15}, /* V */
706 [PIX_FMT_YUV444P16LE] = {
707 .name = "yuv444p16le",
712 {0,1,1,0,15}, /* Y */
713 {1,1,1,0,15}, /* U */
714 {2,1,1,0,15}, /* V */
717 [PIX_FMT_YUV444P16BE] = {
718 .name = "yuv444p16be",
723 {0,1,1,0,15}, /* Y */
724 {1,1,1,0,15}, /* U */
725 {2,1,1,0,15}, /* V */
729 [PIX_FMT_DXVA2_VLD] = {
733 .flags = PIX_FMT_HWACCEL,
737 static enum PixelFormat get_pix_fmt_internal(const char *name)
739 enum PixelFormat pix_fmt;
741 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
742 if (av_pix_fmt_descriptors[pix_fmt].name &&
743 !strcmp(av_pix_fmt_descriptors[pix_fmt].name, name))
750 # define X_NE(be, le) be
752 # define X_NE(be, le) le
755 enum PixelFormat av_get_pix_fmt(const char *name)
757 enum PixelFormat pix_fmt;
759 if (!strcmp(name, "rgb32"))
760 name = X_NE("argb", "bgra");
761 else if (!strcmp(name, "bgr32"))
762 name = X_NE("abgr", "rgba");
764 pix_fmt = get_pix_fmt_internal(name);
765 if (pix_fmt == PIX_FMT_NONE) {
768 snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le"));
769 pix_fmt = get_pix_fmt_internal(name2);
774 int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
777 int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h;
779 for (c = 0; c < pixdesc->nb_components; c++) {
780 int s = c==1 || c==2 ? 0 : log2_pixels;
781 bits += (pixdesc->comp[c].depth_minus1+1) << s;
784 return bits >> log2_pixels;