static void fdct4(const tran_low_t *input, tran_low_t *output) { tran_high_t temp; tran_low_t step[4]; // stage 0 range_check(input, 4, 14); // stage 1 output[0] = input[0] + input[3]; output[1] = input[1] + input[2]; output[2] = input[1] - input[2]; output[3] = input[0] - input[3]; range_check(output, 4, 15); // stage 2 temp = output[0] * cospi_16_64 + output[1] * cospi_16_64; step[0] = (tran_low_t)fdct_round_shift(temp); temp = output[1] * -cospi_16_64 + output[0] * cospi_16_64; step[1] = (tran_low_t)fdct_round_shift(temp); temp = output[2] * cospi_24_64 + output[3] * cospi_8_64; step[2] = (tran_low_t)fdct_round_shift(temp); temp = output[3] * cospi_24_64 + output[2] * -cospi_8_64; step[3] = (tran_low_t)fdct_round_shift(temp); range_check(step, 4, 16); // stage 3 output[0] = step[0]; output[1] = step[2]; output[2] = step[1]; output[3] = step[3]; range_check(output, 4, 16); }
static void fdct8(const tran_low_t *input, tran_low_t *output) { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 // stage 1 s0 = input[0] + input[7]; s1 = input[1] + input[6]; s2 = input[2] + input[5]; s3 = input[3] + input[4]; s4 = input[3] - input[4]; s5 = input[2] - input[5]; s6 = input[1] - input[6]; s7 = input[0] - input[7]; // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x2 * cospi_24_64 + x3 * cospi_8_64; t3 = -x2 * cospi_8_64 + x3 * cospi_24_64; output[0] = (tran_low_t)fdct_round_shift(t0); output[2] = (tran_low_t)fdct_round_shift(t2); output[4] = (tran_low_t)fdct_round_shift(t1); output[6] = (tran_low_t)fdct_round_shift(t3); // Stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = (tran_low_t)fdct_round_shift(t0); t3 = (tran_low_t)fdct_round_shift(t1); // Stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // Stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; output[1] = (tran_low_t)fdct_round_shift(t0); output[3] = (tran_low_t)fdct_round_shift(t2); output[5] = (tran_low_t)fdct_round_shift(t1); output[7] = (tran_low_t)fdct_round_shift(t3); }
static void fdct4(const tran_low_t *input, tran_low_t *output) { tran_high_t step[4]; tran_high_t temp1, temp2; step[0] = input[0] + input[3]; step[1] = input[1] + input[2]; step[2] = input[1] - input[2]; step[3] = input[0] - input[3]; temp1 = (step[0] + step[1]) * cospi_16_64; temp2 = (step[0] - step[1]) * cospi_16_64; output[0] = (tran_low_t)fdct_round_shift(temp1); output[2] = (tran_low_t)fdct_round_shift(temp2); temp1 = step[2] * cospi_24_64 + step[3] * cospi_8_64; temp2 = -step[2] * cospi_8_64 + step[3] * cospi_24_64; output[1] = (tran_low_t)fdct_round_shift(temp1); output[3] = (tran_low_t)fdct_round_shift(temp2); }
static void fadst4(const tran_low_t *input, tran_low_t *output) { tran_high_t x0, x1, x2, x3; tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; x0 = input[0]; x1 = input[1]; x2 = input[2]; x3 = input[3]; if (!(x0 | x1 | x2 | x3)) { output[0] = output[1] = output[2] = output[3] = 0; return; } s0 = sinpi_1_9 * x0; s1 = sinpi_4_9 * x0; s2 = sinpi_2_9 * x1; s3 = sinpi_1_9 * x1; s4 = sinpi_3_9 * x2; s5 = sinpi_4_9 * x3; s6 = sinpi_2_9 * x3; s7 = x0 + x1 - x3; x0 = s0 + s2 + s5; x1 = sinpi_3_9 * s7; x2 = s1 - s3 + s6; x3 = s4; s0 = x0 + x3; s1 = x1; s2 = x2 - x3; s3 = x2 - x0 + x3; // 1-D transform scaling factor is sqrt(2). output[0] = (tran_low_t)fdct_round_shift(s0); output[1] = (tran_low_t)fdct_round_shift(s1); output[2] = (tran_low_t)fdct_round_shift(s2); output[3] = (tran_low_t)fdct_round_shift(s3); }
static void fdct16(const tran_low_t in[16], tran_low_t out[16]) { tran_high_t step1[8]; // canbe16 tran_high_t step2[8]; // canbe16 tran_high_t step3[8]; // canbe16 tran_high_t input[8]; // canbe16 tran_high_t temp1, temp2; // needs32 // step 1 input[0] = in[0] + in[15]; input[1] = in[1] + in[14]; input[2] = in[2] + in[13]; input[3] = in[3] + in[12]; input[4] = in[4] + in[11]; input[5] = in[5] + in[10]; input[6] = in[6] + in[9]; input[7] = in[7] + in[8]; step1[0] = in[7] - in[8]; step1[1] = in[6] - in[9]; step1[2] = in[5] - in[10]; step1[3] = in[4] - in[11]; step1[4] = in[3] - in[12]; step1[5] = in[2] - in[13]; step1[6] = in[1] - in[14]; step1[7] = in[0] - in[15]; // fdct8(step, step); { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 // stage 1 s0 = input[0] + input[7]; s1 = input[1] + input[6]; s2 = input[2] + input[5]; s3 = input[3] + input[4]; s4 = input[3] - input[4]; s5 = input[2] - input[5]; s6 = input[1] - input[6]; s7 = input[0] - input[7]; // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x3 * cospi_8_64 + x2 * cospi_24_64; t3 = x3 * cospi_24_64 - x2 * cospi_8_64; out[0] = (tran_low_t)fdct_round_shift(t0); out[4] = (tran_low_t)fdct_round_shift(t2); out[8] = (tran_low_t)fdct_round_shift(t1); out[12] = (tran_low_t)fdct_round_shift(t3); // Stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = fdct_round_shift(t0); t3 = fdct_round_shift(t1); // Stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // Stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; out[2] = (tran_low_t)fdct_round_shift(t0); out[6] = (tran_low_t)fdct_round_shift(t2); out[10] = (tran_low_t)fdct_round_shift(t1); out[14] = (tran_low_t)fdct_round_shift(t3); } // step 2 temp1 = (step1[5] - step1[2]) * cospi_16_64; temp2 = (step1[4] - step1[3]) * cospi_16_64; step2[2] = fdct_round_shift(temp1); step2[3] = fdct_round_shift(temp2); temp1 = (step1[4] + step1[3]) * cospi_16_64; temp2 = (step1[5] + step1[2]) * cospi_16_64; step2[4] = fdct_round_shift(temp1); step2[5] = fdct_round_shift(temp2); // step 3 step3[0] = step1[0] + step2[3]; step3[1] = step1[1] + step2[2]; step3[2] = step1[1] - step2[2]; step3[3] = step1[0] - step2[3]; step3[4] = step1[7] - step2[4]; step3[5] = step1[6] - step2[5]; step3[6] = step1[6] + step2[5]; step3[7] = step1[7] + step2[4]; // step 4 temp1 = step3[1] * -cospi_8_64 + step3[6] * cospi_24_64; temp2 = step3[2] * cospi_24_64 + step3[5] * cospi_8_64; step2[1] = fdct_round_shift(temp1); step2[2] = fdct_round_shift(temp2); temp1 = step3[2] * cospi_8_64 - step3[5] * cospi_24_64; temp2 = step3[1] * cospi_24_64 + step3[6] * cospi_8_64; step2[5] = fdct_round_shift(temp1); step2[6] = fdct_round_shift(temp2); // step 5 step1[0] = step3[0] + step2[1]; step1[1] = step3[0] - step2[1]; step1[2] = step3[3] + step2[2]; step1[3] = step3[3] - step2[2]; step1[4] = step3[4] - step2[5]; step1[5] = step3[4] + step2[5]; step1[6] = step3[7] - step2[6]; step1[7] = step3[7] + step2[6]; // step 6 temp1 = step1[0] * cospi_30_64 + step1[7] * cospi_2_64; temp2 = step1[1] * cospi_14_64 + step1[6] * cospi_18_64; out[1] = (tran_low_t)fdct_round_shift(temp1); out[9] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[2] * cospi_22_64 + step1[5] * cospi_10_64; temp2 = step1[3] * cospi_6_64 + step1[4] * cospi_26_64; out[5] = (tran_low_t)fdct_round_shift(temp1); out[13] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[3] * -cospi_26_64 + step1[4] * cospi_6_64; temp2 = step1[2] * -cospi_10_64 + step1[5] * cospi_22_64; out[3] = (tran_low_t)fdct_round_shift(temp1); out[11] = (tran_low_t)fdct_round_shift(temp2); temp1 = step1[1] * -cospi_18_64 + step1[6] * cospi_14_64; temp2 = step1[0] * -cospi_2_64 + step1[7] * cospi_30_64; out[7] = (tran_low_t)fdct_round_shift(temp1); out[15] = (tran_low_t)fdct_round_shift(temp2); }
void vp9_fdct8x8_quant_c(const int16_t *input, int stride, tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *round_ptr, const int16_t *quant_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan) { int eob = -1; int i, j; tran_low_t intermediate[64]; (void)iscan; // Transform columns { tran_low_t *output = intermediate; tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 int i; for (i = 0; i < 8; i++) { // stage 1 s0 = (input[0 * stride] + input[7 * stride]) * 4; s1 = (input[1 * stride] + input[6 * stride]) * 4; s2 = (input[2 * stride] + input[5 * stride]) * 4; s3 = (input[3 * stride] + input[4 * stride]) * 4; s4 = (input[3 * stride] - input[4 * stride]) * 4; s5 = (input[2 * stride] - input[5 * stride]) * 4; s6 = (input[1 * stride] - input[6 * stride]) * 4; s7 = (input[0 * stride] - input[7 * stride]) * 4; // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x2 * cospi_24_64 + x3 * cospi_8_64; t3 = -x2 * cospi_8_64 + x3 * cospi_24_64; output[0 * 8] = (tran_low_t)fdct_round_shift(t0); output[2 * 8] = (tran_low_t)fdct_round_shift(t2); output[4 * 8] = (tran_low_t)fdct_round_shift(t1); output[6 * 8] = (tran_low_t)fdct_round_shift(t3); // Stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = fdct_round_shift(t0); t3 = fdct_round_shift(t1); // Stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // Stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; output[1 * 8] = (tran_low_t)fdct_round_shift(t0); output[3 * 8] = (tran_low_t)fdct_round_shift(t2); output[5 * 8] = (tran_low_t)fdct_round_shift(t1); output[7 * 8] = (tran_low_t)fdct_round_shift(t3); input++; output++; } } // Rows for (i = 0; i < 8; ++i) { fdct8(&intermediate[i * 8], &coeff_ptr[i * 8]); for (j = 0; j < 8; ++j) coeff_ptr[j + i * 8] /= 2; } memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); if (!skip_block) { // Quantization pass: All coefficients with index >= zero_flag are // skippable. Note: zero_flag can be zero. for (i = 0; i < n_coeffs; i++) { const int rc = scan[i]; const int coeff = coeff_ptr[rc]; const int coeff_sign = (coeff >> 31); const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); tmp = (tmp * quant_ptr[rc != 0]) >> 16; qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign; dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; if (tmp) eob = i; } } *eob_ptr = eob + 1; }
static void fadst16(const tran_low_t *input, tran_low_t *output) { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7, s8; tran_high_t s9, s10, s11, s12, s13, s14, s15; tran_high_t x0 = input[15]; tran_high_t x1 = input[0]; tran_high_t x2 = input[13]; tran_high_t x3 = input[2]; tran_high_t x4 = input[11]; tran_high_t x5 = input[4]; tran_high_t x6 = input[9]; tran_high_t x7 = input[6]; tran_high_t x8 = input[7]; tran_high_t x9 = input[8]; tran_high_t x10 = input[5]; tran_high_t x11 = input[10]; tran_high_t x12 = input[3]; tran_high_t x13 = input[12]; tran_high_t x14 = input[1]; tran_high_t x15 = input[14]; // stage 1 s0 = x0 * cospi_1_64 + x1 * cospi_31_64; s1 = x0 * cospi_31_64 - x1 * cospi_1_64; s2 = x2 * cospi_5_64 + x3 * cospi_27_64; s3 = x2 * cospi_27_64 - x3 * cospi_5_64; s4 = x4 * cospi_9_64 + x5 * cospi_23_64; s5 = x4 * cospi_23_64 - x5 * cospi_9_64; s6 = x6 * cospi_13_64 + x7 * cospi_19_64; s7 = x6 * cospi_19_64 - x7 * cospi_13_64; s8 = x8 * cospi_17_64 + x9 * cospi_15_64; s9 = x8 * cospi_15_64 - x9 * cospi_17_64; s10 = x10 * cospi_21_64 + x11 * cospi_11_64; s11 = x10 * cospi_11_64 - x11 * cospi_21_64; s12 = x12 * cospi_25_64 + x13 * cospi_7_64; s13 = x12 * cospi_7_64 - x13 * cospi_25_64; s14 = x14 * cospi_29_64 + x15 * cospi_3_64; s15 = x14 * cospi_3_64 - x15 * cospi_29_64; x0 = fdct_round_shift(s0 + s8); x1 = fdct_round_shift(s1 + s9); x2 = fdct_round_shift(s2 + s10); x3 = fdct_round_shift(s3 + s11); x4 = fdct_round_shift(s4 + s12); x5 = fdct_round_shift(s5 + s13); x6 = fdct_round_shift(s6 + s14); x7 = fdct_round_shift(s7 + s15); x8 = fdct_round_shift(s0 - s8); x9 = fdct_round_shift(s1 - s9); x10 = fdct_round_shift(s2 - s10); x11 = fdct_round_shift(s3 - s11); x12 = fdct_round_shift(s4 - s12); x13 = fdct_round_shift(s5 - s13); x14 = fdct_round_shift(s6 - s14); x15 = fdct_round_shift(s7 - s15); // stage 2 s0 = x0; s1 = x1; s2 = x2; s3 = x3; s4 = x4; s5 = x5; s6 = x6; s7 = x7; s8 = x8 * cospi_4_64 + x9 * cospi_28_64; s9 = x8 * cospi_28_64 - x9 * cospi_4_64; s10 = x10 * cospi_20_64 + x11 * cospi_12_64; s11 = x10 * cospi_12_64 - x11 * cospi_20_64; s12 = -x12 * cospi_28_64 + x13 * cospi_4_64; s13 = x12 * cospi_4_64 + x13 * cospi_28_64; s14 = -x14 * cospi_12_64 + x15 * cospi_20_64; s15 = x14 * cospi_20_64 + x15 * cospi_12_64; x0 = s0 + s4; x1 = s1 + s5; x2 = s2 + s6; x3 = s3 + s7; x4 = s0 - s4; x5 = s1 - s5; x6 = s2 - s6; x7 = s3 - s7; x8 = fdct_round_shift(s8 + s12); x9 = fdct_round_shift(s9 + s13); x10 = fdct_round_shift(s10 + s14); x11 = fdct_round_shift(s11 + s15); x12 = fdct_round_shift(s8 - s12); x13 = fdct_round_shift(s9 - s13); x14 = fdct_round_shift(s10 - s14); x15 = fdct_round_shift(s11 - s15); // stage 3 s0 = x0; s1 = x1; s2 = x2; s3 = x3; s4 = x4 * cospi_8_64 + x5 * cospi_24_64; s5 = x4 * cospi_24_64 - x5 * cospi_8_64; s6 = -x6 * cospi_24_64 + x7 * cospi_8_64; s7 = x6 * cospi_8_64 + x7 * cospi_24_64; s8 = x8; s9 = x9; s10 = x10; s11 = x11; s12 = x12 * cospi_8_64 + x13 * cospi_24_64; s13 = x12 * cospi_24_64 - x13 * cospi_8_64; s14 = -x14 * cospi_24_64 + x15 * cospi_8_64; s15 = x14 * cospi_8_64 + x15 * cospi_24_64; x0 = s0 + s2; x1 = s1 + s3; x2 = s0 - s2; x3 = s1 - s3; x4 = fdct_round_shift(s4 + s6); x5 = fdct_round_shift(s5 + s7); x6 = fdct_round_shift(s4 - s6); x7 = fdct_round_shift(s5 - s7); x8 = s8 + s10; x9 = s9 + s11; x10 = s8 - s10; x11 = s9 - s11; x12 = fdct_round_shift(s12 + s14); x13 = fdct_round_shift(s13 + s15); x14 = fdct_round_shift(s12 - s14); x15 = fdct_round_shift(s13 - s15); // stage 4 s2 = (-cospi_16_64) * (x2 + x3); s3 = cospi_16_64 * (x2 - x3); s6 = cospi_16_64 * (x6 + x7); s7 = cospi_16_64 * (-x6 + x7); s10 = cospi_16_64 * (x10 + x11); s11 = cospi_16_64 * (-x10 + x11); s14 = (-cospi_16_64) * (x14 + x15); s15 = cospi_16_64 * (x14 - x15); x2 = fdct_round_shift(s2); x3 = fdct_round_shift(s3); x6 = fdct_round_shift(s6); x7 = fdct_round_shift(s7); x10 = fdct_round_shift(s10); x11 = fdct_round_shift(s11); x14 = fdct_round_shift(s14); x15 = fdct_round_shift(s15); output[0] = (tran_low_t)x0; output[1] = (tran_low_t)-x8; output[2] = (tran_low_t)x12; output[3] = (tran_low_t)-x4; output[4] = (tran_low_t)x6; output[5] = (tran_low_t)x14; output[6] = (tran_low_t)x10; output[7] = (tran_low_t)x2; output[8] = (tran_low_t)x3; output[9] = (tran_low_t)x11; output[10] = (tran_low_t)x15; output[11] = (tran_low_t)x7; output[12] = (tran_low_t)x5; output[13] = (tran_low_t)-x13; output[14] = (tran_low_t)x9; output[15] = (tran_low_t)-x1; }
static void fadst8(const tran_low_t *input, tran_low_t *output) { tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; tran_high_t x0 = input[7]; tran_high_t x1 = input[0]; tran_high_t x2 = input[5]; tran_high_t x3 = input[2]; tran_high_t x4 = input[3]; tran_high_t x5 = input[4]; tran_high_t x6 = input[1]; tran_high_t x7 = input[6]; // stage 1 s0 = cospi_2_64 * x0 + cospi_30_64 * x1; s1 = cospi_30_64 * x0 - cospi_2_64 * x1; s2 = cospi_10_64 * x2 + cospi_22_64 * x3; s3 = cospi_22_64 * x2 - cospi_10_64 * x3; s4 = cospi_18_64 * x4 + cospi_14_64 * x5; s5 = cospi_14_64 * x4 - cospi_18_64 * x5; s6 = cospi_26_64 * x6 + cospi_6_64 * x7; s7 = cospi_6_64 * x6 - cospi_26_64 * x7; x0 = fdct_round_shift(s0 + s4); x1 = fdct_round_shift(s1 + s5); x2 = fdct_round_shift(s2 + s6); x3 = fdct_round_shift(s3 + s7); x4 = fdct_round_shift(s0 - s4); x5 = fdct_round_shift(s1 - s5); x6 = fdct_round_shift(s2 - s6); x7 = fdct_round_shift(s3 - s7); // stage 2 s0 = x0; s1 = x1; s2 = x2; s3 = x3; s4 = cospi_8_64 * x4 + cospi_24_64 * x5; s5 = cospi_24_64 * x4 - cospi_8_64 * x5; s6 = -cospi_24_64 * x6 + cospi_8_64 * x7; s7 = cospi_8_64 * x6 + cospi_24_64 * x7; x0 = s0 + s2; x1 = s1 + s3; x2 = s0 - s2; x3 = s1 - s3; x4 = fdct_round_shift(s4 + s6); x5 = fdct_round_shift(s5 + s7); x6 = fdct_round_shift(s4 - s6); x7 = fdct_round_shift(s5 - s7); // stage 3 s2 = cospi_16_64 * (x2 + x3); s3 = cospi_16_64 * (x2 - x3); s6 = cospi_16_64 * (x6 + x7); s7 = cospi_16_64 * (x6 - x7); x2 = fdct_round_shift(s2); x3 = fdct_round_shift(s3); x6 = fdct_round_shift(s6); x7 = fdct_round_shift(s7); output[0] = (tran_low_t)x0; output[1] = (tran_low_t)-x4; output[2] = (tran_low_t)x6; output[3] = (tran_low_t)-x2; output[4] = (tran_low_t)x3; output[5] = (tran_low_t)-x7; output[6] = (tran_low_t)x5; output[7] = (tran_low_t)-x1; }
static INLINE void fwd_txfm2d_c(const int16_t *input, int32_t *output, const int stride, const TXFM_2D_FLIP_CFG *cfg, int32_t *buf, int bd) { int c, r; // Note when assigning txfm_size_col, we use the txfm_size from the // row configuration and vice versa. This is intentionally done to // accurately perform rectangular transforms. When the transform is // rectangular, the number of columns will be the same as the // txfm_size stored in the row cfg struct. It will make no difference // for square transforms. const int txfm_size_col = cfg->row_cfg->txfm_size; const int txfm_size_row = cfg->col_cfg->txfm_size; // Take the shift from the larger dimension in the rectangular case. const int8_t *shift = (txfm_size_col > txfm_size_row) ? cfg->row_cfg->shift : cfg->col_cfg->shift; int8_t stage_range_col[MAX_TXFM_STAGE_NUM]; int8_t stage_range_row[MAX_TXFM_STAGE_NUM]; assert(cfg->col_cfg->stage_num <= MAX_TXFM_STAGE_NUM); assert(cfg->row_cfg->stage_num <= MAX_TXFM_STAGE_NUM); av1_gen_fwd_stage_range(stage_range_col, stage_range_row, cfg, bd); const int8_t *cos_bit_col = cfg->col_cfg->cos_bit; const int8_t *cos_bit_row = cfg->row_cfg->cos_bit; const TxfmFunc txfm_func_col = fwd_txfm_type_to_func(cfg->col_cfg->txfm_type); const TxfmFunc txfm_func_row = fwd_txfm_type_to_func(cfg->row_cfg->txfm_type); // use output buffer as temp buffer int32_t *temp_in = output; int32_t *temp_out = output + txfm_size_row; // Columns for (c = 0; c < txfm_size_col; ++c) { if (cfg->ud_flip == 0) { for (r = 0; r < txfm_size_row; ++r) temp_in[r] = input[r * stride + c]; } else { for (r = 0; r < txfm_size_row; ++r) // flip upside down temp_in[r] = input[(txfm_size_row - r - 1) * stride + c]; } round_shift_array(temp_in, txfm_size_row, -shift[0]); // Multiply everything by Sqrt2 on the larger dimension if the // transform is rectangular if (txfm_size_col > txfm_size_row) { for (r = 0; r < txfm_size_row; ++r) temp_in[r] = (int32_t)fdct_round_shift(temp_in[r] * Sqrt2); } txfm_func_col(temp_in, temp_out, cos_bit_col, stage_range_col); round_shift_array(temp_out, txfm_size_row, -shift[1]); if (cfg->lr_flip == 0) { for (r = 0; r < txfm_size_row; ++r) buf[r * txfm_size_col + c] = temp_out[r]; } else { for (r = 0; r < txfm_size_row; ++r) // flip from left to right buf[r * txfm_size_col + (txfm_size_col - c - 1)] = temp_out[r]; } } // Rows for (r = 0; r < txfm_size_row; ++r) { // Multiply everything by Sqrt2 on the larger dimension if the // transform is rectangular if (txfm_size_row > txfm_size_col) { for (c = 0; c < txfm_size_col; ++c) buf[r * txfm_size_col + c] = (int32_t)fdct_round_shift(buf[r * txfm_size_col + c] * Sqrt2); } txfm_func_row(buf + r * txfm_size_col, output + r * txfm_size_col, cos_bit_row, stage_range_row); round_shift_array(output + r * txfm_size_col, txfm_size_col, -shift[2]); } }
static void fdct8(const tran_low_t *input, tran_low_t *output) { tran_high_t temp; tran_low_t step[8]; // stage 0 range_check(input, 8, 13); // stage 1 output[0] = input[0] + input[7]; output[1] = input[1] + input[6]; output[2] = input[2] + input[5]; output[3] = input[3] + input[4]; output[4] = input[3] - input[4]; output[5] = input[2] - input[5]; output[6] = input[1] - input[6]; output[7] = input[0] - input[7]; range_check(output, 8, 14); // stage 2 step[0] = output[0] + output[3]; step[1] = output[1] + output[2]; step[2] = output[1] - output[2]; step[3] = output[0] - output[3]; step[4] = output[4]; temp = output[5] * -cospi_16_64 + output[6] * cospi_16_64; step[5] = (tran_low_t)fdct_round_shift(temp); temp = output[6] * cospi_16_64 + output[5] * cospi_16_64; step[6] = (tran_low_t)fdct_round_shift(temp); step[7] = output[7]; range_check(step, 8, 15); // stage 3 temp = step[0] * cospi_16_64 + step[1] * cospi_16_64; output[0] = (tran_low_t)fdct_round_shift(temp); temp = step[1] * -cospi_16_64 + step[0] * cospi_16_64; output[1] = (tran_low_t)fdct_round_shift(temp); temp = step[2] * cospi_24_64 + step[3] * cospi_8_64; output[2] = (tran_low_t)fdct_round_shift(temp); temp = step[3] * cospi_24_64 + step[2] * -cospi_8_64; output[3] = (tran_low_t)fdct_round_shift(temp); output[4] = step[4] + step[5]; output[5] = step[4] - step[5]; output[6] = step[7] - step[6]; output[7] = step[7] + step[6]; range_check(output, 8, 16); // stage 4 step[0] = output[0]; step[1] = output[1]; step[2] = output[2]; step[3] = output[3]; temp = output[4] * cospi_28_64 + output[7] * cospi_4_64; step[4] = (tran_low_t)fdct_round_shift(temp); temp = output[5] * cospi_12_64 + output[6] * cospi_20_64; step[5] = (tran_low_t)fdct_round_shift(temp); temp = output[6] * cospi_12_64 + output[5] * -cospi_20_64; step[6] = (tran_low_t)fdct_round_shift(temp); temp = output[7] * cospi_28_64 + output[4] * -cospi_4_64; step[7] = (tran_low_t)fdct_round_shift(temp); range_check(step, 8, 16); // stage 5 output[0] = step[0]; output[1] = step[4]; output[2] = step[2]; output[3] = step[6]; output[4] = step[1]; output[5] = step[5]; output[6] = step[3]; output[7] = step[7]; range_check(output, 8, 16); }
static void fdct16(const tran_low_t *input, tran_low_t *output) { tran_high_t temp; tran_low_t step[16]; // stage 0 range_check(input, 16, 13); // stage 1 output[0] = input[0] + input[15]; output[1] = input[1] + input[14]; output[2] = input[2] + input[13]; output[3] = input[3] + input[12]; output[4] = input[4] + input[11]; output[5] = input[5] + input[10]; output[6] = input[6] + input[9]; output[7] = input[7] + input[8]; output[8] = input[7] - input[8]; output[9] = input[6] - input[9]; output[10] = input[5] - input[10]; output[11] = input[4] - input[11]; output[12] = input[3] - input[12]; output[13] = input[2] - input[13]; output[14] = input[1] - input[14]; output[15] = input[0] - input[15]; range_check(output, 16, 14); // stage 2 step[0] = output[0] + output[7]; step[1] = output[1] + output[6]; step[2] = output[2] + output[5]; step[3] = output[3] + output[4]; step[4] = output[3] - output[4]; step[5] = output[2] - output[5]; step[6] = output[1] - output[6]; step[7] = output[0] - output[7]; step[8] = output[8]; step[9] = output[9]; temp = output[10] * -cospi_16_64 + output[13] * cospi_16_64; step[10] = (tran_low_t)fdct_round_shift(temp); temp = output[11] * -cospi_16_64 + output[12] * cospi_16_64; step[11] = (tran_low_t)fdct_round_shift(temp); temp = output[12] * cospi_16_64 + output[11] * cospi_16_64; step[12] = (tran_low_t)fdct_round_shift(temp); temp = output[13] * cospi_16_64 + output[10] * cospi_16_64; step[13] = (tran_low_t)fdct_round_shift(temp); step[14] = output[14]; step[15] = output[15]; range_check(step, 16, 15); // stage 3 output[0] = step[0] + step[3]; output[1] = step[1] + step[2]; output[2] = step[1] - step[2]; output[3] = step[0] - step[3]; output[4] = step[4]; temp = step[5] * -cospi_16_64 + step[6] * cospi_16_64; output[5] = (tran_low_t)fdct_round_shift(temp); temp = step[6] * cospi_16_64 + step[5] * cospi_16_64; output[6] = (tran_low_t)fdct_round_shift(temp); output[7] = step[7]; output[8] = step[8] + step[11]; output[9] = step[9] + step[10]; output[10] = step[9] - step[10]; output[11] = step[8] - step[11]; output[12] = step[15] - step[12]; output[13] = step[14] - step[13]; output[14] = step[14] + step[13]; output[15] = step[15] + step[12]; range_check(output, 16, 16); // stage 4 temp = output[0] * cospi_16_64 + output[1] * cospi_16_64; step[0] = (tran_low_t)fdct_round_shift(temp); temp = output[1] * -cospi_16_64 + output[0] * cospi_16_64; step[1] = (tran_low_t)fdct_round_shift(temp); temp = output[2] * cospi_24_64 + output[3] * cospi_8_64; step[2] = (tran_low_t)fdct_round_shift(temp); temp = output[3] * cospi_24_64 + output[2] * -cospi_8_64; step[3] = (tran_low_t)fdct_round_shift(temp); step[4] = output[4] + output[5]; step[5] = output[4] - output[5]; step[6] = output[7] - output[6]; step[7] = output[7] + output[6]; step[8] = output[8]; temp = output[9] * -cospi_8_64 + output[14] * cospi_24_64; step[9] = (tran_low_t)fdct_round_shift(temp); temp = output[10] * -cospi_24_64 + output[13] * -cospi_8_64; step[10] = (tran_low_t)fdct_round_shift(temp); step[11] = output[11]; step[12] = output[12]; temp = output[13] * cospi_24_64 + output[10] * -cospi_8_64; step[13] = (tran_low_t)fdct_round_shift(temp); temp = output[14] * cospi_8_64 + output[9] * cospi_24_64; step[14] = (tran_low_t)fdct_round_shift(temp); step[15] = output[15]; range_check(step, 16, 16); // stage 5 output[0] = step[0]; output[1] = step[1]; output[2] = step[2]; output[3] = step[3]; temp = step[4] * cospi_28_64 + step[7] * cospi_4_64; output[4] = (tran_low_t)fdct_round_shift(temp); temp = step[5] * cospi_12_64 + step[6] * cospi_20_64; output[5] = (tran_low_t)fdct_round_shift(temp); temp = step[6] * cospi_12_64 + step[5] * -cospi_20_64; output[6] = (tran_low_t)fdct_round_shift(temp); temp = step[7] * cospi_28_64 + step[4] * -cospi_4_64; output[7] = (tran_low_t)fdct_round_shift(temp); output[8] = step[8] + step[9]; output[9] = step[8] - step[9]; output[10] = step[11] - step[10]; output[11] = step[11] + step[10]; output[12] = step[12] + step[13]; output[13] = step[12] - step[13]; output[14] = step[15] - step[14]; output[15] = step[15] + step[14]; range_check(output, 16, 16); // stage 6 step[0] = output[0]; step[1] = output[1]; step[2] = output[2]; step[3] = output[3]; step[4] = output[4]; step[5] = output[5]; step[6] = output[6]; step[7] = output[7]; temp = output[8] * cospi_30_64 + output[15] * cospi_2_64; step[8] = (tran_low_t)fdct_round_shift(temp); temp = output[9] * cospi_14_64 + output[14] * cospi_18_64; step[9] = (tran_low_t)fdct_round_shift(temp); temp = output[10] * cospi_22_64 + output[13] * cospi_10_64; step[10] = (tran_low_t)fdct_round_shift(temp); temp = output[11] * cospi_6_64 + output[12] * cospi_26_64; step[11] = (tran_low_t)fdct_round_shift(temp); temp = output[12] * cospi_6_64 + output[11] * -cospi_26_64; step[12] = (tran_low_t)fdct_round_shift(temp); temp = output[13] * cospi_22_64 + output[10] * -cospi_10_64; step[13] = (tran_low_t)fdct_round_shift(temp); temp = output[14] * cospi_14_64 + output[9] * -cospi_18_64; step[14] = (tran_low_t)fdct_round_shift(temp); temp = output[15] * cospi_30_64 + output[8] * -cospi_2_64; step[15] = (tran_low_t)fdct_round_shift(temp); range_check(step, 16, 16); // stage 7 output[0] = step[0]; output[1] = step[8]; output[2] = step[4]; output[3] = step[12]; output[4] = step[2]; output[5] = step[10]; output[6] = step[6]; output[7] = step[14]; output[8] = step[1]; output[9] = step[9]; output[10] = step[5]; output[11] = step[13]; output[12] = step[3]; output[13] = step[11]; output[14] = step[7]; output[15] = step[15]; range_check(output, 16, 16); }
void vp10_fdct8x8_quant_c(const int16_t *input, int stride, tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block, const int16_t *zbin_ptr, const int16_t *round_ptr, const int16_t *quant_ptr, const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr, uint16_t *eob_ptr, const int16_t *scan, const int16_t *iscan #if CONFIG_AOM_QM , const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr #endif ) { int eob = -1; int i, j; tran_low_t intermediate[64]; // Transform columns { tran_low_t *output = intermediate; tran_high_t s0, s1, s2, s3, s4, s5, s6, s7; // canbe16 tran_high_t t0, t1, t2, t3; // needs32 tran_high_t x0, x1, x2, x3; // canbe16 int i; for (i = 0; i < 8; i++) { // stage 1 s0 = (input[0 * stride] + input[7 * stride]) * 4; s1 = (input[1 * stride] + input[6 * stride]) * 4; s2 = (input[2 * stride] + input[5 * stride]) * 4; s3 = (input[3 * stride] + input[4 * stride]) * 4; s4 = (input[3 * stride] - input[4 * stride]) * 4; s5 = (input[2 * stride] - input[5 * stride]) * 4; s6 = (input[1 * stride] - input[6 * stride]) * 4; s7 = (input[0 * stride] - input[7 * stride]) * 4; // fdct4(step, step); x0 = s0 + s3; x1 = s1 + s2; x2 = s1 - s2; x3 = s0 - s3; t0 = (x0 + x1) * cospi_16_64; t1 = (x0 - x1) * cospi_16_64; t2 = x2 * cospi_24_64 + x3 * cospi_8_64; t3 = -x2 * cospi_8_64 + x3 * cospi_24_64; output[0 * 8] = (tran_low_t)fdct_round_shift(t0); output[2 * 8] = (tran_low_t)fdct_round_shift(t2); output[4 * 8] = (tran_low_t)fdct_round_shift(t1); output[6 * 8] = (tran_low_t)fdct_round_shift(t3); // stage 2 t0 = (s6 - s5) * cospi_16_64; t1 = (s6 + s5) * cospi_16_64; t2 = fdct_round_shift(t0); t3 = fdct_round_shift(t1); // stage 3 x0 = s4 + t2; x1 = s4 - t2; x2 = s7 - t3; x3 = s7 + t3; // stage 4 t0 = x0 * cospi_28_64 + x3 * cospi_4_64; t1 = x1 * cospi_12_64 + x2 * cospi_20_64; t2 = x2 * cospi_12_64 + x1 * -cospi_20_64; t3 = x3 * cospi_28_64 + x0 * -cospi_4_64; output[1 * 8] = (tran_low_t)fdct_round_shift(t0); output[3 * 8] = (tran_low_t)fdct_round_shift(t2); output[5 * 8] = (tran_low_t)fdct_round_shift(t1); output[7 * 8] = (tran_low_t)fdct_round_shift(t3); input++; output++; } } // Rows for (i = 0; i < 8; ++i) { fdct8(&intermediate[i * 8], &coeff_ptr[i * 8]); for (j = 0; j < 8; ++j) coeff_ptr[j + i * 8] /= 2; } // TODO(jingning) Decide the need of these arguments after the // quantization process is completed. (void)zbin_ptr; (void)quant_shift_ptr; (void)iscan; memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr)); memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr)); if (!skip_block) { // Quantization pass: All coefficients with index >= zero_flag are // skippable. Note: zero_flag can be zero. for (i = 0; i < n_coeffs; i++) { const int rc = scan[i]; const int coeff = coeff_ptr[rc]; #if CONFIG_AOM_QM const qm_val_t wt = qm_ptr[rc]; const qm_val_t iwt = iqm_ptr[rc]; const int dequant = (dequant_ptr[rc != 0] * iwt + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS; #endif const int coeff_sign = (coeff >> 31); const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign; int64_t tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX); int tmp32; #if CONFIG_AOM_QM tmp32 = (tmp * quant_ptr[rc != 0] * wt) >> (16 + AOM_QM_BITS); qcoeff_ptr[rc] = (tmp32 ^ coeff_sign) - coeff_sign; dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant; #else tmp32 = (tmp * quant_ptr[rc != 0]) >> 16; qcoeff_ptr[rc] = (tmp32 ^ coeff_sign) - coeff_sign; dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0]; #endif if (tmp32) eob = i; } } *eob_ptr = eob + 1; }