Mercurial > libavcodec.hg
annotate rangecoder.h @ 5153:b985439e3e15 libavcodec
fix some printf format specifiers
author | mru |
---|---|
date | Sat, 16 Jun 2007 14:52:05 +0000 |
parents | ce36118abbbb |
children | 4394344397d8 |
rev | line source |
---|---|
2334 | 1 /* |
2 * Range coder | |
3 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | |
4 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2334 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2334 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2334 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2334 | 20 * |
21 */ | |
2967 | 22 |
2334 | 23 /** |
24 * @file rangecoder.h | |
25 * Range coder. | |
26 */ | |
27 | |
28 typedef struct RangeCoder{ | |
29 int low; | |
30 int range; | |
31 int outstanding_count; | |
32 int outstanding_byte; | |
33 uint8_t zero_state[256]; | |
34 uint8_t one_state[256]; | |
35 uint8_t *bytestream_start; | |
36 uint8_t *bytestream; | |
37 uint8_t *bytestream_end; | |
38 }RangeCoder; | |
39 | |
40 void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size); | |
41 void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size); | |
42 int ff_rac_terminate(RangeCoder *c); | |
43 void ff_build_rac_states(RangeCoder *c, int factor, int max_p); | |
44 | |
45 static inline void renorm_encoder(RangeCoder *c){ | |
46 //FIXME optimize | |
47 while(c->range < 0x100){ | |
48 if(c->outstanding_byte < 0){ | |
49 c->outstanding_byte= c->low>>8; | |
50 }else if(c->low <= 0xFF00){ | |
51 *c->bytestream++ = c->outstanding_byte; | |
52 for(;c->outstanding_count; c->outstanding_count--) | |
53 *c->bytestream++ = 0xFF; | |
54 c->outstanding_byte= c->low>>8; | |
55 }else if(c->low >= 0x10000){ | |
56 *c->bytestream++ = c->outstanding_byte + 1; | |
57 for(;c->outstanding_count; c->outstanding_count--) | |
58 *c->bytestream++ = 0x00; | |
59 c->outstanding_byte= (c->low>>8) & 0xFF; | |
60 }else{ | |
61 c->outstanding_count++; | |
62 } | |
2967 | 63 |
2334 | 64 c->low = (c->low & 0xFF)<<8; |
65 c->range <<= 8; | |
66 } | |
67 } | |
68 | |
5082 | 69 static inline int get_rac_count(RangeCoder *c){ |
70 int x= c->bytestream - c->bytestream_start + c->outstanding_count; | |
71 if(c->outstanding_byte >= 0) | |
72 x++; | |
73 return 8*x - av_log2(c->range); | |
74 } | |
75 | |
2334 | 76 static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){ |
77 int range1= (c->range * (*state)) >> 8; | |
78 | |
79 assert(*state); | |
80 assert(range1 < c->range); | |
81 assert(range1 > 0); | |
82 if(!bit){ | |
83 c->range -= range1; | |
84 *state= c->zero_state[*state]; | |
85 }else{ | |
86 c->low += c->range - range1; | |
87 c->range = range1; | |
88 *state= c->one_state[*state]; | |
89 } | |
2967 | 90 |
2334 | 91 renorm_encoder(c); |
92 } | |
93 | |
94 static inline void refill(RangeCoder *c){ | |
95 if(c->range < 0x100){ | |
96 c->range <<= 8; | |
97 c->low <<= 8; | |
98 if(c->bytestream < c->bytestream_end) | |
99 c->low+= c->bytestream[0]; | |
100 c->bytestream++; | |
101 } | |
102 } | |
103 | |
104 static inline int get_rac(RangeCoder *c, uint8_t * const state){ | |
105 int range1= (c->range * (*state)) >> 8; | |
5083
ce36118abbbb
rename attribute_unused to av_unused and moves its declaration to common.h
benoit
parents:
5082
diff
changeset
|
106 int av_unused one_mask; |
2967 | 107 |
2334 | 108 c->range -= range1; |
109 #if 1 | |
110 if(c->low < c->range){ | |
111 *state= c->zero_state[*state]; | |
112 refill(c); | |
113 return 0; | |
114 }else{ | |
115 c->low -= c->range; | |
116 *state= c->one_state[*state]; | |
117 c->range = range1; | |
118 refill(c); | |
119 return 1; | |
120 } | |
121 #else | |
122 one_mask= (c->range - c->low-1)>>31; | |
2967 | 123 |
2334 | 124 c->low -= c->range & one_mask; |
125 c->range += (range1 - c->range) & one_mask; | |
2967 | 126 |
2334 | 127 *state= c->zero_state[(*state) + (256&one_mask)]; |
2967 | 128 |
2334 | 129 refill(c); |
130 | |
131 return one_mask&1; | |
132 #endif | |
133 } | |
134 |