aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ffv1.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2010-10-24 16:55:42 +0000
committerMichael Niedermayer <michaelni@gmx.at>2010-10-24 16:55:42 +0000
commitce3716bf059e79be38dccdfea069e39e179d1a8d (patch)
tree721a8d2e3e76fb1d1e54485731abad821e6a08e7 /libavcodec/ffv1.c
parent19591033f7145115790338bfd038b7ecb6ff39ee (diff)
downloadffmpeg-ce3716bf059e79be38dccdfea069e39e179d1a8d.tar.gz
Move ffv1 state transition table sorting to its own function.
Originally committed as revision 25563 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ffv1.c')
-rw-r--r--libavcodec/ffv1.c85
1 files changed, 45 insertions, 40 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 2ac13a39f1..825b926b4f 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -780,10 +780,53 @@ static int write_extra_header(FFV1Context *f){
return 0;
}
+static int sort_stt(FFV1Context *s, uint8_t stt[256]){
+ int i,i2,changed,print=0;
+
+ do{
+ changed=0;
+ for(i=12; i<244; i++){
+ for(i2=i+1; i2<245 && i2<i+4; i2++){
+#define COST(old, new) \
+ s->rc_stat[old][0]*-log2((256-(new))/256.0)\
+ +s->rc_stat[old][1]*-log2( (new) /256.0)
+
+#define COST2(old, new) \
+ COST(old, new)\
+ +COST(256-(old), 256-(new))
+
+ double size0= COST2(i, i ) + COST2(i2, i2);
+ double sizeX= COST2(i, i2) + COST2(i2, i );
+ if(sizeX < size0 && i!=128 && i2!=128){
+ int j;
+ FFSWAP(int, stt[ i], stt[ i2]);
+ FFSWAP(int, s->rc_stat[i ][0],s->rc_stat[ i2][0]);
+ FFSWAP(int, s->rc_stat[i ][1],s->rc_stat[ i2][1]);
+ if(i != 256-i2){
+ FFSWAP(int, stt[256-i], stt[256-i2]);
+ FFSWAP(int, s->rc_stat[256-i][0],s->rc_stat[256-i2][0]);
+ FFSWAP(int, s->rc_stat[256-i][1],s->rc_stat[256-i2][1]);
+ }
+ for(j=1; j<256; j++){
+ if (stt[j] == i ) stt[j] = i2;
+ else if(stt[j] == i2) stt[j] = i ;
+ if(i != 256-i2){
+ if (stt[256-j] == 256-i ) stt[256-j] = 256-i2;
+ else if(stt[256-j] == 256-i2) stt[256-j] = 256-i ;
+ }
+ }
+ print=changed=1;
+ }
+ }
+ }
+ }while(changed);
+ return print;
+}
+
static av_cold int encode_init(AVCodecContext *avctx)
{
FFV1Context *s = avctx->priv_data;
- int i, j, i2;
+ int i, j;
common_init(avctx);
@@ -864,7 +907,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
if(avctx->stats_in){
char *p= avctx->stats_in;
- int changed;
for(;;){
for(j=0; j<256; j++){
@@ -881,44 +923,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
while(*p=='\n' || *p==' ') p++;
if(p[0]==0) break;
}
-
- do{
- changed=0;
- for(i=12; i<244; i++){
- for(i2=i+1; i2<245 && i2<i+4; i2++){
-#define COST(old, new) \
- s->rc_stat[old][0]*-log2((256-(new))/256.0)\
- +s->rc_stat[old][1]*-log2( (new) /256.0)
-
-#define COST2(old, new) \
- COST(old, new)\
- +COST(256-(old), 256-(new))
-
- double size0= COST2(i, i ) + COST2(i2, i2);
- double sizeX= COST2(i, i2) + COST2(i2, i );
- if(sizeX < size0 && i!=128 && i2!=128){
- int j;
- FFSWAP(int, s->state_transition[ i], s->state_transition[ i2]);
- FFSWAP(int, s->rc_stat[i ][0],s->rc_stat[ i2][0]);
- FFSWAP(int, s->rc_stat[i ][1],s->rc_stat[ i2][1]);
- if(i != 256-i2){
- FFSWAP(int, s->state_transition[256-i], s->state_transition[256-i2]);
- FFSWAP(int, s->rc_stat[256-i][0],s->rc_stat[256-i2][0]);
- FFSWAP(int, s->rc_stat[256-i][1],s->rc_stat[256-i2][1]);
- }
- for(j=1; j<256; j++){
- if (s->state_transition[j] == i ) s->state_transition[j] = i2;
- else if(s->state_transition[j] == i2) s->state_transition[j] = i ;
- if(i != 256-i2){
- if (s->state_transition[256-j] == 256-i ) s->state_transition[256-j] = 256-i2;
- else if(s->state_transition[256-j] == 256-i2) s->state_transition[256-j] = 256-i ;
- }
- }
- changed=1;
- }
- }
- }
- }while(changed);
+ sort_stt(s, s->state_transition);
}
if(s->version>1){