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;
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;
237 for (i = 0; i < k - p; i++)
242 memcpy(m, &n,
sizeof(n));
254 for (
int c = 0;
c <
len;
c++)
261 uint16_t cnts[256] = {0};
262 uint16_t freqs[512] = {0};
266 for (a = 1 << (0 < m->
fshift ? m->
fshift - 1 : 0), b = 0; b < 256; b++)
269 for (a = 0, b = m->
size; a < b; a++)
272 for (b = a = 0; b < 256; b++) {
273 freqs[2 *
b] = cnts[
b];
274 freqs[2 * b + 1] =
a;
282 for (b = 0, c = m->
size; b < c; b++) {
286 g = freqs[2 * e + 1];
287 m->
freqs[2 *
b] = freqs[2 * e];
296 int c, d, e,
f,
g, k, q, p;
301 for (c = m->
size, d = 256 - c, e = 0; e < c; e++)
304 for (e = 0; d <= 2048; e++)
307 for (q = d = 0, g = q = 0; g <
c; g++) {
313 n.
freqs[2 * g + 1] = d << e;
314 n.
cnts[
g] = k - (k >> 1);
325 for (p = f = g = 0; p <
c; p++) {
327 if (k > d && k < value) {
330 f = n.
freqs[2 * p + 1];
333 d = 0 < g ? f + g + (value - d - 1 << n.
fshift) : value << n.
fshift;
336 n.
freqs[2 * c + 1] = d;
337 n.
cnts[
c] = e - (e >> 1);
343 if (n.
cnts[32] + e > 4096)
347 for (c = 0, e = n.
size - 1; c < e; c++) {
348 for (g = c + 1, f = n.
size; g < f; g++) {
349 if (q = n.
freqs[2 * g], k = n.
freqs[2 * c], q > k) {
350 int l = n.
freqs[2 * c + 1];
351 int h = n.
freqs[2 * g + 1];
355 n.
freqs[2 * g + 1] = l;
362 memcpy(m, &n,
sizeof(n));
386 m->
freqs[2 * size + 1] = f2;
401 if (a > 0 && m->
cnts[a] > m->
cnts[a - 1]) {
404 e = m->
freqs[2 * a + 1];
405 g = m->
freqs[2 * (a - 1) + 1];
410 m->
freqs[2 * g + 1] = e;
414 if (m->
cnts[len] + b > 4096)
419 uint16_t *
a, uint16_t *
b)
421 int c, d, e,
f,
g, q;
423 for (c = 0, d = 0, e = 0, f = 0, g = 0, q = m->
size; g < q; g++) {
424 uint32_t p = m->
freqs[2 * g + 1];
427 uint32_t k = m->
freqs[2 *
g];
449 f = code - (d +
c) >> m->
fshift;
451 f = d + c + (f << m->
fshift);
473 static int cmpbytes(
const void *p1,
const void *p2)
475 int left = *(
const uint8_t *)p1;
476 int right = *(
const uint8_t *)p2;
488 for (i = 0; i <
b; i++)
492 memcpy(m, &n,
sizeof(n));
505 for (i = 0; i < n.
size; i++) {
509 for (i = 0; i < n.
size; i++) {
518 memcpy(m, &n,
sizeof(n));
531 for (i = 0; i <
size; i++) {
536 for (i = 0; i <
size; i++) {
545 for (i = 0; i <
size; i++, a += freqs)
550 memcpy(m, &n,
sizeof(n));
560 for (
int i = 0;
i <
size;
i++) {
580 int c, d, e,
f,
g, q;
588 d = 256 - c + (64 * c + 64);
589 for (e = 0; d <= 2048; e++) {
595 for (f = d = 0; f <
c; f++) {
609 n.
freqs[2 * p + 1] = g << e;
611 n.
cnts[p] = l - (l >> 1);
622 g = n.
freqs[2 * d + 1];
626 n.
freqs[2 * d + 1] = e;
631 memcpy(m, &n,
sizeof(n));
649 memcpy(m, &n,
sizeof(n));
659 for (
int i = 0;
i <
size;
i++) {
683 int c, d, e,
f,
g, q;
687 for (c = 0; c < 256; c++) {
693 for (c = m->
size, d = (4096 - (256 - c)) / (c + 1) | 0, e = d - (d >> 1), g = 0; g < c;) {
701 for (d = c = n.
cntsum = 0; 256 > d; d++) {
705 for (g = n.
freqs[e], q = c + 128 - 1 >> 7, f = (c + g - 1 >> 7) + 1; q < f; q++) {
711 memcpy(m, &n,
sizeof(n));
720 for (
int i = 0;
i <
size;
i++) {
736 if (rc->
code1 == 0x20000) {
737 rc->
code = bytestream2_get_le32(gb);
743 uint16_t *freqs1, uint16_t *freqs2,
744 uint16_t *cnts,
uint8_t *dectable,
749 uint32_t
r, y,
a,
b, e,
g, q;
751 r = dectable[(rc->
code & 0xFFF
u) >> 7];
753 while (freqs2[r + 1] <= (rc->
code & 0xFFF)) {
766 if (*cntsum + 16 > 4096) {
768 for (
int c = 0,
i = 0;
i < max + 1;
i++) {
774 q = ((
c - 1) >> 7) + 1;
776 for (
int j = 0; j < q -
g; j++)
798 for (
int b = 0;
b < m->
size;
b++)
817 e += n.
freqs[g++] = 50;
818 for (; c < m->
size; g++, c++) {
828 memcpy(m, &n,
sizeof(n));
837 uint16_t
a = 0,
b = 0;
844 *value = bytestream2_get_byte(&s->
gb);
851 *value = bytestream2_get_byte(&s->
gb);
856 *value = bytestream2_get_byte(&s->
gb);
861 *value = bytestream2_get_byte(&s->
gb);
898 uint32_t *green, uint32_t *blue,
908 *cx1 = (*cx << 6) & 0xFC0;
915 *cx1 = (*cx << 6) & 0xFC0;
922 *cx1 = (*cx << 6) & 0xFC0;
930 rc->
code = bytestream2_get_le32(gb);
939 int cx = 0, cx1 = 0, k = 0;
940 int run, off, y = 0, x = 0, ret;
941 uint32_t backstep = linesize - avctx->
width;
942 uint32_t clr = 0, lx, ly, ptype,
r,
g,
b;
948 while (k < avctx->
width + 1) {
962 clr = (b << 16) + (g << 8) +
r;
968 dst[y * linesize + x] = clr;
972 if (x >= avctx->
width) {
993 clr = (b << 16) + (g << 8) +
r;
1008 dst, linesize, &lx, &ly,
1009 backstep, off, &cx, &cx1);
1018 uint32_t *dst,
int linesize,
1019 uint32_t *prev,
int plinesize)
1023 int ret,
temp,
min,
max, x, y, cx = 0, cx1 = 0;
1024 int backstep = linesize - avctx->
width;
1025 int mvx = 0, mvy = 0;
1027 if (bytestream2_get_byte(gb) == 0)
1059 if (min > max || min >= s->
nbcount)
1064 while (min <= max) {
1082 while (min < s->nbcount && count-- > 0) {
1091 for (y = 0; y < s->
nby; y++) {
1092 for (x = 0; x < s->
nbx; x++) {
1093 int sy1 = 0, sy2 = 16, sx1 = 0, sx2 = 16;
1098 if (((s->
blocks[y * s->
nbx + x] + 1) & 1) > 0) {
1125 if (((s->
blocks[y * s->
nbx + x] + 3) & 2) > 0) {
1126 int i,
a,
b,
c, j, by = y * 16, bx = x * 16;
1138 code = a + ((s->
rc.
code >> 1) & 0xFFFFF800) -
b;
1140 code = bytestream2_get_byteu(gb) | (code << 8);
1163 if (by + mvy + sy1 < 0 || bx + mvx + sx1 < 0 ||
1164 by + mvy + sy1 >= avctx->
height || bx + mvx + sx1 >= avctx->
width)
1167 for (i = 0; i < sy2 - sy1 && (by + sy1 +
i) < avctx->
height && (by + mvy + sy1 + i) < avctx->
height; i++) {
1168 for (j = 0; j < sx2 - sx1 && (bx + sx1 + j) < avctx->
width && (bx + mvx + sx1 + j) < avctx->
width; j++) {
1169 dst[(by + i + sy1) * linesize + bx + sx1 + j] = prev[(by + mvy + sy1 + i) * plinesize + bx + sx1 + mvx + j];
1173 int run, bx = x * 16 + sx1, by = y * 16 + sy1;
1174 uint32_t clr, ptype = 0,
r,
g,
b;
1176 for (; by < y * 16 + sy2 && by < avctx->
height;) {
1189 clr = (b << 16) + (g << 8) +
r;
1204 dst, prev, linesize, plinesize, &bx, &by,
1205 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)
const char const char void * val
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 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 av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
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)
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 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)