45 while ((c->
high >> 15) - (c->
low >> 15) < 2) {
46 if ((c->
low ^ c->
high) & 0x10000) {
51 c->
high = c->
high << 8 & 0xFFFFFF | 0xFF;
53 c->
low = c->
low << 8 & 0xFFFFFF;
64 int split = (n << 1) - range;
67 return split + (value - split >> 1);
73 int low,
int high,
int n)
75 int split = (n << 1) - range;
78 c->
high = split + (high - split << 1);
85 c->
low += split + (low - split << 1);
92 int range = c->
high - c->
low + 1;
96 if (n << scale > range)
112 int range = c->
high - c->
low + 1,
n = *probs;
116 if (
n << scale > range)
122 while (probs[++i] >
val) ;
125 probs[i] << scale, probs[i - 1] << scale,
n);
134 int diff = (c->high >> 16) - (c->low >> 16);
138 while (!(diff & 0x80)) {
143 return (bits + bp + 7 >> 3) + ((c->low >> 16) + 1 == c->high >> 16);
150 c->
value = bytestream2_get_be24(gB);
165 if (ncol > ctx->
free_colours || buf_size < 2 + ncol * 3)
167 for (i = 0; i < ncol; i++)
174 int keyframe,
int w,
int h)
176 int last_symbol = 0, repeat = 0, prev_avail = 0;
179 int x,
y, endx, endy,
t;
181 #define READ_PAIR(a, b) \
182 a = bytestream2_get_byte(gB) << 4; \
183 t = bytestream2_get_byte(gB); \
185 b = (t & 0xF) << 8; \
186 b |= bytestream2_get_byte(gB); \
191 if (endx >= w || endy >= h || x > endx || y > endy)
193 dst += x + stride *
y;
204 int b = bytestream2_get_byte(gB);
206 last_symbol = b << 8 | bytestream2_get_byte(gB);
210 repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
211 if (last_symbol == -2) {
212 int skip =
FFMIN((
unsigned)repeat, dst + w - p);
217 last_symbol = 127 -
b;
219 if (last_symbol >= 0)
221 else if (last_symbol == -1 && prev_avail)
223 }
while (++p < dst + w);
232 uint8_t *rgb_dst,
int rgb_stride, uint32_t *pal,
233 int keyframe,
int kf_slipt,
int slice,
int w,
int h)
239 int current_length = 0, read_codes = 0, next_code = 0, current_codes = 0;
240 int remaining_codes, surplus_codes, i;
242 const int alphabet_size = 270 - keyframe;
244 int last_symbol = 0, repeat = 0, prev_avail = 0;
247 int x,
y, clipw, cliph;
254 if (x + clipw > w || y + cliph > h)
256 pal_dst += pal_stride * y + x;
257 rgb_dst += rgb_stride * y + x * 3;
264 pal_dst += pal_stride * kf_slipt;
265 rgb_dst += rgb_stride * kf_slipt;
274 while (current_codes--) {
276 if (symbol >= 204 - keyframe)
277 symbol += 14 - keyframe;
278 else if (symbol > 189)
279 symbol =
get_bits1(gb) + (symbol << 1) - 190;
282 bits[symbol] = current_length;
283 codes[symbol] = next_code++;
288 remaining_codes = (1 << current_length) - next_code;
289 current_codes =
get_bits(gb, av_ceil_log2(remaining_codes + 1));
290 if (current_length > 22 || current_codes > remaining_codes)
292 }
while (current_codes != remaining_codes);
294 remaining_codes = alphabet_size - read_codes;
297 while ((surplus_codes = (2 << current_length) -
298 (next_code << 1) - remaining_codes) < 0) {
304 for (i = 0; i < alphabet_size; i++)
306 if (surplus_codes-- == 0) {
310 bits[i] = current_length;
311 codes[i] = next_code++;
314 if (next_code != 1 << current_length)
317 if (i =
init_vlc(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0))
339 repeat += (1 <<
b) - 1;
341 if (last_symbol == -2) {
342 int skip =
FFMIN(repeat, pal_dst + w - pp);
348 last_symbol = 267 -
b;
350 if (last_symbol >= 0) {
353 }
else if (last_symbol == -1 && prev_avail) {
354 *pp = *(pp - pal_stride);
355 memcpy(rp, rp - rgb_stride, 3);
358 }
while (++pp < pal_dst + w);
359 pal_dst += pal_stride;
360 rgb_dst += rgb_stride;
369 int x,
int y,
int w,
int h,
int wmv9_mask)
405 v->
bits = buf_size * 8;
428 "Asymmetric WMV9 rectangle subsampling");
456 #define MAX_WMV9_RECTANGLES 20
457 #define ARITH2_PADDING 2
463 int buf_size = avpkt->
size;
471 int keyframe, has_wmv9, has_mv, is_rle, is_555,
ret;
474 int used_rects = 0, i, implicit_rect = 0,
av_uninit(wmv9_mask);
528 implicit_rect = !arith2_get_bit(&acoder);
530 while (arith2_get_bit(&acoder)) {
533 r = &wmv9rects[used_rects];
538 wmv9rects[used_rects - 1].
x) +
539 wmv9rects[used_rects - 1].
x;
546 if (implicit_rect && used_rects) {
554 wmv9rects[0].
w = avctx->
width;
555 wmv9rects[0].
h = avctx->
height;
559 for (i = 0; i < used_rects; i++) {
560 if (!implicit_rect && arith2_get_bit(&acoder)) {
565 wmv9_mask = arith2_get_bit(&acoder) - 1;
579 if (keyframe && !is_555) {
593 if (c->
mvX < 0 || c->
mvY < 0) {
657 }
else if (!implicit_rect || wmv9_mask != -1) {
689 for (i = 0; i < used_rects; i++) {
690 int x = wmv9rects[i].
x;
691 int y = wmv9rects[i].
y;
692 int w = wmv9rects[i].
w;
693 int h = wmv9rects[i].
h;
694 if (wmv9rects[i].coded) {
695 int WMV9codedFrameSize;
696 if (buf_size < 4 || !(WMV9codedFrameSize =
AV_RL24(buf)))
698 if (ret =
decode_wmv9(avctx, buf + 3, buf_size - 3,
699 x, y, w, h, wmv9_mask))
701 buf += WMV9codedFrameSize + 3;
702 buf_size -= WMV9codedFrameSize + 3;
705 if (wmv9_mask != -1) {
713 memset(dst, 0x80, w * 3);
724 if (c->
mvX < 0 || c->
mvY < 0) {