32 #define TOP 0x01000000
41 rc->
code = bytestream2_get_be32(gb);
49 for (j = 0; j < 4096; j++) {
50 if (
s->pixel_model[
comp][j].total_freq != 256) {
51 for (
i = 0;
i < 256;
i++)
52 s->pixel_model[
comp][j].freq[
i] = 1;
54 s->pixel_model[
comp][j].lookup[
i] = 16;
55 s->pixel_model[
comp][j].total_freq = 256;
60 for (j = 0; j < 6; j++) {
61 uint32_t *p =
s->run_model[j];
62 for (
i = 0;
i < 256;
i++)
67 for (j = 0; j < 6; j++) {
68 uint32_t *
op =
s->op_model[j];
69 for (
i = 0;
i < 6;
i++)
74 for (
i = 0;
i < 256;
i++) {
75 s->range_model[
i] = 1;
76 s->count_model[
i] = 1;
78 s->range_model[256] = 256;
79 s->count_model[256] = 256;
81 for (
i = 0;
i < 5;
i++) {
86 for (j = 0; j < 4; j++) {
87 for (
i = 0;
i < 16;
i++) {
88 s->sxy_model[j][
i] = 1;
90 s->sxy_model[j][16] = 16;
93 for (
i = 0;
i < 512;
i++) {
94 s->mv_model[0][
i] = 1;
95 s->mv_model[1][
i] = 1;
97 s->mv_model[0][512] = 512;
98 s->mv_model[1][512] = 512;
107 uint32_t
byte = bytestream2_get_byteu(gb);
137 t = rc->
range * (uint64_t)cumFreq / total_freq;
140 rc->
range = rc->
range * (uint64_t)(freq + cumFreq) / total_freq - (t + 1);
143 uint32_t
byte = bytestream2_get_byteu(gb);
157 *freq = total_freq * (uint64_t)(rc->
code - rc->
code1) / rc->
range;
166 uint32_t totfr = cnt[maxc];
168 uint32_t
c = 0, cumfr = 0, cnt_c = 0;
171 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
176 if (
value >= cumfr + cnt_c)
186 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
189 cnt[
c] = cnt_c +
step;
193 for (
i = 0;
i < maxc;
i++) {
194 uint32_t nc = (cnt[
i] >> 1) + 1;
210 uint32_t totfr =
pixel->total_freq;
211 uint32_t
value, x = 0, cumfr = 0, cnt_x = 0;
212 int i, j,
ret,
c, cnt_c;
214 if ((
ret =
s->get_freq(rc, totfr, &
value)) < 0)
218 cnt_x =
pixel->lookup[x];
219 if (
value >= cumfr + cnt_x)
230 if (
value >= cumfr + cnt_c)
236 if (x >= 16 ||
c >= 256) {
240 if ((
ret =
s->decode(gb, rc, cumfr, cnt_c, totfr)) < 0)
248 for (
i = 0;
i < 256;
i++) {
249 uint32_t nc = (
pixel->freq[
i] >> 1) + 1;
253 for (
i = 0;
i < 16;
i++) {
255 uint32_t i16_17 =
i << 4;
256 for (j = 0; j < 16; j++)
257 sum +=
pixel->freq[i16_17 + j];
261 pixel->total_freq = totfr;
263 *rval =
c &
s->cbits;
271 const int cxshift =
s->cxshift;
278 *cx1 = (*cx << 6) & 0xFC0;
284 *cx1 = (*cx << 6) & 0xFC0;
290 *cx1 = (*cx << 6) & 0xFC0;
300 int cx = 0, cx1 = 0, k = 0;
301 int run, off, y = 0, x = 0,
ret;
302 uint32_t clr = 0,
r,
g,
b, backstep = linesize - avctx->
width;
303 uint32_t lx, ly, ptype;
309 while (k < avctx->
width + 1) {
320 clr = (
b << 16) + (
g << 8) +
r;
326 dst[y * linesize + x] = clr;
330 if (x >= avctx->
width) {
348 clr = (
b << 16) + (
g << 8) +
r;
359 dst, linesize, &lx, &ly,
360 backstep, off, &cx, &cx1);
369 uint32_t *dst,
int linesize,
370 uint32_t *prev,
int plinesize)
375 int backstep = linesize - avctx->
width;
377 if (bytestream2_get_byte(gb) == 0)
397 memset(
s->blocks, 0,
sizeof(*
s->blocks) *
s->nbcount);
409 while (min < s->nbcount && count-- > 0) {
410 s->blocks[
min++] = fill;
418 for (y = 0; y <
s->nby; y++) {
419 for (x = 0; x <
s->nbx; x++) {
420 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
422 if (
s->blocks[y *
s->nbx + x] == 0)
425 if (((
s->blocks[y *
s->nbx + x] - 1) & 1) > 0) {
436 if (((
s->blocks[y *
s->nbx + x] - 1) & 2) > 0) {
437 int i, j, by = y * 16, bx = x * 16;
448 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
449 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
452 for (
i = 0;
i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 +
i) < avctx->
height;
i++) {
453 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
454 dst[(by +
i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 +
i) * plinesize + bx + sx1 + mvx + j];
458 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
459 uint32_t
r,
g,
b, clr, ptype = 0;
461 if (bx >= avctx->
width)
464 for (; by < y * 16 + sy2 && by < avctx->
height;) {
473 clr = (
b << 16) + (
g << 8) +
r;
484 dst, prev, linesize, plinesize, &bx, &by,
485 backstep, sx1, sx2, &cx, &cx1);
513 type = bytestream2_peek_byte(gb);
519 frame->key_frame = 1;
521 s->current_frame->linesize[0] / 4);
522 }
else if (
type == 18) {
526 frame->key_frame = 1;
528 s->current_frame->linesize[0] / 4);
529 }
else if (
type == 34) {
530 frame->key_frame = 1;
533 s->current_frame->linesize[0] / 4);
534 }
else if (
type == 17 ||
type == 33) {
535 uint32_t clr, *dst = (uint32_t *)
s->current_frame->data[0];
541 frame->key_frame = 1;
544 uint16_t
value = bytestream2_get_le16(gb);
550 clr = (
r << 16) + (
g << 8) +
b;
552 clr = bytestream2_get_le24(gb);
554 for (y = 0; y < avctx->
height; y++) {
557 dst +=
s->current_frame->linesize[0] / 4;
559 }
else if (
type == 0 ||
type == 1) {
560 frame->key_frame = 0;
562 if (
s->version == 1 ||
s->version == 2)
564 s->current_frame->linesize[0] / 4,
565 (uint32_t *)
s->last_frame->data[0],
566 s->last_frame->linesize[0] / 4);
569 s->current_frame->linesize[0] / 4,
570 (uint32_t *)
s->last_frame->data[0],
571 s->last_frame->linesize[0] / 4);
589 uint8_t *dst =
frame->data[0];
597 for (y = 0; y < avctx->
height; y++) {
599 if (!(((uintptr_t)dst) & 7)) {
600 uint64_t *dst64 = (uint64_t *)dst;
602 for (x = 0; x <
w; x++) {
603 dst64[x] = (dst64[x] << 3) & 0xFCFCFCFCFCFCFCFCULL;
608 for (; x < avctx->
width * 4; x++) {
609 dst[x] = dst[x] << 3;
611 dst +=
frame->linesize[0];
620 frame->linesize[0] *= -1;
645 s->nbx = (avctx->
width + 15) / 16;
646 s->nby = (avctx->
height + 15) / 16;
647 s->nbcount =
s->nbx *
s->nby;
654 if (!
s->last_frame || !
s->current_frame)