1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/magicyuvenc: Fix Huffman element probabilities

The earlier code only used the counts from the last slice.
The two FATE tests using slices show compression improvements
due to this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-11 23:23:56 +02:00
parent 0e4d513f99
commit a6c2c463c7
3 changed files with 11 additions and 11 deletions

View File

@ -395,20 +395,20 @@ static int encode_table(AVCodecContext *avctx,
PutBitContext *pb, HuffEntry *he, int plane) PutBitContext *pb, HuffEntry *he, int plane)
{ {
MagicYUVContext *s = avctx->priv_data; MagicYUVContext *s = avctx->priv_data;
PTable counts[256] = { {0} }; PTable counts[256];
uint16_t codes_counts[33] = { 0 }; uint16_t codes_counts[33] = { 0 };
for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
counts[i].prob = 1;
counts[i].value = i;
}
for (int n = 0; n < s->nb_slices; n++) { for (int n = 0; n < s->nb_slices; n++) {
Slice *sl = &s->slices[n * s->planes + plane]; Slice *sl = &s->slices[n * s->planes + plane];
PTable *slice_counts = sl->counts; PTable *slice_counts = sl->counts;
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
counts[i].prob = slice_counts[i].prob; counts[i].prob += slice_counts[i].prob;
}
for (int i = 0; i < 256; i++) {
counts[i].prob++;
counts[i].value = i;
} }
magy_huffman_compute_bits(counts, he, codes_counts, 256, 12); magy_huffman_compute_bits(counts, he, codes_counts, 256, 12);

View File

@ -1,4 +1,4 @@
dc919cb0b3415d31fd51dfc6d7c22a6b *tests/data/fate/vsynth1-magicyuv.avi c52dd1622adefa1d863ed3fea03b304e *tests/data/fate/vsynth1-magicyuv.avi
3013600 tests/data/fate/vsynth1-magicyuv.avi 2972044 tests/data/fate/vsynth1-magicyuv.avi
c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-magicyuv.out.rawvideo c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-magicyuv.out.rawvideo
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200

View File

@ -1,4 +1,4 @@
3f74bf17bb8d9ba2022004f95de4b666 *tests/data/fate/vsynth_lena-magicyuv.avi b7cd87cec898d66cfce82e649376bb0d *tests/data/fate/vsynth_lena-magicyuv.avi
3477676 tests/data/fate/vsynth_lena-magicyuv.avi 3471504 tests/data/fate/vsynth_lena-magicyuv.avi
d7bfbe259af9ae323bb94b09c33570a5 *tests/data/fate/vsynth_lena-magicyuv.out.rawvideo d7bfbe259af9ae323bb94b09c33570a5 *tests/data/fate/vsynth_lena-magicyuv.out.rawvideo
stddev: 18.65 PSNR: 22.72 MAXDIFF: 72 bytes: 7603200/ 7603200 stddev: 18.65 PSNR: 22.72 MAXDIFF: 72 bytes: 7603200/ 7603200