guetzli--更高压缩比的jepg编码器
graph LR main --> Process
核心代码
调整dct系数,调整量化表,再编码jpeg,用butteraugli跟原图比较,看相似度是否过关,不过关的话,再做调整,不断重复这个循环。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
29for (int downsample = force_420; downsample <= try_420; ++downsample) {
JPEGData jpg = jpg_in;
RemoveOriginalQuantization(&jpg, q_in);
OutputImage img(jpg.width, jpg.height);
img.CopyFromJpegData(jpg);
if (downsample) {
DownsampleImage(&img);
img.SaveToJpegData(&jpg);
}
int best_q[3][kDCTBlockSize];
memcpy(best_q, q_in, sizeof(best_q));
if (!SelectQuantMatrix(jpg, downsample != 0, best_q, &img)) {
for (int c = 0; c < 3; ++c) {
for (int i = 0; i < kDCTBlockSize; ++i) {
best_q[c][i] = 1;
}
}
}
img.CopyFromJpegData(jpg);
img.ApplyGlobalQuantization(best_q);
if (!downsample) {
SelectFrequencyMasking(jpg, &img, 7, 1.0, false);
} else {
const float ymul = jpg.components.size() == 1 ? 1.0f : 0.97f;
SelectFrequencyMasking(jpg, &img, 1, ymul, false);
SelectFrequencyMasking(jpg, &img, 6, 1.0, true);
}
}
重点函数解析
1 | Process(params, &stats, rgb, xsize, ysize, &out_data) |