34 #define MAX_TABLE_DEPTH(table_bits, max_bits) \
35 ((max_bits + table_bits - 1) / table_bits)
41 #define DC_VLC_MTD MAX_TABLE_DEPTH(DC_VLC_BITS, MAX_DC_VLC_BITS)
42 #define AC_VLC_MTD MAX_TABLE_DEPTH(AC_VLC_BITS, MAX_AC_VLC_BITS)
43 #define OR_VLC_MTD MAX_TABLE_DEPTH(OR_VLC_BITS, MAX_OR_VLC_BITS)
54 static const uint16_t
sizes[8 * 4 + 8 * 2 + 2 + 4] = {
55 576, 548, 582, 618, 546, 616, 560, 642,
56 584, 582, 704, 664, 512, 544, 656, 640,
57 512, 648, 582, 566, 532, 614, 596, 648,
58 586, 552, 584, 590, 544, 578, 584, 624,
60 528, 528, 526, 528, 536, 528, 526, 544,
61 544, 512, 512, 528, 528, 544, 512, 544,
63 128, 128, 128, 128, 128, 128,
69 #define init_ac_vlc(dst, src) \
71 dst.table = &table[offset]; \
72 dst.table_allocated = sizes[sizeidx]; \
73 offset += sizes[sizeidx++]; \
74 init_vlc(&dst, AC_VLC_BITS, 77, &src[1], 4, 2, &src[0], 4, 2, \
75 INIT_VLC_USE_NEW_STATIC); \
78 for (
i = 0;
i < 8;
i++) {
87 #define init_dc_vlc(dst, src) \
89 dst.table = &table[offset]; \
90 dst.table_allocated = sizes[sizeidx]; \
91 offset += sizes[sizeidx++]; \
92 init_vlc(&dst, DC_VLC_BITS, 34, &src[1], 4, 2, &src[0], 4, 2, \
93 INIT_VLC_USE_NEW_STATIC); \
96 for (
i = 0;
i < 8;
i++) {
103 #define init_or_vlc(dst, src) \
105 dst.table = &table[offset]; \
106 dst.table_allocated = sizes[sizeidx]; \
107 offset += sizes[sizeidx++]; \
108 init_vlc(&dst, OR_VLC_BITS, 12, &src[1], 4, 2, &src[0], 4, 2, \
109 INIT_VLC_USE_NEW_STATIC); \
112 for (
i = 0;
i < 2;
i++)
114 for (
i = 0;
i < 4;
i++)
129 memset(
w->j_dc_vlc, 0,
sizeof(
w->j_dc_vlc));
130 memset(
w->j_ac_vlc, 0,
sizeof(
w->j_ac_vlc));
131 w->j_orient_vlc =
NULL;
140 if (
w->j_ac_vlc[
mode])
151 if (!
w->j_orient_vlc) {
152 int table_index =
get_bits(
w->gb, 1 + (
w->quant < 13));
159 #define extra_bits(eb) (eb) // 3 bits
160 #define extra_run (0xFF << 8) // 1 bit
161 #define extra_level (0x00 << 8) // 1 bit
162 #define run_offset(r) ((r) << 16) // 6 bits
163 #define level_offset(l) ((l) << 24) // 5 bits
207 int *
const run,
int *
const level,
int *
const final)
236 l = (0xE50000 >> (
i & 0x1E)) & 3;
240 t = 0x01030F >> (l << 3);
256 *
run = (sm & 0xff) + (e &
mask);
258 *
final =
i > (58 - 46);
260 static const uint8_t crazy_mix_runlevel[32] = {
261 0x22, 0x32, 0x33, 0x53, 0x23, 0x42, 0x43, 0x63,
262 0x24, 0x52, 0x34, 0x73, 0x25, 0x62, 0x44, 0x83,
263 0x26, 0x72, 0x35, 0x54, 0x27, 0x82, 0x45, 0x64,
264 0x28, 0x92, 0x36, 0x74, 0x29, 0xa2, 0x46, 0x84,
269 *
run = crazy_mix_runlevel[e] >> 4;
270 *
level = crazy_mix_runlevel[e] & 0x0F;
283 0, 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
287 int *
const level,
int *
const final)
292 if (!
w->j_dc_vlc[
mode]) {
328 w->dsp.setup_spatial_compensation(
w->dest[
chroma],
w->scratchpad,
329 w->frame->linesize[
chroma > 0],
330 &range, &sum,
w->edges);
332 w->orient =
w->chroma_orient;
333 quant =
w->quant_dc_chroma;
339 if (range <
quant || range < 3) {
347 w->predicted_dc = sum * 6899 >> 17;
354 if (range < 2 * w->
quant) {
355 if ((
w->edges & 3) == 0) {
365 static const uint8_t prediction_table[3][12] = {
366 { 0, 8, 4, 10, 11, 2, 6, 9, 1, 3, 5, 7 },
367 { 4, 0, 8, 11, 10, 3, 5, 2, 6, 9, 1, 7 },
368 { 8, 0, 4, 10, 11, 1, 7, 2, 6, 9, 3, 5 },
371 if (
w->raw_orient < 0)
375 w->orient=prediction_table[
w->orient][
w->raw_orient];
383 w->prediction_table[
w->mb_x * 2 + (
w->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orient == 8);
392 w->edges = 1 * !(
w->mb_x >> 1);
393 w->edges |= 2 * !(
w->mb_y >> 1);
394 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
399 w->chroma_orient = 4 << ((0xCC >>
w->edges) & 1);
403 w->chroma_orient = (
w->prediction_table[2 *
w->mb_x - 2] & 0x03) << 2;
410 w->edges = 1 * !
w->mb_x;
411 w->edges |= 2 * !
w->mb_y;
412 w->edges |= 4 * (
w->mb_x >= (2 *
w->mb_width - 1));
414 switch (
w->edges & 3) {
419 w->est_run =
w->prediction_table[!(
w->mb_y & 1)] >> 2;
424 w->est_run =
w->prediction_table[2 *
w->mb_x - 2] >> 2;
433 b =
w->prediction_table[2 *
w->mb_x + !(
w->mb_y & 1)];
434 a =
w->prediction_table[2 *
w->mb_x - 2 + (
w->mb_y & 1)];
435 c =
w->prediction_table[2 *
w->mb_x - 2 + !(
w->mb_y & 1)];
441 if ((
w->mb_x &
w->mb_y) != 0)
449 i = (0xFFEAF4C4 >> (2 *
b + 8 *
a)) & 3;
453 w->orient = (0xFFEAD8 >> (2 *
c + 8 * (
w->quant > 12))) & 3;
479 #define B(x,y) w->block[0][w->idct_permutation[(x) + (y) * 8]]
480 #define T(x) ((x) * dc_level + 0x8000) >> 16;
523 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
531 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7 * 8);
539 w->block_last_index[0] =
FFMAX(
w->block_last_index[0], 7);
547 const ptrdiff_t linesize)
550 for (k = 0; k < 8; k++) {
557 256, 256, 256, 256, 256, 256, 259, 262,
558 265, 269, 272, 275, 278, 282, 285, 288,
559 292, 295, 299, 303, 306, 310, 314, 317,
560 321, 325, 329, 333, 337, 341, 345, 349,
561 353, 358, 362, 366, 371, 375, 379, 384,
562 389, 393, 398, 403, 408, 413, 417, 422,
563 428, 433, 438, 443, 448, 454, 459, 465,
564 470, 476, 482, 488, 493, 499, 505, 511,
571 int ac_mode, dc_mode, est_run, dc_level;
574 int use_quant_matrix;
578 w->bdsp.clear_block(
w->block[0]);
583 dc_mode = !!
w->est_run;
590 use_quant_matrix =
w->use_quant_matrix;
595 if (
w->raw_orient < 3)
596 use_quant_matrix = 0;
598 if (
w->raw_orient > 4) {
602 if (
w->est_run > 1) {
604 est_run =
w->est_run;
614 scantable =
w->scantable[(0x928548 >> (2 *
w->orient)) & 3].permutated;
636 if (use_quant_matrix)
639 w->block[0][scantable[pos]] =
level;
642 w->block_last_index[0] = pos;
644 w->block_last_index[0] = 0;
645 if (
w->flat_dc && ((
unsigned) (dc_level + 1)) < 3) {
647 :
w->divide_quant_dc_chroma;
649 :
w->quant_dc_chroma;
653 dc_level += (
w->predicted_dc * divide_quant + (1 << 12)) >> 13;
661 zeros_only = dc_level == 0;
664 w->block[0][0] = dc_level *
w->quant;
666 w->block[0][0] = dc_level *
w->quant_dc_chroma;
669 if ((
unsigned int) (dc_level + 1) >= 3 && (
w->edges & 3) != 3) {
673 direction = (0x6A017C >> (
w->orient * 2)) & 3;
674 if (direction != 3) {
684 w->dsp.spatial_compensation[
w->orient](
w->scratchpad,
699 ptrdiff_t linesize =
w->frame->linesize[!!
chroma];
701 if (!((
w->edges & 2) || (zeros_only && (
w->orient | 4) == 4)))
702 w->dsp.h_loop_filter(ptr, linesize,
w->quant);
704 if (!((
w->edges & 1) || (zeros_only && (
w->orient | 8) == 8)))
705 w->dsp.v_loop_filter(ptr, linesize,
w->quant);
715 const ptrdiff_t linesize =
frame->linesize[0];
716 const ptrdiff_t uvlinesize =
frame->linesize[1];
718 w->dest[0] =
frame->data[0];
719 w->dest[1] =
frame->data[1];
720 w->dest[2] =
frame->data[2];
722 w->dest[0] +=
w->mb_y * linesize << 3;
724 w->dest[1] += (
w->mb_y & ~1) * uvlinesize << 2;
725 w->dest[2] += (
w->mb_y & ~1) * uvlinesize << 2;
730 int16_t (*
block)[64],
731 int block_last_index[12],
732 int mb_width,
int mb_height)
740 w->mb_width = mb_width;
741 w->mb_height = mb_height;
743 w->block_last_index = block_last_index;
747 if (!
w->prediction_table)
775 int dquant,
int quant_offset,
776 int loopfilter,
int lowdelay)
782 w->quant = dquant >> 1;
783 w->qsum = quant_offset;
785 w->loopfilter = loopfilter;
791 w->divide_quant_dc_luma = ((1 << 16) + (
w->quant >> 1)) /
w->quant;
793 w->quant_dc_chroma =
w->quant;
794 w->divide_quant_dc_chroma =
w->divide_quant_dc_luma;
796 w->quant_dc_chroma =
w->quant + ((
w->quant + 3) >> 3);
797 w->divide_quant_dc_chroma = ((1 << 16) + (
w->quant_dc_chroma >> 1)) /
w->quant_dc_chroma;
801 for (
w->mb_y = 0;
w->mb_y <
w->mb_height * 2;
w->mb_y++) {
803 mb_xy = (
w->mb_y >> 1) * (
w->mb_width + 1);
806 for (
w->mb_x = 0;
w->mb_x <
w->mb_width * 2;
w->mb_x++) {
813 if (
w->mb_x &
w->mb_y & 1) {
836 (
w->mb_y - 1) * 8, 16,