32 #define BITSTREAM_READER_LE
35 #define BINK_FLAG_ALPHA 0x00100000
36 #define BINK_FLAG_GRAY 0x00020000
59 4, 8, 8, 5, 5, 11, 11, 4, 4, 7
63 0, 0, 0, 1, 1, 0, 1, 0, 0, 0
94 #define GET_HUFF(gb, tree) (tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\
95 bink_trees[(tree).vlc_num].bits, 1)]
226 }
while (size && size2);
242 uint8_t tmp1[16] = { 0 }, tmp2[16], *
in = tmp1, *
out = tmp2;
247 for (i = 0; i < 16; i++)
253 for (i = 0; i <=
len; i++) {
255 tmp1[tree->
syms[i]] = 1;
257 for (i = 0; i < 16 && len < 16 - 1; i++)
262 for (i = 0; i < 16; i++)
264 for (i = 0; i <=
len; i++) {
266 for (t = 0; t < 16; t += size << 1)
267 merge(gb, out + t, in + t, size);
270 memcpy(tree->
syms, in, 16);
286 for (i = 0; i < 16; i++)
303 #define CHECK_READ_VAL(gb, b, t) \
304 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
306 t = get_bits(gb, b->len); \
349 v = (v ^ sign) - sign;
358 v = (v ^ sign) - sign;
393 if (dec_end - b->
cur_dec < run)
439 sign = ((int8_t) v) >> 7;
440 v = ((v & 0x7F) ^ sign) - sign;
451 sign = ((int8_t) v) >> 7;
452 v = ((v & 0x7F) ^ sign) - sign;
462 #define DC_START_BITS 11
465 int start_bits,
int has_sign)
467 int i, j,
len, len2, bsize, sign,
v, v2;
469 int16_t *dst_end = (int16_t*)b->
data_end;
472 v =
get_bits(gb, start_bits - has_sign);
475 v = (v ^ sign) - sign;
477 if (dst_end - dst < 1)
481 for (i = 0; i <
len; i += 8) {
482 len2 =
FFMIN(len - i, 8);
483 if (dst_end - dst < len2)
487 for (j = 0; j < len2; j++) {
491 v2 = (v2 ^ sign) - sign;
495 if (v < -32768 || v > 32767) {
501 for (j = 0; j < len2; j++)
546 const int mask = 1 << (bits - 1);
556 for (i = 0; i <
len; i++)
559 for (i = 0; i <
len; i++)
566 for (i = 0; i <
len; i++)
569 for (i = 0; i <
len; i++)
601 const int32_t quant_matrices[16][64],
int q)
606 int list_start = 64, list_end = 64, list_pos;
612 coef_list[list_end] = 4; mode_list[list_end++] = 0;
613 coef_list[list_end] = 24; mode_list[list_end++] = 0;
614 coef_list[list_end] = 44; mode_list[list_end++] = 0;
615 coef_list[list_end] = 1; mode_list[list_end++] = 3;
616 coef_list[list_end] = 2; mode_list[list_end++] = 3;
617 coef_list[list_end] = 3; mode_list[list_end++] = 3;
619 for (bits =
get_bits(gb, 4) - 1; bits >= 0; bits--) {
620 list_pos = list_start;
621 while (list_pos < list_end) {
622 if (!(mode_list[list_pos] | coef_list[list_pos]) || !
get_bits1(gb)) {
626 ccoef = coef_list[list_pos];
627 mode = mode_list[list_pos];
630 coef_list[list_pos] = ccoef + 4;
631 mode_list[list_pos] = 1;
634 coef_list[list_pos] = 0;
635 mode_list[list_pos++] = 0;
637 for (i = 0; i < 4; i++, ccoef++) {
639 coef_list[--list_start] = ccoef;
640 mode_list[ list_start] = 3;
647 t = (t ^ sign) - sign;
649 block[scan[ccoef]] =
t;
650 coef_idx[coef_count++] = ccoef;
655 mode_list[list_pos] = 2;
656 for (i = 0; i < 3; i++) {
658 coef_list[list_end] = ccoef;
659 mode_list[list_end++] = 2;
668 t = (t ^ sign) - sign;
670 block[scan[ccoef]] =
t;
671 coef_idx[coef_count++] = ccoef;
672 coef_list[list_pos] = 0;
673 mode_list[list_pos++] = 0;
683 if (quant_idx > 15
U) {
689 quant = quant_matrices[quant_idx];
691 block[0] = (block[0] * quant[0]) >> 11;
692 for (i = 0; i < coef_count; i++) {
693 int idx = coef_idx[i];
694 block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
713 int list_start = 64, list_end = 64, list_pos;
715 int nz_coeff_count = 0;
717 coef_list[list_end] = 4; mode_list[list_end++] = 0;
718 coef_list[list_end] = 24; mode_list[list_end++] = 0;
719 coef_list[list_end] = 44; mode_list[list_end++] = 0;
720 coef_list[list_end] = 0; mode_list[list_end++] = 2;
723 for (i = 0; i < nz_coeff_count; i++) {
726 if (block[nz_coeff[i]] < 0)
727 block[nz_coeff[i]] -=
mask;
729 block[nz_coeff[i]] +=
mask;
734 list_pos = list_start;
735 while (list_pos < list_end) {
736 if (!(coef_list[list_pos] | mode_list[list_pos]) || !
get_bits1(gb)) {
740 ccoef = coef_list[list_pos];
741 mode = mode_list[list_pos];
744 coef_list[list_pos] = ccoef + 4;
745 mode_list[list_pos] = 1;
748 coef_list[list_pos] = 0;
749 mode_list[list_pos++] = 0;
751 for (i = 0; i < 4; i++, ccoef++) {
753 coef_list[--list_start] = ccoef;
754 mode_list[ list_start] = 3;
756 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
758 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
766 mode_list[list_pos] = 2;
767 for (i = 0; i < 3; i++) {
769 coef_list[list_end] = ccoef;
770 mode_list[list_end++] = 2;
774 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
776 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
777 coef_list[list_pos] = 0;
778 mode_list[list_pos++] = 0;
797 for (i = 0; i < 8; i++)
798 memcpy(tmp + i*8, src + i*stride, 8);
799 for (i = 0; i < 8; i++)
800 memcpy(dst + i*stride, tmp + i*8, 8);
804 int is_key,
int is_chroma)
815 int ybias = is_key ? -15 : 0;
823 ref_start = c->
pic->
data[plane_idx];
826 for (i = 0; i < 64; i++)
827 coordmap[i] = (i & 7) + (i >> 3) * stride;
829 for (by = 0; by < bh; by++) {
836 for (bx = 0; bx < bw; bx++, dst += 8) {
857 for (j = 0; j <
run; j++)
858 dst[coordmap[*scan++]] = v;
860 for (j = 0; j <
run; j++)
868 memset(dctblock, 0,
sizeof(*dctblock) * 64);
877 ref = dst + xoff + yoff *
stride;
878 if (ref < ref_start || ref + 8*stride > ref_end) {
880 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
893 ref = dst + xoff + yoff *
stride;
894 if (ref < ref_start || ref + 8 * stride > ref_end) {
896 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
901 memset(dctblock, 0,
sizeof(*dctblock) * 64);
912 for (i = 0; i < 2; i++)
914 for (i = 0; i < 8; i++) {
916 for (j = 0; j < 8; j++, v >>= 1)
917 dst[i*stride + j] = col[v & 1];
923 ref = dst + xoff + yoff *
stride;
924 if (ref < ref_start || ref + 8 * stride > ref_end) {
926 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
933 for (i = 0; i < 8; i++)
954 uint8_t *
dst, *prev, *ref, *ref_start, *ref_end;
975 + (bw - 1 + c->
last->
linesize[plane_idx] * (bh - 1)) * 8;
977 for (i = 0; i < 64; i++)
978 coordmap[i] = (i & 7) + (i >> 3) * stride;
980 for (by = 0; by < bh; by++) {
1004 : c->
pic->
data[plane_idx]) + 8*by*stride;
1005 for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1034 for (j = 0; j <
run; j++)
1035 ublock[*scan++] = v;
1037 for (j = 0; j <
run; j++)
1045 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1055 for (i = 0; i < 2; i++)
1057 for (j = 0; j < 8; j++) {
1059 for (i = 0; i < 8; i++, v >>= 1)
1060 ublock[i + j*8] = col[v & 1];
1064 for (j = 0; j < 8; j++)
1065 for (i = 0; i < 8; i++)
1081 ref = prev + xoff + yoff *
stride;
1082 if (ref < ref_start || ref > ref_end) {
1084 bx*8 + xoff, by*8 + yoff);
1102 for (j = 0; j <
run; j++)
1103 dst[coordmap[*scan++]] = v;
1105 for (j = 0; j <
run; j++)
1115 ref = prev + xoff + yoff *
stride;
1116 if (ref < ref_start || ref > ref_end) {
1118 bx*8 + xoff, by*8 + yoff);
1128 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1140 ref = prev + xoff + yoff *
stride;
1141 if (ref < ref_start || ref > ref_end) {
1143 bx*8 + xoff, by*8 + yoff);
1147 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1153 for (i = 0; i < 2; i++)
1155 for (i = 0; i < 8; i++) {
1157 for (j = 0; j < 8; j++, v >>= 1)
1158 dst[i*stride + j] = col[v & 1];
1162 for (i = 0; i < 8; i++)
1182 int plane, plane_idx, ret;
1183 int bits_count = pkt->
size << 3;
1210 for (plane = 0; plane < 3; plane++) {
1211 plane_idx = (!plane || !c->
swap_planes) ? plane : (plane ^ 3);
1242 static const int s[64]={
1243 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1244 1489322693,2065749918,1945893874,1751258219,1489322693,1170153332, 806015634, 410903207,
1245 1402911301,1945893874,1832991949,1649649171,1402911301,1102260336, 759250125, 387062357,
1246 1262586814,1751258219,1649649171,1484645031,1262586814, 992008094, 683307060, 348346918,
1247 1073741824,1489322693,1402911301,1262586814,1073741824, 843633538, 581104888, 296244703,
1248 843633538,1170153332,1102260336, 992008094, 843633538, 662838617, 456571181, 232757969,
1249 581104888, 806015634, 759250125, 683307060, 581104888, 456571181, 314491699, 160326478,
1250 296244703, 410903207, 387062357, 348346918, 296244703, 232757969, 160326478, 81733730,
1254 for (i = 0; i < 64; i++)
1257 for (j = 0; j < 16; j++) {
1258 for (i = 0; i < 64; i++) {
1259 int k = inv_bink_scan[i];
1272 static int binkb_initialised = 0;
1284 if (!bink_trees[15].table) {
1285 for (i = 0; i < 16; i++) {
1287 bink_trees[i].
table = table + i*128;
1289 init_vlc(&bink_trees[i], maxbits, 16,
1318 if (!binkb_initialised) {
1320 binkb_initialised = 1;
1343 .
name =
"binkvideo",