35 uint16_t *freqs, uint16_t *freqs1,
36 uint16_t *cnts,
uint8_t *dectab)
38 uint32_t
a = 0,
b = 4096 / nsym,
c =
b - (
b >> 1);
42 for (
int d = 0; d < nsym; d++) {
46 for (
int q = a + 128 - 1 >> 7,
f = (a +
b - 1 >> 7) + 1; q <
f; q++)
55 for (
int i = 0;
i < 3;
i++) {
56 for (
int j = 0; j < 4096; j++) {
62 for (
int i = 0;
i < 6;
i++) {
80 for (
int i = 0;
i < 4;
i++) {
86 for (
int i = 0;
i < 2;
i++) {
92 for (
int i = 0;
i < 6;
i++) {
101 uint32_t
code = a * (rc->
code >> 12) + (rc->
code & 0xFFF) -
b;
104 code = bytestream2_get_byteu(gb) | (code << 8);
115 for (
int b = 0;
b < m->
size;
b++) {
128 for (
int c = m->
size - 1;
c >= index;
c--) {
141 if (*totfr + 50 > 4096)
148 uint16_t *
a, uint16_t *
b, uint32_t *
c,
int max)
150 uint32_t q,
g, maxpos, d, e = *
c, totfr = *
c;
153 for (d = 0; e <= 2048; d++)
157 *c = m->
freqs[maxpos];
158 m->
freqs[maxpos] += 4096 - e >> d;
160 for (q = 0, g = 0, e = 0; q < m->
size; q++) {
162 uint32_t p = e + f -
g;
163 uint32_t k = m->
freqs[q];
166 *value = rccode - e +
g;
175 if (p + k > rccode) {
183 if ((q != maxpos) && (m->
freqs[q] > m->
freqs[maxpos]))
185 if (totfr + 50 > 4096)
196 *value = g + rccode - e;
207 int c, d, e,
f, k, p, length,
i, j,
index;
208 uint16_t *freqs, *freqs1, *cnts;
217 for (i = 0; i < length; i++) {
227 for (j = 0, e = 0; j < 256; j++) {
236 k = ((f + e - 1) >> 7) + 1;
239 for (i = 0; i < k - p; i++)
244 memcpy(m, &n,
sizeof(n));
256 for (
int c = 0;
c <
len;
c++)
263 uint16_t cnts[256] = {0};
264 uint16_t freqs[512] = {0};
268 for (a = 1 << (0 < m->
fshift ? m->
fshift - 1 : 0), b = 0; b < 256; b++)
271 for (a = 0, b = m->
size; a < b; a++)
274 for (b = a = 0; b < 256; b++) {
275 freqs[2 *
b] = cnts[
b];
276 freqs[2 * b + 1] =
a;
284 for (b = 0, c = m->
size; b < c; b++) {
288 g = freqs[2 * e + 1];
289 m->
freqs[2 *
b] = freqs[2 * e];
298 int c, d, e,
f,
g, k, q, p;
303 for (c = m->
size, d = 256 - c, e = 0; e < c; e++)
306 for (e = 0; d <= 2048; e++)
309 for (q = d = 0, g = q = 0; g <
c; g++) {
315 n.
freqs[2 * g + 1] = d << e;
316 n.
cnts[
g] = k - (k >> 1);
327 for (p = f = g = 0; p <
c; p++) {
329 if (k > d && k < value) {
332 f = n.
freqs[2 * p + 1];
335 d = 0 < g ? f + g + (value - d - 1 << n.
fshift) : value << n.
fshift;
338 n.
freqs[2 * c + 1] = d;
339 n.
cnts[
c] = e - (e >> 1);
345 if (n.
cnts[32] + e > 4096)
349 for (c = 0, e = n.
size - 1; c < e; c++) {
350 for (g = c + 1, f = n.
size; g < f; g++) {
351 if (q = n.
freqs[2 * g], k = n.
freqs[2 * c], q > k) {
352 int l = n.
freqs[2 * c + 1];
353 int h = n.
freqs[2 * g + 1];
357 n.
freqs[2 * g + 1] = l;
364 memcpy(m, &n,
sizeof(n));
388 m->
freqs[2 * size + 1] = f2;
403 if (a > 0 && m->
cnts[a] > m->
cnts[a - 1]) {
406 e = m->
freqs[2 * a + 1];
407 g = m->
freqs[2 * (a - 1) + 1];
412 m->
freqs[2 * g + 1] = e;
416 if (m->
cnts[len] + b > 4096)
421 uint16_t *
a, uint16_t *
b)
423 int c, d, e,
f,
g, q;
425 for (c = 0, d = 0, e = 0, f = 0, g = 0, q = m->
size; g < q; g++) {
426 uint32_t p = m->
freqs[2 * g + 1];
429 uint32_t k = m->
freqs[2 *
g];
451 f = code - (d +
c) >> m->
fshift;
453 f = d + c + (f << m->
fshift);
475 static int cmpbytes(
const void *p1,
const void *p2)
477 int left = *(
const uint8_t *)p1;
478 int right = *(
const uint8_t *)p2;
490 for (i = 0; i <
b; i++)
494 memcpy(m, &n,
sizeof(n));
507 for (i = 0; i < n.
size; i++) {
511 for (i = 0; i < n.
size; i++) {
520 memcpy(m, &n,
sizeof(n));
533 for (i = 0; i <
size; i++) {
538 for (i = 0; i <
size; i++) {
547 for (i = 0; i <
size; i++, a += freqs)
552 memcpy(m, &n,
sizeof(n));
562 for (
int i = 0;
i <
size;
i++) {
582 int c, d, e,
f,
g, q;
590 d = 256 - c + (64 * c + 64);
591 for (e = 0; d <= 2048; e++) {
597 for (f = d = 0; f <
c; f++) {
611 n.
freqs[2 * p + 1] = g << e;
613 n.
cnts[p] = l - (l >> 1);
624 g = n.
freqs[2 * d + 1];
628 n.
freqs[2 * d + 1] = e;
633 memcpy(m, &n,
sizeof(n));
651 memcpy(m, &n,
sizeof(n));
661 for (
int i = 0;
i <
size;
i++) {
685 int c, d, e,
f,
g, q;
689 for (c = 0; c < 256; c++) {
695 for (c = m->
size, d = (4096 - (256 - c)) / (c + 1) | 0, e = d - (d >> 1), g = 0; g < c;) {
703 for (d = c = n.
cntsum = 0; 256 > d; d++) {
708 f = (c + g - 1 >> 7) + 1;
711 for (q = c + 128 - 1 >> 7; q <
f; q++) {
717 memcpy(m, &n,
sizeof(n));
726 for (
int i = 0;
i <
size;
i++) {
742 if (rc->
code1 == 0x20000) {
743 rc->
code = bytestream2_get_le32(gb);
749 uint16_t *freqs1, uint16_t *freqs2,
750 uint16_t *cnts,
uint8_t *dectable,
755 uint32_t
r, y,
a,
b, e,
g, q;
757 r = dectable[(rc->
code & 0xFFF
u) >> 7];
759 while (freqs2[r + 1] <= (rc->
code & 0xFFF)) {
772 if (*cntsum + 16 > 4096) {
774 for (
int c = 0,
i = 0;
i < max + 1;
i++) {
780 q = ((
c - 1) >> 7) + 1;
782 for (
int j = 0; j < q -
g; j++)
804 for (
int b = 0;
b < m->
size;
b++)
823 e += n.
freqs[g++] = 50;
824 for (; c < m->
size; g++, c++) {
834 memcpy(m, &n,
sizeof(n));
843 uint16_t
a = 0,
b = 0;
851 *value = bytestream2_get_byte(&s->
gb);
858 *value = bytestream2_get_byte(&s->
gb);
863 *value = bytestream2_get_byte(&s->
gb);
868 *value = bytestream2_get_byte(&s->
gb);
909 uint32_t *green, uint32_t *blue,
919 *cx1 = (*cx << 6) & 0xFC0;
926 *cx1 = (*cx << 6) & 0xFC0;
933 *cx1 = (*cx << 6) & 0xFC0;
941 rc->
code = bytestream2_get_le32(gb);
950 int cx = 0, cx1 = 0, k = 0;
951 int run, off, y = 0, x = 0, ret;
952 uint32_t backstep = linesize - avctx->
width;
953 uint32_t clr = 0, lx, ly, ptype,
r,
g,
b;
959 while (k < avctx->
width + 1) {
973 clr = (b << 16) + (g << 8) +
r;
979 dst[y * linesize + x] = clr;
983 if (x >= avctx->
width) {
1004 clr = (b << 16) + (g << 8) +
r;
1019 dst, linesize, &lx, &ly,
1020 backstep, off, &cx, &cx1);
1029 uint32_t *dst,
int linesize,
1030 uint32_t *prev,
int plinesize)
1034 int ret,
temp,
min,
max, x, y, cx = 0, cx1 = 0;
1035 int backstep = linesize - avctx->
width;
1036 int mvx = 0, mvy = 0;
1038 if (bytestream2_get_byte(gb) == 0)
1070 if (min > max || min >= s->
nbcount)
1075 while (min <= max) {
1093 while (min < s->nbcount && count-- > 0) {
1102 for (y = 0; y < s->
nby; y++) {
1103 for (x = 0; x < s->
nbx; x++) {
1104 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
1109 if (((s->
blocks[y * s->
nbx + x] + 1) & 1) > 0) {
1136 if (((s->
blocks[y * s->
nbx + x] + 3) & 2) > 0) {
1137 int i,
a,
b,
c, j, by = y * 16, bx = x * 16;
1149 code = a + ((s->
rc.
code >> 1) & 0xFFFFF800) -
b;
1151 code = bytestream2_get_byteu(gb) | (code << 8);
1174 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
1175 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
1178 for (i = 0; i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 + i) < avctx->
height; i++) {
1179 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
1180 dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];
1184 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
1185 uint32_t clr, ptype = 0,
r,
g,
b;
1187 if (bx >= avctx->
width)
1190 for (; by < y * 16 + sy2 && by < avctx->
height;) {
1203 clr = (b << 16) + (g << 8) +
r;
1218 dst, prev, linesize, plinesize, &bx, &by,
1219 backstep, sx1, sx2, &cx, &cx1);
static int update_model2_to_6(PixelModel3 *m, uint8_t value, int a4)
static int decode_run_i(AVCodecContext *avctx, uint32_t ptype, int run, int *px, int *py, uint32_t clr, uint32_t *dst, int linesize, uint32_t *plx, uint32_t *ply, uint32_t backstep, int off, int *cx, int *cx1)
static int add_symbol(PixelModel3 *m, int index, uint32_t symbol, int *totfr, int max)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void reinit_tables3(SCPRContext *s)
PixelModel3 pixel_model3[3][4096]
static int decode_unit3(SCPRContext *s, PixelModel3 *m, uint32_t code, uint32_t *value)
static void sync_code3(GetByteContext *gb, RangeCoder *rc)
static int decompress_p3(AVCodecContext *avctx, uint32_t *dst, int linesize, uint32_t *prev, int plinesize)
static int update_model1_to_2(PixelModel3 *m, uint32_t val)
#define u(width, name, range_min, range_max)
static int decode_run_p(AVCodecContext *avctx, uint32_t ptype, int run, int x, int y, uint32_t clr, uint32_t *dst, uint32_t *prev, int linesize, int plinesize, uint32_t *bx, uint32_t *by, uint32_t backstep, int sx1, int sx2, int *cx, int *cx1)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static int decode_adaptive45(PixelModel3 *m, int rccode, uint32_t *value, uint16_t *a, uint16_t *b, uint32_t *c, int max)
#define i(width, name, range_min, range_max)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static int decode3(GetByteContext *gb, RangeCoder *rc, uint32_t a, uint32_t b)
static void calc_sum5(PixelModel3 *m)
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
static void grow_dec(PixelModel3 *m)
#define FFDIFFSIGN(x, y)
Comparator.
int width
picture width / height.
static int update_model1_to_5(PixelModel3 *m, uint32_t val)
static void rescale(PixelModel3 *m, int *totfr)
#define FF_ARRAY_ELEMS(a)
static int update_model4_to_5(PixelModel3 *m, uint32_t value)
static int update_model5_to_6(PixelModel3 *m, uint8_t value)
static int add_dec(PixelModel3 *m, int sym, int f1, int f2)
Libavcodec external API header.
main external API structure.
static void init_rangecoder3(RangeCoder *rc, GetByteContext *gb)
static void incr_cntdec(PixelModel3 *m, int a)
static void renew_table3(uint32_t nsym, uint32_t *cntsum, uint16_t *freqs, uint16_t *freqs1, uint16_t *cnts, uint8_t *dectab)
static void rescale_dec(PixelModel3 *m)
static int decode_adaptive6(PixelModel3 *m, uint32_t code, uint32_t *value, uint16_t *a, uint16_t *b)
common internal api header.
static int update_model2_to_3(PixelModel3 *m, uint32_t val)
static void calc_sum(PixelModel3 *m)
static int decode_static2(PixelModel3 *m, uint32_t val)
static int update_model6_to_7(PixelModel3 *m)
static int decompress_i3(AVCodecContext *avctx, uint32_t *dst, int linesize)
static int update_model3_to_7(PixelModel3 *m, uint8_t value)
#define FFSWAP(type, a, b)
static int decode_units3(SCPRContext *s, uint32_t *red, uint32_t *green, uint32_t *blue, int *cx, int *cx1)
static int decode_static1(PixelModel3 *m, uint32_t val)
static int cmpbytes(const void *p1, const void *p2)
static double val(void *priv, double ch)
static int update_model1_to_4(PixelModel3 *m, uint32_t val)
static int decode_static3(PixelModel3 *m, uint32_t val)
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
static int decode_value3(SCPRContext *s, uint32_t max, uint32_t *cntsum, uint16_t *freqs1, uint16_t *freqs2, uint16_t *cnts, uint8_t *dectable, uint32_t *value)