Skip to content
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dba50f0
`fn read_pal_uv`: Make local `fn` non-`extern "C"`.
kkysen May 11, 2023
86ed229
`fn read_pal_uv`: Make `t` arg a ref.
kkysen May 11, 2023
b86e6e6
`fn read_pal_uv`: Make `b` arg a ref.
kkysen May 11, 2023
a1a596d
`fn read_pal_uv`: Make `ts` var a ref.
kkysen May 11, 2023
b347a5d
`fn read_pal_uv`: Make `f` var a ref.
kkysen May 11, 2023
234bb09
`fn read_pal_uv`: Make `pal` var a slice (and hoist `DEBUG_BLOCK_INFO…
kkysen May 11, 2023
e8e6473
`fn read_pal_uv`: Remove `_[0-9]+` var suffixes.
kkysen May 11, 2023
25c5422
`fn read_pal_uv`: Translate `printf`s as `print{,ln}!`s.
kkysen May 11, 2023
a42a4de
`fn read_pal_uv`: Use accessor methods for `.pal_sz`.
kkysen May 11, 2023
7dcf08b
`fn read_pal_uv`: Cleanup `as` casts.
kkysen May 11, 2023
cd2c76f
`fn read_pal_uv`: Replace `.wrapping*` calls with normal arithmetic.
kkysen May 11, 2023
344768c
`fn read_pal_uv`: Translate `for` loops.
kkysen May 11, 2023
2f866dc
`fn read_pal_uv`: Remove `fresh[0-9]+` vars.
kkysen May 11, 2023
913e041
`fn read_pal_uv`: Make `bits` var a `u32` to reduce casts.
kkysen May 11, 2023
a193033
`fn read_pal_uv`: Make parentheses around `&` clearer.
kkysen May 11, 2023
14564dd
`fn read_pal_uv`: Make `prev` a `u16` reduce casts.
kkysen May 11, 2023
8bbcb3d
`fn read_pal_uv`: Make `delta` an `i16`.
kkysen May 11, 2023
3845811
`fn read_pal_uv`: Slice `pal` to `b.pal_sz()[1]` len and use `pal.len…
kkysen May 11, 2023
879a89e
`fn read_pal_uv`: Replace indexing loops with iterators and slices.
kkysen May 11, 2023
507d194
`fn read_pal_uv`: Use `.fill_with` instead of a loop.
kkysen May 12, 2023
cbd2c01
`fn read_pal_uv`: Reverse the order of `pal[i]` and `prev` writes (or…
kkysen May 12, 2023
d332eaa
`fn read_pal_uv`: Add back comments and spacing/line breaks from C.
kkysen May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 36 additions & 53 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,71 +1735,54 @@ unsafe fn read_pal_plane(
}
}

unsafe extern "C" fn read_pal_uv(
t: *mut Dav1dTaskContext,
b: *mut Av1Block,
unsafe fn read_pal_uv(
t: &mut Dav1dTaskContext,
b: &mut Av1Block,
sz_ctx: u8,
bx4: usize,
by4: usize,
) {
read_pal_plane(&mut *t, &mut *b, true, sz_ctx, bx4, by4);
let ts: *mut Dav1dTileState = (*t).ts;
let f: *const Dav1dFrameContext = (*t).f;
let pal: *mut uint16_t = if (*t).frame_thread.pass != 0 {
((*((*f).frame_thread.pal).offset(
((((*t).by >> 1) + ((*t).bx & 1)) as isize * ((*f).b4_stride >> 1)
+ (((*t).bx >> 1) + ((*t).by & 1)) as isize) as isize,
))[2])
.as_mut_ptr()
read_pal_plane(t, b, true, sz_ctx, bx4, by4);

// V pal coding
let ts = &mut *t.ts;
let f = &*t.f;

// Hoisted so the `&` borrow of `t`
// doesn't conflict with `pal`'s `&mut` borrow of `t`.
let dbg = DEBUG_BLOCK_INFO(&*f, &*t);

let pal = if t.frame_thread.pass != 0 {
&mut (*(f.frame_thread.pal).offset(
((t.by >> 1) + (t.bx & 1)) as isize * (f.b4_stride >> 1)
+ ((t.bx >> 1) + (t.by & 1)) as isize,
))[2]
} else {
((*t).scratch.c2rust_unnamed_0.pal[2]).as_mut_ptr()
&mut t.scratch.c2rust_unnamed_0.pal[2]
};
if dav1d_msac_decode_bool_equi(&mut (*ts).msac) {
let bits = (((*f).cur.p.bpc - 4) as libc::c_uint).wrapping_add(dav1d_msac_decode_bools(
&mut (*ts).msac,
2 as libc::c_int as libc::c_uint,
)) as libc::c_int;
let ref mut fresh19 = *pal.offset(0);
*fresh19 =
dav1d_msac_decode_bools(&mut (*ts).msac, (*f).cur.p.bpc as libc::c_uint) as uint16_t;
let mut prev = *fresh19 as libc::c_int;
let max = ((1 as libc::c_int) << (*f).cur.p.bpc) - 1;
let mut i = 1;
while i < (*b).c2rust_unnamed.c2rust_unnamed.pal_sz[1] as libc::c_int {
let mut delta =
dav1d_msac_decode_bools(&mut (*ts).msac, bits as libc::c_uint) as libc::c_int;
if delta != 0 && dav1d_msac_decode_bool_equi(&mut (*ts).msac) {
let pal = &mut pal[..b.pal_sz()[1] as usize];
if dav1d_msac_decode_bool_equi(&mut ts.msac) {
let bits = f.cur.p.bpc as u32 + dav1d_msac_decode_bools(&mut ts.msac, 2) - 4;
let mut prev = dav1d_msac_decode_bools(&mut ts.msac, f.cur.p.bpc as libc::c_uint) as u16;
pal[0] = prev;
let max = (1 << f.cur.p.bpc) - 1;
for pal in &mut pal[1..] {
let mut delta = dav1d_msac_decode_bools(&mut ts.msac, bits) as i16;
if delta != 0 && dav1d_msac_decode_bool_equi(&mut ts.msac) {
delta = -delta;
}
let ref mut fresh20 = *pal.offset(i as isize);
*fresh20 = (prev + delta & max) as uint16_t;
prev = *fresh20 as libc::c_int;
i += 1;
prev = ((prev as i16 + delta) as u16) & max;
*pal = prev;
}
} else {
let mut i_0 = 0;
while i_0 < (*b).c2rust_unnamed.c2rust_unnamed.pal_sz[1] as libc::c_int {
*pal.offset(i_0 as isize) =
dav1d_msac_decode_bools(&mut (*ts).msac, (*f).cur.p.bpc as libc::c_uint)
as uint16_t;
i_0 += 1;
}
pal.fill_with(|| dav1d_msac_decode_bools(&mut ts.msac, f.cur.p.bpc as libc::c_uint) as u16);
}
if DEBUG_BLOCK_INFO(&*f, &*t) {
printf(
b"Post-pal[pl=2]: r=%d \0" as *const u8 as *const libc::c_char,
(*ts).msac.rng,
);
let mut n = 0;
while n < (*b).c2rust_unnamed.c2rust_unnamed.pal_sz[1] as libc::c_int {
printf(
b"%c%02x\0" as *const u8 as *const libc::c_char,
if n != 0 { ' ' as i32 } else { '[' as i32 },
*pal.offset(n as isize) as libc::c_int,
);
n += 1;
if dbg {
print!("Post-pal[pl=2]: r={} ", ts.msac.rng);
for (n, pal) in pal.iter().enumerate() {
print!("{}{:02x}", if n != 0 { ' ' } else { '[' }, pal);
}
printf(b"]\n\0" as *const u8 as *const libc::c_char);
println!("]");
}
}

Expand Down