forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

wave.rs712 lines, 23.6 KiBHistoryRawDownload
1//! Superblock-row wavefront reconstruction, in safe Rust.
2//!
3//! The tile thread parses. While a wavefront is installed, every
4//! reconstruction write it would make ([`super::exec_intra`] and
5//! [`super::exec_mc`]) is queued as an owned [`ReconOp`] instead. The queue
6//! is cut into one [`Job`] per superblock and sent to the worker that owns
7//! that superblock row (`row % workers`).
8//!
9//! A worker never shares a plane. It reconstructs into its own full-size
10//! copy, seeded with the rows it owns. Intra prediction reads one pixel row
11//! above a superblock row, and superblock `c` of row `r` reads up to
12//! superblock `c + 1` of that row (above-right). Row `r - 1` therefore
13//! publishes the bottom pixel row of each superblock it finishes into a
14//! shared line buffer. Superblock `c` of row `r` waits until row `r - 1` has
15//! finished column `c + 1`, copies that segment into the row above its own
16//! strip, and then reconstructs. When the tile is done each worker's rows are
17//! copied back into the frame planes, and its worker context's corrupt flag
18//! is carried over to the tile's context.
19
20use super::block::PlaneBuf;
21use super::TxParams;
22use super::{CflSrc, FrameCtx, Reach, RefPix, SharedRefs, WithRef, exec_intra, exec_mc};
23use std::borrow::Cow;
24use std::cell::{Cell, RefCell};
25use crate::encode::Picture;
26use ec_core::Result;
27use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock, PoisonError, mpsc};
28use crate::par::Batch;
29
30/// A deferred residual: either finished, or the transform's inputs, run by
31/// the worker that replays the write (the inverse transform is most of the
32/// reconstruction work, so it must not stay on the parse thread).
33pub(super) enum Residual {
34 /// Codes nothing: the empty marker the reconstruction reads as all zeros.
35 Zero,
36 /// An already-transformed residual: `(offset, len)` in the job's arena.
37 Ready(usize, usize),
38 /// The transform's inputs: `(offset, len)` of the coefficients in the
39 /// job's arena.
40 Tx(TxParams, usize, usize),
41}
42
43impl Residual {
44 /// An already-transformed residual; the shared zero block (a skipped
45 /// block) is the marker, not a copy.
46 pub(super) fn ready(residual: &[i32]) -> Self {
47 if residual.is_empty() || std::ptr::eq(residual.as_ptr(), super::ZERO_RESIDUAL.as_ptr()) {
48 Self::Zero
49 } else {
50 let off = push_coeffs(residual);
51 Self::Ready(off, residual.len())
52 }
53 }
54
55 /// The transform's inputs; a grid that codes nothing needs no transform.
56 pub(super) fn tx(tx: TxParams, grid: &[i32]) -> Self {
57 if super::is_zero_grid(grid) {
58 Self::Zero
59 } else {
60 let off = push_coeffs(grid);
61 Self::Tx(tx, off, grid.len())
62 }
63 }
64
65 /// The residual to reconstruct with; `scratch` is where a transform lands.
66 fn resolve<'a>(self, arena: &'a [i32], scratch: &'a mut Vec<i32>) -> &'a [i32] {
67 match self {
68 Self::Zero => &[],
69 Self::Ready(off, len) => &arena[off..][..len],
70 Self::Tx(tx, off, len) => {
71 *scratch = tx.run(&arena[off..][..len]);
72 scratch
73 }
74 }
75 }
76}
77
78/// Appends to the superblock's coefficient arena, returning the offset.
79fn push_coeffs(v: &[i32]) -> usize {
80 QUEUE.with(|q| {
81 let mut q = q.borrow_mut();
82 let off = q.coeffs.len();
83 q.coeffs.extend_from_slice(v);
84 off
85 })
86}
87
88/// The ops of the superblock being parsed, with the arena their residuals
89/// live in.
90#[derive(Default)]
91struct Queue {
92 ops: Vec<ReconOp>,
93 coeffs: Vec<i32>,
94}
95
96/// A block's whole-block prediction build, run by the worker into its
97/// prediction slots (one `Vec` per plane). Owned, so it can cross to a worker.
98pub(super) type PredFn = Box<
99 dyn FnOnce(
100 &mut PlaneBuf<'static>,
101 &mut PlaneBuf<'static>,
102 &mut PlaneBuf<'static>,
103 &RefPix<'_>,
104 &FrameCtx,
105 &mut [Vec<u16>; 3],
106 ) + Send,
107>;
108
109/// Where a deferred motion-compensated write reads its prediction from.
110pub(super) enum PredSrc {
111 /// The samples, carried by the op.
112 Owned(Vec<u16>),
113 /// A window of the block prediction the last [`ReconOp::Pred`] left in the
114 /// worker's slot `plane`, at offset `off`, read at stride `src`.
115 Cur { plane: usize, off: usize, src: usize },
116}
117
118/// One deferred reconstruction write. Owned, so it can cross to a worker.
119pub(super) enum ReconOp {
120 /// Build this block's prediction into the worker's slots.
121 Pred(PredFn),
122 Intra {
123 plane: usize,
124 x: usize,
125 oy: usize,
126 bw: usize,
127 bh: usize,
128 rect: bool,
129 mode: usize,
130 angle_delta: i32,
131 reach: Reach,
132 residual: Residual,
133 cfl: Option<(i32, CflSrc)>,
134 filter_intra: Option<usize>,
135 smooth_neighbor: bool,
136 pred: Option<Vec<u16>>,
137 },
138 Mc {
139 plane: usize,
140 x: usize,
141 oy: usize,
142 stride: usize,
143 w: usize,
144 h: usize,
145 prediction: PredSrc,
146 residual: Residual,
147 },
148}
149
150thread_local! {
151 /// Whether this thread's reconstruction is being deferred.
152 static ACTIVE: Cell<bool> = const { Cell::new(false) };
153 /// The running wavefront of this thread's current tile, if any.
154 static GUARD: RefCell<Option<WaveGuard>> = const { RefCell::new(None) };
155 /// The superblock being parsed (tile-relative), sent by the next `begin_sb`.
156 static CURRENT: Cell<Option<(usize, usize)>> = const { Cell::new(None) };
157 /// The ops of the superblock being parsed, cut by [`submit`].
158 static QUEUE: RefCell<Queue> = const { RefCell::new(Queue { ops: Vec::new(), coeffs: Vec::new() }) };
159 /// Plane sets of finished workers, reused by the next tile so that a
160 /// tile does not fault in fresh full-frame planes.
161 static POOL: RefCell<Vec<[Vec<u16>; 3]>> = const { RefCell::new(Vec::new()) };
162}
163
164/// Plane sets kept for reuse; more than a tile's worth of workers is waste.
165const POOL_SETS: usize = 4;
166
167/// Ends the thread's wavefront when a tile's scope unwinds, so an error
168/// return never leaves later reconstruction deferred.
169pub(super) struct TileScope;
170
171impl Drop for TileScope {
172 fn drop(&mut self) {
173 let guard = GUARD.with(|g| g.borrow_mut().take());
174 drop(guard);
175 ACTIVE.with(|a| a.set(false));
176 CURRENT.with(|c| c.set(None));
177 QUEUE.with(|q| {
178 let mut q = q.borrow_mut();
179 q.ops.clear();
180 q.coeffs.clear();
181 });
182 }
183}
184
185/// Whether the current thread defers its reconstruction writes.
186pub(super) fn active() -> bool {
187 ACTIVE.with(Cell::get)
188}
189
190/// Queues one write. Only meaningful while [`active`].
191pub(super) fn push(op: ReconOp) {
192 QUEUE.with(|q| q.borrow_mut().ops.push(op));
193}
194
195/// Geometry of one tile's wavefront, in plane samples.
196#[derive(Clone, Copy)]
197struct Grid {
198 /// Superblock width and height per plane.
199 ux: [usize; 3],
200 uy: [usize; 3],
201 /// First superblock row and column of the tile, in units.
202 row0: usize,
203 col0: usize,
204 /// Superblock columns of the tile.
205 cols: usize,
206 /// Superblock rows of the tile.
207 rows: usize,
208}
209
210/// One superblock's ops, addressed in tile-relative units.
211struct Job {
212 row: usize,
213 col: usize,
214 ops: Vec<ReconOp>,
215 /// The arena the ops' residuals live in.
216 coeffs: Vec<i32>,
217}
218
219/// State shared by the tile thread and every worker.
220struct Shared {
221 /// Superblock columns each row has finished.
222 done: Vec<usize>,
223 /// Per row, the bottom pixel row of its last finished superblock, per
224 /// plane, indexed by absolute column.
225 lines: Vec<[Vec<u16>; 3]>,
226 /// Set when a worker or the tile thread panicked: waiters give up.
227 abort: bool,
228}
229
230struct Link {
231 state: Mutex<Shared>,
232 moved: Condvar,
233}
234
235impl Link {
236 fn lock(&self) -> MutexGuard<'_, Shared> {
237 self.state.lock().unwrap_or_else(PoisonError::into_inner)
238 }
239
240 fn abort(&self) {
241 self.lock().abort = true;
242 self.moved.notify_all();
243 }
244}
245
246/// What a worker hands back when its job stream ends.
247struct Out {
248 planes: [PlaneBuf<'static>; 3],
249 corrupt: Option<&'static str>,
250 /// The first reference-picture failure a deferred prediction parked.
251 err: Option<ec_core::Error>,
252}
253
254/// Sets the abort flag when a worker unwinds, so its waiters do not hang.
255struct AbortOnPanic(Arc<Link>);
256
257impl Drop for AbortOnPanic {
258 fn drop(&mut self) {
259 if std::thread::panicking() {
260 self.0.abort();
261 }
262 }
263}
264
265struct Worker {
266 link: Arc<Link>,
267 grid: Grid,
268 planes: [PlaneBuf<'static>; 3],
269 fctx: FrameCtx,
270 /// The frame's reference pictures, waited for at the first deferred
271 /// prediction.
272 refs: Option<SharedRefs>,
273 /// The block predictions the last [`ReconOp::Pred`] built, per plane.
274 cur: [Vec<u16>; 3],
275}
276
277impl Worker {
278 fn run(mut self, jobs: mpsc::Receiver<Job>) -> Out {
279 let _abort = AbortOnPanic(Arc::clone(&self.link));
280 let shared = self.refs.take();
281 let pics: OnceLock<[Option<Arc<Picture>>; 8]> = OnceLock::new();
282 let wait = || -> Result<[Option<&Picture>; 8]> {
283 let Some(shared) = &shared else {
284 return Ok([None; 8]);
285 };
286 if pics.get().is_none() {
287 let _ = pics.set((shared.wait)()?);
288 }
289 let got = pics.get().expect("the pictures were just set");
290 Ok(std::array::from_fn(|i| got[i].as_deref()))
291 };
292 let refpix = RefPix::lazy(shared.as_ref().map_or([None; 8], |s| s.dims), &wait, None);
293 while let Ok(job) = jobs.recv() {
294 if !self.job(job, &refpix) {
295 break;
296 }
297 }
298 Out {
299 planes: self.planes,
300 corrupt: self.fctx.corrupt.get(),
301 err: refpix.take_err().err(),
302 }
303 }
304
305 /// Reconstructs one superblock. `false` when the wavefront aborted.
306 fn job(&mut self, job: Job, refpix: &RefPix<'_>) -> bool {
307 crate::fault::point("recon");
308 let Job { row, col, ops, coeffs } = job;
309 let mut scratch = Vec::new();
310 if row > 0 && !self.halo(row, col) {
311 return false;
312 }
313 let [y, u, v] = &mut self.planes;
314 for op in ops {
315 match op {
316 ReconOp::Pred(build) => build(y, u, v, refpix, &self.fctx, &mut self.cur),
317 ReconOp::Intra {
318 plane,
319 x,
320 oy,
321 bw,
322 bh,
323 rect,
324 mode,
325 angle_delta,
326 reach,
327 residual,
328 cfl,
329 filter_intra,
330 smooth_neighbor,
331 pred,
332 } => {
333 let res = residual.resolve(&coeffs, &mut scratch);
334 exec_intra(
335 y,
336 u,
337 v,
338 plane,
339 x,
340 oy,
341 bw,
342 bh,
343 rect,
344 mode,
345 angle_delta,
346 reach,
347 res,
348 cfl,
349 filter_intra,
350 smooth_neighbor,
351 pred,
352 &self.fctx,
353 );
354 }
355 ReconOp::Mc {
356 plane,
357 x,
358 oy,
359 stride,
360 w,
361 h,
362 prediction,
363 residual,
364 } => {
365 let res = residual.resolve(&coeffs, &mut scratch);
366 match prediction {
367 PredSrc::Owned(p) => {
368 exec_mc(y, u, v, plane, x, oy, stride, w, h, &p, res, &self.fctx);
369 }
370 PredSrc::Cur { plane: sp, off, src } => {
371 let block = &self.cur[sp][off..];
372 if src == stride {
373 exec_mc(y, u, v, plane, x, oy, stride, w, h, block, res, &self.fctx);
374 } else {
375 // A transform unit's residual is dense, so its window
376 // of the block prediction is taken out dense too.
377 let mut window = Vec::with_capacity(w * h);
378 for row in 0..h {
379 window.extend_from_slice(&block[row * src..][..w]);
380 }
381 exec_mc(y, u, v, plane, x, oy, stride, w, h, &window, res, &self.fctx);
382 }
383 }
384 }
385 }
386 }
387 }
388 self.publish(row, col);
389 true
390 }
391
392 /// Waits for row `row - 1` to clear column `col + 1`, then copies the
393 /// pixels above this superblock into the row above the local strip.
394 fn halo(&mut self, row: usize, col: usize) -> bool {
395 let g = self.grid;
396 let need = (col + 2).min(g.cols);
397 let mut s = self.link.lock();
398 while s.done[row - 1] < need && !s.abort {
399 s = self
400 .link
401 .moved
402 .wait(s)
403 .unwrap_or_else(PoisonError::into_inner);
404 }
405 if s.abort {
406 return false;
407 }
408 for p in 0..3 {
409 let w = self.planes[p].width;
410 if w == 0 {
411 continue;
412 }
413 let halo_row = (g.row0 + row) * g.uy[p] - 1;
414 let c0 = (g.col0 + col) * g.ux[p];
415 let from = c0.saturating_sub(1);
416 let to = (c0 + 2 * g.ux[p]).min(w);
417 self.planes[p].data.to_mut()[halo_row * w + from..halo_row * w + to]
418 .copy_from_slice(&s.lines[row - 1][p][from..to]);
419 }
420 true
421 }
422
423 /// Publishes this superblock's bottom pixel row, per plane, and wakes the
424 /// row below.
425 fn publish(&self, row: usize, col: usize) {
426 let g = self.grid;
427 let mut s = self.link.lock();
428 for p in 0..3 {
429 let w = self.planes[p].width;
430 if w == 0 {
431 continue;
432 }
433 let h = self.planes[p].height;
434 let last = ((g.row0 + row + 1) * g.uy[p]).min(h).saturating_sub(1);
435 let c0 = (g.col0 + col) * g.ux[p];
436 let end = (c0 + g.ux[p]).min(w);
437 s.lines[row][p][c0..end]
438 .copy_from_slice(&self.planes[p].data[last * w + c0..last * w + end]);
439 }
440 s.done[row] = col + 1;
441 drop(s);
442 self.link.moved.notify_all();
443 }
444}
445
446/// The tile thread's end of a running wavefront. Dropping it without
447/// [`WaveGuard::finish`] (a parse error or panic) aborts the workers.
448pub(super) struct WaveGuard {
449 link: Arc<Link>,
450 grid: Grid,
451 jobs: Vec<mpsc::Sender<Job>>,
452 /// The workers, on the thread's persistent pool: their thread-local
453 /// scratch outlives the tile. Dropping it waits for every worker.
454 batch: Option<Batch>,
455 outs: mpsc::Receiver<(usize, Out)>,
456}
457
458/// Starts the wavefront for one tile of `planes` (`[y, u, v]`), when the tile
459/// is worth splitting: more than one recon thread and at least two superblock
460/// rows. Otherwise reconstruction stays inline.
461pub(super) fn install(
462 fctx: &FrameCtx,
463 refpix: &RefPix<'_>,
464 planes: [&PlaneBuf<'static>; 3],
465 unit: usize,
466 span: (usize, usize, usize, usize),
467) {
468 let (row0, rows, col0, cols) = span;
469 let workers = crate::par::recon_threads().min(rows);
470 if workers < 2 || cols == 0 {
471 return;
472 }
473 let (ss_x, ss_y) = (super::ss_x(fctx), super::ss_y(fctx));
474 let grid = Grid {
475 ux: [unit, unit >> ss_x, unit >> ss_x],
476 uy: [unit, unit >> ss_y, unit >> ss_y],
477 row0,
478 col0,
479 cols,
480 rows,
481 };
482 let link = Arc::new(Link {
483 state: Mutex::new(Shared {
484 done: vec![0; rows],
485 lines: (0..rows)
486 .map(|_| [0, 1, 2].map(|p| vec![0u16; planes[p].width]))
487 .collect(),
488 abort: false,
489 }),
490 moved: Condvar::new(),
491 });
492 let mut jobs = Vec::with_capacity(workers);
493 let batch = Batch::new("ec-av1-recon");
494 let (out_tx, outs) = mpsc::channel();
495 for w in 0..workers {
496 let mut own = take_planes(planes);
497 for rr in (w..rows).step_by(workers) {
498 for p in 0..3 {
499 let src = planes[p];
500 let (top, end, x0, x1) = strip(&grid, p, row0 + rr, src);
501 for y in top..end {
502 own[p].data.to_mut()[y * src.width + x0..y * src.width + x1]
503 .copy_from_slice(&src.data[y * src.width + x0..y * src.width + x1]);
504 }
505 }
506 }
507 let worker = Worker {
508 link: Arc::clone(&link),
509 grid,
510 planes: own,
511 fctx: recon_ctx(fctx),
512 refs: refpix.shared(),
513 cur: Default::default(),
514 };
515 let (tx, rx) = mpsc::channel();
516 jobs.push(tx);
517 let out_tx = out_tx.clone();
518 batch.submit(move || {
519 let out = worker.run(rx);
520 let _ = out_tx.send((w, out));
521 });
522 }
523 CURRENT.with(|c| c.set(None));
524 ACTIVE.with(|a| a.set(true));
525 let guard = WaveGuard {
526 link,
527 grid,
528 jobs,
529 batch: Some(batch),
530 outs,
531 };
532 GUARD.with(|g| *g.borrow_mut() = Some(guard));
533}
534
535/// Cuts the queue: the superblock `(row, col)` (tile-relative) that was being
536/// parsed is handed to its worker, and `(row, col)` becomes the one in flight.
537pub(super) fn begin_sb(row: usize, col: usize) {
538 if !active() {
539 return;
540 }
541 if let Some((r, c)) = CURRENT.with(|cur| cur.replace(Some((row, col)))) {
542 send(r, c);
543 }
544}
545
546/// Sends the superblock `(row, col)` with every op queued since the last cut.
547fn send(row: usize, col: usize) {
548 let (ops, coeffs) = QUEUE.with(|q| {
549 let mut q = q.borrow_mut();
550 let next = Queue {
551 ops: Vec::with_capacity(q.ops.len()),
552 coeffs: Vec::with_capacity(q.coeffs.len()),
553 };
554 let Queue { ops, coeffs } = std::mem::replace(&mut *q, next);
555 (ops, coeffs)
556 });
557 GUARD.with(|g| {
558 if let Some(guard) = g.borrow().as_ref() {
559 // A dead worker has already aborted the wavefront; its error surfaces
560 // at `finish`.
561 let _ = guard.jobs[row % guard.jobs.len()].send(Job { row, col, ops, coeffs });
562 }
563 });
564}
565
566/// Ends the tile's wavefront (if one is running): sends the last superblock,
567/// joins the workers and copies their rows into `planes`. Reconstruction then
568/// stays inline for the rest of the tile. Called at the end of each tile, and
569/// before an inter-intra block, which reads its neighbours' reconstructed pixels
570/// while it is parsed.
571pub(super) fn finish_tile(
572 fctx: &FrameCtx,
573 refpix: &RefPix<'_>,
574 planes: [&mut PlaneBuf<'static>; 3],
575) {
576 if !active() {
577 return;
578 }
579 if let Some((row, col)) = CURRENT.with(|c| c.take()) {
580 send(row, col);
581 }
582 ACTIVE.with(|a| a.set(false));
583 let guard = GUARD.with(|g| g.borrow_mut().take());
584 if let Some(guard) = guard {
585 guard.finish(fctx, refpix, planes);
586 }
587}
588
589impl WaveGuard {
590 /// Joins the workers and copies their rows back into `planes`. A worker
591 /// panic is resumed here; its corrupt flag is carried into `fctx`.
592 pub(super) fn finish(
593 mut self,
594 fctx: &FrameCtx,
595 refpix: &RefPix<'_>,
596 mut planes: [&mut PlaneBuf<'static>; 3],
597 ) {
598 // Closing the queues lets every worker run out its jobs and return.
599 self.jobs.clear();
600 // Waits for the workers, and resumes the first one's panic.
601 drop(self.batch.take());
602 let mut outs: Vec<(usize, Out)> = self.outs.try_iter().collect();
603 outs.sort_by_key(|(w, _)| *w);
604 let nw = outs.len();
605 let g = self.grid;
606 for (w, out) in outs {
607 for rr in (w..g.rows).step_by(nw) {
608 for (p, dst) in planes.iter_mut().enumerate() {
609 let width = dst.width;
610 let (top, end, x0, x1) = strip(&g, p, g.row0 + rr, dst);
611 for y in top..end {
612 dst.data.to_mut()[y * width + x0..y * width + x1]
613 .copy_from_slice(&out.planes[p].data[y * width + x0..y * width + x1]);
614 }
615 }
616 }
617 if let Some(why) = out.corrupt {
618 fctx.flag_corrupt(why);
619 }
620 if let Some(e) = out.err {
621 refpix.park_err(e);
622 }
623 let [a, b, c] = out.planes;
624 give_planes([a.data.into_owned(), b.data.into_owned(), c.data.into_owned()]);
625 }
626 }
627}
628
629impl Drop for WaveGuard {
630 fn drop(&mut self) {
631 // Abort first, so no worker waits on a row that will never finish.
632 self.link.abort();
633 self.jobs.clear();
634 // Unwinding already: a worker's panic must not be raised a second time.
635 if let Some(batch) = self.batch.take() {
636 if std::thread::panicking() {
637 std::mem::forget(batch);
638 } else {
639 drop(batch);
640 }
641 }
642 }
643}
644
645/// The rows `[top, end)` and columns `[x0, x1)` of superblock row `unit_row`
646/// in plane `p`, clipped to the plane and to the tile's superblock columns.
647fn strip(g: &Grid, p: usize, unit_row: usize, plane: &PlaneBuf<'static>) -> (usize, usize, usize, usize) {
648 let top = unit_row * g.uy[p];
649 let end = ((unit_row + 1) * g.uy[p]).min(plane.height);
650 let x0 = (g.col0 * g.ux[p]).min(plane.width);
651 let x1 = ((g.col0 + g.cols) * g.ux[p]).min(plane.width);
652 if top >= end {
653 (0, 0, 0, 0)
654 } else {
655 (top, end, x0, x1)
656 }
657}
658
659/// Plane buffers for one worker: a recycled set if one of this size is
660/// pooled, else fresh zeroed ones. Recycled planes keep their old samples
661/// outside the rows and columns the worker is seeded with, and the decode
662/// never reads a sample it has not written or seeded.
663fn take_planes(planes: [&PlaneBuf<'static>; 3]) -> [PlaneBuf<'static>; 3] {
664 let lens = planes.map(|p| p.data.len());
665 let reuse = POOL.with(|pool| {
666 let mut pool = pool.borrow_mut();
667 let at = pool
668 .iter()
669 .position(|set| [0, 1, 2].iter().all(|&p| set[p].len() == lens[p]))?;
670 Some(pool.swap_remove(at))
671 });
672 let bufs = reuse.unwrap_or_else(|| lens.map(|n| vec![0u16; n]));
673 let [a, b, c] = bufs;
674 [
675 blank_like(planes[0], a),
676 blank_like(planes[1], b),
677 blank_like(planes[2], c),
678 ]
679}
680
681/// Returns a finished worker's plane set to the pool.
682fn give_planes(set: [Vec<u16>; 3]) {
683 POOL.with(|pool| {
684 let mut pool = pool.borrow_mut();
685 if pool.len() < POOL_SETS {
686 pool.push(set);
687 }
688 });
689}
690
691/// A plane with `src`'s geometry and tile bounds over `data`.
692fn blank_like(src: &PlaneBuf<'static>, data: Vec<u16>) -> PlaneBuf<'static> {
693 PlaneBuf {
694 data: Cow::Owned(data),
695 width: src.width,
696 height: src.height,
697 true_width: src.true_width,
698 true_height: src.true_height,
699 tile_x0: src.tile_x0,
700 tile_y0: src.tile_y0,
701 tile_x1: src.tile_x1,
702 tile_y1: src.tile_y1,
703 plane: src.plane,
704 }
705}
706
707/// A worker's own context: the frame's values the reconstruction reads.
708fn recon_ctx(fctx: &FrameCtx) -> FrameCtx {
709 let out = super::filter_ctx_copy(fctx);
710 super::set_enable_edge_filter(fctx.enable_edge_filter.with(Cell::get), &out);
711 out
712}