#include <assert.h>
#include "src/enc/vp8i_enc.h"
#include "src/dsp/dsp.h"
#define MAX_DELTA_SIZE …
static const uint8_t kLevelsFromDelta[8][MAX_DELTA_SIZE] = …;
int VP8FilterStrengthFromDelta(int sharpness, int delta) { … }
#if !defined(WEBP_REDUCE_SIZE)
static int GetILevel(int sharpness, int level) {
if (sharpness > 0) {
if (sharpness > 4) {
level >>= 2;
} else {
level >>= 1;
}
if (level > 9 - sharpness) {
level = 9 - sharpness;
}
}
if (level < 1) level = 1;
return level;
}
static void DoFilter(const VP8EncIterator* const it, int level) {
const VP8Encoder* const enc = it->enc_;
const int ilevel = GetILevel(enc->config_->filter_sharpness, level);
const int limit = 2 * level + ilevel;
uint8_t* const y_dst = it->yuv_out2_ + Y_OFF_ENC;
uint8_t* const u_dst = it->yuv_out2_ + U_OFF_ENC;
uint8_t* const v_dst = it->yuv_out2_ + V_OFF_ENC;
memcpy(y_dst, it->yuv_out_, YUV_SIZE_ENC * sizeof(uint8_t));
if (enc->filter_hdr_.simple_ == 1) {
VP8SimpleHFilter16i(y_dst, BPS, limit);
VP8SimpleVFilter16i(y_dst, BPS, limit);
} else {
const int hev_thresh = (level >= 40) ? 2 : (level >= 15) ? 1 : 0;
VP8HFilter16i(y_dst, BPS, limit, ilevel, hev_thresh);
VP8HFilter8i(u_dst, v_dst, BPS, limit, ilevel, hev_thresh);
VP8VFilter16i(y_dst, BPS, limit, ilevel, hev_thresh);
VP8VFilter8i(u_dst, v_dst, BPS, limit, ilevel, hev_thresh);
}
}
static double GetMBSSIM(const uint8_t* yuv1, const uint8_t* yuv2) {
int x, y;
double sum = 0.;
for (y = VP8_SSIM_KERNEL; y < 16 - VP8_SSIM_KERNEL; y++) {
for (x = VP8_SSIM_KERNEL; x < 16 - VP8_SSIM_KERNEL; x++) {
sum += VP8SSIMGetClipped(yuv1 + Y_OFF_ENC, BPS, yuv2 + Y_OFF_ENC, BPS,
x, y, 16, 16);
}
}
for (x = 1; x < 7; x++) {
for (y = 1; y < 7; y++) {
sum += VP8SSIMGetClipped(yuv1 + U_OFF_ENC, BPS, yuv2 + U_OFF_ENC, BPS,
x, y, 8, 8);
sum += VP8SSIMGetClipped(yuv1 + V_OFF_ENC, BPS, yuv2 + V_OFF_ENC, BPS,
x, y, 8, 8);
}
}
return sum;
}
#endif
void VP8InitFilter(VP8EncIterator* const it) { … }
void VP8StoreFilterStats(VP8EncIterator* const it) { … }
void VP8AdjustFilterStrength(VP8EncIterator* const it) { … }