48 while ((c->
high >> 15) - (c->
low >> 15) < 2) {
49 if ((c->
low ^ c->
high) & 0x10000) {
54 c->
high = c->
high << 8 & 0xFFFFFF | 0xFF;
56 c->
low = c->
low << 8 & 0xFFFFFF;
67 int split = (n << 1) - range;
70 return split + (value - split >> 1);
76 int low,
int high,
int n)
78 int split = (n << 1) - range;
81 c->
high = split + (high - split << 1);
88 c->
low += split + (low - split << 1);
95 int range = c->
high - c->
low + 1;
99 if (n << scale > range)
115 int range = c->
high - c->
low + 1,
n = *probs;
119 if (
n << scale > range)
125 while (probs[++i] >
val) ;
128 probs[i] << scale, probs[i - 1] << scale,
n);
137 int diff = (c->high >> 16) - (c->low >> 16);
141 while (!(diff & 0x80)) {
146 return (bits + bp + 7 >> 3) + ((c->low >> 16) + 1 == c->high >> 16);
153 c->
value = bytestream2_get_be24(gB);
168 if (ncol > ctx->
free_colours || buf_size < 2 + ncol * 3)
170 for (i = 0; i < ncol; i++)
177 int keyframe,
int w,
int h)
179 int last_symbol = 0, repeat = 0, prev_avail = 0;
182 int x,
y, endx, endy, t;
184 #define READ_PAIR(a, b) \
185 a = bytestream2_get_byte(gB) << 4; \
186 t = bytestream2_get_byte(gB); \
188 b = (t & 0xF) << 8; \
189 b |= bytestream2_get_byte(gB); \
194 if (endx >= w || endy >= h || x > endx || y > endy)
196 dst += x + stride *
y;
207 int b = bytestream2_get_byte(gB);
209 last_symbol = b << 8 | bytestream2_get_byte(gB);
213 if (repeat >= (INT_MAX >> 8) - 1) {
217 repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
219 if (last_symbol == -2) {
220 int skip =
FFMIN((
unsigned)repeat, dst + w - p);
225 last_symbol = 127 -
b;
227 if (last_symbol >= 0)
229 else if (last_symbol == -1 && prev_avail)
231 }
while (++p < dst + w);
240 uint8_t *rgb_dst,
int rgb_stride, uint32_t *pal,
241 int keyframe,
int kf_slipt,
int slice,
int w,
int h)
247 int current_length = 0, read_codes = 0, next_code = 0, current_codes = 0;
248 int remaining_codes, surplus_codes, i;
250 const int alphabet_size = 270 - keyframe;
252 int last_symbol = 0, repeat = 0, prev_avail = 0;
255 int x,
y, clipw, cliph;
262 if (x + clipw > w || y + cliph > h)
264 pal_dst += pal_stride * y + x;
265 rgb_dst += rgb_stride * y + x * 3;
272 pal_dst += pal_stride * kf_slipt;
273 rgb_dst += rgb_stride * kf_slipt;
282 while (current_codes--) {
284 if (symbol >= 204 - keyframe)
285 symbol += 14 - keyframe;
286 else if (symbol > 189)
287 symbol =
get_bits1(gb) + (symbol << 1) - 190;
290 bits[symbol] = current_length;
291 codes[symbol] = next_code++;
296 remaining_codes = (1 << current_length) - next_code;
297 current_codes =
get_bits(gb, av_ceil_log2(remaining_codes + 1));
298 if (current_length > 22 || current_codes > remaining_codes)
300 }
while (current_codes != remaining_codes);
302 remaining_codes = alphabet_size - read_codes;
305 while ((surplus_codes = (2 << current_length) -
306 (next_code << 1) - remaining_codes) < 0) {
312 for (i = 0; i < alphabet_size; i++)
314 if (surplus_codes-- == 0) {
318 bits[i] = current_length;
319 codes[i] = next_code++;
322 if (next_code != 1 << current_length)
325 if (i =
init_vlc(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0))
347 repeat += (1 <<
b) - 1;
349 if (last_symbol == -2) {
350 int skip =
FFMIN(repeat, pal_dst + w - pp);
356 last_symbol = 267 -
b;
358 if (last_symbol >= 0) {
361 }
else if (last_symbol == -1 && prev_avail) {
362 *pp = *(pp - pal_stride);
363 memcpy(rp, rp - rgb_stride, 3);
366 }
while (++pp < pal_dst + w);
367 pal_dst += pal_stride;
368 rgb_dst += rgb_stride;
377 int x,
int y,
int w,
int h,
int wmv9_mask)
413 v->
bits = buf_size * 8;
436 "Asymmetric WMV9 rectangle subsampling");
464 #define MAX_WMV9_RECTANGLES 20
465 #define ARITH2_PADDING 2
471 int buf_size = avpkt->
size;
479 int keyframe, has_wmv9, has_mv, is_rle, is_555,
ret;
482 int used_rects = 0, i, implicit_rect = 0,
av_uninit(wmv9_mask);
536 implicit_rect = !arith2_get_bit(&acoder);
538 while (arith2_get_bit(&acoder)) {
541 r = &wmv9rects[used_rects];
546 wmv9rects[used_rects - 1].
x) +
547 wmv9rects[used_rects - 1].
x;
554 if (implicit_rect && used_rects) {
562 wmv9rects[0].
w = avctx->
width;
563 wmv9rects[0].
h = avctx->
height;
567 for (i = 0; i < used_rects; i++) {
568 if (!implicit_rect && arith2_get_bit(&acoder)) {
573 wmv9_mask = arith2_get_bit(&acoder) - 1;
587 if (keyframe && !is_555) {
601 if (c->
mvX < 0 || c->
mvY < 0) {
665 }
else if (!implicit_rect || wmv9_mask != -1) {
697 for (i = 0; i < used_rects; i++) {
698 int x = wmv9rects[i].
x;
699 int y = wmv9rects[i].
y;
700 int w = wmv9rects[i].
w;
701 int h = wmv9rects[i].
h;
702 if (wmv9rects[i].coded) {
703 int WMV9codedFrameSize;
704 if (buf_size < 4 || !(WMV9codedFrameSize =
AV_RL24(buf)))
706 if (ret =
decode_wmv9(avctx, buf + 3, buf_size - 3,
707 x, y, w, h, wmv9_mask))
709 buf += WMV9codedFrameSize + 3;
710 buf_size -= WMV9codedFrameSize + 3;
713 if (wmv9_mask != -1) {
721 memset(dst, 0x80, w * 3);
732 if (c->
mvX < 0 || c->
mvY < 0) {