34 #define TOP 0x01000000
43 rc->
code = bytestream2_get_be32(gb);
51 for (j = 0; j < 4096; j++) {
52 if (
s->pixel_model[
comp][j].total_freq != 256) {
53 for (
i = 0;
i < 256;
i++)
54 s->pixel_model[
comp][j].freq[
i] = 1;
56 s->pixel_model[
comp][j].lookup[
i] = 16;
57 s->pixel_model[
comp][j].total_freq = 256;
62 for (j = 0; j < 6; j++) {
63 uint32_t *p =
s->run_model[j];
64 for (
i = 0;
i < 256;
i++)
69 for (j = 0; j < 6; j++) {
70 uint32_t *
op =
s->op_model[j];
71 for (
i = 0;
i < 6;
i++)
76 for (
i = 0;
i < 256;
i++) {
77 s->range_model[
i] = 1;
78 s->count_model[
i] = 1;
80 s->range_model[256] = 256;
81 s->count_model[256] = 256;
83 for (
i = 0;
i < 5;
i++) {
88 for (j = 0; j < 4; j++) {
89 for (
i = 0;
i < 16;
i++) {
90 s->sxy_model[j][
i] = 1;
92 s->sxy_model[j][16] = 16;
95 for (
i = 0;
i < 512;
i++) {
96 s->mv_model[0][
i] = 1;
97 s->mv_model[1][
i] = 1;
99 s->mv_model[0][512] = 512;
100 s->mv_model[1][512] = 512;
109 uint32_t
byte = bytestream2_get_byteu(gb);
139 t = rc->
range * (uint64_t)cumFreq / total_freq;
142 rc->
range = rc->
range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
145 uint32_t
byte = bytestream2_get_byteu(gb);
159 *freq = total_freq * (uint64_t)(rc->
code - rc->
code1) / rc->
range;
168 uint32_t totfr = cnt[maxc];
170 uint32_t
c = 0, cumfr = 0, cnt_c = 0;
173 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
178 if (
value >= cumfr + cnt_c)
188 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
191 cnt[
c] = cnt_c +
step;
195 for (
i = 0;
i < maxc;
i++) {
196 uint32_t nc = (cnt[
i] >> 1) + 1;
212 uint32_t totfr =
pixel->total_freq;
213 uint32_t
value, x = 0, cumfr = 0, cnt_x = 0;
214 int i, j,
ret,
c, cnt_c;
216 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
220 cnt_x =
pixel->lookup[x];
221 if (
value >= cumfr + cnt_x)
232 if (
value >= cumfr + cnt_c)
238 if (x >= 16 ||
c >= 256) {
242 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
250 for (
i = 0;
i < 256;
i++) {
251 uint32_t nc = (
pixel->freq[
i] >> 1) + 1;
255 for (
i = 0;
i < 16;
i++) {
257 uint32_t i16_17 =
i << 4;
258 for (j = 0; j < 16; j++)
259 sum +=
pixel->freq[i16_17 + j];
263 pixel->total_freq = totfr;
265 *rval =
c &
s->cbits;
273 const int cxshift =
s->cxshift;
280 *cx1 = (*cx << 6) & 0xFC0;
286 *cx1 = (*cx << 6) & 0xFC0;
292 *cx1 = (*cx << 6) & 0xFC0;
302 int cx = 0, cx1 = 0, k = 0;
303 int run, off, y = 0, x = 0,
ret;
304 uint32_t clr = 0,
r,
g,
b, backstep = linesize - avctx->
width;
305 uint32_t lx, ly, ptype;
311 while (k < avctx->
width + 1) {
322 clr = (
b << 16) + (
g << 8) +
r;
328 dst[y * linesize + x] = clr;
332 if (x >= avctx->
width) {
350 clr = (
b << 16) + (
g << 8) +
r;
361 dst, linesize, &lx, &ly,
362 backstep, off, &cx, &cx1);
371 uint32_t *dst,
int linesize,
372 uint32_t *prev,
int plinesize)
377 int backstep = linesize - avctx->
width;
379 if (bytestream2_get_byte(gb) == 0)
399 memset(
s->blocks, 0,
sizeof(*
s->blocks) *
s->nbcount);
411 while (min < s->nbcount && count-- > 0) {
412 s->blocks[
min++] = fill;
420 for (y = 0; y <
s->nby; y++) {
421 for (x = 0; x <
s->nbx; x++) {
422 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
424 if (
s->blocks[y *
s->nbx + x] == 0)
427 if (((
s->blocks[y *
s->nbx + x] - 1) & 1) > 0) {
438 if (((
s->blocks[y *
s->nbx + x] - 1) & 2) > 0) {
439 int i, j, by = y * 16, bx = x * 16;
450 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
451 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
454 for (
i = 0;
i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 +
i) < avctx->
height;
i++) {
455 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
456 dst[(by +
i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 +
i) * plinesize + bx + sx1 + mvx + j];
460 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
461 uint32_t
r,
g,
b, clr, ptype = 0;
463 for (; by < y * 16 + sy2 && by < avctx->
height;) {
472 clr = (
b << 16) + (
g << 8) +
r;
483 dst, prev, linesize, plinesize, &bx, &by,
484 backstep, sx1, sx2, &cx, &cx1);
512 type = bytestream2_peek_byte(gb);
518 frame->key_frame = 1;
520 s->current_frame->linesize[0] / 4);
521 }
else if (
type == 18) {
525 frame->key_frame = 1;
527 s->current_frame->linesize[0] / 4);
528 }
else if (
type == 34) {
529 frame->key_frame = 1;
532 s->current_frame->linesize[0] / 4);
533 }
else if (
type == 17 ||
type == 33) {
534 uint32_t clr, *dst = (uint32_t *)
s->current_frame->data[0];
540 frame->key_frame = 1;
543 uint16_t
value = bytestream2_get_le16(gb);
549 clr = (
r << 16) + (
g << 8) +
b;
551 clr = bytestream2_get_le24(gb);
553 for (y = 0; y < avctx->
height; y++) {
556 dst +=
s->current_frame->linesize[0] / 4;
558 }
else if (
type == 0 ||
type == 1) {
559 frame->key_frame = 0;
561 if (
s->version == 1 ||
s->version == 2)
563 s->current_frame->linesize[0] / 4,
564 (uint32_t *)
s->last_frame->data[0],
565 s->last_frame->linesize[0] / 4);
568 s->current_frame->linesize[0] / 4,
569 (uint32_t *)
s->last_frame->data[0],
570 s->last_frame->linesize[0] / 4);
588 uint8_t *dst =
frame->data[0];
596 for (y = 0; y < avctx->
height; y++) {
598 if (!(((uintptr_t)dst) & 7)) {
599 uint64_t *dst64 = (uint64_t *)dst;
601 for (x = 0; x <
w; x++) {
602 dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
607 for (; x < avctx->
width * 4; x++) {
608 dst[x] = dst[x] << 3;
610 dst +=
frame->linesize[0];
619 frame->linesize[0] *= -1;
644 s->nbx = (avctx->
width + 15) / 16;
645 s->nby = (avctx->
height + 15) / 16;
646 s->nbcount =
s->nbx *
s->nby;
653 if (!
s->last_frame || !
s->current_frame)