[FFmpeg-cvslog] avcodec/huffyuv: add YUVA420P, YUVA422P, YUVA444P, GBRAP, GRAY8A

Michael Niedermayer git at videolan.org
Mon Jan 6 21:26:03 CET 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Jan  6 19:47:34 2014 +0100| [13f3092b387fb1e0f9b281e94ae725b537304af6] | committer: Michael Niedermayer

avcodec/huffyuv: add YUVA420P, YUVA422P, YUVA444P, GBRAP, GRAY8A

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=13f3092b387fb1e0f9b281e94ae725b537304af6
---

 libavcodec/huffyuv.h    |    8 ++++----
 libavcodec/huffyuvdec.c |   45 ++++++++++++++++++++++++++++++++-------------
 libavcodec/huffyuvenc.c |   29 ++++++++++++++++++++---------
 3 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/libavcodec/huffyuv.h b/libavcodec/huffyuv.h
index 774a742..b75cc89 100644
--- a/libavcodec/huffyuv.h
+++ b/libavcodec/huffyuv.h
@@ -79,11 +79,11 @@ typedef struct HYuvContext {
     int picture_number;
     int last_slice_end;
     uint8_t *temp[3];
-    uint64_t stats[3][256];
-    uint8_t len[3][256];
-    uint32_t bits[3][256];
+    uint64_t stats[4][256];
+    uint8_t len[4][256];
+    uint32_t bits[4][256];
     uint32_t pix_bgr_map[1<<VLC_BITS];
-    VLC vlc[6];                             //Y,U,V,YY,YU,YV
+    VLC vlc[8];                             //Y,U,V,A,YY,YU,YV,AA
     uint8_t *bitstream_buffer;
     unsigned int bitstream_buffer_size;
     DSPContext dsp;
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index b37c457..611757d 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -116,7 +116,7 @@ static int generate_joint_tables(HYuvContext *s)
 
     if (s->bitstream_bpp < 24 || s->version > 2) {
         int p, i, y, u;
-        for (p = 0; p < 3; p++) {
+        for (p = 0; p < 4; p++) {
             int p0 = s->version > 2 ? p : 0;
             for (i = y = 0; y < 256; y++) {
                 int len0 = s->len[p0][y];
@@ -135,8 +135,8 @@ static int generate_joint_tables(HYuvContext *s)
                         i++;
                 }
             }
-            ff_free_vlc(&s->vlc[3 + p]);
-            if ((ret = ff_init_vlc_sparse(&s->vlc[3 + p], VLC_BITS, i, len, 1, 1,
+            ff_free_vlc(&s->vlc[4 + p]);
+            if ((ret = ff_init_vlc_sparse(&s->vlc[4 + p], VLC_BITS, i, len, 1, 1,
                                           bits, 2, 2, symbols, 2, 2, 0)) < 0)
                 return ret;
         }
@@ -179,8 +179,8 @@ static int generate_joint_tables(HYuvContext *s)
                 }
             }
         }
-        ff_free_vlc(&s->vlc[3]);
-        if ((ret = init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0)) < 0)
+        ff_free_vlc(&s->vlc[4]);
+        if ((ret = init_vlc(&s->vlc[4], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0)) < 0)
             return ret;
     }
     return 0;
@@ -191,10 +191,14 @@ static int read_huffman_tables(HYuvContext *s, const uint8_t *src, int length)
     GetBitContext gb;
     int i;
     int ret;
+    int count = 3;
 
     init_get_bits(&gb, src, length * 8);
 
-    for (i = 0; i < 3; i++) {
+    if (s->version > 2)
+        count = 1 + s->alpha + 2*s->chroma;
+
+    for (i = 0; i < count; i++) {
         if (read_len_table(s->len[i], &gb) < 0)
             return -1;
         if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0) {
@@ -238,7 +242,7 @@ static int read_old_huffman_tables(HYuvContext *s)
     memcpy(s->bits[2], s->bits[1], 256 * sizeof(uint32_t));
     memcpy(s->len[2] , s->len [1], 256 * sizeof(uint8_t));
 
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < 4; i++) {
         ff_free_vlc(&s->vlc[i]);
         if ((ret = init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1,
                             s->bits[i], 4, 4, 0)) < 0)
@@ -256,7 +260,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     HYuvContext *s = avctx->priv_data;
 
     ff_huffyuv_common_init(avctx);
-    memset(s->vlc, 0, 3 * sizeof(VLC));
+    memset(s->vlc, 0, 4 * sizeof(VLC));
 
     s->interlaced = s->height > 288;
 
@@ -367,9 +371,15 @@ static av_cold int decode_init(AVCodecContext *avctx)
         case 0x070:
             avctx->pix_fmt = AV_PIX_FMT_GRAY8;
             break;
+        case 0x170:
+            avctx->pix_fmt = AV_PIX_FMT_GRAY8A;
+            break;
         case 0x470:
             avctx->pix_fmt = AV_PIX_FMT_GBRP;
             break;
+        case 0x570:
+            avctx->pix_fmt = AV_PIX_FMT_GBRAP;
+            break;
         case 0x670:
             avctx->pix_fmt = AV_PIX_FMT_YUV444P;
             break;
@@ -388,6 +398,15 @@ static av_cold int decode_init(AVCodecContext *avctx)
         case 0x67A:
             avctx->pix_fmt = AV_PIX_FMT_YUV410P;
             break;
+        case 0x770:
+            avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
+            break;
+        case 0x771:
+            avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
+            break;
+        case 0x775:
+            avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
+            break;
         }
     }
 
@@ -418,7 +437,7 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
         return AVERROR(ENOMEM);
     }
 
-    for (i = 0; i < 6; i++)
+    for (i = 0; i < 8; i++)
         s->vlc[i].table = NULL;
 
     if (s->version >= 2) {
@@ -436,7 +455,7 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
 /* TODO instead of restarting the read when the code isn't in the first level
  * of the joint table, jump into the 2nd level of the individual table. */
 #define READ_2PIX(dst0, dst1, plane1){\
-    uint16_t code = get_vlc2(&s->gb, s->vlc[3+plane1].table, VLC_BITS, 1);\
+    uint16_t code = get_vlc2(&s->gb, s->vlc[4+plane1].table, VLC_BITS, 1);\
     if(code != 0xffff){\
         dst0 = code>>8;\
         dst1 = code;\
@@ -469,7 +488,7 @@ static void decode_422_bitstream(HYuvContext *s, int count)
 }
 
 #define READ_2PIX_PLANE(dst0, dst1, plane){\
-    uint16_t code = get_vlc2(&s->gb, s->vlc[3+plane].table, VLC_BITS, 1);\
+    uint16_t code = get_vlc2(&s->gb, s->vlc[4+plane].table, VLC_BITS, 1);\
     if(code != 0xffff){\
         dst0 = code>>8;\
         dst1 = code;\
@@ -517,7 +536,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count,
 {
     int i;
     for (i = 0; i < count; i++) {
-        int code = get_vlc2(&s->gb, s->vlc[3].table, VLC_BITS, 1);
+        int code = get_vlc2(&s->gb, s->vlc[4].table, VLC_BITS, 1);
         if (code != -1) {
             *(uint32_t*)&s->temp[0][4 * i] = s->pix_bgr_map[code];
         } else if(decorrelate) {
@@ -902,7 +921,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
     ff_huffyuv_common_end(s);
     av_freep(&s->bitstream_buffer);
 
-    for (i = 0; i < 6; i++) {
+    for (i = 0; i < 8; i++) {
         ff_free_vlc(&s->vlc[i]);
     }
 
diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c
index 4684896..f825fe3 100644
--- a/libavcodec/huffyuvenc.c
+++ b/libavcodec/huffyuvenc.c
@@ -147,6 +147,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     HYuvContext *s = avctx->priv_data;
     int i, j;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+    int extradata_tables;
 
     ff_huffyuv_common_init(avctx);
 
@@ -188,6 +189,11 @@ static av_cold int encode_init(AVCodecContext *avctx)
     case AV_PIX_FMT_YUV440P:
     case AV_PIX_FMT_GBRP:
     case AV_PIX_FMT_GRAY8:
+    case AV_PIX_FMT_YUVA444P:
+    case AV_PIX_FMT_YUVA420P:
+    case AV_PIX_FMT_YUVA422P:
+    case AV_PIX_FMT_GBRAP:
+    case AV_PIX_FMT_GRAY8A:
         s->version = 3;
         break;
     case AV_PIX_FMT_RGB32:
@@ -251,6 +257,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
         return AVERROR(EINVAL);
     }
 
+    extradata_tables = 1 + 2*s->chroma + s->alpha;
     ((uint8_t*)avctx->extradata)[0] = s->predictor | (s->decorrelate << 6);
     ((uint8_t*)avctx->extradata)[2] = s->interlaced ? 0x10 : 0x20;
     if (s->context)
@@ -258,6 +265,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     if (s->version < 3) {
         ((uint8_t*)avctx->extradata)[1] = s->bitstream_bpp;
         ((uint8_t*)avctx->extradata)[3] = 0;
+        extradata_tables = 3;
     } else {
         ((uint8_t*)avctx->extradata)[1] = ((s->bps-1)<<4) | s->chroma_h_shift | (s->chroma_v_shift<<2);
         if (s->chroma)
@@ -271,12 +279,12 @@ static av_cold int encode_init(AVCodecContext *avctx)
     if (avctx->stats_in) {
         char *p = avctx->stats_in;
 
-        for (i = 0; i < 3; i++)
+        for (i = 0; i < 4; i++)
             for (j = 0; j < 256; j++)
                 s->stats[i][j] = 1;
 
         for (;;) {
-            for (i = 0; i < 3; i++) {
+            for (i = 0; i < 4; i++) {
                 char *next;
 
                 for (j = 0; j < 256; j++) {
@@ -288,7 +296,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
             if (p[0] == 0 || p[1] == 0 || p[2] == 0) break;
         }
     } else {
-        for (i = 0; i < 3; i++)
+        for (i = 0; i < 4; i++)
             for (j = 0; j < 256; j++) {
                 int d = FFMIN(j, 256 - j);
 
@@ -296,7 +304,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
             }
     }
 
-    for (i = 0; i < 3; i++) {
+    for (i = 0; i < extradata_tables; i++) {
         ff_huff_gen_len_table(s->len[i], s->stats[i]);
 
         if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0) {
@@ -308,7 +316,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     }
 
     if (s->context) {
-        for (i = 0; i < 3; i++) {
+        for (i = 0; i < 4; i++) {
             int pels = s->width * s->height / (i ? 40 : 10);
             for (j = 0; j < 256; j++) {
                 int d = FFMIN(j, 256 - j);
@@ -316,7 +324,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
             }
         }
     } else {
-        for (i = 0; i < 3; i++)
+        for (i = 0; i < 4; i++)
             for (j = 0; j < 256; j++)
                 s->stats[i][j]= 0;
     }
@@ -546,14 +554,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         return ret;
 
     if (s->context) {
-        for (i = 0; i < 3; i++) {
+        for (i = 0; i < 4; i++) {
             ff_huff_gen_len_table(s->len[i], s->stats[i]);
             if (ff_huffyuv_generate_bits_table(s->bits[i], s->len[i]) < 0)
                 return -1;
             size += store_table(s, s->len[i], &pkt->data[size]);
         }
 
-        for (i = 0; i < 3; i++)
+        for (i = 0; i < 4; i++)
             for (j = 0; j < 256; j++)
                 s->stats[i][j] >>= 1;
     }
@@ -789,7 +797,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         int j;
         char *p = avctx->stats_out;
         char *end = p + 1024*30;
-        for (i = 0; i < 3; i++) {
+        for (i = 0; i < 4; i++) {
             for (j = 0; j < 256; j++) {
                 snprintf(p, end-p, "%"PRIu64" ", s->stats[i][j]);
                 p += strlen(p);
@@ -860,6 +868,9 @@ AVCodec ff_ffvhuff_encoder = {
         AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P,
         AV_PIX_FMT_GBRP,
         AV_PIX_FMT_GRAY8,
+        AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
+        AV_PIX_FMT_GBRAP,
+        AV_PIX_FMT_GRAY8A,
         AV_PIX_FMT_RGB24,
         AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE
     },



More information about the ffmpeg-cvslog mailing list