Skip to content

Commit ec82d80

Browse files
rom1vtdaede
authored andcommitted
Use the biggest tile for CDF update
Use the tile that takes the largest number of bytes for CDF update. It should be better for entropy coding.
1 parent a9159f1 commit ec82d80

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/encoder.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ pub struct FrameState<T: Pixel> {
417417
pub input_qres: Plane<T>, // quarter-resolution version of input luma
418418
pub rec: Frame<T>,
419419
pub cdfs: CDFContext,
420+
pub context_update_tile_id: usize, // tile id used for the CDFontext
420421
pub deblock: DeblockState,
421422
pub segmentation: SegmentationState,
422423
pub restoration: RestorationState,
@@ -445,6 +446,7 @@ impl<T: Pixel> FrameState<T> {
445446
input_qres: Plane::new(luma_width / 4, luma_height / 4, 2, 2, luma_padding_x / 4, luma_padding_y / 4),
446447
rec: Frame::new(luma_width, luma_height, fi.sequence.chroma_sampling),
447448
cdfs: CDFContext::new(0),
449+
context_update_tile_id: 0,
448450
deblock: Default::default(),
449451
segmentation: Default::default(),
450452
restoration: rs,
@@ -2142,8 +2144,16 @@ fn encode_tile_group<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>)
21422144
fs.t.print_code();
21432145
}
21442146

2145-
// for now, always keep the CDF from the first tile
2146-
fs.cdfs = cdfs[0];
2147+
let (idx_max, _max_len) = raw_tiles
2148+
.iter()
2149+
.map(Vec::len)
2150+
.enumerate()
2151+
.max_by_key(|&(_, len)| len)
2152+
.unwrap();
2153+
2154+
// use the biggest tile (in bytes) for CDF update
2155+
fs.context_update_tile_id = idx_max;
2156+
fs.cdfs = cdfs[idx_max];
21472157
fs.cdfs.reset_counts();
21482158

21492159
build_raw_tile_group(ti, &raw_tiles)

src/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
642642
if tiles_log2 > 0 {
643643
// context_update_tile_id
644644
// for now, always use the first tile CDF
645-
self.write(tiles_log2 as u32, 0)?;
645+
self.write(tiles_log2 as u32, fs.context_update_tile_id as u32)?;
646646

647647
// tile_size_bytes_minus_1
648648
// force TileSizeBytes == 4, to be optimized using actual tile sizes

0 commit comments

Comments
 (0)