]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/ffv1.c
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
[ffmpeg] / libavcodec / ffv1.c
index 1b505c22cc171f9b3e1d80d8a9d944b64339c504..2ff994e53d658d45a7b410decfbf1db7dca76be9 100644 (file)
@@ -21,7 +21,7 @@
  
 /**
  * @file ffv1.c
- * FF Video Codec 1 (a experimental lossless codec)
+ * FF Video Codec 1 (an experimental lossless codec)
  */
 
 #include "common.h"
@@ -185,10 +185,8 @@ static inline int predict(uint8_t *src, uint8_t *last){
     const int LT= last[-1];
     const int  T= last[ 0];
     const int L =  src[-1];
-    uint8_t *cm = cropTbl + MAX_NEG_CROP;    
-    const int gradient= cm[L + T - LT];
 
-    return mid_pred(L, gradient, T);
+    return mid_pred(L, L + T - LT, T);
 }
 
 static inline int get_context(FFV1Context *f, uint8_t *src, uint8_t *last, uint8_t *last2){
@@ -302,6 +300,9 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState * const state, int
         k++;
         i += i;
     }
+
+    assert(k<=8);
+
 #if 0 // JPEG LS
     if(k==0 && 2*state->drift <= - state->count) code= v ^ (-1);
     else                                         code= v;
@@ -312,7 +313,7 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState * const state, int
     code = -2*code-1;
     code^= (code>>31);
 //printf("v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v, code, state->bias, state->error_sum, state->drift, state->count, k);
-    set_ur_golomb(pb, code, k, 8, 8);
+    set_ur_golomb(pb, code, k, 12, 8);
 
     update_vlc_state(state, v);
 }
@@ -326,10 +327,12 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state){
         k++;
         i += i;
     }
-    
-    v= get_ur_golomb(gb, k, 8, 8);
+
+    assert(k<=8);
+
+    v= get_ur_golomb(gb, k, 12, 8);
 //printf("v:%d bias:%d error:%d drift:%d count:%d k:%d", v, state->bias, state->error_sum, state->drift, state->count, k);
-    
+
     v++;
     if(v&1) v=  (v>>1);
     else    v= -(v>>1);
@@ -487,7 +490,7 @@ static int encode_init(AVCodecContext *avctx)
     s->version=0;
     s->ac= avctx->coder_type;
     
-    s->plane_count=3;
+    s->plane_count=2;
     for(i=0; i<256; i++){
         s->quant_table[0][i]=           quant11[i];
         s->quant_table[1][i]=        11*quant11[i];
@@ -596,7 +599,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
     if(!f->ac){
         used_count += put_cabac_terminate(c, 1);
 //printf("pos=%d\n", used_count);
-        init_put_bits(&f->pb, buf + used_count, buf_size - used_count, NULL, NULL);
+        init_put_bits(&f->pb, buf + used_count, buf_size - used_count);
     }
     
     if(1){
@@ -606,7 +609,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size,
         encode_plane(f, p->data[0], width, height, p->linesize[0], 0);
 
         encode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
-        encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 2);
+        encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
     }
     emms_c();
     
@@ -751,7 +754,7 @@ static int read_header(FFV1Context *f){
     f->chroma_h_shift= get_symbol(c, state, 0, 7);
     f->chroma_v_shift= get_symbol(c, state, 0, 7);
     get_cabac(c, state); //transparency plane
-    f->plane_count= 3;
+    f->plane_count= 2;
 
     switch(16*f->chroma_h_shift + f->chroma_v_shift){
     case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;
@@ -862,6 +865,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
         if(bytes_read ==0) printf("error at end of AC stream\n");
 //printf("pos=%d\n", bytes_read);
         init_get_bits(&f->gb, buf + bytes_read, buf_size - bytes_read);
+    } else {
+        bytes_read = 0; /* avoid warning */
     }
     
     if(1){
@@ -870,7 +875,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8
         decode_plane(f, p->data[0], width, height, p->linesize[0], 0);
         
         decode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
-        decode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 2);
+        decode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
     }
         
     emms_c();