Mercurial > libavcodec.hg
changeset 2215:2a767157935e libavcodec
new signed golomb routines
author | alex |
---|---|
date | Wed, 08 Sep 2004 17:59:22 +0000 |
parents | de5ed621effc |
children | 1d6835102c51 |
files | ffv1.c golomb.h |
diffstat | 2 files changed, 68 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/ffv1.c Wed Sep 08 17:57:25 2004 +0000 +++ b/ffv1.c Wed Sep 08 17:59:22 2004 +0000 @@ -324,10 +324,8 @@ code= v ^ ((2*state->drift + state->count)>>31); #endif - 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, 12, bits); + set_sr_golomb_ffv1(pb, code, k, 12, bits); update_vlc_state(state, v); } @@ -344,13 +342,9 @@ assert(k<=8); - v= get_ur_golomb(gb, k, 12, bits); + v= get_sr_golomb_ffv1(gb, k, 12, bits); //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); - #if 0 // JPEG LS if(k==0 && 2*state->drift <= - state->count) v ^= (-1); #else
--- a/golomb.h Wed Sep 08 17:57:25 2004 +0000 +++ b/golomb.h Wed Sep 08 17:59:22 2004 +0000 @@ -1,6 +1,7 @@ /* * exp golomb vlc stuff * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> + * Copyright (c) 2004 Alex Beregszaszi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -22,7 +23,7 @@ * @file golomb.h * @brief * exp golomb vlc stuff - * @author Michael Niedermayer <michaelni@gmx.at> + * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi */ #define INVALID_VLC 0x80000000 @@ -260,13 +261,37 @@ } /** - * read unsigned golomb rice code (flac). + * read signed golomb rice code (ffv1). + */ +static inline int get_sr_golomb_ffv1(GetBitContext *gb, int k, int limit, int esc_len){ + int v= get_ur_golomb(gb, k, limit, esc_len); + + v++; + if (v&1) return v>>1; + else return -(v>>1); + +// return (v>>1) ^ -(v&1); +} +/** + + * read signed golomb rice code (flac). */ static inline int get_sr_golomb_flac(GetBitContext *gb, int k, int limit, int esc_len){ int v= get_ur_golomb_jpegls(gb, k, limit, esc_len); return (v>>1) ^ -(v&1); } +/** + * read signed golomb rice code (sonic). + */ +static inline int get_sr_golomb_sonic(GetBitContext *gb, int k, int limit, int esc_len){ + int v= get_ur_golomb(gb, k, limit, esc_len); + + v++; + if (v&1) return -(v>>1); + else return v>>1; +} + #ifdef TRACE static inline int get_ue(GetBitContext *s, char *file, char *func, int line){ @@ -278,7 +303,7 @@ print_bin(bits, len); - printf("%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); return i; } @@ -292,7 +317,7 @@ print_bin(bits, len); - printf("%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); return i; } @@ -306,7 +331,7 @@ print_bin(bits, len); - printf("%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line); return i; } @@ -403,3 +428,39 @@ put_bits(pb, esc_len, i - 1); } } + +/** + * write signed golomb rice code (ffv1). + */ +static inline void set_sr_golomb_ffv1(PutBitContext *pb, int i, int k, int limit, int esc_len){ + int v; + + v = -2*i-1; + v ^= (v>>31); + + set_ur_golomb(pb, v, k, limit, esc_len); +} + +/** + * write signed golomb rice code (flac). + */ +static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit, int esc_len){ + int v; + + v = -2*i-1; + v ^= (v>>31); + + set_ur_golomb_jpegls(pb, v, k, limit, esc_len); +} + +/** + * write signed golomb rice code (sonic). + */ +static inline void set_sr_golomb_sonic(PutBitContext *pb, int i, int k, int limit, int esc_len){ + int v; + + v = 2*i-1; + if (v<0) v ^= -1; + + set_ur_golomb(pb, v, k, limit, esc_len); +}