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 repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
214 if (last_symbol == -2) {
215 int skip =
FFMIN((
unsigned)repeat, dst + w - p);
220 last_symbol = 127 -
b;
222 if (last_symbol >= 0)
224 else if (last_symbol == -1 && prev_avail)
226 }
while (++p < dst + w);
235 uint8_t *rgb_dst,
int rgb_stride, uint32_t *pal,
236 int keyframe,
int kf_slipt,
int slice,
int w,
int h)
242 int current_length = 0, read_codes = 0, next_code = 0, current_codes = 0;
243 int remaining_codes, surplus_codes, i;
245 const int alphabet_size = 270 - keyframe;
247 int last_symbol = 0, repeat = 0, prev_avail = 0;
250 int x,
y, clipw, cliph;
257 if (x + clipw > w || y + cliph > h)
259 pal_dst += pal_stride * y + x;
260 rgb_dst += rgb_stride * y + x * 3;
267 pal_dst += pal_stride * kf_slipt;
268 rgb_dst += rgb_stride * kf_slipt;
277 while (current_codes--) {
279 if (symbol >= 204 - keyframe)
280 symbol += 14 - keyframe;
281 else if (symbol > 189)
282 symbol =
get_bits1(gb) + (symbol << 1) - 190;
285 bits[symbol] = current_length;
286 codes[symbol] = next_code++;
291 remaining_codes = (1 << current_length) - next_code;
292 current_codes =
get_bits(gb, av_ceil_log2(remaining_codes + 1));
293 if (current_length > 22 || current_codes > remaining_codes)
295 }
while (current_codes != remaining_codes);
297 remaining_codes = alphabet_size - read_codes;
300 while ((surplus_codes = (2 << current_length) -
301 (next_code << 1) - remaining_codes) < 0) {
307 for (i = 0; i < alphabet_size; i++)
309 if (surplus_codes-- == 0) {
313 bits[i] = current_length;
314 codes[i] = next_code++;
317 if (next_code != 1 << current_length)
320 if (i =
init_vlc(&vlc, 9, alphabet_size, bits, 1, 1, codes, 4, 4, 0))
342 repeat += (1 <<
b) - 1;
344 if (last_symbol == -2) {
345 int skip =
FFMIN(repeat, pal_dst + w - pp);
351 last_symbol = 267 -
b;
353 if (last_symbol >= 0) {
356 }
else if (last_symbol == -1 && prev_avail) {
357 *pp = *(pp - pal_stride);
358 memcpy(rp, rp - rgb_stride, 3);
361 }
while (++pp < pal_dst + w);
362 pal_dst += pal_stride;
363 rgb_dst += rgb_stride;
372 int x,
int y,
int w,
int h,
int wmv9_mask)
408 v->
bits = buf_size * 8;
431 "Asymmetric WMV9 rectangle subsampling");
459 #define MAX_WMV9_RECTANGLES 20
460 #define ARITH2_PADDING 2
466 int buf_size = avpkt->
size;
474 int keyframe, has_wmv9, has_mv, is_rle, is_555,
ret;
477 int used_rects = 0, i, implicit_rect = 0,
av_uninit(wmv9_mask);
531 implicit_rect = !arith2_get_bit(&acoder);
533 while (arith2_get_bit(&acoder)) {
536 r = &wmv9rects[used_rects];
541 wmv9rects[used_rects - 1].
x) +
542 wmv9rects[used_rects - 1].
x;
549 if (implicit_rect && used_rects) {
557 wmv9rects[0].
w = avctx->
width;
558 wmv9rects[0].
h = avctx->
height;
562 for (i = 0; i < used_rects; i++) {
563 if (!implicit_rect && arith2_get_bit(&acoder)) {
568 wmv9_mask = arith2_get_bit(&acoder) - 1;
582 if (keyframe && !is_555) {
596 if (c->
mvX < 0 || c->
mvY < 0) {
660 }
else if (!implicit_rect || wmv9_mask != -1) {
692 for (i = 0; i < used_rects; i++) {
693 int x = wmv9rects[i].
x;
694 int y = wmv9rects[i].
y;
695 int w = wmv9rects[i].
w;
696 int h = wmv9rects[i].
h;
697 if (wmv9rects[i].coded) {
698 int WMV9codedFrameSize;
699 if (buf_size < 4 || !(WMV9codedFrameSize =
AV_RL24(buf)))
701 if (ret =
decode_wmv9(avctx, buf + 3, buf_size - 3,
702 x, y, w, h, wmv9_mask))
704 buf += WMV9codedFrameSize + 3;
705 buf_size -= WMV9codedFrameSize + 3;
708 if (wmv9_mask != -1) {
716 memset(dst, 0x80, w * 3);
727 if (c->
mvX < 0 || c->
mvY < 0) {