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)]
221 }
while (size && size2);
237 uint8_t tmp1[16] = { 0 }, tmp2[16], *in = tmp1, *out = tmp2;
242 for (i = 0; i < 16; i++)
248 for (i = 0; i <=
len; i++) {
250 tmp1[tree->
syms[i]] = 1;
252 for (i = 0; i < 16 && len < 16 - 1; i++)
257 for (i = 0; i < 16; i++)
259 for (i = 0; i <=
len; i++) {
261 for (t = 0; t < 16; t += size << 1)
262 merge(gb, out + t, in + t, size);
265 memcpy(tree->
syms, in, 16);
281 for (i = 0; i < 16; i++)
298 #define CHECK_READ_VAL(gb, b, t) \
299 if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \
301 t = get_bits(gb, b->len); \
344 v = (v ^ sign) - sign;
353 v = (v ^ sign) - sign;
388 if (dec_end - b->
cur_dec < run)
434 sign = ((int8_t) v) >> 7;
435 v = ((v & 0x7F) ^ sign) - sign;
446 sign = ((int8_t) v) >> 7;
447 v = ((v & 0x7F) ^ sign) - sign;
457 #define DC_START_BITS 11
460 int start_bits,
int has_sign)
462 int i, j,
len, len2, bsize, sign, v, v2;
463 int16_t *dst = (int16_t*)b->
cur_dec;
464 int16_t *dst_end = (int16_t*)b->
data_end;
467 v =
get_bits(gb, start_bits - has_sign);
470 v = (v ^ sign) - sign;
472 if (dst_end - dst < 1)
476 for (i = 0; i <
len; i += 8) {
477 len2 =
FFMIN(len - i, 8);
478 if (dst_end - dst < len2)
482 for (j = 0; j < len2; j++) {
486 v2 = (v2 ^ sign) - sign;
490 if (v < -32768 || v > 32767) {
496 for (j = 0; j < len2; j++)
541 const int mask = 1 << (bits - 1);
551 for (i = 0; i <
len; i++)
554 for (i = 0; i <
len; i++)
558 int16_t *dst = (int16_t*)b->
cur_dec;
561 for (i = 0; i <
len; i++)
564 for (i = 0; i <
len; i++)
596 const int32_t quant_matrices[16][64],
int q)
600 int i,
t,
bits, ccoef, mode, sign;
601 int list_start = 64, list_end = 64, list_pos;
607 coef_list[list_end] = 4; mode_list[list_end++] = 0;
608 coef_list[list_end] = 24; mode_list[list_end++] = 0;
609 coef_list[list_end] = 44; mode_list[list_end++] = 0;
610 coef_list[list_end] = 1; mode_list[list_end++] = 3;
611 coef_list[list_end] = 2; mode_list[list_end++] = 3;
612 coef_list[list_end] = 3; mode_list[list_end++] = 3;
614 for (bits =
get_bits(gb, 4) - 1; bits >= 0; bits--) {
615 list_pos = list_start;
616 while (list_pos < list_end) {
617 if (!(mode_list[list_pos] | coef_list[list_pos]) || !
get_bits1(gb)) {
621 ccoef = coef_list[list_pos];
622 mode = mode_list[list_pos];
625 coef_list[list_pos] = ccoef + 4;
626 mode_list[list_pos] = 1;
629 coef_list[list_pos] = 0;
630 mode_list[list_pos++] = 0;
632 for (i = 0; i < 4; i++, ccoef++) {
634 coef_list[--list_start] = ccoef;
635 mode_list[ list_start] = 3;
642 t = (t ^ sign) - sign;
644 block[scan[ccoef]] =
t;
645 coef_idx[coef_count++] = ccoef;
650 mode_list[list_pos] = 2;
651 for (i = 0; i < 3; i++) {
653 coef_list[list_end] = ccoef;
654 mode_list[list_end++] = 2;
663 t = (t ^ sign) - sign;
665 block[scan[ccoef]] =
t;
666 coef_idx[coef_count++] = ccoef;
667 coef_list[list_pos] = 0;
668 mode_list[list_pos++] = 0;
683 quant = quant_matrices[quant_idx];
685 block[0] = (block[0] * quant[0]) >> 11;
686 for (i = 0; i < coef_count; i++) {
687 int idx = coef_idx[i];
688 block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11;
706 int i, sign,
mask, ccoef, mode;
707 int list_start = 64, list_end = 64, list_pos;
709 int nz_coeff_count = 0;
711 coef_list[list_end] = 4; mode_list[list_end++] = 0;
712 coef_list[list_end] = 24; mode_list[list_end++] = 0;
713 coef_list[list_end] = 44; mode_list[list_end++] = 0;
714 coef_list[list_end] = 0; mode_list[list_end++] = 2;
717 for (i = 0; i < nz_coeff_count; i++) {
720 if (block[nz_coeff[i]] < 0)
721 block[nz_coeff[i]] -=
mask;
723 block[nz_coeff[i]] +=
mask;
728 list_pos = list_start;
729 while (list_pos < list_end) {
730 if (!(coef_list[list_pos] | mode_list[list_pos]) || !
get_bits1(gb)) {
734 ccoef = coef_list[list_pos];
735 mode = mode_list[list_pos];
738 coef_list[list_pos] = ccoef + 4;
739 mode_list[list_pos] = 1;
742 coef_list[list_pos] = 0;
743 mode_list[list_pos++] = 0;
745 for (i = 0; i < 4; i++, ccoef++) {
747 coef_list[--list_start] = ccoef;
748 mode_list[ list_start] = 3;
750 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
752 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
760 mode_list[list_pos] = 2;
761 for (i = 0; i < 3; i++) {
763 coef_list[list_end] = ccoef;
764 mode_list[list_end++] = 2;
768 nz_coeff[nz_coeff_count++] =
bink_scan[ccoef];
770 block[
bink_scan[ccoef]] = (mask ^ sign) - sign;
771 coef_list[list_pos] = 0;
772 mode_list[list_pos++] = 0;
791 for (i = 0; i < 8; i++)
792 memcpy(tmp + i*8, src + i*stride, 8);
793 for (i = 0; i < 8; i++)
794 memcpy(dst + i*stride, tmp + i*8, 8);
798 int is_key,
int is_chroma)
802 uint8_t *dst, *ref, *ref_start, *ref_end;
809 int ybias = is_key ? -15 : 0;
817 ref_start = c->
pic.
data[plane_idx];
820 for (i = 0; i < 64; i++)
821 coordmap[i] = (i & 7) + (i >> 3) * stride;
823 for (by = 0; by < bh; by++) {
830 for (bx = 0; bx < bw; bx++, dst += 8) {
851 for (j = 0; j <
run; j++)
852 dst[coordmap[*scan++]] = v;
854 for (j = 0; j <
run; j++)
862 memset(dctblock, 0,
sizeof(*dctblock) * 64);
871 ref = dst + xoff + yoff *
stride;
872 if (ref < ref_start || ref + 8*stride > ref_end) {
874 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
887 ref = dst + xoff + yoff *
stride;
888 if (ref < ref_start || ref + 8 * stride > ref_end) {
890 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
895 memset(dctblock, 0,
sizeof(*dctblock) * 64);
906 for (i = 0; i < 2; i++)
908 for (i = 0; i < 8; i++) {
910 for (j = 0; j < 8; j++, v >>= 1)
911 dst[i*stride + j] = col[v & 1];
917 ref = dst + xoff + yoff *
stride;
918 if (ref < ref_start || ref + 8 * stride > ref_end) {
920 }
else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
927 for (i = 0; i < 8; i++)
948 uint8_t *dst, *prev, *ref, *ref_start, *ref_end;
969 + (bw - 1 + c->
last.
linesize[plane_idx] * (bh - 1)) * 8;
971 for (i = 0; i < 64; i++)
972 coordmap[i] = (i & 7) + (i >> 3) * stride;
974 for (by = 0; by < bh; by++) {
998 : c->
pic.
data[plane_idx]) + 8*by*stride;
999 for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
1028 for (j = 0; j <
run; j++)
1029 ublock[*scan++] = v;
1031 for (j = 0; j <
run; j++)
1039 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1049 for (i = 0; i < 2; i++)
1051 for (j = 0; j < 8; j++) {
1053 for (i = 0; i < 8; i++, v >>= 1)
1054 ublock[i + j*8] = col[v & 1];
1058 for (j = 0; j < 8; j++)
1059 for (i = 0; i < 8; i++)
1075 ref = prev + xoff + yoff *
stride;
1076 if (ref < ref_start || ref > ref_end) {
1078 bx*8 + xoff, by*8 + yoff);
1096 for (j = 0; j <
run; j++)
1097 dst[coordmap[*scan++]] = v;
1099 for (j = 0; j <
run; j++)
1109 ref = prev + xoff + yoff *
stride;
1110 if (ref < ref_start || ref > ref_end) {
1112 bx*8 + xoff, by*8 + yoff);
1122 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1134 ref = prev + xoff + yoff *
stride;
1136 memset(dctblock, 0,
sizeof(*dctblock) * 64);
1142 for (i = 0; i < 2; i++)
1144 for (i = 0; i < 8; i++) {
1146 for (j = 0; j < 8; j++, v >>= 1)
1147 dst[i*stride + j] = col[v & 1];
1151 for (i = 0; i < 8; i++)
1171 int plane, plane_idx;
1172 int bits_count = pkt->
size << 3;
1199 for (plane = 0; plane < 3; plane++) {
1200 plane_idx = (!plane || !c->
swap_planes) ? plane : (plane ^ 3);
1233 for (j = 0; j < 8; j++) {
1234 for (i = 0; i < 8; i++) {
1237 s[j*8 + i] = cos(j * M_PI/16.0) * cos(i * M_PI/16.0) * 2.0;
1239 s[j*8 + i] = cos(j * M_PI/16.0) * sqrt(2.0);
1242 s[j*8 + i] = cos(i * M_PI/16.0) * sqrt(2.0);
1248 for (i = 0; i < 64; i++)
1251 for (j = 0; j < 16; j++) {
1252 for (i = 0; i < 64; i++) {
1253 int k = inv_bink_scan[i];
1272 static VLC_TYPE table[16 * 128][2];
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,
1312 if (!binkb_initialised) {
1314 binkb_initialised = 1;
1335 .
name =
"binkvideo",
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
static const uint8_t bink_tree_lens[16][16]
8-bit values for 2-colour pattern fill
This structure describes decoded (raw) audio or video data.
static const uint8_t bink_tree_bits[16][16]
#define CHECK_READ_VAL(gb, b, t)
common check before starting decoding bundle data
static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_chroma)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
void(* scale_block)(const uint8_t src[64], uint8_t *dst, int linesize)
static void skip_bits_long(GetBitContext *s, int n)
static void binkb_init_bundle(BinkContext *c, int bundle_num)
static const uint8_t binkb_den[16]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
8-bit values for 2-colour pattern fill
static const uint8_t bink_scan[64]
Bink DCT and residue 8x8 block scan order.
Tree col_high[16]
trees for decoding high nibble in "colours" data type
16x16 block types (a subset of 8x8 block types)
int len
length of number of entries to decode (in bits)
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
static int32_t binkb_inter_quant[16][64]
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
quantizer values for interblocks with DCT
static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
X components of motion value.
#define FFSWAP(type, a, b)
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
motion block with DCT applied to the difference
static int binkb_get_value(BinkContext *c, int bundle_num)
static void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stride)
Copy 8x8 block from source to destination, where src and dst may be overlapped.
Tree tree
Huffman tree-related data.
struct Tree Tree
data needed to decode 4-bit Huffman-coded value
BlockTypes
Bink video block types.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const int32_t bink_inter_quant[16][64]
static int get_bits_count(const GetBitContext *s)
int vlc_num
tree number (in bink_trees[])
static av_cold void init_bundles(BinkContext *c)
Allocate memory for bundles.
bitstream reader API header.
static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
data structure used for decoding single Bink data type
#define LOCAL_ALIGNED_16(t, v,...)
static const uint8_t bink_patterns[16][64]
static int init(AVCodecParserContext *s)
uint8_t * data
buffer for decoded symbols
block is copied from previous frame with some offset
static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan, const int32_t quant_matrices[16][64], int q)
Read 8x8 block of DCT coefficients.
uint8_t * data_end
buffer end
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold void free_bundles(BinkContext *c)
Free memory used by bundles.
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int col_lastval
value of last decoded high nibble in "colours" data type
void(* clear_block)(DCTELEM *block)
DC values for interblocks with DCT.
void(* add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size)
block is composed from runs of colours with custom scan order
block is filled with single colour
static av_cold void binkb_calc_quant(void)
Caclulate quantization tables for version b.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
int width
picture width / height.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Y components of motion value.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
number of coefficients for residue blocks
static const uint8_t binkb_inter_seed[64]
#define INIT_VLC_USE_NEW_STATIC
static const uint8_t binkb_runbits[64]
data needed to decode 4-bit Huffman-coded value
uint8_t * cur_dec
pointer to the not yet decoded part of the buffer
quantizer values for intrablocks with DCT
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
#define DC_START_BITS
number of bits used to store first DC value in bundle
main external API structure.
static void close(AVCodecParserContext *s)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
op_fill_func fill_block_tab[2]
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
static av_cold int decode_init(AVCodecContext *avctx)
static unsigned int get_bits1(GetBitContext *s)
static const int32_t bink_intra_quant[16][64]
DC values for interblocks with DCT.
Sources
IDs for different data types used in Bink video codec.
block is filled with two colours following custom pattern
static int32_t binkb_intra_quant[16][64]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int read_residue(GetBitContext *gb, DCTELEM block[64], int masks_count)
Read 8x8 block with residue after motion compensation.
static const uint8_t binkb_num[16]
void ff_binkdsp_init(BinkDSPContext *c)
#define GET_HUFF(gb, tree)
run lengths for special fill block
Y components of motion value.
static VLC bink_trees[16]
struct Bundle Bundle
data structure used for decoding single Bink data type
static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size)
Merge two consequent lists of equal size depending on bits read.
Bundle bundle[BINKB_NB_SRC]
bundles for decoding all data types
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
pixel values used for different block types
void(* idct_add)(uint8_t *dest, int line_size, int32_t *block)
X components of motion value.
uint8_t * cur_ptr
pointer to the data that is not read from buffer yet
static const uint8_t binkb_intra_seed[64]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num)
common internal api header.
static void init_lengths(BinkContext *c, int width, int bw)
Initialize length length in all bundles.
#define AVERROR_INVALIDDATA
static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c)
static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
static void read_tree(GetBitContext *gb, Tree *tree)
Read information about Huffman tree used to decode data.
static void binkb_init_bundles(BinkContext *c)
uint8_t syms[16]
leaf value to symbol mapping
static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, int start_bits, int has_sign)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
DC values for intrablocks with DCT.
static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle *b)
struct BinkContext BinkContext
motion block with some difference added
static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, int is_key, int is_chroma)
VLC_TYPE(* table)[2]
code, bits
void(* idct_put)(uint8_t *dest, int line_size, int32_t *block)
static const int binkb_bundle_sizes[BINKB_NB_SRC]
int version
internal Bink file version
static const int binkb_bundle_signed[BINKB_NB_SRC]
static av_cold int decode_end(AVCodecContext *avctx)
static void read_bundle(GetBitContext *gb, BinkContext *c, int bundle_num)
Prepare bundle for decoding data.
static const uint8_t bink_rlelens[4]
pixel values used for different block types
static int get_value(BinkContext *c, int bundle)
Retrieve next value from bundle.
This structure stores compressed data.
DC values for intrablocks with DCT.
OldSources
IDs for different data types used in old version of Bink video codec.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)