mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
move some SSIM-accumulation function for dsp/
This is in preparation for some SSE2 code. And generally speaking, the whole SSIM code needs some revamp: we're not averaging the SSIM value at each pixels but just computing the overall SSIM value once, for the whole plane. The former might be better than the latter. Change-Id: I935784a917f84a18ef08dc5ec9a7b528abea46a5
This commit is contained in:
@ -215,6 +215,35 @@ extern VP8GetResidualCostFunc VP8GetResidualCost;
|
||||
// must be called before anything using the above
|
||||
void VP8EncDspCostInit(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// SSIM utils
|
||||
|
||||
// struct for accumulating statistical moments
|
||||
typedef struct {
|
||||
double w; // sum(w_i) : sum of weights
|
||||
double xm, ym; // sum(w_i * x_i), sum(w_i * y_i)
|
||||
double xxm, xym, yym; // sum(w_i * x_i * x_i), etc.
|
||||
} VP8DistoStats;
|
||||
|
||||
#define VP8_SSIM_KERNEL 3 // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1
|
||||
typedef void (*VP8SSIMAccumulateClippedFunc)(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int xo, int yo, // center position
|
||||
int W, int H, // plane dimension
|
||||
VP8DistoStats* const stats);
|
||||
|
||||
// This version is called with the guarantee that you can load 8 bytes and
|
||||
// 8 rows at offset src1 and src2
|
||||
typedef void (*VP8SSIMAccumulateFunc)(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
VP8DistoStats* const stats);
|
||||
|
||||
VP8SSIMAccumulateFunc VP8SSIMAccumulate; // unclipped / unchecked
|
||||
VP8SSIMAccumulateClippedFunc VP8SSIMAccumulateClipped; // with clipping
|
||||
|
||||
// must be called before using any of the above directly
|
||||
void VP8SSIMDspInit(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Decoding
|
||||
|
||||
|
@ -702,6 +702,68 @@ static void Copy16x8(const uint8_t* src, uint8_t* dst) {
|
||||
Copy(src, dst, 16, 8);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static void SSIMAccumulateClipped(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int xo, int yo, int W, int H,
|
||||
VP8DistoStats* const stats) {
|
||||
const int ymin = (yo - VP8_SSIM_KERNEL < 0) ? 0 : yo - VP8_SSIM_KERNEL;
|
||||
const int ymax = (yo + VP8_SSIM_KERNEL > H - 1) ? H - 1
|
||||
: yo + VP8_SSIM_KERNEL;
|
||||
const int xmin = (xo - VP8_SSIM_KERNEL < 0) ? 0 : xo - VP8_SSIM_KERNEL;
|
||||
const int xmax = (xo + VP8_SSIM_KERNEL > W - 1) ? W - 1
|
||||
: xo + VP8_SSIM_KERNEL;
|
||||
int x, y;
|
||||
src1 += ymin * stride1;
|
||||
src2 += ymin * stride2;
|
||||
for (y = ymin; y <= ymax; ++y, src1 += stride1, src2 += stride2) {
|
||||
for (x = xmin; x <= xmax; ++x) {
|
||||
const int s1 = src1[x];
|
||||
const int s2 = src2[x];
|
||||
stats->w += 1;
|
||||
stats->xm += s1;
|
||||
stats->ym += s2;
|
||||
stats->xxm += s1 * s1;
|
||||
stats->xym += s1 * s2;
|
||||
stats->yym += s2 * s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SSIMAccumulate(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
VP8DistoStats* const stats) {
|
||||
int x, y;
|
||||
for (y = 0; y <= 2 * VP8_SSIM_KERNEL; ++y, src1 += stride1, src2 += stride2) {
|
||||
for (x = 0; x <= 2 * VP8_SSIM_KERNEL; ++x) {
|
||||
const int s1 = src1[x];
|
||||
const int s2 = src2[x];
|
||||
stats->w += 1;
|
||||
stats->xm += s1;
|
||||
stats->ym += s2;
|
||||
stats->xxm += s1 * s1;
|
||||
stats->xym += s1 * s2;
|
||||
stats->yym += s2 * s2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VP8SSIMAccumulateFunc VP8SSIMAccumulate;
|
||||
VP8SSIMAccumulateClippedFunc VP8SSIMAccumulateClipped;
|
||||
|
||||
static volatile VP8CPUInfo ssim_last_cpuinfo_used =
|
||||
(VP8CPUInfo)&ssim_last_cpuinfo_used;
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8SSIMDspInit(void) {
|
||||
if (ssim_last_cpuinfo_used == VP8GetCPUInfo) return;
|
||||
|
||||
VP8SSIMAccumulate = SSIMAccumulate;
|
||||
VP8SSIMAccumulateClipped = SSIMAccumulateClipped;
|
||||
|
||||
ssim_last_cpuinfo_used = VP8GetCPUInfo;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Initialization
|
||||
|
||||
|
Reference in New Issue
Block a user