34 #define BITSTREAM_READER_LE
37 #define BINK_FLAG_ALPHA 0x00100000
38 #define BINK_FLAG_GRAY 0x00020000
61 4, 8, 8, 5, 5, 11, 11, 4, 4, 7
65 0, 0, 0, 1, 1, 0, 1, 0, 0, 0
96 #define GET_HUFF(gb, tree) (tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\
97 bink_trees[(tree).vlc_num].bits, 1)]
230 }
while (size && size2);
246 uint8_t tmp1[16] = { 0 }, tmp2[16], *
in = tmp1, *
out = tmp2;
251 for (i = 0; i < 16; i++)
257 for (i = 0; i <=
len; i++) {
259 tmp1[tree->
syms[i]] = 1;
261 for (i = 0; i < 16 && len < 16 - 1; i++)
266 for (i = 0; i < 16; i++)
268 for (i = 0; i <=
len; i++) {
270 for (t = 0; t < 16; t += size << 1)
271 merge(gb, out + t, in + t, size);
274 memcpy(tree->
syms, in, 16);
290 for (i = 0; i < 16; i++)
307 #define CHECK_READ_VAL(gb, b, t) \
308 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
310 t = get_bits(gb, b->len); \
353 v = (v ^ sign) - sign;
362 v = (v ^ sign) - sign;
397 if (dec_end - b->
cur_dec < run)
443 sign = ((int8_t) v) >> 7;
444 v = ((v & 0x7F) ^ sign) - sign;
455 sign = ((int8_t) v) >> 7;
456 v = ((v & 0x7F) ^ sign) - sign;
466 #define DC_START_BITS 11
469 int start_bits,
int has_sign)
471 int i, j,
len, len2, bsize, sign,
v, v2;
472 int16_t *dst = (int16_t*)b->
cur_dec;
473 int16_t *dst_end = (int16_t*)b->
data_end;
476 v =
get_bits(gb, start_bits - has_sign);
479 v = (v ^ sign) - sign;
481 if (dst_end - dst < 1)
485 for (i = 0; i <
len; i += 8) {
486 len2 =
FFMIN(len - i, 8);
487 if (dst_end - dst < len2)
491 for (j = 0; j < len2; j++) {
495 v2 = (v2 ^ sign) - sign;
499 if (v < -32768 || v > 32767) {
505 for (j = 0; j < len2; j++)
550 const int mask = 1 << (bits - 1);
560 for (i = 0; i <
len; i++)
563 for (i = 0; i <
len; i++)
567 int16_t *dst = (int16_t*)b->
cur_dec;
570 for (i = 0; i <
len; i++)
573 for (i = 0; i <
len; i++)
605 const int32_t quant_matrices[16][64],
int q)
610 int list_start = 64, list_end = 64, list_pos;
616 coef_list[list_end] = 4; mode_list[list_end++] = 0;
617 coef_list[list_end] = 24; mode_list[list_end++] = 0;
618 coef_list[list_end] = 44; mode_list[list_end++] = 0;
619 coef_list[list_end] = 1; mode_list[list_end++] = 3;
620 coef_list[list_end] = 2; mode_list[list_end++] = 3;
621 coef_list[list_end] = 3; mode_list[list_end++] = 3;
623 for (bits =
get_bits(gb, 4) - 1; bits >= 0; bits--) {
624 list_pos = list_start;
625 while (list_pos < list_end) {
626 if (!(mode_list[list_pos] | coef_list[list_pos]) || !
get_bits1(gb)) {
630 ccoef = coef_list[list_pos];
631 mode = mode_list[list_pos];
634 coef_list[list_pos] = ccoef + 4;
635 mode_list[list_pos] = 1;
638 coef_list[list_pos] = 0;
639 mode_list[list_pos++] = 0;
641 for (i = 0; i < 4; i++, ccoef++) {
643 coef_list[--list_start] = ccoef;
644 mode_list[ list_start] = 3;
651 t = (t ^ sign) - sign;
653 block[scan[ccoef]] =
t;
654 coef_idx[coef_count++] = ccoef;
659 mode_list[list_pos] = 2;
660 for (i = 0; i < 3; i++) {
662 coef_list[list_end] = ccoef;
663 mode_list[list_end++] = 2;
672 t = (t ^ sign) - sign;
674 block[scan[ccoef]] =
t;
675 coef_idx[coef_count++] = ccoef;
676 coef_list[list_pos] = 0;
677 mode_list[list_pos++] = 0;
687 if (quant_idx > 15
U) {
693 quant = quant_matrices[quant_idx];
695 block[0] = (block[0] * quant[0]) >> 11;
696 for (i = 0; i < coef_count; i++) {
697 int idx = coef_idx[i];
698 block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
717 int list_start = 64, list_end = 64, list_pos;
719 int nz_coeff_count = 0;
721 coef_list[list_end] = 4; mode_list[list_end++] = 0;
722 coef_list[list_end] = 24; mode_list[list_end++] = 0;
723 coef_list[list_end] = 44; mode_list[list_end++] = 0;
724 coef_list[list_end] = 0; mode_list[list_end++] = 2;
727 for (i = 0; i < nz_coeff_count; i++) {
730 if (block[nz_coeff[i]] < 0)
731 block[nz_coeff[i]] -=
mask;
733 block[nz_coeff[i]] +=
mask;
738 list_pos = list_start;
739 while (list_pos < list_end) {
740 if (!(coef_list[list_pos] | mode_list[list_pos]) || !
get_bits1(gb)) {
744 ccoef = coef_list[list_pos];
745 mode = mode_list[list_pos];
748 coef_list[list_pos] = ccoef + 4;
749 mode_list[list_pos] = 1;
752 coef_list[list_pos] = 0;
753 mode_list[list_pos++] = 0;
755 for (i = 0; i < 4; i++, ccoef++) {
757 coef_list[--list_start] = ccoef;
758 mode_list[ list_start] = 3;
760 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
762 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
770 mode_list[list_pos] = 2;
771 for (i = 0; i < 3; i++) {
773 coef_list[list_end] = ccoef;
774 mode_list[list_end++] = 2;
778 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
780 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
781 coef_list[list_pos] = 0;
782 mode_list[list_pos++] = 0;
801 for (i = 0; i < 8; i++)
802 memcpy(tmp + i*8, src + i*stride, 8);
803 for (i = 0; i < 8; i++)
804 memcpy(dst + i*stride, tmp + i*8, 8);
808 int plane_idx,
int is_key,
int is_chroma)
812 uint8_t *dst, *ref, *ref_start, *ref_end;
819 int ybias = is_key ? -15 : 0;
827 ref_start = frame->
data[plane_idx];
828 ref_end = frame->
data[plane_idx] + (bh * frame->
linesize[plane_idx] + bw) * 8;
830 for (i = 0; i < 64; i++)
831 coordmap[i] = (i & 7) + (i >> 3) * stride;
833 for (by = 0; by < bh; by++) {
839 dst = frame->
data[plane_idx] + 8*by*stride;
840 for (bx = 0; bx < bw; bx++, dst += 8) {
861 for (j = 0; j <
run; j++)
862 dst[coordmap[*scan++]] = v;
864 for (j = 0; j <
run; j++)
872 memset(dctblock, 0,
sizeof(*dctblock) * 64);
881 ref = dst + xoff + yoff * stride;
882 if (ref < ref_start || ref + 8*stride > ref_end) {
897 ref = dst + xoff + yoff * stride;
898 if (ref < ref_start || ref + 8 * stride > ref_end) {
905 memset(dctblock, 0,
sizeof(*dctblock) * 64);
916 for (i = 0; i < 2; i++)
918 for (i = 0; i < 8; i++) {
920 for (j = 0; j < 8; j++, v >>= 1)
921 dst[i*stride + j] = col[v & 1];
927 ref = dst + xoff + yoff * stride;
928 if (ref < ref_start || ref + 8 * stride > ref_end) {
937 for (i = 0; i < 8; i++)
954 int plane_idx,
int is_chroma)
958 uint8_t *dst, *prev, *ref, *ref_start, *ref_end;
977 : frame->
data[plane_idx];
979 + (bw - 1 + c->
last->
linesize[plane_idx] * (bh - 1)) * 8;
981 for (i = 0; i < 64; i++)
982 coordmap[i] = (i & 7) + (i >> 3) * stride;
984 for (by = 0; by < bh; by++) {
1006 dst = frame->
data[plane_idx] + 8*by*stride;
1008 : frame->
data[plane_idx]) + 8*by*stride;
1009 for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1038 for (j = 0; j <
run; j++)
1039 ublock[*scan++] = v;
1041 for (j = 0; j <
run; j++)
1049 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1059 for (i = 0; i < 2; i++)
1061 for (j = 0; j < 8; j++) {
1063 for (i = 0; i < 8; i++, v >>= 1)
1064 ublock[i + j*8] = col[v & 1];
1068 for (j = 0; j < 8; j++)
1069 for (i = 0; i < 8; i++)
1085 ref = prev + xoff + yoff * stride;
1086 if (ref < ref_start || ref > ref_end) {
1088 bx*8 + xoff, by*8 + yoff);
1106 for (j = 0; j <
run; j++)
1107 dst[coordmap[*scan++]] = v;
1109 for (j = 0; j <
run; j++)
1119 ref = prev + xoff + yoff * stride;
1120 if (ref < ref_start || ref > ref_end) {
1122 bx*8 + xoff, by*8 + yoff);
1132 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1144 ref = prev + xoff + yoff * stride;
1145 if (ref < ref_start || ref > ref_end) {
1147 bx*8 + xoff, by*8 + yoff);
1151 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1157 for (i = 0; i < 2; i++)
1159 for (i = 0; i < 8; i++) {
1161 for (j = 0; j < 8; j++, v >>= 1)
1162 dst[i*stride + j] = col[v & 1];
1166 for (i = 0; i < 8; i++)
1187 int plane, plane_idx,
ret;
1188 int bits_count = pkt->
size << 3;
1212 for (plane = 0; plane < 3; plane++) {
1213 plane_idx = (!plane || !c->
swap_planes) ? plane : (plane ^ 3);
1246 static const int s[64]={
1247 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1248 1489322693,2065749918,1945893874,1751258219,1489322693,1170153332, 806015634, 410903207,
1249 1402911301,1945893874,1832991949,1649649171,1402911301,1102260336, 759250125, 387062357,
1250 1262586814,1751258219,1649649171,1484645031,1262586814, 992008094, 683307060, 348346918,
1251 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1252 843633538,1170153332,1102260336, 992008094, 843633538, 662838617, 456571181, 232757969,
1253 581104888, 806015634, 759250125, 683307060, 581104888, 456571181, 314491699, 160326478,
1254 296244703, 410903207, 387062357, 348346918, 296244703, 232757969, 160326478, 81733730,
1258 for (i = 0; i < 64; i++)
1261 for (j = 0; j < 16; j++) {
1262 for (i = 0; i < 64; i++) {
1263 int k = inv_bink_scan[i];
1276 static int binkb_initialised = 0;
1288 if (!bink_trees[15].table) {
1289 for (i = 0; i < 16; i++) {
1291 bink_trees[i].
table = table + i*128;
1293 init_vlc(&bink_trees[i], maxbits, 16,
1319 if (!binkb_initialised) {
1321 binkb_initialised = 1;
1346 .
name =
"binkvideo",