forge
Explore
Log in

Don't you dare go Hollow

S7: vp8 one clamp255 (frame.rs) shared by intra and mc; same clamp, u8 casts at intra call sites

Browse files at this commit

eb7a1988e87bc11c50b9fe5a91cd5c2c4056a687Ahmet Kaan GümüşParent: 91fc6e6
crates/ec-vp8/src/frame.rsmodified+5 -0
@@ -101,6 +101,11 @@ pub fn parse_keyframe_dims(data: &[u8]) -> Result<KeyFrameDims> {
101101 })
102102 }
103103
104+/// Clamp an integer sample into the 8-bit pixel range (RFC 6386 `clamp255`).
105+pub(crate) fn clamp255(v: i32) -> i32 {
106+ v.clamp(0, 255)
107+}
108+
104109 /// Number of 16×16 macroblock columns/rows covering `width × height`
105110 /// pixels (the encoded frame is padded up to whole macroblocks).
106111 pub fn mb_geometry(width: u16, height: u16) -> (usize, usize) {
crates/ec-vp8/src/intra.rsmodified+3 -9
@@ -30,6 +30,7 @@
3030 //! row); on the top frame row they are 127. [`predict4`] only consumes
3131 //! `A[0..8]` as given.
3232
33+use crate::frame::clamp255;
3334
3435 /// Weighted average of three adjacent pixels centered at `y`
3536 /// (RFC 6386 Section 12.3 `avg3`: `(x + 2y + z + 2) >> 2`; libvpx `AVG3`).
@@ -48,13 +49,6 @@ fn avg2(x: u8, y: u8) -> u8 {
4849 ((u32::from(x) + u32::from(y) + 1) >> 1) as u8
4950 }
5051
51-/// `clamp255(v)`: clamp an integer pixel difference into the valid `u8` range
52-/// (RFC 6386 Section 12.2 `TMpred` / Section 12.3 `B_TM_PRED`).
53-#[inline]
54-fn clamp255(v: i32) -> u8 {
55- v.clamp(0, 255) as u8
56-}
57-
5852 /// Shared DC/V/H/TM core for the 16x16 luma and 8x8 chroma blocks
5953 /// (RFC 6386 Section 12.2 semantics; Section 12.3 states 16x16 luma is
6054 /// "essentially identical" with 16-pixel edges).
@@ -106,7 +100,7 @@ fn predict_block<const N: usize>(
106100 3 => {
107101 for (row, &l) in out.as_chunks_mut::<N>().0.iter_mut().zip(left.iter()) {
108102 for (o, &a) in row.iter_mut().zip(above.iter()) {
109- *o = clamp255(i32::from(l) + i32::from(a) - i32::from(above_left));
103+ *o = clamp255(i32::from(l) + i32::from(a) - i32::from(above_left)) as u8;
110104 }
111105 }
112106 }
@@ -215,7 +209,7 @@ pub fn predict4(
215209 for r in 0..4 {
216210 for c in 0..4 {
217211 b[r * 4 + c] =
218- clamp255(i32::from(left[r]) + i32::from(above[c]) - i32::from(above_left));
212+ clamp255(i32::from(left[r]) + i32::from(above[c]) - i32::from(above_left)) as u8;
219213 }
220214 }
221215 }
crates/ec-vp8/src/mc.rsmodified+1 -5
@@ -23,6 +23,7 @@
2323 //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc6386
2424 use archmage::SimdToken;
2525 use multiversion::target::match_target;
26+use crate::frame::clamp255;
2627 use crate::modes;
2728
2829 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.
@@ -55,11 +56,6 @@ const BILINEAR_FILTERS: [[i32; 2]; 8] = [
5556 [16, 112],
5657 ];
5758
58-#[inline]
59-fn clamp255(v: i32) -> i32 {
60- v.clamp(0, 255)
61-}
62-
6359 /// Extends the visible `vis_w` x `vis_h` region of `plane` into the `border`
6460 /// ring on all four sides by edge replication: every out-of-image sample
6561 /// becomes the nearest in-image sample.