Skip to content

Commit

Permalink
Rav1dTileState::lflvl: Make into enum
Browse files Browse the repository at this point in the history
Rename `TileStateDq` to `TileStateRef` and use it for both fields, since both have the same structure of either referencing a field in the frame data or referencing the local tile state field.
  • Loading branch information
randomPoison committed Mar 21, 2024
1 parent d2c6009 commit 7e4c714
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
22 changes: 15 additions & 7 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use crate::src::internal::Rav1dTaskContext;
use crate::src::internal::Rav1dTaskContext_scratch_pal;
use crate::src::internal::Rav1dTileState;
use crate::src::internal::ScalableMotionParams;
use crate::src::internal::TileStateDq;
use crate::src::internal::TileStateRef;
use crate::src::intra_edge::EdgeFlags;
use crate::src::intra_edge::EdgeIndex;
use crate::src::intra_edge::IntraEdges;
Expand Down Expand Up @@ -1867,19 +1867,19 @@ unsafe fn decode_b_inner(
}
if ts.last_qidx == frame_hdr.quant.yac {
// assign frame-wide q values to this sb
ts.dq = TileStateDq::Frame;
ts.dq = TileStateRef::Frame;
} else if ts.last_qidx != prev_qidx {
// find sb-specific quant parameters
init_quant_tables(seq_hdr, frame_hdr, ts.last_qidx, &mut ts.dqmem);
ts.dq = TileStateDq::Local;
ts.dq = TileStateRef::Local;
}
if ts.last_delta_lf == [0, 0, 0, 0] {
// assign frame-wide lf values to this sb
ts.lflvl = f.lf.lvl.as_ptr();
ts.lflvl = TileStateRef::Frame;
} else if ts.last_delta_lf != prev_delta_lf {
// find sb-specific lf lvl parameters
rav1d_calc_lf_values(&mut ts.lflvlmem, frame_hdr, &ts.last_delta_lf);
ts.lflvl = ts.lflvlmem.as_ptr();
ts.lflvl = TileStateRef::Local;
}
}

Expand Down Expand Up @@ -2154,11 +2154,15 @@ unsafe fn decode_b_inner(
}

if f.frame_hdr().loopfilter.level_y != [0, 0] {
let lflvl = match ts.lflvl {
TileStateRef::Frame => &f.lf.lvl,
TileStateRef::Local => &ts.lflvlmem,
};
rav1d_create_lf_mask_intra(
&mut *t.lf_mask,
&mut f.lf.level,
f.b4_stride,
&*ts.lflvl.offset(b.seg_id as isize),
&lflvl[b.seg_id as usize],
t.bx,
t.by,
f.w4,
Expand Down Expand Up @@ -3152,6 +3156,10 @@ unsafe fn decode_b_inner(
ytx = TX_4X4 as RectTxfmSize;
uvtx = TX_4X4 as RectTxfmSize;
}
let lflvl = match ts.lflvl {
TileStateRef::Frame => &f.lf.lvl,
TileStateRef::Local => &ts.lflvlmem,
};
rav1d_create_lf_mask_inter(
&mut *t.lf_mask,
&mut f.lf.level,
Expand All @@ -3161,7 +3169,7 @@ unsafe fn decode_b_inner(
// even though the whole array is not passed.
// Dereferencing this in Rust is UB, so instead
// we pass the indices as args, which are then applied at the use sites.
&*ts.lflvl.offset(b.seg_id as isize),
&lflvl[b.seg_id as usize],
(b.r#ref()[0] + 1) as usize,
is_globalmv == 0,
t.bx,
Expand Down
6 changes: 3 additions & 3 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,17 +644,17 @@ pub struct Rav1dTileState {
pub lowest_pixel: *mut [[c_int; 2]; 7],

pub dqmem: [[[u16; 2]; 3]; RAV1D_MAX_SEGMENTS as usize], /* [RAV1D_MAX_SEGMENTS][3 plane][2 dc/ac] */
pub dq: TileStateDq,
pub dq: TileStateRef,
pub last_qidx: c_int,
pub last_delta_lf: [i8; 4],
pub lflvlmem: [[[[u8; 2]; 8]; 4]; 8], /* [8 seg_id][4 dir][8 ref][2 is_gmv] */
pub lflvl: *const [[[u8; 2]; 8]; 4],
pub lflvl: TileStateRef,

pub lr_ref: [Av1RestorationUnit; 3],
}

#[derive(Clone, Copy)]
pub enum TileStateDq {
pub enum TileStateRef {
Frame,
Local,
}
Expand Down
6 changes: 3 additions & 3 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::src::internal::Rav1dDSPContext;
use crate::src::internal::Rav1dFrameData;
use crate::src::internal::Rav1dTaskContext;
use crate::src::internal::Rav1dTileState;
use crate::src::internal::TileStateDq;
use crate::src::internal::TileStateRef;
use crate::src::intra_edge::EdgeFlags;
use crate::src::ipred_prepare::rav1d_prepare_intra_edges;
use crate::src::ipred_prepare::sm_flag;
Expand Down Expand Up @@ -1380,8 +1380,8 @@ unsafe fn decode_coefs<BD: BitDepth>(
rc = 0 as c_int as c_uint;
}
let dq = match (*ts).dq {
TileStateDq::Frame => &f.dq,
TileStateDq::Local => &(*ts).dqmem,
TileStateRef::Frame => &f.dq,
TileStateRef::Local => &(*ts).dqmem,
};
let dq_tbl = &dq[b.seg_id as usize][plane as usize];
let qm_tbl: *const u8 = if (*txtp as c_uint) < IDTX as c_int as c_uint {
Expand Down

0 comments on commit 7e4c714

Please sign in to comment.