34 #define VLC_BUFFER_SIZE 28150
36 #define MAX_TABLE_DEPTH(table_bits, max_bits) \
37 ((max_bits + table_bits - 1) / table_bits)
43 #define DC_VLC_MTD MAX_TABLE_DEPTH(DC_VLC_BITS, MAX_DC_VLC_BITS)
44 #define AC_VLC_MTD MAX_TABLE_DEPTH(AC_VLC_BITS, MAX_AC_VLC_BITS)
45 #define OR_VLC_MTD MAX_TABLE_DEPTH(OR_VLC_BITS, MAX_OR_VLC_BITS)
69 for (
int i = 0;
i < 2;
i++)
70 for (
int j = 0; j < 2; j++)
71 for (
int k = 0; k < 8; k++)
76 for (
int i = 0;
i < 2;
i++)
77 for (
int j = 0; j < 8; j++)
82 for (
i = 0;
i < 2;
i++)
85 for (
i = 0;
i < 4;
i++)
94 memset(
w->j_dc_vlc_table, 0,
sizeof(
w->j_dc_vlc_table));
95 memset(
w->j_ac_vlc_table, 0,
sizeof(
w->j_ac_vlc_table));
96 w->j_orient_vlc_table =
NULL;
105 if (
w->j_ac_vlc_table[
mode])
116 if (!
w->j_orient_vlc_table) {
117 int table_index =
get_bits(
w->gb, 1 + (
w->quant < 13));
124 #define extra_bits(eb) (eb) // 3 bits
125 #define extra_run (0xFF << 8) // 1 bit
126 #define extra_level (0x00 << 8) // 1 bit
127 #define run_offset(r) ((r) << 16) // 6 bits
128 #define level_offset(l) ((l) << 24) // 5 bits
172 int *
const run,
int *
const level,
int *
const final)
201 l = (0xE50000 >> (
i & 0x1E)) & 3;
205 t = 0x01030F >> (l << 3);
221 *
run = (sm & 0xff) + (e &
mask);
223 *
final =
i > (58 - 46);
225 static const uint8_t crazy_mix_runlevel[32] = {
226 0x22, 0x32, 0x33, 0x53, 0x23, 0x42, 0x43, 0x63,
227 0x24, 0x52, 0x34, 0x73, 0x25, 0x62, 0x44, 0x83,
228 0x26, 0x72, 0x35, 0x54, 0x27, 0x82, 0x45, 0x64,
229 0x28, 0x92, 0x36, 0x74, 0x29, 0xa2, 0x46, 0x84,
234 *
run = crazy_mix_runlevel[e] >> 4;
235 *
level = crazy_mix_runlevel[e] & 0x0F;
248 0, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
252 int *
const level,
int *
const final)
257 if (!
w->j_dc_vlc_table[
mode]) {
293 w->dsp.setup_spatial_compensation(
w->dest[
chroma],
w->scratchpad,
294 w->frame->linesize[
chroma > 0],
295 &range, &sum,
w->edges);
297 w->orient =
w->chroma_orient;
298 quant =
w->quant_dc_chroma;
304 if (range <
quant || range < 3) {
312 w->predicted_dc = sum * 6899 >> 17;
319 if (range < 2 * w->
quant) {
320 if ((
w->edges & 3) == 0) {
330 static const uint8_t prediction_table[3][12] = {
331 { 0, 8, 4, 10, 11, 2, 6, 9, 1, 3, 5, 7 },
332 { 4, 0, 8, 11, 10, 3, 5, 2, 6, 9, 1, 7 },
333 { 8, 0, 4, 10, 11, 1, 7, 2, 6, 9, 3, 5 },
336 if (
w->raw_orient < 0)
340 w->orient=prediction_table[
w->orient][
w->raw_orient];
348 w->prediction_table[
w->mb_x * 2 + (
w->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orient == 8);
357 w->edges = 1 * !(
w->mb_x >> 1);
358 w->edges |= 2 * !(
w->mb_y >> 1);
359 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
364 w->chroma_orient = 4 << ((0xCC >>
w->edges) & 1);
368 w->chroma_orient = (
w->prediction_table[2 *
w->mb_x - 2] & 0x03) << 2;
375 w->edges = 1 * !
w->mb_x;
376 w->edges |= 2 * !
w->mb_y;
377 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
379 switch (
w->edges & 3) {
384 w->est_run =
w->prediction_table[!(
w->mb_y & 1)] >> 2;
389 w->est_run =
w->prediction_table[2 *
w->mb_x - 2] >> 2;
398 b =
w->prediction_table[2 *
w->mb_x + !(
w->mb_y & 1)];
399 a =
w->prediction_table[2 *
w->mb_x - 2 + (
w->mb_y & 1)];
400 c =
w->prediction_table[2 *
w->mb_x - 2 + !(
w->mb_y & 1)];
406 if ((
w->mb_x &
w->mb_y) != 0)
414 i = (0xFFEAF4C4 >> (2 *
b + 8 *
a)) & 3;
418 w->orient = (0xFFEAD8 >> (2 *
c + 8 * (
w->quant > 12))) & 3;
444 #define B(x,y) w->block[0][w->idct_permutation[(x) + (y) * 8]]
445 #define T(x) ((x) * dc_level + 0x8000) >> 16;
488 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
496 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
504 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7);
512 const ptrdiff_t linesize)
515 for (k = 0; k < 8; k++) {
522 256, 256, 256, 256, 256, 256, 259, 262,
523 265, 269, 272, 275, 278, 282, 285, 288,
524 292, 295, 299, 303, 306, 310, 314, 317,
525 321, 325, 329, 333, 337, 341, 345, 349,
526 353, 358, 362, 366, 371, 375, 379, 384,
527 389, 393, 398, 403, 408, 413, 417, 422,
528 428, 433, 438, 443, 448, 454, 459, 465,
529 470, 476, 482, 488, 493, 499, 505, 511,
536 int ac_mode, dc_mode, est_run, dc_level;
539 int use_quant_matrix;
543 w->bdsp.clear_block(
w->block[0]);
548 dc_mode = !!
w->est_run;
555 use_quant_matrix =
w->use_quant_matrix;
560 if (
w->raw_orient < 3)
561 use_quant_matrix = 0;
563 if (
w->raw_orient > 4) {
567 if (
w->est_run > 1) {
569 est_run =
w->est_run;
579 scantable =
w->scantable[(0x928548 >> (2 *
w->orient)) & 3].permutated;
601 if (use_quant_matrix)
607 w->block_last_index[0] =
pos;
609 w->block_last_index[0] = 0;
610 if (
w->flat_dc && ((
unsigned) (dc_level + 1)) < 3) {
612 :
w->divide_quant_dc_chroma;
614 :
w->quant_dc_chroma;
618 dc_level += (
w->predicted_dc * divide_quant + (1 << 12)) >> 13;
626 zeros_only = dc_level == 0;
629 w->block[0][0] = dc_level *
w->quant;
631 w->block[0][0] = dc_level *
w->quant_dc_chroma;
634 if ((
unsigned int) (dc_level + 1) >= 3 && (
w->edges & 3) != 3) {
638 direction = (0x6A017C >> (
w->orient * 2)) & 3;
639 if (direction != 3) {
649 w->dsp.spatial_compensation[
w->orient](
w->scratchpad,
663 uint8_t *ptr =
w->dest[
chroma];
664 ptrdiff_t linesize =
w->frame->linesize[!!
chroma];
666 if (!((
w->edges & 2) || (zeros_only && (
w->orient | 4) == 4)))
667 w->dsp.h_loop_filter(ptr, linesize,
w->quant);
669 if (!((
w->edges & 1) || (zeros_only && (
w->orient | 8) == 8)))
670 w->dsp.v_loop_filter(ptr, linesize,
w->quant);
680 const ptrdiff_t linesize =
frame->linesize[0];
681 const ptrdiff_t uvlinesize =
frame->linesize[1];
683 w->dest[0] =
frame->data[0];
684 w->dest[1] =
frame->data[1];
685 w->dest[2] =
frame->data[2];
687 w->dest[0] +=
w->mb_y * linesize << 3;
689 w->dest[1] += (
w->mb_y & ~1) * uvlinesize << 2;
690 w->dest[2] += (
w->mb_y & ~1) * uvlinesize << 2;
695 int16_t (*
block)[64],
696 int block_last_index[12],
697 int mb_width,
int mb_height)
702 w->mb_width = mb_width;
703 w->mb_height = mb_height;
705 w->block_last_index = block_last_index;
709 if (!
w->prediction_table)
739 int dquant,
int quant_offset,
740 int loopfilter,
int lowdelay)
746 w->quant = dquant >> 1;
747 w->qsum = quant_offset;
749 w->loopfilter = loopfilter;
755 w->divide_quant_dc_luma = ((1 << 16) + (
w->quant >> 1)) /
w->quant;
757 w->quant_dc_chroma =
w->quant;
758 w->divide_quant_dc_chroma =
w->divide_quant_dc_luma;
760 w->quant_dc_chroma =
w->quant + ((
w->quant + 3) >> 3);
761 w->divide_quant_dc_chroma = ((1 << 16) + (
w->quant_dc_chroma >> 1)) /
w->quant_dc_chroma;
765 for (
w->mb_y = 0;
w->mb_y <
w->mb_height * 2;
w->mb_y++) {
767 mb_xy = (
w->mb_y >> 1) * (
w->mb_width + 1);
770 for (
w->mb_x = 0;
w->mb_x <
w->mb_width * 2;
w->mb_x++) {
777 if (
w->mb_x &
w->mb_y & 1) {
800 (
w->mb_y - 1) * 8, 16,