mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-04 01:19:40 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1870455f66 |
@@ -777,14 +777,6 @@ fn decode_frame(job: &FrameJob, pool: &Pool, stats: &mut DecodeStats) -> Result<
|
||||
Ok((rf, pic))
|
||||
}
|
||||
|
||||
/// Bytes all parallel tile states may hold of whole-frame CDEF and restoration metadata; past it
|
||||
/// the tiles decode one after another on the frame's own metadata.
|
||||
const TILE_METADATA_BUDGET: usize = 256 << 20;
|
||||
|
||||
fn tile_metadata_fits(tiles: usize, per_tile: usize) -> bool {
|
||||
tiles.checked_mul(per_tile).is_some_and(|n| n <= TILE_METADATA_BUDGET)
|
||||
}
|
||||
|
||||
/// Decode the tiles of a frame (tile number, data), in parallel when several; returns the final
|
||||
/// CDFs of tile context_update_tile_id.
|
||||
fn decode_tiles(pool: &Pool, fs: &mut FrameState, cdfs: &Cdfs, tiles: &[(usize, Vec<u8>)]) -> Result<Option<Box<Cdfs>>> {
|
||||
@@ -798,7 +790,7 @@ fn decode_tiles(pool: &Pool, fs: &mut FrameState, cdfs: &Cdfs, tiles: &[(usize,
|
||||
};
|
||||
// Intra block copy reads the current frame through the tile's own buffer: keep whole-frame
|
||||
// buffers (tiles one after another) for it.
|
||||
if tiles.len() > 1 && pool.is_parallel() && !fs.fh.allow_intrabc && tile_metadata_fits(tiles.len(), fs.tile_metadata_bytes()) {
|
||||
if tiles.len() > 1 && pool.is_parallel() && !fs.fh.allow_intrabc {
|
||||
let mut states: Vec<TileState> = tiles
|
||||
.iter()
|
||||
.map(|(num, _)| {
|
||||
@@ -1083,14 +1075,6 @@ mod guard_tests {
|
||||
#[cfg(test)]
|
||||
mod budget_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn tile_metadata_copies_are_budgeted() {
|
||||
assert!(tile_metadata_fits(64, 1 << 20));
|
||||
assert!(!tile_metadata_fits(4096, 1 << 20));
|
||||
assert!(!tile_metadata_fits(usize::MAX, 2));
|
||||
}
|
||||
|
||||
use deckcraft_bitstream::budget::DECODE_MEMORY_BUDGET;
|
||||
|
||||
fn color(mono: bool) -> crate::header::ColorConfig {
|
||||
|
||||
@@ -253,13 +253,6 @@ impl FrameState {
|
||||
self.lr = t.lr;
|
||||
}
|
||||
|
||||
/// Bytes of CDEF and loop-restoration metadata each parallel tile state copies whole.
|
||||
pub fn tile_metadata_bytes(&self) -> usize {
|
||||
let lr = &self.lr;
|
||||
// 1 (type) + 6 (Wiener) + 1 (SGR set) + 2 (SGR weights) bytes per unit.
|
||||
self.cdef.len() + lr.lr_type.iter().map(|v| v.len() * 10).sum::<usize>()
|
||||
}
|
||||
|
||||
/// Private buffers for the tile covering mode info rows [r0, r1) x columns [c0, c1); tiles
|
||||
/// on the right / bottom frame edge also cover the allocation margins.
|
||||
pub fn tile_state(&self, r0: usize, r1: usize, c0: usize, c1: usize) -> TileState {
|
||||
|
||||
@@ -304,7 +304,12 @@ impl Dictionary {
|
||||
|
||||
/// `w` made of dictionary parts allowed in compounds (`COMPOUNDFLAG`, or the begin, middle and
|
||||
/// end flags), each at least `COMPOUNDMIN` characters long.
|
||||
fn compounded(&self, w: &[char], index: usize) -> bool {
|
||||
fn compounded(&self, w: &[char], index: usize, failed: &mut HashSet<(usize, usize)>) -> bool {
|
||||
// `w` is always a tail of the checked word, so its length names it: a (tail, part index)
|
||||
// that failed once fails again however the earlier parts were split.
|
||||
if failed.contains(&(w.len(), index)) {
|
||||
return false;
|
||||
}
|
||||
if self.compound.is_none() && self.compound_end.is_none() {
|
||||
return false;
|
||||
}
|
||||
@@ -322,10 +327,11 @@ impl Dictionary {
|
||||
if [self.compound, self.compound_end].into_iter().flatten().any(|f| self.compound_part(rest, f, true)) {
|
||||
return true;
|
||||
}
|
||||
if self.compounded(rest, index + 1) {
|
||||
if self.compounded(rest, index + 1, failed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
failed.insert((w.len(), index));
|
||||
false
|
||||
}
|
||||
|
||||
@@ -352,7 +358,7 @@ impl Dictionary {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self.compounded(&w, 0)
|
||||
self.compounded(&w, 0, &mut HashSet::new())
|
||||
}
|
||||
|
||||
/// Is `word` spelt correctly? Capitalised and upper-case forms of a lower-case word pass.
|
||||
@@ -931,6 +937,15 @@ SFX D Y 1\nSFX D 0 ed/S .\n";
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_compound_roots_with_a_failing_ending_stay_cheap() {
|
||||
// Every split of "aaa…ab" reaches the same (tail, part) states; unmemoized this is
|
||||
// ~C(99, 7) searches.
|
||||
let d = Dictionary::parse(b"COMPOUNDFLAG X\nCOMPOUNDMIN 1\n".as_slice(), b"1\na/X\n".as_slice());
|
||||
assert!(!d.check(&format!("{}b", "a".repeat(99))));
|
||||
assert!(d.check(&"a".repeat(5)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_give_words_their_language() {
|
||||
use deckcraft_model::{Paragraph, Run, RunProps};
|
||||
|
||||
Reference in New Issue
Block a user