]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/huffyuv.c
rv20 / h263 b frame fix
[ffmpeg] / libavcodec / huffyuv.c
index a6220f0ac892c5dfc42d595c4d8cfeba0f3986e9..41294c85fc4e71f3dab0269c33e4ce5fb28f87d7 100644 (file)
@@ -57,7 +57,7 @@ typedef struct HYuvContext{
     int flags;
     int picture_number;
     int last_slice_end;
-    uint8_t __align8 temp[3][2500];
+    uint8_t __align8 temp[3][2560];
     uint64_t stats[3][256];
     uint8_t len[3][256];
     uint32_t bits[3][256];
@@ -153,25 +153,6 @@ static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *d
     *left_top= lt;
 }
 
-//FIXME optimize
-static inline void sub_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
-    int i;
-    uint8_t l, lt;
-
-    l= *left;
-    lt= *left_top;
-
-    for(i=0; i<w; i++){
-        const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
-        lt= src1[i];
-        l= src2[i];
-        dst[i]= l - pred;
-    }    
-
-    *left= l;
-    *left_top= lt;
-}
-
 static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
     int i;
     int r,g,b;
@@ -238,7 +219,7 @@ static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
                 dst[index]= bits++;
         }
         if(bits & 1){
-            fprintf(stderr, "Error generating huffman table\n");
+            av_log(NULL, AV_LOG_ERROR, "Error generating huffman table\n");
             return -1;
         }
         bits >>= 1;
@@ -457,14 +438,13 @@ static void store_table(HYuvContext *s, uint8_t *len){
     int index= s->avctx->extradata_size;
 
     for(i=0; i<256;){
-        int cur=i;
         int val= len[i];
-        int repeat;
-        
-        for(; i<256 && len[i]==val; i++);
+        int repeat=0;
         
-        repeat= i - cur;
+        for(; i<256 && len[i]==val && repeat<255; i++)
+            repeat++;
         
+        assert(val < 32 && val >0 && repeat<256 && repeat>0);
         if(repeat>7){
             ((uint8_t*)s->avctx->extradata)[index++]= val;
             ((uint8_t*)s->avctx->extradata)[index++]= repeat;
@@ -500,7 +480,7 @@ static int encode_init(AVCodecContext *avctx)
     switch(avctx->pix_fmt){
     case PIX_FMT_YUV420P:
         if(avctx->strict_std_compliance>=0){
-            fprintf(stderr, "YV12-huffyuv is experimental, there WILL be no compatbility! (use (v)strict=-1)\n");
+            av_log(avctx, AV_LOG_ERROR, "YV12-huffyuv is experimental, there WILL be no compatbility! (use (v)strict=-1)\n");
             return -1;
         }
         s->bitstream_bpp= 12;
@@ -509,7 +489,7 @@ static int encode_init(AVCodecContext *avctx)
         s->bitstream_bpp= 16;
         break;
     default:
-        fprintf(stderr, "format not supported\n");
+        av_log(avctx, AV_LOG_ERROR, "format not supported\n");
         return -1;
     }
     avctx->bits_per_sample= s->bitstream_bpp;
@@ -723,7 +703,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
 
     p->reference= 0;
     if(avctx->get_buffer(avctx, p) < 0){
-        fprintf(stderr, "get_buffer() failed\n");
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return -1;
     }
 
@@ -744,7 +724,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
             p->data[0][1]= get_bits(&s->gb, 8);
             p->data[0][0]= get_bits(&s->gb, 8);
             
-            fprintf(stderr, "YUY2 output isnt implemenetd yet\n");
+            av_log(avctx, AV_LOG_ERROR, "YUY2 output isnt implemenetd yet\n");
             return -1;
         }else{
         
@@ -916,11 +896,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
                 draw_slice(s, height); // just 1 large slice as this isnt possible in reverse order
                 break;
             default:
-                fprintf(stderr, "prediction type not supported!\n");
+                av_log(avctx, AV_LOG_ERROR, "prediction type not supported!\n");
             }
         }else{
 
-            fprintf(stderr, "BGR24 output isnt implemenetd yet\n");
+            av_log(avctx, AV_LOG_ERROR, "BGR24 output isnt implemenetd yet\n");
             return -1;
         }
     }
@@ -999,9 +979,9 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
             lefttopy= p->data[0][3];
             lefttopu= p->data[1][1];
             lefttopv= p->data[2][1];
-            sub_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
-            sub_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
-            sub_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
+            s->dsp.sub_hfyu_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
+            s->dsp.sub_hfyu_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
+            s->dsp.sub_hfyu_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
             encode_422_bitstream(s, width-4);
             y++; cy++;
 
@@ -1011,7 +991,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
                 if(s->bitstream_bpp==12){
                     while(2*cy > y){
                         ydst= p->data[0] + p->linesize[0]*y;
-                        sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
+                        s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
                         encode_gray_bitstream(s, width);
                         y++;
                     }
@@ -1021,9 +1001,9 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
                 udst= p->data[1] + p->linesize[1]*cy;
                 vdst= p->data[2] + p->linesize[2]*cy;
 
-                sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
-                sub_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
-                sub_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
+                s->dsp.sub_hfyu_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
+                s->dsp.sub_hfyu_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
+                s->dsp.sub_hfyu_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
 
                 encode_422_bitstream(s, width);
             }
@@ -1069,7 +1049,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
             }
         }        
     }else{
-        fprintf(stderr, "Format not supported!\n");
+        av_log(avctx, AV_LOG_ERROR, "Format not supported!\n");
     }
     emms_c();