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)]
229 }
while (size && size2);
245 uint8_t tmp1[16] = { 0 }, tmp2[16], *
in = tmp1, *
out = tmp2;
250 for (i = 0; i < 16; i++)
256 for (i = 0; i <=
len; i++) {
258 tmp1[tree->
syms[i]] = 1;
260 for (i = 0; i < 16 && len < 16 - 1; i++)
265 for (i = 0; i < 16; i++)
267 for (i = 0; i <=
len; i++) {
269 for (t = 0; t < 16; t += size << 1)
270 merge(gb, out + t, in + t, size);
273 memcpy(tree->
syms, in, 16);
289 for (i = 0; i < 16; i++)
306 #define CHECK_READ_VAL(gb, b, t) \
307 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
309 t = get_bits(gb, b->len); \
352 v = (v ^ sign) - sign;
361 v = (v ^ sign) - sign;
396 if (dec_end - b->
cur_dec < run)
442 sign = ((int8_t) v) >> 7;
443 v = ((v & 0x7F) ^ sign) - sign;
454 sign = ((int8_t) v) >> 7;
455 v = ((v & 0x7F) ^ sign) - sign;
465 #define DC_START_BITS 11
468 int start_bits,
int has_sign)
470 int i, j,
len, len2, bsize, sign,
v, v2;
471 int16_t *dst = (int16_t*)b->
cur_dec;
472 int16_t *dst_end = (int16_t*)b->
data_end;
475 v =
get_bits(gb, start_bits - has_sign);
478 v = (v ^ sign) - sign;
480 if (dst_end - dst < 1)
484 for (i = 0; i <
len; i += 8) {
485 len2 =
FFMIN(len - i, 8);
486 if (dst_end - dst < len2)
490 for (j = 0; j < len2; j++) {
494 v2 = (v2 ^ sign) - sign;
498 if (v < -32768 || v > 32767) {
504 for (j = 0; j < len2; j++)
549 const int mask = 1 << (bits - 1);
559 for (i = 0; i <
len; i++)
562 for (i = 0; i <
len; i++)
566 int16_t *dst = (int16_t*)b->
cur_dec;
569 for (i = 0; i <
len; i++)
572 for (i = 0; i <
len; i++)
604 const int32_t quant_matrices[16][64],
int q)
609 int list_start = 64, list_end = 64, list_pos;
615 coef_list[list_end] = 4; mode_list[list_end++] = 0;
616 coef_list[list_end] = 24; mode_list[list_end++] = 0;
617 coef_list[list_end] = 44; mode_list[list_end++] = 0;
618 coef_list[list_end] = 1; mode_list[list_end++] = 3;
619 coef_list[list_end] = 2; mode_list[list_end++] = 3;
620 coef_list[list_end] = 3; mode_list[list_end++] = 3;
622 for (bits =
get_bits(gb, 4) - 1; bits >= 0; bits--) {
623 list_pos = list_start;
624 while (list_pos < list_end) {
625 if (!(mode_list[list_pos] | coef_list[list_pos]) || !
get_bits1(gb)) {
629 ccoef = coef_list[list_pos];
630 mode = mode_list[list_pos];
633 coef_list[list_pos] = ccoef + 4;
634 mode_list[list_pos] = 1;
637 coef_list[list_pos] = 0;
638 mode_list[list_pos++] = 0;
640 for (i = 0; i < 4; i++, ccoef++) {
642 coef_list[--list_start] = ccoef;
643 mode_list[ list_start] = 3;
650 t = (t ^ sign) - sign;
652 block[scan[ccoef]] =
t;
653 coef_idx[coef_count++] = ccoef;
658 mode_list[list_pos] = 2;
659 for (i = 0; i < 3; i++) {
661 coef_list[list_end] = ccoef;
662 mode_list[list_end++] = 2;
671 t = (t ^ sign) - sign;
673 block[scan[ccoef]] =
t;
674 coef_idx[coef_count++] = ccoef;
675 coef_list[list_pos] = 0;
676 mode_list[list_pos++] = 0;
686 if (quant_idx > 15
U) {
692 quant = quant_matrices[quant_idx];
694 block[0] = (block[0] * quant[0]) >> 11;
695 for (i = 0; i < coef_count; i++) {
696 int idx = coef_idx[i];
697 block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
716 int list_start = 64, list_end = 64, list_pos;
718 int nz_coeff_count = 0;
720 coef_list[list_end] = 4; mode_list[list_end++] = 0;
721 coef_list[list_end] = 24; mode_list[list_end++] = 0;
722 coef_list[list_end] = 44; mode_list[list_end++] = 0;
723 coef_list[list_end] = 0; mode_list[list_end++] = 2;
726 for (i = 0; i < nz_coeff_count; i++) {
729 if (block[nz_coeff[i]] < 0)
730 block[nz_coeff[i]] -=
mask;
732 block[nz_coeff[i]] +=
mask;
737 list_pos = list_start;
738 while (list_pos < list_end) {
739 if (!(coef_list[list_pos] | mode_list[list_pos]) || !
get_bits1(gb)) {
743 ccoef = coef_list[list_pos];
744 mode = mode_list[list_pos];
747 coef_list[list_pos] = ccoef + 4;
748 mode_list[list_pos] = 1;
751 coef_list[list_pos] = 0;
752 mode_list[list_pos++] = 0;
754 for (i = 0; i < 4; i++, ccoef++) {
756 coef_list[--list_start] = ccoef;
757 mode_list[ list_start] = 3;
759 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
761 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
769 mode_list[list_pos] = 2;
770 for (i = 0; i < 3; i++) {
772 coef_list[list_end] = ccoef;
773 mode_list[list_end++] = 2;
777 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
779 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
780 coef_list[list_pos] = 0;
781 mode_list[list_pos++] = 0;
800 for (i = 0; i < 8; i++)
801 memcpy(tmp + i*8, src + i*stride, 8);
802 for (i = 0; i < 8; i++)
803 memcpy(dst + i*stride, tmp + i*8, 8);
807 int plane_idx,
int is_key,
int is_chroma)
811 uint8_t *dst, *ref, *ref_start, *ref_end;
818 int ybias = is_key ? -15 : 0;
826 ref_start = frame->
data[plane_idx];
827 ref_end = frame->
data[plane_idx] + (bh * frame->
linesize[plane_idx] + bw) * 8;
829 for (i = 0; i < 64; i++)
830 coordmap[i] = (i & 7) + (i >> 3) * stride;
832 for (by = 0; by < bh; by++) {
839 for (bx = 0; bx < bw; bx++, dst += 8) {
860 for (j = 0; j <
run; j++)
861 dst[coordmap[*scan++]] = v;
863 for (j = 0; j <
run; j++)
871 memset(dctblock, 0,
sizeof(*dctblock) * 64);
880 ref = dst + xoff + yoff *
stride;
881 if (ref < ref_start || ref + 8*stride > ref_end) {
883 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
896 ref = dst + xoff + yoff *
stride;
897 if (ref < ref_start || ref + 8 * stride > ref_end) {
899 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
904 memset(dctblock, 0,
sizeof(*dctblock) * 64);
915 for (i = 0; i < 2; i++)
917 for (i = 0; i < 8; i++) {
919 for (j = 0; j < 8; j++, v >>= 1)
920 dst[i*stride + j] = col[v & 1];
926 ref = dst + xoff + yoff *
stride;
927 if (ref < ref_start || ref + 8 * stride > ref_end) {
929 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
936 for (i = 0; i < 8; i++)
953 int plane_idx,
int is_chroma)
957 uint8_t *dst, *prev, *ref, *ref_start, *ref_end;
976 : frame->
data[plane_idx];
978 + (bw - 1 + c->
last->
linesize[plane_idx] * (bh - 1)) * 8;
980 for (i = 0; i < 64; i++)
981 coordmap[i] = (i & 7) + (i >> 3) * stride;
983 for (by = 0; by < bh; by++) {
1007 : frame->
data[plane_idx]) + 8*by*stride;
1008 for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1037 for (j = 0; j <
run; j++)
1038 ublock[*scan++] = v;
1040 for (j = 0; j <
run; j++)
1048 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1058 for (i = 0; i < 2; i++)
1060 for (j = 0; j < 8; j++) {
1062 for (i = 0; i < 8; i++, v >>= 1)
1063 ublock[i + j*8] = col[v & 1];
1067 for (j = 0; j < 8; j++)
1068 for (i = 0; i < 8; i++)
1084 ref = prev + xoff + yoff *
stride;
1085 if (ref < ref_start || ref > ref_end) {
1087 bx*8 + xoff, by*8 + yoff);
1105 for (j = 0; j <
run; j++)
1106 dst[coordmap[*scan++]] = v;
1108 for (j = 0; j <
run; j++)
1118 ref = prev + xoff + yoff *
stride;
1119 if (ref < ref_start || ref > ref_end) {
1121 bx*8 + xoff, by*8 + yoff);
1131 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1143 ref = prev + xoff + yoff *
stride;
1144 if (ref < ref_start || ref > ref_end) {
1146 bx*8 + xoff, by*8 + yoff);
1150 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1156 for (i = 0; i < 2; i++)
1158 for (i = 0; i < 8; i++) {
1160 for (j = 0; j < 8; j++, v >>= 1)
1161 dst[i*stride + j] = col[v & 1];
1165 for (i = 0; i < 8; i++)
1186 int plane, plane_idx,
ret;
1187 int bits_count = pkt->
size << 3;
1209 for (plane = 0; plane < 3; plane++) {
1210 plane_idx = (!plane || !c->
swap_planes) ? plane : (plane ^ 3);
1243 static const int s[64]={
1244 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1245 1489322693,2065749918,1945893874,1751258219,1489322693,1170153332, 806015634, 410903207,
1246 1402911301,1945893874,1832991949,1649649171,1402911301,1102260336, 759250125, 387062357,
1247 1262586814,1751258219,1649649171,1484645031,1262586814, 992008094, 683307060, 348346918,
1248 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1249 843633538,1170153332,1102260336, 992008094, 843633538, 662838617, 456571181, 232757969,
1250 581104888, 806015634, 759250125, 683307060, 581104888, 456571181, 314491699, 160326478,
1251 296244703, 410903207, 387062357, 348346918, 296244703, 232757969, 160326478, 81733730,
1255 for (i = 0; i < 64; i++)
1258 for (j = 0; j < 16; j++) {
1259 for (i = 0; i < 64; i++) {
1260 int k = inv_bink_scan[i];
1273 static int binkb_initialised = 0;
1285 if (!bink_trees[15].table) {
1286 for (i = 0; i < 16; i++) {
1288 bink_trees[i].
table = table + i*128;
1290 init_vlc(&bink_trees[i], maxbits, 16,
1316 if (!binkb_initialised) {
1318 binkb_initialised = 1;
1336 .
name =
"binkvideo",