add support for yuva420p colorspace (yuv420p + alpha)
authorAurelien Jacobs <aurel@gnuage.org>
Mon, 24 Sep 2007 13:21:41 +0000 (13:21 +0000)
committerAurelien Jacobs <aurel@gnuage.org>
Mon, 24 Sep 2007 13:21:41 +0000 (13:21 +0000)
Originally committed as revision 10565 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/imgconvert.c
libavcodec/utils.c
libavutil/avutil.h

index 05af023..d1f9bba 100644 (file)
@@ -129,6 +129,16 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
         .x_chroma_shift = 0, .y_chroma_shift = 1,
     },
 
+    /* YUV formats with alpha plane */
+    [PIX_FMT_YUVA420P] = {
+        .name = "yuva420p",
+        .nb_channels = 4,
+        .color_type = FF_COLOR_YUV,
+        .pixel_type = FF_PIXEL_PLANAR,
+        .depth = 8,
+        .x_chroma_shift = 1, .y_chroma_shift = 1,
+    },
+
     /* JPEG YUV */
     [PIX_FMT_YUVJ420P] = {
         .name = "yuvj420p",
@@ -444,10 +454,25 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = picture->data[0] + size;
         picture->data[2] = picture->data[1] + size2;
+        picture->data[3] = NULL;
         picture->linesize[0] = width;
         picture->linesize[1] = w2;
         picture->linesize[2] = w2;
+        picture->linesize[3] = 0;
         return size + 2 * size2;
+    case PIX_FMT_YUVA420P:
+        w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
+        h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
+        size2 = w2 * h2;
+        picture->data[0] = ptr;
+        picture->data[1] = picture->data[0] + size;
+        picture->data[2] = picture->data[1] + size2;
+        picture->data[3] = picture->data[1] + size2 + size2;
+        picture->linesize[0] = width;
+        picture->linesize[1] = w2;
+        picture->linesize[2] = w2;
+        picture->linesize[3] = width;
+        return 2 * size + 2 * size2;
     case PIX_FMT_NV12:
     case PIX_FMT_NV21:
         w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
@@ -456,15 +481,18 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = picture->data[0] + size;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width;
         picture->linesize[1] = w2;
         picture->linesize[2] = 0;
+        picture->linesize[3] = 0;
         return size + 2 * size2;
     case PIX_FMT_RGB24:
     case PIX_FMT_BGR24:
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width * 3;
         return size * 3;
     case PIX_FMT_RGB32:
@@ -474,6 +502,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width * 4;
         return size * 4;
     case PIX_FMT_GRAY16BE:
@@ -486,18 +515,21 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width * 2;
         return size * 2;
     case PIX_FMT_UYVY422:
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width * 2;
         return size * 2;
     case PIX_FMT_UYYVYY411:
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width + width/2;
         return size + size/2;
     case PIX_FMT_RGB8:
@@ -508,6 +540,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width;
         return size;
     case PIX_FMT_RGB4:
@@ -515,6 +548,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width / 2;
         return size / 2;
     case PIX_FMT_MONOWHITE:
@@ -522,6 +556,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = NULL;
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = (width + 7) >> 3;
         return picture->linesize[0] * height;
     case PIX_FMT_PAL8:
@@ -529,6 +564,7 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr,
         picture->data[0] = ptr;
         picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
         picture->data[2] = NULL;
+        picture->data[3] = NULL;
         picture->linesize[0] = width;
         picture->linesize[1] = 4;
         return size2 + 256 * 4;
index 9ca8a2d..f2c77b7 100644 (file)
@@ -171,6 +171,7 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
     case PIX_FMT_YUVJ420P:
     case PIX_FMT_YUVJ422P:
     case PIX_FMT_YUVJ444P:
+    case PIX_FMT_YUVA420P:
         w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
         h_align= 16;
         break;
@@ -265,7 +266,7 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
         buf->last_pic_num= *picture_number;
     }else{
         int h_chroma_shift, v_chroma_shift;
-        int pixel_size, size[3];
+        int pixel_size, size[4];
         AVPicture picture;
 
         avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
@@ -290,16 +291,17 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
         size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
         size[0] = picture.linesize[0] * h;
         size[1] -= size[0];
+        size[2] = size[3] = 0;
         if(picture.data[2])
             size[1]= size[2]= size[1]/2;
-        else
-            size[2]= 0;
+        if(picture.data[3])
+            size[3] = picture.linesize[3] * h;
 
         buf->last_pic_num= -256*256*256*64;
         memset(buf->base, 0, sizeof(buf->base));
         memset(buf->data, 0, sizeof(buf->data));
 
-        for(i=0; i<3 && size[i]; i++){
+        for(i=0; i<4 && size[i]; i++){
             const int h_shift= i==0 ? 0 : h_chroma_shift;
             const int v_shift= i==0 ? 0 : v_chroma_shift;
 
@@ -351,7 +353,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
 
     FFSWAP(InternalBuffer, *buf, *last);
 
-    for(i=0; i<3; i++){
+    for(i=0; i<4; i++){
         pic->data[i]=NULL;
 //        pic->base[i]=NULL;
     }
index 518de4b..7025286 100644 (file)
@@ -105,6 +105,7 @@ enum PixelFormat {
     PIX_FMT_GRAY16LE,  ///<        Y        , 16bpp, little-endian
     PIX_FMT_YUV440P,   ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
     PIX_FMT_YUVJ440P,  ///< Planar YUV 4:4:0 full scale (jpeg)
+    PIX_FMT_YUVA420P,  ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
     PIX_FMT_NB,        ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions
 };