31 #define BITSTREAM_READER_LE
34 #define BINK_FLAG_ALPHA 0x00100000
35 #define BINK_FLAG_GRAY 0x00020000
58 4, 8, 8, 5, 5, 11, 11, 4, 4, 7
62 0, 0, 0, 1, 1, 0, 1, 0, 0, 0
93 #define GET_HUFF(gb, tree) (tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\
94 bink_trees[(tree).vlc_num].bits, 1)]
225 }
while (size && size2);
241 uint8_t tmp1[16] = { 0 }, tmp2[16], *in = tmp1, *out = tmp2;
246 for (i = 0; i < 16; i++)
252 for (i = 0; i <=
len; i++) {
254 tmp1[tree->
syms[i]] = 1;
256 for (i = 0; i < 16 && len < 16 - 1; i++)
261 for (i = 0; i < 16; i++)
263 for (i = 0; i <=
len; i++) {
265 for (t = 0; t < 16; t += size << 1)
266 merge(gb, out + t, in + t, size);
269 memcpy(tree->
syms, in, 16);
285 for (i = 0; i < 16; i++)
302 #define CHECK_READ_VAL(gb, b, t) \
303 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
305 t = get_bits(gb, b->len); \
348 v = (v ^ sign) - sign;
357 v = (v ^ sign) - sign;
392 if (dec_end - b->
cur_dec < run)
438 sign = ((int8_t) v) >> 7;
439 v = ((v & 0x7F) ^ sign) - sign;
450 sign = ((int8_t) v) >> 7;
451 v = ((v & 0x7F) ^ sign) - sign;
461 #define DC_START_BITS 11
464 int start_bits,
int has_sign)
466 int i, j,
len, len2, bsize, sign, v, v2;
468 int16_t *dst_end = (int16_t*)b->
data_end;
471 v =
get_bits(gb, start_bits - has_sign);
474 v = (v ^ sign) - sign;
476 if (dst_end - dst < 1)
480 for (i = 0; i <
len; i += 8) {
481 len2 =
FFMIN(len - i, 8);
482 if (dst_end - dst < len2)
486 for (j = 0; j < len2; j++) {
490 v2 = (v2 ^ sign) - sign;
494 if (v < -32768 || v > 32767) {
500 for (j = 0; j < len2; j++)
545 const int mask = 1 << (bits - 1);
555 for (i = 0; i <
len; i++)
558 for (i = 0; i <
len; i++)
565 for (i = 0; i <
len; i++)
568 for (i = 0; i <
len; i++)
600 const int32_t quant_matrices[16][64],
int q)
605 int list_start = 64, list_end = 64, list_pos;
611 coef_list[list_end] = 4; mode_list[list_end++] = 0;
612 coef_list[list_end] = 24; mode_list[list_end++] = 0;
613 coef_list[list_end] = 44; mode_list[list_end++] = 0;
614 coef_list[list_end] = 1; mode_list[list_end++] = 3;
615 coef_list[list_end] = 2; mode_list[list_end++] = 3;
616 coef_list[list_end] = 3; mode_list[list_end++] = 3;
618 for (bits =
get_bits(gb, 4) - 1; bits >= 0; bits--) {
619 list_pos = list_start;
620 while (list_pos < list_end) {
621 if (!(mode_list[list_pos] | coef_list[list_pos]) || !
get_bits1(gb)) {
625 ccoef = coef_list[list_pos];
626 mode = mode_list[list_pos];
629 coef_list[list_pos] = ccoef + 4;
630 mode_list[list_pos] = 1;
633 coef_list[list_pos] = 0;
634 mode_list[list_pos++] = 0;
636 for (i = 0; i < 4; i++, ccoef++) {
638 coef_list[--list_start] = ccoef;
639 mode_list[ list_start] = 3;
646 t = (t ^ sign) - sign;
648 block[scan[ccoef]] =
t;
649 coef_idx[coef_count++] = ccoef;
654 mode_list[list_pos] = 2;
655 for (i = 0; i < 3; i++) {
657 coef_list[list_end] = ccoef;
658 mode_list[list_end++] = 2;
667 t = (t ^ sign) - sign;
669 block[scan[ccoef]] =
t;
670 coef_idx[coef_count++] = ccoef;
671 coef_list[list_pos] = 0;
672 mode_list[list_pos++] = 0;
682 if (quant_idx > 15
U) {
688 quant = quant_matrices[quant_idx];
690 block[0] = (block[0] * quant[0]) >> 11;
691 for (i = 0; i < coef_count; i++) {
692 int idx = coef_idx[i];
693 block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
712 int list_start = 64, list_end = 64, list_pos;
714 int nz_coeff_count = 0;
716 coef_list[list_end] = 4; mode_list[list_end++] = 0;
717 coef_list[list_end] = 24; mode_list[list_end++] = 0;
718 coef_list[list_end] = 44; mode_list[list_end++] = 0;
719 coef_list[list_end] = 0; mode_list[list_end++] = 2;
722 for (i = 0; i < nz_coeff_count; i++) {
725 if (block[nz_coeff[i]] < 0)
726 block[nz_coeff[i]] -=
mask;
728 block[nz_coeff[i]] +=
mask;
733 list_pos = list_start;
734 while (list_pos < list_end) {
735 if (!(coef_list[list_pos] | mode_list[list_pos]) || !
get_bits1(gb)) {
739 ccoef = coef_list[list_pos];
740 mode = mode_list[list_pos];
743 coef_list[list_pos] = ccoef + 4;
744 mode_list[list_pos] = 1;
747 coef_list[list_pos] = 0;
748 mode_list[list_pos++] = 0;
750 for (i = 0; i < 4; i++, ccoef++) {
752 coef_list[--list_start] = ccoef;
753 mode_list[ list_start] = 3;
755 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
757 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
765 mode_list[list_pos] = 2;
766 for (i = 0; i < 3; i++) {
768 coef_list[list_end] = ccoef;
769 mode_list[list_end++] = 2;
773 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
775 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
776 coef_list[list_pos] = 0;
777 mode_list[list_pos++] = 0;
796 for (i = 0; i < 8; i++)
797 memcpy(tmp + i*8, src + i*stride, 8);
798 for (i = 0; i < 8; i++)
799 memcpy(dst + i*stride, tmp + i*8, 8);
803 int is_key,
int is_chroma)
814 int ybias = is_key ? -15 : 0;
822 ref_start = c->
pic.
data[plane_idx];
825 for (i = 0; i < 64; i++)
826 coordmap[i] = (i & 7) + (i >> 3) * stride;
828 for (by = 0; by < bh; by++) {
835 for (bx = 0; bx < bw; bx++, dst += 8) {
856 for (j = 0; j <
run; j++)
857 dst[coordmap[*scan++]] = v;
859 for (j = 0; j <
run; j++)
867 memset(dctblock, 0,
sizeof(*dctblock) * 64);
876 ref = dst + xoff + yoff *
stride;
877 if (ref < ref_start || ref + 8*stride > ref_end) {
879 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
892 ref = dst + xoff + yoff *
stride;
893 if (ref < ref_start || ref + 8 * stride > ref_end) {
895 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
900 memset(dctblock, 0,
sizeof(*dctblock) * 64);
911 for (i = 0; i < 2; i++)
913 for (i = 0; i < 8; i++) {
915 for (j = 0; j < 8; j++, v >>= 1)
916 dst[i*stride + j] = col[v & 1];
922 ref = dst + xoff + yoff *
stride;
923 if (ref < ref_start || ref + 8 * stride > ref_end) {
925 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
932 for (i = 0; i < 8; i++)
953 uint8_t *
dst, *prev, *ref, *ref_start, *ref_end;
974 + (bw - 1 + c->
last.
linesize[plane_idx] * (bh - 1)) * 8;
976 for (i = 0; i < 64; i++)
977 coordmap[i] = (i & 7) + (i >> 3) * stride;
979 for (by = 0; by < bh; by++) {
1003 : c->
pic.
data[plane_idx]) + 8*by*stride;
1004 for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1033 for (j = 0; j <
run; j++)
1034 ublock[*scan++] = v;
1036 for (j = 0; j <
run; j++)
1044 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1054 for (i = 0; i < 2; i++)
1056 for (j = 0; j < 8; j++) {
1058 for (i = 0; i < 8; i++, v >>= 1)
1059 ublock[i + j*8] = col[v & 1];
1063 for (j = 0; j < 8; j++)
1064 for (i = 0; i < 8; i++)
1080 ref = prev + xoff + yoff *
stride;
1081 if (ref < ref_start || ref > ref_end) {
1083 bx*8 + xoff, by*8 + yoff);
1101 for (j = 0; j <
run; j++)
1102 dst[coordmap[*scan++]] = v;
1104 for (j = 0; j <
run; j++)
1114 ref = prev + xoff + yoff *
stride;
1115 if (ref < ref_start || ref > ref_end) {
1117 bx*8 + xoff, by*8 + yoff);
1127 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1139 ref = prev + xoff + yoff *
stride;
1140 if (ref < ref_start || ref > ref_end) {
1142 bx*8 + xoff, by*8 + yoff);
1146 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1152 for (i = 0; i < 2; i++)
1154 for (i = 0; i < 8; i++) {
1156 for (j = 0; j < 8; j++, v >>= 1)
1157 dst[i*stride + j] = col[v & 1];
1161 for (i = 0; i < 8; i++)
1181 int plane, plane_idx;
1182 int bits_count = pkt->
size << 3;
1209 for (plane = 0; plane < 3; plane++) {
1210 plane_idx = (!plane || !c->
swap_planes) ? plane : (plane ^ 3);
1240 static const int s[64]={
1241 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1242 1489322693,2065749918,1945893874,1751258219,1489322693,1170153332, 806015634, 410903207,
1243 1402911301,1945893874,1832991949,1649649171,1402911301,1102260336, 759250125, 387062357,
1244 1262586814,1751258219,1649649171,1484645031,1262586814, 992008094, 683307060, 348346918,
1245 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1246 843633538,1170153332,1102260336, 992008094, 843633538, 662838617, 456571181, 232757969,
1247 581104888, 806015634, 759250125, 683307060, 581104888, 456571181, 314491699, 160326478,
1248 296244703, 410903207, 387062357, 348346918, 296244703, 232757969, 160326478, 81733730,
1252 for (i = 0; i < 64; i++)
1255 for (j = 0; j < 16; j++) {
1256 for (i = 0; i < 64; i++) {
1257 int k = inv_bink_scan[i];
1270 static int binkb_initialised = 0;
1282 if (!bink_trees[15].table) {
1283 for (i = 0; i < 16; i++) {
1285 bink_trees[i].
table = table + i*128;
1287 init_vlc(&bink_trees[i], maxbits, 16,
1312 if (!binkb_initialised) {
1314 binkb_initialised = 1;
1335 .
name =
"binkvideo",