2014-01-24 10:37:15 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
2014-02-21 13:00:20 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-01-24 10:37:15 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
2014-01-24 10:37:15 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* \file
|
2012-06-11 15:43:29 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-18 09:16:03 +00:00
|
|
|
#include "transform.h"
|
|
|
|
|
2012-06-11 15:43:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-05-12 08:35:40 +00:00
|
|
|
#include <assert.h>
|
2013-09-18 09:16:03 +00:00
|
|
|
|
2013-02-05 13:48:06 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "nal.h"
|
2014-05-12 08:35:40 +00:00
|
|
|
#include "rdo.h"
|
2014-07-29 15:10:47 +00:00
|
|
|
#include "strategies/strategies-dct.h"
|
2012-06-11 15:43:29 +00:00
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// INITIALIZATIONS
|
2014-02-21 13:00:20 +00:00
|
|
|
//
|
config: Add --cqmfile to use custom quantization matrices from a file.
The coefficients in a matrix are stored in up-right diagonal order.
The following indicates the default matrices specified in the spec.
INTRA4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA8X8_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER8X8_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER16X16_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA32X32_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER32X32_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA_DC
16
INTRA16X16_CHROMAU_DC
16
INTRA16X16_CHROMAV_DC
16
INTER16X16_LUMA_DC
16
INTER16X16_CHROMAU_DC
16
INTER16X16_CHROMAV_DC
16
INTRA32X32_LUMA_DC
16
INTER32X32_LUMA_DC
16
2014-02-11 10:55:21 +00:00
|
|
|
|
2013-03-07 15:42:00 +00:00
|
|
|
|
2013-09-18 12:12:40 +00:00
|
|
|
const uint8_t g_chroma_scale[58]=
|
2013-03-07 15:42:00 +00:00
|
|
|
{
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,
|
|
|
|
17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,
|
|
|
|
33,33,34,34,35,35,36,36,37,37,38,39,40,41,42,43,44,
|
|
|
|
45,46,47,48,49,50,51
|
|
|
|
};
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// FUNCTIONS
|
2014-02-21 13:00:20 +00:00
|
|
|
//
|
2012-06-11 15:43:29 +00:00
|
|
|
|
2014-02-21 13:41:55 +00:00
|
|
|
/**
|
|
|
|
* \brief Get scaled QP used in quantization
|
2014-02-21 13:00:20 +00:00
|
|
|
*
|
2014-02-21 13:41:55 +00:00
|
|
|
*/
|
|
|
|
int32_t get_scaled_qp(int8_t type, int8_t qp, int8_t qp_offset)
|
|
|
|
{
|
|
|
|
int32_t qp_scaled = 0;
|
|
|
|
if(type == 0) {
|
|
|
|
qp_scaled = qp + qp_offset;
|
|
|
|
} else {
|
|
|
|
qp_scaled = CLIP(-qp_offset, 57, qp);
|
|
|
|
if(qp_scaled < 0) {
|
|
|
|
qp_scaled = qp_scaled + qp_offset;
|
|
|
|
} else {
|
|
|
|
qp_scaled = g_chroma_scale[qp_scaled] + qp_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return qp_scaled;
|
|
|
|
}
|
2013-09-20 08:50:53 +00:00
|
|
|
|
2014-04-02 07:54:03 +00:00
|
|
|
/**
|
|
|
|
* \brief NxN inverse transform (2D)
|
|
|
|
* \param coeff input data (transform coefficients)
|
|
|
|
* \param block output data (residual)
|
|
|
|
* \param block_size input data (width of transform)
|
|
|
|
*/
|
2015-03-04 10:26:57 +00:00
|
|
|
void transformskip(const encoder_control_t * const encoder, int16_t *block,int16_t *coeff, int8_t block_size)
|
2014-04-02 07:54:03 +00:00
|
|
|
{
|
|
|
|
uint32_t log2_tr_size = g_convert_to_bit[block_size] + 2;
|
2014-04-17 08:28:20 +00:00
|
|
|
int32_t shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size;
|
2014-04-02 07:54:03 +00:00
|
|
|
int32_t j,k;
|
|
|
|
for (j = 0; j < block_size; j++) {
|
|
|
|
for(k = 0; k < block_size; k ++) {
|
|
|
|
coeff[j * block_size + k] = block[j * block_size + k] << shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief inverse transform skip
|
|
|
|
* \param coeff input data (transform coefficients)
|
|
|
|
* \param block output data (residual)
|
|
|
|
* \param block_size width of transform
|
|
|
|
*/
|
2015-03-04 10:26:57 +00:00
|
|
|
void itransformskip(const encoder_control_t * const encoder, int16_t *block,int16_t *coeff, int8_t block_size)
|
2014-04-02 07:54:03 +00:00
|
|
|
{
|
|
|
|
uint32_t log2_tr_size = g_convert_to_bit[block_size] + 2;
|
2014-04-17 08:28:20 +00:00
|
|
|
int32_t shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size;
|
2014-04-02 07:54:03 +00:00
|
|
|
int32_t j,k;
|
|
|
|
int32_t offset;
|
|
|
|
offset = (1 << (shift -1)); // For rounding
|
|
|
|
for ( j = 0; j < block_size; j++ ) {
|
|
|
|
for(k = 0; k < block_size; k ++) {
|
|
|
|
block[j * block_size + k] = (coeff[j * block_size + k] + offset) >> shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-07 15:42:00 +00:00
|
|
|
|
2014-02-21 13:00:20 +00:00
|
|
|
/**
|
2013-09-20 08:50:53 +00:00
|
|
|
* \brief forward transform (2D)
|
|
|
|
* \param block input residual
|
|
|
|
* \param coeff transform coefficients
|
|
|
|
* \param block_size width of transform
|
|
|
|
*/
|
2015-03-04 10:26:57 +00:00
|
|
|
void transform2d(const encoder_control_t * const encoder, int16_t *block, int16_t *coeff, int8_t block_size, int32_t mode)
|
2013-02-05 13:48:06 +00:00
|
|
|
{
|
2014-07-29 15:10:47 +00:00
|
|
|
dct_func *dct_func = get_dct_func(block_size, mode);
|
|
|
|
dct_func(encoder->bitdepth, block, coeff);
|
2013-02-05 13:48:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-04 10:26:57 +00:00
|
|
|
void itransform2d(const encoder_control_t * const encoder, int16_t *block, int16_t *coeff, int8_t block_size, int32_t mode)
|
2013-03-07 15:42:00 +00:00
|
|
|
{
|
2014-07-29 15:10:47 +00:00
|
|
|
dct_func *idct_func = get_idct_func(block_size, mode);
|
2014-10-02 13:10:17 +00:00
|
|
|
idct_func(encoder->bitdepth, coeff, block);
|
2013-03-07 15:42:00 +00:00
|
|
|
}
|
2013-02-05 13:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define QUANT_SHIFT 14
|
2013-09-20 08:50:53 +00:00
|
|
|
/**
|
|
|
|
* \brief quantize transformed coefficents
|
2014-02-21 13:00:20 +00:00
|
|
|
*
|
2013-09-20 08:50:53 +00:00
|
|
|
*/
|
2015-03-04 15:00:23 +00:00
|
|
|
void quant(const encoder_state_t * const state, int16_t *coef, int16_t *q_coef, int32_t width,
|
2014-05-13 12:08:34 +00:00
|
|
|
int32_t height, int8_t type, int8_t scan_idx, int8_t block_type )
|
2013-02-05 13:48:06 +00:00
|
|
|
{
|
2015-03-04 15:00:23 +00:00
|
|
|
const encoder_control_t * const encoder = state->encoder_control;
|
2014-04-15 14:08:01 +00:00
|
|
|
const uint32_t log2_block_size = g_convert_to_bit[ width ] + 2;
|
|
|
|
const uint32_t * const scan = g_sig_last_scan[ scan_idx ][ log2_block_size - 1 ];
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2015-03-04 15:00:23 +00:00
|
|
|
int32_t qp_scaled = get_scaled_qp(type, state->global->QP, 0);
|
2013-11-05 07:41:14 +00:00
|
|
|
|
2015-01-23 14:03:59 +00:00
|
|
|
const uint32_t log2_tr_size = g_convert_to_bit[ width ] + 2;
|
|
|
|
const int32_t scalinglist_type = (block_type == CU_INTRA ? 0 : 3) + (int8_t)("\0\3\1\2"[type]);
|
2014-04-16 07:40:42 +00:00
|
|
|
const int32_t *quant_coeff = encoder->scaling_list.quant_coeff[log2_tr_size-2][scalinglist_type][qp_scaled%6];
|
2015-01-23 14:03:59 +00:00
|
|
|
const int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform
|
|
|
|
const int32_t q_bits = QUANT_SHIFT + qp_scaled/6 + transform_shift;
|
2015-03-04 15:00:23 +00:00
|
|
|
const int32_t add = ((state->global->slicetype == SLICE_I) ? 171 : 85) << (q_bits - 9);
|
2015-01-23 14:03:59 +00:00
|
|
|
const int32_t q_bits8 = q_bits - 8;
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2015-01-24 18:04:45 +00:00
|
|
|
uint32_t ac_sum = 0;
|
|
|
|
|
2015-01-23 14:03:59 +00:00
|
|
|
for (int32_t n = 0; n < width * height; n++) {
|
2013-08-02 13:35:30 +00:00
|
|
|
int32_t level;
|
|
|
|
int32_t sign;
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
level = coef[n];
|
|
|
|
sign = (level < 0 ? -1: 1);
|
|
|
|
|
2015-01-24 18:04:45 +00:00
|
|
|
level = ((int64_t)abs(level) * quant_coeff[n] + add) >> q_bits;
|
|
|
|
ac_sum += level;
|
2013-02-05 13:48:06 +00:00
|
|
|
|
2013-08-02 13:35:30 +00:00
|
|
|
level *= sign;
|
2014-02-06 11:54:11 +00:00
|
|
|
q_coef[n] = (int16_t)(CLIP( -32768, 32767, level));
|
2013-09-20 08:50:53 +00:00
|
|
|
}
|
2013-06-12 12:41:57 +00:00
|
|
|
|
2015-01-24 18:04:45 +00:00
|
|
|
if (!(encoder->sign_hiding && ac_sum >= 2)) return;
|
|
|
|
|
2015-01-23 14:03:59 +00:00
|
|
|
int32_t delta_u[LCU_WIDTH*LCU_WIDTH >> 2];
|
|
|
|
|
|
|
|
for (int32_t n = 0; n < width * height; n++) {
|
|
|
|
int32_t level;
|
|
|
|
level = coef[n];
|
|
|
|
level = ((int64_t)abs(level) * quant_coeff[n] + add) >> q_bits;
|
|
|
|
delta_u[n] = (int32_t)(((int64_t)abs(coef[n]) * quant_coeff[n] - (level << q_bits)) >> q_bits8);
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:08:34 +00:00
|
|
|
if(ac_sum >= 2) {
|
2013-06-12 12:41:57 +00:00
|
|
|
#define SCAN_SET_SIZE 16
|
|
|
|
#define LOG2_SCAN_SET_SIZE 4
|
2013-09-20 08:50:53 +00:00
|
|
|
int32_t n,last_cg = -1, abssum = 0, subset, subpos;
|
|
|
|
for(subset = (width*height - 1)>>LOG2_SCAN_SET_SIZE; subset >= 0; subset--) {
|
|
|
|
int32_t first_nz_pos_in_cg = SCAN_SET_SIZE, last_nz_pos_in_cg=-1;
|
2013-06-12 12:41:57 +00:00
|
|
|
subpos = subset<<LOG2_SCAN_SET_SIZE;
|
|
|
|
abssum = 0;
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
// Find last coeff pos
|
|
|
|
for (n = SCAN_SET_SIZE - 1; n >= 0; n--) {
|
|
|
|
if (q_coef[scan[n + subpos]]) {
|
|
|
|
last_nz_pos_in_cg = n;
|
2013-06-12 12:41:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
// First coeff pos
|
|
|
|
for (n = 0; n <SCAN_SET_SIZE; n++) {
|
|
|
|
if (q_coef[scan[n + subpos]]) {
|
|
|
|
first_nz_pos_in_cg = n;
|
2013-06-12 12:41:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
// Sum all quant coeffs between first and last
|
|
|
|
for(n = first_nz_pos_in_cg; n <= last_nz_pos_in_cg; n++) {
|
|
|
|
abssum += q_coef[scan[n + subpos]];
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
if(last_nz_pos_in_cg >= 0 && last_cg == -1) {
|
|
|
|
last_cg = 1;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
if(last_nz_pos_in_cg - first_nz_pos_in_cg >= 4) {
|
2014-02-06 11:54:11 +00:00
|
|
|
int32_t signbit = (q_coef[scan[subpos + first_nz_pos_in_cg]] > 0 ? 0 : 1) ;
|
2013-09-20 08:50:53 +00:00
|
|
|
if(signbit != (abssum&0x1)) { // compare signbit with sum_parity
|
2014-02-06 11:54:11 +00:00
|
|
|
int32_t min_cost_inc = 0x7fffffff, min_pos =-1, cur_cost=0x7fffffff;
|
|
|
|
int16_t final_change = 0, cur_change=0;
|
2013-09-20 08:50:53 +00:00
|
|
|
for(n = (last_cg == 1 ? last_nz_pos_in_cg : SCAN_SET_SIZE - 1); n >= 0; n--) {
|
|
|
|
uint32_t blkPos = scan[n + subpos];
|
|
|
|
if(q_coef[blkPos] != 0) {
|
|
|
|
if(delta_u[blkPos] > 0) {
|
|
|
|
cur_cost = -delta_u[blkPos];
|
|
|
|
cur_change=1;
|
|
|
|
} else if(n == first_nz_pos_in_cg && abs(q_coef[blkPos]) == 1) {
|
|
|
|
cur_cost=0x7fffffff;
|
|
|
|
} else {
|
|
|
|
cur_cost = delta_u[blkPos];
|
|
|
|
cur_change =-1;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
2013-09-20 08:50:53 +00:00
|
|
|
} else if(n < first_nz_pos_in_cg && ((coef[blkPos] >= 0)?0:1) != signbit) {
|
|
|
|
cur_cost = 0x7fffffff;
|
|
|
|
} else {
|
|
|
|
cur_cost = -delta_u[blkPos];
|
|
|
|
cur_change = 1;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
if(cur_cost < min_cost_inc) {
|
|
|
|
min_cost_inc = cur_cost;
|
|
|
|
final_change = cur_change;
|
|
|
|
min_pos = blkPos;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
2013-09-20 08:50:53 +00:00
|
|
|
} // CG loop
|
2013-06-12 12:41:57 +00:00
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
if(q_coef[min_pos] == 32767 || q_coef[min_pos] == -32768) {
|
|
|
|
final_change = -1;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
if(coef[min_pos] >= 0) q_coef[min_pos] += final_change;
|
|
|
|
else q_coef[min_pos] -= final_change;
|
2013-06-12 12:41:57 +00:00
|
|
|
} // Hide
|
|
|
|
}
|
2014-02-21 13:00:20 +00:00
|
|
|
if (last_cg == 1) last_cg=0;
|
2013-06-12 12:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef SCAN_SET_SIZE
|
|
|
|
#undef LOG2_SCAN_SET_SIZE
|
2013-02-05 13:48:06 +00:00
|
|
|
}
|
2013-03-07 15:42:00 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
/**
|
|
|
|
* \brief inverse quantize transformed and quantized coefficents
|
2014-02-21 13:00:20 +00:00
|
|
|
*
|
2013-09-20 08:50:53 +00:00
|
|
|
*/
|
2015-03-04 15:00:23 +00:00
|
|
|
void dequant(const encoder_state_t * const state, int16_t *q_coef, int16_t *coef, int32_t width, int32_t height,int8_t type, int8_t block_type)
|
2013-03-07 15:42:00 +00:00
|
|
|
{
|
2015-03-04 15:00:23 +00:00
|
|
|
const encoder_control_t * const encoder = state->encoder_control;
|
2014-04-29 06:02:21 +00:00
|
|
|
int32_t shift,add,coeff_q;
|
2013-03-19 14:23:33 +00:00
|
|
|
int32_t n;
|
2014-04-17 08:28:20 +00:00
|
|
|
int32_t transform_shift = 15 - encoder->bitdepth - (g_convert_to_bit[ width ] + 2);
|
2013-09-20 08:50:53 +00:00
|
|
|
|
2015-03-04 15:00:23 +00:00
|
|
|
int32_t qp_scaled = get_scaled_qp(type, state->global->QP, 0);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2013-09-20 08:50:53 +00:00
|
|
|
shift = 20 - QUANT_SHIFT - transform_shift;
|
2014-02-06 11:54:11 +00:00
|
|
|
|
2014-04-16 09:00:04 +00:00
|
|
|
if (encoder->scaling_list.enable)
|
2014-02-06 11:54:11 +00:00
|
|
|
{
|
|
|
|
uint32_t log2_tr_size = g_convert_to_bit[ width ] + 2;
|
|
|
|
int32_t scalinglist_type = (block_type == CU_INTRA ? 0 : 3) + (int8_t)("\0\3\1\2"[type]);
|
|
|
|
|
2014-04-16 07:40:42 +00:00
|
|
|
const int32_t *dequant_coef = encoder->scaling_list.de_quant_coeff[log2_tr_size-2][scalinglist_type][qp_scaled%6];
|
2014-02-06 11:54:11 +00:00
|
|
|
shift += 4;
|
2013-03-11 15:15:11 +00:00
|
|
|
|
2014-02-06 11:54:11 +00:00
|
|
|
if (shift >qp_scaled / 6) {
|
|
|
|
add = 1 << (shift - qp_scaled/6 - 1);
|
2014-02-21 13:00:20 +00:00
|
|
|
|
2014-02-06 11:54:11 +00:00
|
|
|
for (n = 0; n < width * height; n++) {
|
2014-04-29 06:02:21 +00:00
|
|
|
coeff_q = ((q_coef[n] * dequant_coef[n]) + add ) >> (shift - qp_scaled/6);
|
2014-02-06 11:54:11 +00:00
|
|
|
coef[n] = (int16_t)CLIP(-32768,32767,coeff_q);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (n = 0; n < width * height; n++) {
|
|
|
|
// Clip to avoid possible overflow in following shift left operation
|
2014-04-29 06:02:21 +00:00
|
|
|
coeff_q = CLIP(-32768, 32767, q_coef[n] * dequant_coef[n]);
|
2014-02-06 11:54:11 +00:00
|
|
|
coef[n] = (int16_t)CLIP(-32768, 32767, coeff_q << (qp_scaled/6 - shift));
|
|
|
|
}
|
2013-03-11 15:15:11 +00:00
|
|
|
}
|
config: Add --cqmfile to use custom quantization matrices from a file.
The coefficients in a matrix are stored in up-right diagonal order.
The following indicates the default matrices specified in the spec.
INTRA4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA8X8_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER8X8_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER16X16_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA32X32_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER32X32_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA_DC
16
INTRA16X16_CHROMAU_DC
16
INTRA16X16_CHROMAV_DC
16
INTER16X16_LUMA_DC
16
INTER16X16_CHROMAU_DC
16
INTER16X16_CHROMAV_DC
16
INTRA32X32_LUMA_DC
16
INTER32X32_LUMA_DC
16
2014-02-11 10:55:21 +00:00
|
|
|
} else {
|
2014-02-06 11:54:11 +00:00
|
|
|
int32_t scale = g_inv_quant_scales[qp_scaled%6] << (qp_scaled/6);
|
|
|
|
add = 1 << (shift-1);
|
2013-03-07 15:42:00 +00:00
|
|
|
|
2014-02-06 11:54:11 +00:00
|
|
|
for (n = 0; n < width*height; n++) {
|
2014-04-29 06:02:21 +00:00
|
|
|
coeff_q = (q_coef[n] * scale + add) >> shift;
|
2014-02-06 11:54:11 +00:00
|
|
|
coef[n] = (int16_t)CLIP(-32768, 32767, coeff_q);
|
|
|
|
}
|
2013-08-02 13:35:30 +00:00
|
|
|
}
|
config: Add --cqmfile to use custom quantization matrices from a file.
The coefficients in a matrix are stored in up-right diagonal order.
The following indicates the default matrices specified in the spec.
INTRA4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_LUMA
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAU
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTER4X4_CHROMAV
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16,
16, 16, 16, 16
INTRA8X8_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA8X8_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER8X8_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER8X8_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAU
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTRA16X16_CHROMAV
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER16X16_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAU
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTER16X16_CHROMAV
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA32X32_LUMA
16, 16, 16, 16, 17, 18, 21, 24,
16, 16, 16, 16, 17, 19, 22, 25,
16, 16, 17, 18, 20, 22, 25, 29,
16, 16, 18, 21, 24, 27, 31, 36,
17, 17, 20, 24, 30, 35, 41, 47,
18, 19, 22, 27, 35, 44, 54, 65,
21, 22, 25, 31, 41, 54, 70, 88,
24, 25, 29, 36, 47, 65, 88, 115
INTER32X32_LUMA
16, 16, 16, 16, 17, 18, 20, 24,
16, 16, 16, 17, 18, 20, 24, 25,
16, 16, 17, 18, 20, 24, 25, 28,
16, 17, 18, 20, 24, 25, 28, 33,
17, 18, 20, 24, 25, 28, 33, 41,
18, 20, 24, 25, 28, 33, 41, 54,
20, 24, 25, 28, 33, 41, 54, 71,
24, 25, 28, 33, 41, 54, 71, 91
INTRA16X16_LUMA_DC
16
INTRA16X16_CHROMAU_DC
16
INTRA16X16_CHROMAV_DC
16
INTER16X16_LUMA_DC
16
INTER16X16_CHROMAU_DC
16
INTER16X16_CHROMAV_DC
16
INTRA32X32_LUMA_DC
16
INTER32X32_LUMA_DC
16
2014-02-11 10:55:21 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 08:35:40 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
/**
|
2014-05-13 14:52:01 +00:00
|
|
|
* \brief Quantize residual and get both the reconstruction and coeffs.
|
|
|
|
*
|
2014-05-13 14:36:49 +00:00
|
|
|
* \param width Transform width.
|
|
|
|
* \param color Color.
|
|
|
|
* \param scan_order Coefficient scan order.
|
|
|
|
* \param use_trskip Whether transform skip is used.
|
|
|
|
* \param stride Stride for ref_in, pred_in rec_out and coeff_out.
|
|
|
|
* \param ref_in Reference pixels.
|
|
|
|
* \param pred_in Predicted pixels.
|
|
|
|
* \param rec_out Reconstructed pixels.
|
|
|
|
* \param coeff_out Coefficients used for reconstruction of rec_out.
|
2014-05-13 14:52:01 +00:00
|
|
|
*
|
2014-05-13 14:36:49 +00:00
|
|
|
* \returns Whether coeff_out contains any non-zero coefficients.
|
|
|
|
*/
|
2015-03-04 15:00:23 +00:00
|
|
|
int quantize_residual(encoder_state_t *const state,
|
2015-03-04 14:37:35 +00:00
|
|
|
const cu_info_t *const cur_cu, const int width, const color_t color,
|
2014-05-13 14:36:49 +00:00
|
|
|
const coeff_scan_order_t scan_order, const int use_trskip,
|
2014-05-13 16:45:50 +00:00
|
|
|
const int in_stride, const int out_stride,
|
2015-03-04 14:35:17 +00:00
|
|
|
const pixel_t *const ref_in, const pixel_t *const pred_in,
|
|
|
|
pixel_t *rec_out, coeff_t *coeff_out)
|
2014-05-13 11:55:41 +00:00
|
|
|
{
|
2014-05-13 14:36:49 +00:00
|
|
|
// Temporary arrays to pass data to and from quant and transform functions.
|
|
|
|
int16_t residual[TR_MAX_WIDTH * TR_MAX_WIDTH];
|
2015-03-04 14:33:47 +00:00
|
|
|
coeff_t quant_coeff[TR_MAX_WIDTH * TR_MAX_WIDTH];
|
|
|
|
coeff_t coeff[TR_MAX_WIDTH * TR_MAX_WIDTH];
|
2014-05-13 11:55:41 +00:00
|
|
|
|
|
|
|
int has_coeffs = 0;
|
|
|
|
|
2014-09-05 08:29:30 +00:00
|
|
|
assert(width <= TR_MAX_WIDTH);
|
|
|
|
assert(width >= TR_MIN_WIDTH);
|
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Get residual. (ref_in - pred_in -> residual)
|
2014-05-13 11:55:41 +00:00
|
|
|
{
|
|
|
|
int y, x;
|
2014-05-13 14:36:49 +00:00
|
|
|
for (y = 0; y < width; ++y) {
|
|
|
|
for (x = 0; x < width; ++x) {
|
2014-05-13 16:45:50 +00:00
|
|
|
residual[x + y * width] = (int16_t)(ref_in[x + y * in_stride] - pred_in[x + y * in_stride]);
|
2014-05-13 11:55:41 +00:00
|
|
|
}
|
2014-05-12 09:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-13 11:55:41 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Transform residual. (residual -> coeff)
|
2014-05-13 14:52:01 +00:00
|
|
|
if (use_trskip) {
|
2015-03-04 15:00:23 +00:00
|
|
|
transformskip(state->encoder_control, residual, coeff, width);
|
2014-05-13 14:52:01 +00:00
|
|
|
} else {
|
2015-03-04 15:00:23 +00:00
|
|
|
transform2d(state->encoder_control, residual, coeff, width, (color == COLOR_Y ? 0 : 65535));
|
2014-05-13 14:52:01 +00:00
|
|
|
}
|
2014-05-13 11:55:41 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Quantize coeffs. (coeff -> quant_coeff)
|
2015-03-04 15:00:23 +00:00
|
|
|
if (state->encoder_control->rdoq_enable) {
|
2014-09-23 12:17:56 +00:00
|
|
|
int8_t tr_depth = cur_cu->tr_depth - cur_cu->depth;
|
|
|
|
tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0);
|
2015-03-04 15:00:23 +00:00
|
|
|
rdoq(state, coeff, quant_coeff, width, width, (color == COLOR_Y ? 0 : 2),
|
2014-09-23 12:17:56 +00:00
|
|
|
scan_order, cur_cu->type, tr_depth);
|
2014-05-13 11:55:41 +00:00
|
|
|
} else {
|
2015-03-04 15:00:23 +00:00
|
|
|
quant(state, coeff, quant_coeff, width, width, (color == COLOR_Y ? 0 : 2),
|
2014-05-13 11:55:41 +00:00
|
|
|
scan_order, cur_cu->type);
|
|
|
|
}
|
2014-05-12 09:06:58 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Check if there are any non-zero coefficients.
|
2014-05-12 08:35:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
2014-05-13 14:36:49 +00:00
|
|
|
for (i = 0; i < width * width; ++i) {
|
|
|
|
if (quant_coeff[i] != 0) {
|
2014-05-12 08:35:40 +00:00
|
|
|
has_coeffs = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-13 11:55:41 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Copy coefficients to coeff_out.
|
2014-06-05 12:54:58 +00:00
|
|
|
coefficients_blit(quant_coeff, coeff_out, width, width, width, out_stride);
|
2014-05-13 11:55:41 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Do the inverse quantization and transformation and the reconstruction to
|
|
|
|
// rec_out.
|
2014-05-12 08:35:40 +00:00
|
|
|
if (has_coeffs) {
|
2014-05-13 14:36:49 +00:00
|
|
|
int y, x;
|
2014-05-12 09:06:58 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Get quantized residual. (quant_coeff -> coeff -> residual)
|
2015-03-04 15:00:23 +00:00
|
|
|
dequant(state, quant_coeff, coeff, width, width, (color == COLOR_Y ? 0 : (color == COLOR_U ? 2 : 3)), cur_cu->type);
|
2014-05-13 14:52:01 +00:00
|
|
|
if (use_trskip) {
|
2015-03-04 15:00:23 +00:00
|
|
|
itransformskip(state->encoder_control, residual, coeff, width);
|
2014-05-13 14:52:01 +00:00
|
|
|
} else {
|
2015-03-04 15:00:23 +00:00
|
|
|
itransform2d(state->encoder_control, residual, coeff, width, (color == COLOR_Y ? 0 : 65535));
|
2014-05-13 14:52:01 +00:00
|
|
|
}
|
2014-05-12 09:06:58 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
// Get quantized reconstruction. (residual + pred_in -> rec_out)
|
|
|
|
for (y = 0; y < width; ++y) {
|
|
|
|
for (x = 0; x < width; ++x) {
|
2014-05-13 16:45:50 +00:00
|
|
|
int16_t val = residual[x + y * width] + pred_in[x + y * in_stride];
|
|
|
|
rec_out[x + y * out_stride] = (uint8_t)CLIP(0, 255, val);
|
2014-05-13 14:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (rec_out != pred_in) {
|
|
|
|
// With no coeffs and rec_out == pred_int we skip copying the coefficients
|
|
|
|
// because the reconstruction is just the prediction.
|
|
|
|
int y, x;
|
2014-05-12 09:06:58 +00:00
|
|
|
|
2014-05-13 14:36:49 +00:00
|
|
|
for (y = 0; y < width; ++y) {
|
|
|
|
for (x = 0; x < width; ++x) {
|
2014-05-13 16:45:50 +00:00
|
|
|
rec_out[x + y * out_stride] = pred_in[x + y * in_stride];
|
2014-05-12 09:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-12 08:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return has_coeffs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-13 16:41:29 +00:00
|
|
|
/**
|
|
|
|
* \brief Like quantize_residual except that this uses trskip if that is better.
|
|
|
|
*
|
|
|
|
* Using this function saves one step of quantization and inverse quantization
|
|
|
|
* compared to doing the decision separately from the actual operation.
|
|
|
|
*
|
|
|
|
* \param width Transform width.
|
|
|
|
* \param color Color.
|
|
|
|
* \param scan_order Coefficient scan order.
|
|
|
|
* \param trskip_out Whether transform skip is used.
|
|
|
|
* \param stride Stride for ref_in, pred_in rec_out and coeff_out.
|
|
|
|
* \param ref_in Reference pixels.
|
|
|
|
* \param pred_in Predicted pixels.
|
|
|
|
* \param rec_out Reconstructed pixels.
|
|
|
|
* \param coeff_out Coefficients used for reconstruction of rec_out.
|
|
|
|
*
|
|
|
|
* \returns Whether coeff_out contains any non-zero coefficients.
|
|
|
|
*/
|
|
|
|
int quantize_residual_trskip(
|
2015-03-04 15:00:23 +00:00
|
|
|
encoder_state_t *const state,
|
2015-03-04 14:37:35 +00:00
|
|
|
const cu_info_t *const cur_cu, const int width, const color_t color,
|
2014-05-13 16:41:29 +00:00
|
|
|
const coeff_scan_order_t scan_order, int8_t *trskip_out,
|
|
|
|
const int in_stride, const int out_stride,
|
2015-03-04 14:35:17 +00:00
|
|
|
const pixel_t *const ref_in, const pixel_t *const pred_in,
|
|
|
|
pixel_t *rec_out, coeff_t *coeff_out)
|
2014-05-13 16:41:29 +00:00
|
|
|
{
|
2014-05-13 17:35:30 +00:00
|
|
|
struct {
|
2015-03-04 14:35:17 +00:00
|
|
|
pixel_t rec[4*4];
|
2015-03-04 14:33:47 +00:00
|
|
|
coeff_t coeff[4*4];
|
2014-05-14 08:35:38 +00:00
|
|
|
uint32_t cost;
|
2014-05-13 17:35:30 +00:00
|
|
|
int has_coeffs;
|
|
|
|
} skip, noskip, *best;
|
2014-05-14 08:35:38 +00:00
|
|
|
|
2015-03-04 15:00:23 +00:00
|
|
|
const int bit_cost = (int)(state->global->cur_lambda_cost+0.5);
|
2014-05-13 17:35:30 +00:00
|
|
|
|
|
|
|
noskip.has_coeffs = quantize_residual(
|
2015-03-04 15:00:23 +00:00
|
|
|
state, cur_cu, width, color, scan_order,
|
2014-05-13 16:41:29 +00:00
|
|
|
0, in_stride, 4,
|
2014-05-13 17:35:30 +00:00
|
|
|
ref_in, pred_in, noskip.rec, noskip.coeff);
|
2014-06-05 12:54:58 +00:00
|
|
|
noskip.cost = pixels_calc_ssd(ref_in, noskip.rec, in_stride, 4, 4);
|
2015-03-04 15:00:23 +00:00
|
|
|
noskip.cost += get_coeff_cost(state, noskip.coeff, 4, 0, scan_order) * bit_cost;
|
2014-05-13 16:41:29 +00:00
|
|
|
|
2015-03-04 15:00:23 +00:00
|
|
|
skip.cost += get_coeff_cost(state, skip.coeff, 4, 0, scan_order) * bit_cost;
|
2014-05-13 16:41:29 +00:00
|
|
|
|
2014-05-13 17:35:30 +00:00
|
|
|
if (noskip.cost <= skip.cost) {
|
2014-05-13 16:41:29 +00:00
|
|
|
*trskip_out = 0;
|
2014-05-13 17:35:30 +00:00
|
|
|
best = &noskip;
|
2014-05-13 16:41:29 +00:00
|
|
|
} else {
|
|
|
|
*trskip_out = 1;
|
2014-05-13 17:35:30 +00:00
|
|
|
best = &skip;
|
2014-05-13 16:41:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-13 17:35:30 +00:00
|
|
|
if (best->has_coeffs || rec_out != pred_in) {
|
|
|
|
// If there is no residual and reconstruction is already in rec_out,
|
|
|
|
// we can skip this.
|
2014-06-05 12:54:58 +00:00
|
|
|
pixels_blit(best->rec, rec_out, width, width, 4, out_stride);
|
2014-05-13 16:41:29 +00:00
|
|
|
}
|
2014-06-05 12:54:58 +00:00
|
|
|
coefficients_blit(best->coeff, coeff_out, width, width, 4, out_stride);
|
2014-05-13 16:41:29 +00:00
|
|
|
|
2014-05-13 17:35:30 +00:00
|
|
|
return best->has_coeffs;
|
2014-05-13 16:41:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 08:35:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function calculates the residual coefficients for a region of the LCU
|
|
|
|
* (defined by x, y and depth) and updates the reconstruction with the
|
|
|
|
* kvantized residual.
|
|
|
|
*
|
|
|
|
* It handles recursion for transform split, but that is currently only work
|
|
|
|
* for 64x64 inter to 32x32 transform blocks.
|
|
|
|
*
|
|
|
|
* Inputs are:
|
|
|
|
* - lcu->rec pixels after prediction for the area
|
|
|
|
* - lcu->ref reference pixels for the area
|
|
|
|
* - lcu->cu for the area
|
|
|
|
*
|
|
|
|
* Outputs are:
|
|
|
|
* - lcu->rec reconstruction after quantized residual
|
|
|
|
* - lcu->coeff quantized coefficients for the area
|
|
|
|
* - lcu->cbf coded block flags for the area
|
|
|
|
* - lcu->cu.intra[].tr_skip for the area
|
|
|
|
*/
|
2015-03-04 15:00:23 +00:00
|
|
|
void quantize_lcu_luma_residual(encoder_state_t * const state, int32_t x, int32_t y, const uint8_t depth, cu_info_t *cur_cu, lcu_t* lcu)
|
2014-05-12 08:35:40 +00:00
|
|
|
{
|
|
|
|
// we have 64>>depth transform size
|
2015-03-04 11:32:11 +00:00
|
|
|
const vector2d_t lcu_px = {x & 0x3f, y & 0x3f};
|
2014-05-12 08:35:40 +00:00
|
|
|
const int pu_index = PU_INDEX(lcu_px.x / 4, lcu_px.y / 4);
|
2014-09-23 11:41:25 +00:00
|
|
|
if (cur_cu == NULL) {
|
|
|
|
cur_cu = &lcu->cu[LCU_CU_OFFSET + (lcu_px.x >> 3) + (lcu_px.y >> 3)*LCU_T_CU_WIDTH];
|
|
|
|
}
|
2014-05-12 08:35:40 +00:00
|
|
|
const int8_t width = LCU_WIDTH>>depth;
|
|
|
|
|
|
|
|
// Tell clang-analyzer what is up. For some reason it can't figure out from
|
|
|
|
// asserting just depth.
|
|
|
|
assert(width == 4 || width == 8 || width == 16 || width == 32 || width == 64);
|
|
|
|
|
|
|
|
// Split transform and increase depth
|
|
|
|
if (depth == 0 || cur_cu->tr_depth > depth) {
|
|
|
|
int offset = width / 2;
|
2015-03-04 15:00:23 +00:00
|
|
|
quantize_lcu_luma_residual(state, x, y, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_luma_residual(state, x + offset, y, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_luma_residual(state, x, y + offset, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_luma_residual(state, x + offset, y + offset, depth+1, NULL, lcu);
|
2014-05-12 08:35:40 +00:00
|
|
|
|
|
|
|
// Propagate coded block flags from child CUs to parent CU.
|
|
|
|
if (depth < MAX_DEPTH) {
|
2015-03-04 11:15:45 +00:00
|
|
|
cu_info_t *cu_a = &lcu->cu[LCU_CU_OFFSET + ((lcu_px.x + offset) >> 3) + (lcu_px.y >> 3) *LCU_T_CU_WIDTH];
|
|
|
|
cu_info_t *cu_b = &lcu->cu[LCU_CU_OFFSET + (lcu_px.x >> 3) + ((lcu_px.y + offset) >> 3)*LCU_T_CU_WIDTH];
|
|
|
|
cu_info_t *cu_c = &lcu->cu[LCU_CU_OFFSET + ((lcu_px.x + offset) >> 3) + ((lcu_px.y + offset) >> 3)*LCU_T_CU_WIDTH];
|
2014-05-12 08:35:40 +00:00
|
|
|
if (cbf_is_set(cu_a->cbf.y, depth+1) || cbf_is_set(cu_b->cbf.y, depth+1) || cbf_is_set(cu_c->cbf.y, depth+1)) {
|
|
|
|
cbf_set(&cur_cu->cbf.y, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const int luma_offset = lcu_px.x + lcu_px.y * LCU_WIDTH;
|
|
|
|
|
|
|
|
// Pointers to current location in arrays with prediction.
|
2015-03-04 14:35:17 +00:00
|
|
|
pixel_t *recbase_y = &lcu->rec.y[luma_offset];
|
2014-05-12 08:35:40 +00:00
|
|
|
// Pointers to current location in arrays with reference.
|
2015-03-04 14:35:17 +00:00
|
|
|
const pixel_t *base_y = &lcu->ref.y[luma_offset];
|
2014-05-12 08:35:40 +00:00
|
|
|
// Pointers to current location in arrays with kvantized coefficients.
|
2015-03-04 14:33:47 +00:00
|
|
|
coeff_t *orig_coeff_y = &lcu->coeff.y[luma_offset];
|
2014-05-12 08:35:40 +00:00
|
|
|
|
2014-05-13 11:55:41 +00:00
|
|
|
coeff_scan_order_t scan_idx_luma = get_scan_order(cur_cu->type, cur_cu->intra[pu_index].mode, depth);
|
2014-05-12 08:35:40 +00:00
|
|
|
|
|
|
|
#if OPTIMIZATION_SKIP_RESIDUAL_ON_THRESHOLD
|
|
|
|
uint32_t residual_sum = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Clear coded block flag structures for depths lower than current depth.
|
|
|
|
// This should ensure that the CBF data doesn't get corrupted if this function
|
|
|
|
// is called more than once.
|
|
|
|
cbf_clear(&cur_cu->cbf.y, depth + pu_index);
|
|
|
|
|
2014-05-14 08:35:38 +00:00
|
|
|
if (width == 4 &&
|
2015-03-04 15:00:23 +00:00
|
|
|
state->encoder_control->trskip_enable)
|
2014-05-14 08:35:38 +00:00
|
|
|
{
|
2014-05-13 17:35:30 +00:00
|
|
|
// Try quantization with trskip and use it if it's better.
|
2014-05-13 16:41:29 +00:00
|
|
|
int has_coeffs = quantize_residual_trskip(
|
2015-03-04 15:00:23 +00:00
|
|
|
state, cur_cu, width, COLOR_Y, scan_idx_luma,
|
2014-05-13 16:41:29 +00:00
|
|
|
&cur_cu->intra[pu_index].tr_skip,
|
|
|
|
LCU_WIDTH, LCU_WIDTH,
|
|
|
|
base_y, recbase_y, recbase_y, orig_coeff_y
|
2014-05-13 16:45:50 +00:00
|
|
|
);
|
2014-05-13 16:41:29 +00:00
|
|
|
if (has_coeffs) {
|
|
|
|
cbf_set(&cur_cu->cbf.y, depth + pu_index);
|
2014-05-13 16:45:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int has_coeffs = quantize_residual(
|
2015-03-04 15:00:23 +00:00
|
|
|
state, cur_cu, width, COLOR_Y, scan_idx_luma,
|
2014-05-13 16:41:29 +00:00
|
|
|
0,
|
|
|
|
LCU_WIDTH, LCU_WIDTH,
|
2014-05-13 14:52:01 +00:00
|
|
|
base_y, recbase_y, recbase_y, orig_coeff_y
|
|
|
|
);
|
|
|
|
if (has_coeffs) {
|
|
|
|
cbf_set(&cur_cu->cbf.y, depth + pu_index);
|
|
|
|
}
|
2014-05-12 08:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 08:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-04 15:00:23 +00:00
|
|
|
void quantize_lcu_chroma_residual(encoder_state_t * const state, int32_t x, int32_t y, const uint8_t depth, cu_info_t *cur_cu, lcu_t* lcu)
|
2014-05-14 08:19:48 +00:00
|
|
|
{
|
|
|
|
// we have 64>>depth transform size
|
2015-03-04 11:32:11 +00:00
|
|
|
const vector2d_t lcu_px = {x & 0x3f, y & 0x3f};
|
2014-05-14 08:19:48 +00:00
|
|
|
const int pu_index = PU_INDEX(lcu_px.x / 4, lcu_px.y / 4);
|
|
|
|
const int8_t width = LCU_WIDTH>>depth;
|
2014-09-23 11:41:25 +00:00
|
|
|
if (cur_cu == NULL) {
|
|
|
|
cur_cu = &lcu->cu[LCU_CU_OFFSET + (lcu_px.x >> 3) + (lcu_px.y >> 3)*LCU_T_CU_WIDTH];
|
|
|
|
}
|
2014-05-14 08:19:48 +00:00
|
|
|
|
|
|
|
// Tell clang-analyzer what is up. For some reason it can't figure out from
|
|
|
|
// asserting just depth.
|
|
|
|
assert(width == 4 || width == 8 || width == 16 || width == 32 || width == 64);
|
|
|
|
|
|
|
|
// Split transform and increase depth
|
|
|
|
if (depth == 0 || cur_cu->tr_depth > depth) {
|
|
|
|
int offset = width / 2;
|
2015-03-04 15:00:23 +00:00
|
|
|
quantize_lcu_chroma_residual(state, x, y, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_chroma_residual(state, x + offset, y, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_chroma_residual(state, x, y + offset, depth+1, NULL, lcu);
|
|
|
|
quantize_lcu_chroma_residual(state, x + offset, y + offset, depth+1, NULL, lcu);
|
2014-05-14 08:19:48 +00:00
|
|
|
|
|
|
|
// Propagate coded block flags from child CUs to parent CU.
|
|
|
|
if (depth < MAX_DEPTH) {
|
2015-03-04 11:15:45 +00:00
|
|
|
cu_info_t *cu_a = &lcu->cu[LCU_CU_OFFSET + ((lcu_px.x + offset) >> 3) + (lcu_px.y >> 3) *LCU_T_CU_WIDTH];
|
|
|
|
cu_info_t *cu_b = &lcu->cu[LCU_CU_OFFSET + (lcu_px.x >> 3) + ((lcu_px.y + offset) >> 3)*LCU_T_CU_WIDTH];
|
|
|
|
cu_info_t *cu_c = &lcu->cu[LCU_CU_OFFSET + ((lcu_px.x + offset) >> 3) + ((lcu_px.y + offset) >> 3)*LCU_T_CU_WIDTH];
|
2014-05-14 08:19:48 +00:00
|
|
|
if (cbf_is_set(cu_a->cbf.u, depth+1) || cbf_is_set(cu_b->cbf.u, depth+1) || cbf_is_set(cu_c->cbf.u, depth+1)) {
|
|
|
|
cbf_set(&cur_cu->cbf.u, depth);
|
|
|
|
}
|
|
|
|
if (cbf_is_set(cu_a->cbf.v, depth+1) || cbf_is_set(cu_b->cbf.v, depth+1) || cbf_is_set(cu_c->cbf.v, depth+1)) {
|
|
|
|
cbf_set(&cur_cu->cbf.v, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2014-05-12 08:35:40 +00:00
|
|
|
|
|
|
|
// If luma is 4x4, do chroma for the 8x8 luma area when handling the top
|
|
|
|
// left PU because the coordinates are correct.
|
|
|
|
if (depth <= MAX_DEPTH || pu_index == 0) {
|
2014-10-15 13:01:58 +00:00
|
|
|
cbf_clear(&cur_cu->cbf.u, depth);
|
|
|
|
cbf_clear(&cur_cu->cbf.v, depth);
|
|
|
|
|
2014-05-13 07:04:05 +00:00
|
|
|
const int chroma_offset = lcu_px.x / 2 + lcu_px.y / 2 * LCU_WIDTH_C;
|
2015-03-04 14:35:17 +00:00
|
|
|
pixel_t *recbase_u = &lcu->rec.u[chroma_offset];
|
|
|
|
pixel_t *recbase_v = &lcu->rec.v[chroma_offset];
|
|
|
|
const pixel_t *base_u = &lcu->ref.u[chroma_offset];
|
|
|
|
const pixel_t *base_v = &lcu->ref.v[chroma_offset];
|
2015-03-04 14:33:47 +00:00
|
|
|
coeff_t *orig_coeff_u = &lcu->coeff.u[chroma_offset];
|
|
|
|
coeff_t *orig_coeff_v = &lcu->coeff.v[chroma_offset];
|
2014-05-13 11:55:41 +00:00
|
|
|
coeff_scan_order_t scan_idx_chroma;
|
|
|
|
int tr_skip = 0;
|
|
|
|
int chroma_depth = (depth == MAX_PU_DEPTH ? depth - 1 : depth);
|
|
|
|
int chroma_width = LCU_WIDTH_C >> chroma_depth;
|
2014-05-12 08:35:40 +00:00
|
|
|
|
2014-05-13 11:55:41 +00:00
|
|
|
scan_idx_chroma = get_scan_order(cur_cu->type, cur_cu->intra[0].mode_chroma, depth);
|
2015-03-04 15:00:23 +00:00
|
|
|
if (quantize_residual(state, cur_cu, chroma_width, COLOR_U, scan_idx_chroma, tr_skip, LCU_WIDTH_C, LCU_WIDTH_C, base_u, recbase_u, recbase_u, orig_coeff_u)) {
|
2014-05-12 08:35:40 +00:00
|
|
|
cbf_set(&cur_cu->cbf.u, depth);
|
|
|
|
}
|
2015-03-04 15:00:23 +00:00
|
|
|
if (quantize_residual(state, cur_cu, chroma_width, COLOR_V, scan_idx_chroma, tr_skip, LCU_WIDTH_C, LCU_WIDTH_C, base_v, recbase_v, recbase_v, orig_coeff_v)) {
|
2014-05-12 08:35:40 +00:00
|
|
|
cbf_set(&cur_cu->cbf.v, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|