Skip to content

Commit cb5e4a8

Browse files
jyrkialakuijalarobryk
authored andcommitted
Improve lower quality behaviour.
This change reduces the amount of banding that is generated at lower qualities. At the same time it causes images at low fixed Butteraugli score to be smaller, so it seems to fix some suboptimality in the optimization process.
1 parent 32eb462 commit cb5e4a8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

guetzli/processor.cc

+12-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,18 @@ void Processor::SelectFrequencyMasking(const JPEGData& jpg, OutputImage* img,
719719
coeff_t block[kDCTBlockSize] = { 0 };
720720
img->component(c).GetCoeffBlock(block_x, block_y, block);
721721
UpdateACHistogram(-1, block, quant, &ac_histograms[c]);
722-
block[k] = newval;
722+
double sum_of_hf = 0;
723+
for (int ii = 3; ii < 64; ++ii) {
724+
if ((ii & 7) < 3 && ii < 3 * 8) continue;
725+
sum_of_hf += std::abs(comp.coeffs[jpg_block_ix * kDCTBlockSize + ii]);
726+
}
727+
int limit = sum_of_hf < 60 ? 4 : 8;
728+
bool precious =
729+
(k == 1 || k == 8) &&
730+
std::abs(comp.coeffs[jpg_block_ix * kDCTBlockSize + k]) >= limit;
731+
if (!precious || newval != 0) {
732+
block[k] = newval;
733+
}
723734
UpdateACHistogram(1, block, quant, &ac_histograms[c]);
724735
img->component(c).SetCoeffBlock(block_x, block_y, block);
725736
last_indexes[block_ix] += direction;

0 commit comments

Comments
 (0)