#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include "src/dsp/quant.h"
#include "src/enc/vp8i_enc.h"
#include "src/enc/cost_enc.h"
#define DO_TRELLIS_I4 …
#define DO_TRELLIS_I16 …
#define DO_TRELLIS_UV …
#define USE_TDISTO …
#define MID_ALPHA …
#define MIN_ALPHA …
#define MAX_ALPHA …
#define SNS_TO_DQ …
#define FLATNESS_LIMIT_I16 …
#define FLATNESS_LIMIT_I4 …
#define FLATNESS_LIMIT_UV …
#define FLATNESS_PENALTY …
#define MULT_8B(a, b) …
#define RD_DISTO_MULT …
#if defined(DEBUG_BLOCK)
#include <stdio.h>
#include <stdlib.h>
static void PrintBlockInfo(const VP8EncIterator* const it,
const VP8ModeScore* const rd) {
int i, j;
const int is_i16 = (it->mb_->type_ == 1);
const uint8_t* const y_in = it->yuv_in_ + Y_OFF_ENC;
const uint8_t* const y_out = it->yuv_out_ + Y_OFF_ENC;
const uint8_t* const uv_in = it->yuv_in_ + U_OFF_ENC;
const uint8_t* const uv_out = it->yuv_out_ + U_OFF_ENC;
printf("SOURCE / OUTPUT / ABS DELTA\n");
for (j = 0; j < 16; ++j) {
for (i = 0; i < 16; ++i) printf("%3d ", y_in[i + j * BPS]);
printf(" ");
for (i = 0; i < 16; ++i) printf("%3d ", y_out[i + j * BPS]);
printf(" ");
for (i = 0; i < 16; ++i) {
printf("%1d ", abs(y_in[i + j * BPS] - y_out[i + j * BPS]));
}
printf("\n");
}
printf("\n");
for (j = 0; j < 8; ++j) {
for (i = 0; i < 8; ++i) printf("%3d ", uv_in[i + j * BPS]);
printf(" ");
for (i = 8; i < 16; ++i) printf("%3d ", uv_in[i + j * BPS]);
printf(" ");
for (i = 0; i < 8; ++i) printf("%3d ", uv_out[i + j * BPS]);
printf(" ");
for (i = 8; i < 16; ++i) printf("%3d ", uv_out[i + j * BPS]);
printf(" ");
for (i = 0; i < 8; ++i) {
printf("%1d ", abs(uv_out[i + j * BPS] - uv_in[i + j * BPS]));
}
printf(" ");
for (i = 8; i < 16; ++i) {
printf("%1d ", abs(uv_out[i + j * BPS] - uv_in[i + j * BPS]));
}
printf("\n");
}
printf("\nD:%d SD:%d R:%d H:%d nz:0x%x score:%d\n",
(int)rd->D, (int)rd->SD, (int)rd->R, (int)rd->H, (int)rd->nz,
(int)rd->score);
if (is_i16) {
printf("Mode: %d\n", rd->mode_i16);
printf("y_dc_levels:");
for (i = 0; i < 16; ++i) printf("%3d ", rd->y_dc_levels[i]);
printf("\n");
} else {
printf("Modes[16]: ");
for (i = 0; i < 16; ++i) printf("%d ", rd->modes_i4[i]);
printf("\n");
}
printf("y_ac_levels:\n");
for (j = 0; j < 16; ++j) {
for (i = is_i16 ? 1 : 0; i < 16; ++i) {
printf("%4d ", rd->y_ac_levels[j][i]);
}
printf("\n");
}
printf("\n");
printf("uv_levels (mode=%d):\n", rd->mode_uv);
for (j = 0; j < 8; ++j) {
for (i = 0; i < 16; ++i) {
printf("%4d ", rd->uv_levels[j][i]);
}
printf("\n");
}
}
#endif
static WEBP_INLINE int clip(int v, int m, int M) { … }
static const uint8_t kZigzag[16] = …;
static const uint8_t kDcTable[128] = …;
static const uint16_t kAcTable[128] = …;
static const uint16_t kAcTable2[128] = …;
static const uint8_t kBiasMatrices[3][2] = …;
#define SHARPEN_BITS …
static const uint8_t kFreqSharpening[16] = …;
static int ExpandMatrix(VP8Matrix* const m, int type) { … }
static void CheckLambdaValue(int* const v) { … }
static void SetupMatrices(VP8Encoder* enc) { … }
#define FSTRENGTH_CUTOFF …
static void SetupFilterStrength(VP8Encoder* const enc) { … }
#define MAX_DQ_UV …
#define MIN_DQ_UV …
static double QualityToCompression(double c) { … }
static double QualityToJPEGCompression(double c, double alpha) { … }
static int SegmentsAreEquivalent(const VP8SegmentInfo* const S1,
const VP8SegmentInfo* const S2) { … }
static void SimplifySegments(VP8Encoder* const enc) { … }
void VP8SetSegmentParams(VP8Encoder* const enc, float quality) { … }
const uint16_t VP8I16ModeOffsets[4] = …;
const uint16_t VP8UVModeOffsets[4] = …;
const uint16_t VP8I4ModeOffsets[NUM_BMODES] = …;
void VP8MakeLuma16Preds(const VP8EncIterator* const it) { … }
void VP8MakeChroma8Preds(const VP8EncIterator* const it) { … }
void VP8MakeIntra4Preds(const VP8EncIterator* const it) { … }
const uint16_t VP8Scan[16] = …;
static const uint16_t VP8ScanUV[4 + 4] = …;
static const uint16_t kWeightY[16] = …;
static const uint16_t kWeightTrellis[16] = …;
static void InitScore(VP8ModeScore* const rd) { … }
static void CopyScore(VP8ModeScore* WEBP_RESTRICT const dst,
const VP8ModeScore* WEBP_RESTRICT const src) { … }
static void AddScore(VP8ModeScore* WEBP_RESTRICT const dst,
const VP8ModeScore* WEBP_RESTRICT const src) { … }
#define Node …
Node_libwebp_quant;
ScoreState;
#define MIN_DELTA …
#define MAX_DELTA …
#define NUM_NODES …
#define NODE …
#define SCORE_STATE(n, l) …
static WEBP_INLINE void SetRDScore(int lambda, VP8ModeScore* const rd) { … }
static WEBP_INLINE score_t RDScoreTrellis(int lambda, score_t rate,
score_t distortion) { … }
enum { … };
static int TrellisQuantizeBlock(const VP8Encoder* WEBP_RESTRICT const enc,
int16_t in[16], int16_t out[16],
int ctx0, int coeff_type,
const VP8Matrix* WEBP_RESTRICT const mtx,
int lambda) { … }
#undef NODE
static int ReconstructIntra16(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd,
uint8_t* WEBP_RESTRICT const yuv_out,
int mode) { … }
static int ReconstructIntra4(VP8EncIterator* WEBP_RESTRICT const it,
int16_t levels[16],
const uint8_t* WEBP_RESTRICT const src,
uint8_t* WEBP_RESTRICT const yuv_out,
int mode) { … }
#define C1 …
#define C2 …
#define DSHIFT …
#define DSCALE …
static int QuantizeSingle(int16_t* WEBP_RESTRICT const v,
const VP8Matrix* WEBP_RESTRICT const mtx) { … }
static void CorrectDCValues(const VP8EncIterator* WEBP_RESTRICT const it,
const VP8Matrix* WEBP_RESTRICT const mtx,
int16_t tmp[][16],
VP8ModeScore* WEBP_RESTRICT const rd) { … }
static void StoreDiffusionErrors(VP8EncIterator* WEBP_RESTRICT const it,
const VP8ModeScore* WEBP_RESTRICT const rd) { … }
#undef C1
#undef C2
#undef DSHIFT
#undef DSCALE
static int ReconstructUV(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd,
uint8_t* WEBP_RESTRICT const yuv_out, int mode) { … }
static void StoreMaxDelta(VP8SegmentInfo* const dqm, const int16_t DCs[16]) { … }
static void SwapModeScore(VP8ModeScore** a, VP8ModeScore** b) { … }
static void SwapPtr(uint8_t** a, uint8_t** b) { … }
static void SwapOut(VP8EncIterator* const it) { … }
static void PickBestIntra16(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT rd) { … }
static const uint16_t* GetCostModeI4(VP8EncIterator* WEBP_RESTRICT const it,
const uint8_t modes[16]) { … }
static int PickBestIntra4(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd) { … }
static void PickBestUV(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd) { … }
static void SimpleQuantize(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd) { … }
static void RefineUsingDistortion(VP8EncIterator* WEBP_RESTRICT const it,
int try_both_modes, int refine_uv_mode,
VP8ModeScore* WEBP_RESTRICT const rd) { … }
int VP8Decimate(VP8EncIterator* WEBP_RESTRICT const it,
VP8ModeScore* WEBP_RESTRICT const rd,
VP8RDLevel rd_opt) { … }