mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-19 20:08:28 +01:00
quant_enc.c: use WEBP_RESTRICT qualifier
results in code layout changes, a couple fewer instructions; some of the smaller functions were unaffected as they were inlined, but are updated for consistency. this mostly affects VP8Decimate(), ReconstructIntra16() and ReconstructUV(). Change-Id: Icc2582278987a66ad1110bab683d1e0c21e6591a
This commit is contained in:
parent
ec178f2c7f
commit
b9d2f9cd3b
@ -533,7 +533,8 @@ static void InitScore(VP8ModeScore* const rd) {
|
|||||||
rd->score = MAX_COST;
|
rd->score = MAX_COST;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CopyScore(VP8ModeScore* const dst, const VP8ModeScore* const src) {
|
static void CopyScore(VP8ModeScore* WEBP_RESTRICT const dst,
|
||||||
|
const VP8ModeScore* WEBP_RESTRICT const src) {
|
||||||
dst->D = src->D;
|
dst->D = src->D;
|
||||||
dst->SD = src->SD;
|
dst->SD = src->SD;
|
||||||
dst->R = src->R;
|
dst->R = src->R;
|
||||||
@ -542,7 +543,8 @@ static void CopyScore(VP8ModeScore* const dst, const VP8ModeScore* const src) {
|
|||||||
dst->score = src->score;
|
dst->score = src->score;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddScore(VP8ModeScore* const dst, const VP8ModeScore* const src) {
|
static void AddScore(VP8ModeScore* WEBP_RESTRICT const dst,
|
||||||
|
const VP8ModeScore* WEBP_RESTRICT const src) {
|
||||||
dst->D += src->D;
|
dst->D += src->D;
|
||||||
dst->SD += src->SD;
|
dst->SD += src->SD;
|
||||||
dst->R += src->R;
|
dst->R += src->R;
|
||||||
@ -588,10 +590,10 @@ static WEBP_INLINE score_t RDScoreTrellis(int lambda, score_t rate,
|
|||||||
// Coefficient type.
|
// Coefficient type.
|
||||||
enum { TYPE_I16_AC = 0, TYPE_I16_DC = 1, TYPE_CHROMA_A = 2, TYPE_I4_AC = 3 };
|
enum { TYPE_I16_AC = 0, TYPE_I16_DC = 1, TYPE_CHROMA_A = 2, TYPE_I4_AC = 3 };
|
||||||
|
|
||||||
static int TrellisQuantizeBlock(const VP8Encoder* const enc,
|
static int TrellisQuantizeBlock(const VP8Encoder* WEBP_RESTRICT const enc,
|
||||||
int16_t in[16], int16_t out[16],
|
int16_t in[16], int16_t out[16],
|
||||||
int ctx0, int coeff_type,
|
int ctx0, int coeff_type,
|
||||||
const VP8Matrix* const mtx,
|
const VP8Matrix* WEBP_RESTRICT const mtx,
|
||||||
int lambda) {
|
int lambda) {
|
||||||
const ProbaArray* const probas = enc->proba_.coeffs_[coeff_type];
|
const ProbaArray* const probas = enc->proba_.coeffs_[coeff_type];
|
||||||
CostArrayPtr const costs =
|
CostArrayPtr const costs =
|
||||||
@ -767,9 +769,9 @@ static int TrellisQuantizeBlock(const VP8Encoder* const enc,
|
|||||||
// all at once. Output is the reconstructed block in *yuv_out, and the
|
// all at once. Output is the reconstructed block in *yuv_out, and the
|
||||||
// quantized levels in *levels.
|
// quantized levels in *levels.
|
||||||
|
|
||||||
static int ReconstructIntra16(VP8EncIterator* const it,
|
static int ReconstructIntra16(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
VP8ModeScore* const rd,
|
VP8ModeScore* WEBP_RESTRICT const rd,
|
||||||
uint8_t* const yuv_out,
|
uint8_t* WEBP_RESTRICT const yuv_out,
|
||||||
int mode) {
|
int mode) {
|
||||||
const VP8Encoder* const enc = it->enc_;
|
const VP8Encoder* const enc = it->enc_;
|
||||||
const uint8_t* const ref = it->yuv_p_ + VP8I16ModeOffsets[mode];
|
const uint8_t* const ref = it->yuv_p_ + VP8I16ModeOffsets[mode];
|
||||||
@ -819,10 +821,10 @@ static int ReconstructIntra16(VP8EncIterator* const it,
|
|||||||
return nz;
|
return nz;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ReconstructIntra4(VP8EncIterator* const it,
|
static int ReconstructIntra4(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
int16_t levels[16],
|
int16_t levels[16],
|
||||||
const uint8_t* const src,
|
const uint8_t* WEBP_RESTRICT const src,
|
||||||
uint8_t* const yuv_out,
|
uint8_t* WEBP_RESTRICT const yuv_out,
|
||||||
int mode) {
|
int mode) {
|
||||||
const VP8Encoder* const enc = it->enc_;
|
const VP8Encoder* const enc = it->enc_;
|
||||||
const uint8_t* const ref = it->yuv_p_ + VP8I4ModeOffsets[mode];
|
const uint8_t* const ref = it->yuv_p_ + VP8I4ModeOffsets[mode];
|
||||||
@ -855,7 +857,8 @@ static int ReconstructIntra4(VP8EncIterator* const it,
|
|||||||
|
|
||||||
// Quantize as usual, but also compute and return the quantization error.
|
// Quantize as usual, but also compute and return the quantization error.
|
||||||
// Error is already divided by DSHIFT.
|
// Error is already divided by DSHIFT.
|
||||||
static int QuantizeSingle(int16_t* const v, const VP8Matrix* const mtx) {
|
static int QuantizeSingle(int16_t* WEBP_RESTRICT const v,
|
||||||
|
const VP8Matrix* WEBP_RESTRICT const mtx) {
|
||||||
int V = *v;
|
int V = *v;
|
||||||
const int sign = (V < 0);
|
const int sign = (V < 0);
|
||||||
if (sign) V = -V;
|
if (sign) V = -V;
|
||||||
@ -869,9 +872,10 @@ static int QuantizeSingle(int16_t* const v, const VP8Matrix* const mtx) {
|
|||||||
return (sign ? -V : V) >> DSCALE;
|
return (sign ? -V : V) >> DSCALE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CorrectDCValues(const VP8EncIterator* const it,
|
static void CorrectDCValues(const VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
const VP8Matrix* const mtx,
|
const VP8Matrix* WEBP_RESTRICT const mtx,
|
||||||
int16_t tmp[][16], VP8ModeScore* const rd) {
|
int16_t tmp[][16],
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
// | top[0] | top[1]
|
// | top[0] | top[1]
|
||||||
// --------+--------+---------
|
// --------+--------+---------
|
||||||
// left[0] | tmp[0] tmp[1] <-> err0 err1
|
// left[0] | tmp[0] tmp[1] <-> err0 err1
|
||||||
@ -902,8 +906,8 @@ static void CorrectDCValues(const VP8EncIterator* const it,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StoreDiffusionErrors(VP8EncIterator* const it,
|
static void StoreDiffusionErrors(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
const VP8ModeScore* const rd) {
|
const VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
int ch;
|
int ch;
|
||||||
for (ch = 0; ch <= 1; ++ch) {
|
for (ch = 0; ch <= 1; ++ch) {
|
||||||
int8_t* const top = it->top_derr_[it->x_][ch];
|
int8_t* const top = it->top_derr_[it->x_][ch];
|
||||||
@ -922,8 +926,9 @@ static void StoreDiffusionErrors(VP8EncIterator* const it,
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static int ReconstructUV(VP8EncIterator* const it, VP8ModeScore* const rd,
|
static int ReconstructUV(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
uint8_t* const yuv_out, int mode) {
|
VP8ModeScore* WEBP_RESTRICT const rd,
|
||||||
|
uint8_t* WEBP_RESTRICT const yuv_out, int mode) {
|
||||||
const VP8Encoder* const enc = it->enc_;
|
const VP8Encoder* const enc = it->enc_;
|
||||||
const uint8_t* const ref = it->yuv_p_ + VP8UVModeOffsets[mode];
|
const uint8_t* const ref = it->yuv_p_ + VP8UVModeOffsets[mode];
|
||||||
const uint8_t* const src = it->yuv_in_ + U_OFF_ENC;
|
const uint8_t* const src = it->yuv_in_ + U_OFF_ENC;
|
||||||
@ -994,7 +999,8 @@ static void SwapOut(VP8EncIterator* const it) {
|
|||||||
SwapPtr(&it->yuv_out_, &it->yuv_out2_);
|
SwapPtr(&it->yuv_out_, &it->yuv_out2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PickBestIntra16(VP8EncIterator* const it, VP8ModeScore* rd) {
|
static void PickBestIntra16(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT rd) {
|
||||||
const int kNumBlocks = 16;
|
const int kNumBlocks = 16;
|
||||||
VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
|
VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
|
||||||
const int lambda = dqm->lambda_i16_;
|
const int lambda = dqm->lambda_i16_;
|
||||||
@ -1054,7 +1060,7 @@ static void PickBestIntra16(VP8EncIterator* const it, VP8ModeScore* rd) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// return the cost array corresponding to the surrounding prediction modes.
|
// return the cost array corresponding to the surrounding prediction modes.
|
||||||
static const uint16_t* GetCostModeI4(VP8EncIterator* const it,
|
static const uint16_t* GetCostModeI4(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
const uint8_t modes[16]) {
|
const uint8_t modes[16]) {
|
||||||
const int preds_w = it->enc_->preds_w_;
|
const int preds_w = it->enc_->preds_w_;
|
||||||
const int x = (it->i4_ & 3), y = it->i4_ >> 2;
|
const int x = (it->i4_ & 3), y = it->i4_ >> 2;
|
||||||
@ -1063,7 +1069,8 @@ static const uint16_t* GetCostModeI4(VP8EncIterator* const it,
|
|||||||
return VP8FixedCostsI4[top][left];
|
return VP8FixedCostsI4[top][left];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int PickBestIntra4(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
static int PickBestIntra4(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
const VP8Encoder* const enc = it->enc_;
|
const VP8Encoder* const enc = it->enc_;
|
||||||
const VP8SegmentInfo* const dqm = &enc->dqm_[it->mb_->segment_];
|
const VP8SegmentInfo* const dqm = &enc->dqm_[it->mb_->segment_];
|
||||||
const int lambda = dqm->lambda_i4_;
|
const int lambda = dqm->lambda_i4_;
|
||||||
@ -1159,7 +1166,8 @@ static int PickBestIntra4(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
static void PickBestUV(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
static void PickBestUV(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
const int kNumBlocks = 8;
|
const int kNumBlocks = 8;
|
||||||
const VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
|
const VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
|
||||||
const int lambda = dqm->lambda_uv_;
|
const int lambda = dqm->lambda_uv_;
|
||||||
@ -1211,7 +1219,8 @@ static void PickBestUV(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Final reconstruction and quantization.
|
// Final reconstruction and quantization.
|
||||||
|
|
||||||
static void SimpleQuantize(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
static void SimpleQuantize(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
const VP8Encoder* const enc = it->enc_;
|
const VP8Encoder* const enc = it->enc_;
|
||||||
const int is_i16 = (it->mb_->type_ == 1);
|
const int is_i16 = (it->mb_->type_ == 1);
|
||||||
int nz = 0;
|
int nz = 0;
|
||||||
@ -1236,9 +1245,9 @@ static void SimpleQuantize(VP8EncIterator* const it, VP8ModeScore* const rd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Refine intra16/intra4 sub-modes based on distortion only (not rate).
|
// Refine intra16/intra4 sub-modes based on distortion only (not rate).
|
||||||
static void RefineUsingDistortion(VP8EncIterator* const it,
|
static void RefineUsingDistortion(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
int try_both_modes, int refine_uv_mode,
|
int try_both_modes, int refine_uv_mode,
|
||||||
VP8ModeScore* const rd) {
|
VP8ModeScore* WEBP_RESTRICT const rd) {
|
||||||
score_t best_score = MAX_COST;
|
score_t best_score = MAX_COST;
|
||||||
int nz = 0;
|
int nz = 0;
|
||||||
int mode;
|
int mode;
|
||||||
@ -1352,7 +1361,8 @@ static void RefineUsingDistortion(VP8EncIterator* const it,
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Entry point
|
// Entry point
|
||||||
|
|
||||||
int VP8Decimate(VP8EncIterator* const it, VP8ModeScore* const rd,
|
int VP8Decimate(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd,
|
||||||
VP8RDLevel rd_opt) {
|
VP8RDLevel rd_opt) {
|
||||||
int is_skipped;
|
int is_skipped;
|
||||||
const int method = it->enc_->method_;
|
const int method = it->enc_->method_;
|
||||||
|
@ -470,7 +470,8 @@ int VP8EncAnalyze(VP8Encoder* const enc);
|
|||||||
// Sets up segment's quantization values, base_quant_ and filter strengths.
|
// Sets up segment's quantization values, base_quant_ and filter strengths.
|
||||||
void VP8SetSegmentParams(VP8Encoder* const enc, float quality);
|
void VP8SetSegmentParams(VP8Encoder* const enc, float quality);
|
||||||
// Pick best modes and fills the levels. Returns true if skipped.
|
// Pick best modes and fills the levels. Returns true if skipped.
|
||||||
int VP8Decimate(VP8EncIterator* const it, VP8ModeScore* const rd,
|
int VP8Decimate(VP8EncIterator* WEBP_RESTRICT const it,
|
||||||
|
VP8ModeScore* WEBP_RESTRICT const rd,
|
||||||
VP8RDLevel rd_opt);
|
VP8RDLevel rd_opt);
|
||||||
|
|
||||||
// in alpha.c
|
// in alpha.c
|
||||||
|
Loading…
Reference in New Issue
Block a user