35 #define VLC_BUFFER_SIZE 28150
37 #define MAX_TABLE_DEPTH(table_bits, max_bits) \
38 ((max_bits + table_bits - 1) / table_bits)
44 #define DC_VLC_MTD MAX_TABLE_DEPTH(DC_VLC_BITS, MAX_DC_VLC_BITS)
45 #define AC_VLC_MTD MAX_TABLE_DEPTH(AC_VLC_BITS, MAX_AC_VLC_BITS)
46 #define OR_VLC_MTD MAX_TABLE_DEPTH(OR_VLC_BITS, MAX_OR_VLC_BITS)
70 for (
int i = 0;
i < 2;
i++)
71 for (
int j = 0; j < 2; j++)
72 for (
int k = 0; k < 8; k++)
77 for (
int i = 0;
i < 2;
i++)
78 for (
int j = 0; j < 8; j++)
83 for (
i = 0;
i < 2;
i++)
86 for (
i = 0;
i < 4;
i++)
95 memset(
w->j_dc_vlc, 0,
sizeof(
w->j_dc_vlc));
96 memset(
w->j_ac_vlc, 0,
sizeof(
w->j_ac_vlc));
97 w->j_orient_vlc =
NULL;
106 if (
w->j_ac_vlc[
mode])
117 if (!
w->j_orient_vlc) {
118 int table_index =
get_bits(
w->gb, 1 + (
w->quant < 13));
125 #define extra_bits(eb) (eb)
126 #define extra_run (0xFF << 8)
127 #define extra_level (0x00 << 8)
128 #define run_offset(r) ((r) << 16)
129 #define level_offset(l) ((l) << 24)
173 int *
const run,
int *
const level,
int *
const final)
202 l = (0xE50000 >> (
i & 0x1E)) & 3;
206 t = 0x01030F >> (l << 3);
222 *
run = (sm & 0xff) + (e &
mask);
224 *
final =
i > (58 - 46);
226 static const uint8_t crazy_mix_runlevel[32] = {
227 0x22, 0x32, 0x33, 0x53, 0x23, 0x42, 0x43, 0x63,
228 0x24, 0x52, 0x34, 0x73, 0x25, 0x62, 0x44, 0x83,
229 0x26, 0x72, 0x35, 0x54, 0x27, 0x82, 0x45, 0x64,
230 0x28, 0x92, 0x36, 0x74, 0x29, 0xa2, 0x46, 0x84,
235 *
run = crazy_mix_runlevel[e] >> 4;
236 *
level = crazy_mix_runlevel[e] & 0x0F;
249 0, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
253 int *
const level,
int *
const final)
258 if (!
w->j_dc_vlc[
mode]) {
294 w->dsp.setup_spatial_compensation(
w->dest[
chroma],
w->scratchpad,
295 w->frame->linesize[
chroma > 0],
296 &range, &sum,
w->edges);
298 w->orient =
w->chroma_orient;
299 quant =
w->quant_dc_chroma;
305 if (range <
quant || range < 3) {
313 w->predicted_dc = sum * 6899 >> 17;
320 if (range < 2 * w->
quant) {
321 if ((
w->edges & 3) == 0) {
331 static const uint8_t prediction_table[3][12] = {
332 { 0, 8, 4, 10, 11, 2, 6, 9, 1, 3, 5, 7 },
333 { 4, 0, 8, 11, 10, 3, 5, 2, 6, 9, 1, 7 },
334 { 8, 0, 4, 10, 11, 1, 7, 2, 6, 9, 3, 5 },
337 if (
w->raw_orient < 0)
341 w->orient=prediction_table[
w->orient][
w->raw_orient];
349 w->prediction_table[
w->mb_x * 2 + (
w->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orient == 8);
358 w->edges = 1 * !(
w->mb_x >> 1);
359 w->edges |= 2 * !(
w->mb_y >> 1);
360 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
365 w->chroma_orient = 4 << ((0xCC >>
w->edges) & 1);
369 w->chroma_orient = (
w->prediction_table[2 *
w->mb_x - 2] & 0x03) << 2;
376 w->edges = 1 * !
w->mb_x;
377 w->edges |= 2 * !
w->mb_y;
378 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
380 switch (
w->edges & 3) {
385 w->est_run =
w->prediction_table[!(
w->mb_y & 1)] >> 2;
390 w->est_run =
w->prediction_table[2 *
w->mb_x - 2] >> 2;
399 b =
w->prediction_table[2 *
w->mb_x + !(
w->mb_y & 1)];
400 a =
w->prediction_table[2 *
w->mb_x - 2 + (
w->mb_y & 1)];
401 c =
w->prediction_table[2 *
w->mb_x - 2 + !(
w->mb_y & 1)];
407 if ((
w->mb_x &
w->mb_y) != 0)
415 i = (0xFFEAF4C4 >> (2 *
b + 8 *
a)) & 3;
419 w->orient = (0xFFEAD8 >> (2 *
c + 8 * (
w->quant > 12))) & 3;
445 #define B(x,y) w->block[0][w->idct_permutation[(x) + (y) * 8]]
446 #define T(x) ((x) * dc_level + 0x8000) >> 16;
489 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
497 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
505 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7);
513 const ptrdiff_t linesize)
516 for (k = 0; k < 8; k++) {
523 256, 256, 256, 256, 256, 256, 259, 262,
524 265, 269, 272, 275, 278, 282, 285, 288,
525 292, 295, 299, 303, 306, 310, 314, 317,
526 321, 325, 329, 333, 337, 341, 345, 349,
527 353, 358, 362, 366, 371, 375, 379, 384,
528 389, 393, 398, 403, 408, 413, 417, 422,
529 428, 433, 438, 443, 448, 454, 459, 465,
530 470, 476, 482, 488, 493, 499, 505, 511,
537 int ac_mode, dc_mode, est_run, dc_level;
540 int use_quant_matrix;
544 w->bdsp.clear_block(
w->block[0]);
549 dc_mode = !!
w->est_run;
556 use_quant_matrix =
w->use_quant_matrix;
561 if (
w->raw_orient < 3)
562 use_quant_matrix = 0;
564 if (
w->raw_orient > 4) {
568 if (
w->est_run > 1) {
570 est_run =
w->est_run;
580 scantable =
w->scantable[(0x928548 >> (2 *
w->orient)) & 3].permutated;
602 if (use_quant_matrix)
608 w->block_last_index[0] =
pos;
610 w->block_last_index[0] = 0;
611 if (
w->flat_dc && ((
unsigned) (dc_level + 1)) < 3) {
613 :
w->divide_quant_dc_chroma;
615 :
w->quant_dc_chroma;
619 dc_level += (
w->predicted_dc * divide_quant + (1 << 12)) >> 13;
627 zeros_only = dc_level == 0;
630 w->block[0][0] = dc_level *
w->quant;
632 w->block[0][0] = dc_level *
w->quant_dc_chroma;
635 if ((
unsigned int) (dc_level + 1) >= 3 && (
w->edges & 3) != 3) {
639 direction = (0x6A017C >> (
w->orient * 2)) & 3;
640 if (direction != 3) {
650 w->dsp.spatial_compensation[
w->orient](
w->scratchpad,
665 ptrdiff_t linesize =
w->frame->linesize[!!
chroma];
667 if (!((
w->edges & 2) || (zeros_only && (
w->orient | 4) == 4)))
668 w->dsp.h_loop_filter(ptr, linesize,
w->quant);
670 if (!((
w->edges & 1) || (zeros_only && (
w->orient | 8) == 8)))
671 w->dsp.v_loop_filter(ptr, linesize,
w->quant);
688 w->dest[0] +=
w->mb_y * linesize << 3;
690 w->dest[1] += (
w->mb_y & ~1) * uvlinesize << 2;
691 w->dest[2] += (
w->mb_y & ~1) * uvlinesize << 2;
696 int16_t (*
block)[64],
697 int block_last_index[12],
698 int mb_width,
int mb_height)
704 w->mb_width = mb_width;
705 w->mb_height = mb_height;
707 w->block_last_index = block_last_index;
711 if (!
w->prediction_table)
741 int dquant,
int quant_offset,
742 int loopfilter,
int lowdelay)
748 w->quant = dquant >> 1;
749 w->qsum = quant_offset;
751 w->loopfilter = loopfilter;
757 w->divide_quant_dc_luma = ((1 << 16) + (
w->quant >> 1)) /
w->quant;
759 w->quant_dc_chroma =
w->quant;
760 w->divide_quant_dc_chroma =
w->divide_quant_dc_luma;
762 w->quant_dc_chroma =
w->quant + ((
w->quant + 3) >> 3);
763 w->divide_quant_dc_chroma = ((1 << 16) + (
w->quant_dc_chroma >> 1)) /
w->quant_dc_chroma;
767 for (
w->mb_y = 0;
w->mb_y <
w->mb_height * 2;
w->mb_y++) {
769 mb_xy = (
w->mb_y >> 1) * (
w->mb_width + 1);
772 for (
w->mb_x = 0;
w->mb_x <
w->mb_width * 2;
w->mb_x++) {
779 if (
w->mb_x &
w->mb_y & 1) {
802 (
w->mb_y - 1) * 8, 16,
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Libavcodec external API header.
int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
static VLC_TYPE vlc_buf[16716][2]
mode
Use these values in ebur128_init (or'ed).
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
av_cold void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
av_cold int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, int16_t(*block)[64], int block_last_index[12], int mb_width, int mb_height)
Initialize IntraX8 frame decoder.
int ff_intrax8_decode_picture(IntraX8Context *w, Picture *pict, GetBitContext *gb, int *mb_x, int *mb_y, int dquant, int quant_offset, int loopfilter, int lowdelay)
Decode single IntraX8 frame.
static void x8_update_predictions(IntraX8Context *const w, const int orient, const int est_run)
static VLC j_ac_vlc[2][2][8]
static void x8_reset_vlc_tables(IntraX8Context *w)
static av_cold void x8_vlc_init(void)
static const int16_t quant_table[64]
av_cold void ff_intrax8_common_end(IntraX8Context *w)
Destroy IntraX8 frame structure.
static void x8_get_prediction_chroma(IntraX8Context *const w)
static VLC j_orient_vlc[2][4]
static const uint32_t ac_decode_table[]
static void dsp_x8_put_solidcolor(const uint8_t pix, uint8_t *dst, const ptrdiff_t linesize)
static int x8_get_orient_vlc(IntraX8Context *w)
static void x8_ac_compensation(IntraX8Context *const w, const int direction, const int dc_level)
static int x8_get_dc_rlf(IntraX8Context *const w, const int mode, int *const level, int *const final)
static const uint8_t dc_index_offset[]
static VLC j_dc_vlc[2][8]
static void x8_get_prediction(IntraX8Context *const w)
static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes, int *offset, const uint8_t table[][2])
static void x8_select_ac_table(IntraX8Context *const w, int mode)
static int x8_setup_spatial_predictor(IntraX8Context *const w, const int chroma)
static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
static void x8_init_block_index(IntraX8Context *w, AVFrame *frame)
static void x8_get_ac_rlf(IntraX8Context *const w, const int mode, int *const run, int *const level, int *const final)
av_cold void ff_intrax8dsp_init(IntraX8DSPContext *dsp)
static const uint8_t x8_dc_quant_table[2][8][34][2]
static const uint8_t x8_orient_lowquant_table[4][12][2]
static const uint8_t x8_orient_highquant_table[2][12][2]
static const uint8_t x8_ac_quant_table[2][2][8][77][2]
av_cold void ff_blockdsp_init(BlockDSPContext *c, AVCodecContext *avctx)
static int ff_thread_once(char *control, void(*routine)(void))
static const uint16_t mask[17]
void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last, int y, int h, int picture_structure, int first_field, int low_delay)
Draw a horizontal band if supported.
const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64]
static const uint16_t table[]
main external API structure.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
VLC_TYPE(* table)[2]
code, bits
static void error(const char *err)
static const uint8_t offset[127][2]
#define INIT_VLC_STATIC_OVERLONG
av_cold void ff_wmv2dsp_init(WMV2DSPContext *c)