diff --git a/src/enc/histogram.c b/src/enc/histogram.c index 286676e7..ea336781 100644 --- a/src/enc/histogram.c +++ b/src/enc/histogram.c @@ -214,10 +214,19 @@ static double InitialHuffmanCost(void) { // Finalize the Huffman cost based on streak numbers and length type (<3 or >=3) static double FinalHuffmanCost(const VP8LStreaks* const stats) { + // The constants in this function are experimental and got rounded from + // their original values in 1/8 when switched to 1/1024. double retval = InitialHuffmanCost(); + // Second coefficient: Many zeros in the histogram are covered efficiently + // by a run-length encode. Originally 2/8. retval += stats->counts[0] * 1.5625 + 0.234375 * stats->streaks[0][1]; + // Second coefficient: Constant values are encoded less efficiently, but still + // RLE'ed. Originally 6/8. retval += stats->counts[1] * 2.578125 + 0.703125 * stats->streaks[1][1]; + // 0s are usually encoded more efficiently than non-0s. + // Originally 15/8. retval += 1.796875 * stats->streaks[0][0]; + // Originally 26/8. retval += 3.28125 * stats->streaks[1][0]; return retval; }