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> {
101 })101 })
102 }102 }
103 103
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+
104 /// Number of 16×16 macroblock columns/rows covering `width × height`109 /// Number of 16×16 macroblock columns/rows covering `width × height`
105 /// pixels (the encoded frame is padded up to whole macroblocks).110 /// pixels (the encoded frame is padded up to whole macroblocks).
106 pub fn mb_geometry(width: u16, height: u16) -> (usize, usize) {111 pub fn mb_geometry(width: u16, height: u16) -> (usize, usize) {
crates/ec-vp8/src/intra.rsmodified+3 -9
@@ -30,6 +30,7 @@
30 //! row); on the top frame row they are 127. [`predict4`] only consumes30 //! row); on the top frame row they are 127. [`predict4`] only consumes
31 //! `A[0..8]` as given.31 //! `A[0..8]` as given.
32 32
33+use crate::frame::clamp255;
33 34
34 /// Weighted average of three adjacent pixels centered at `y`35 /// Weighted average of three adjacent pixels centered at `y`
35 /// (RFC 6386 Section 12.3 `avg3`: `(x + 2y + z + 2) >> 2`; libvpx `AVG3`).36 /// (RFC 6386 Section 12.3 `avg3`: `(x + 2y + z + 2) >> 2`; libvpx `AVG3`).
@@ -48,13 +49,6 @@ fn avg2(x: u8, y: u8) -> u8 {
48 ((u32::from(x) + u32::from(y) + 1) >> 1) as u849 ((u32::from(x) + u32::from(y) + 1) >> 1) as u8
49 }50 }
50 51
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-
58 /// Shared DC/V/H/TM core for the 16x16 luma and 8x8 chroma blocks52 /// Shared DC/V/H/TM core for the 16x16 luma and 8x8 chroma blocks
59 /// (RFC 6386 Section 12.2 semantics; Section 12.3 states 16x16 luma is53 /// (RFC 6386 Section 12.2 semantics; Section 12.3 states 16x16 luma is
60 /// "essentially identical" with 16-pixel edges).54 /// "essentially identical" with 16-pixel edges).
@@ -106,7 +100,7 @@ fn predict_block<const N: usize>(
106 3 => {100 3 => {
107 for (row, &l) in out.as_chunks_mut::<N>().0.iter_mut().zip(left.iter()) {101 for (row, &l) in out.as_chunks_mut::<N>().0.iter_mut().zip(left.iter()) {
108 for (o, &a) in row.iter_mut().zip(above.iter()) {102 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;
110 }104 }
111 }105 }
112 }106 }
@@ -215,7 +209,7 @@ pub fn predict4(
215 for r in 0..4 {209 for r in 0..4 {
216 for c in 0..4 {210 for c in 0..4 {
217 b[r * 4 + c] =211 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;
219 }213 }
220 }214 }
221 }215 }
crates/ec-vp8/src/mc.rsmodified+1 -5
@@ -23,6 +23,7 @@
23 //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc638623 //! [RFC 6386]: https://www.rfc-editor.org/rfc/rfc6386
24 use archmage::SimdToken;24 use archmage::SimdToken;
25 use multiversion::target::match_target;25 use multiversion::target::match_target;
26+use crate::frame::clamp255;
26 use crate::modes;27 use crate::modes;
27 28
28 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.29 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.
@@ -55,11 +56,6 @@ const BILINEAR_FILTERS: [[i32; 2]; 8] = [
55 [16, 112],56 [16, 112],
56 ];57 ];
57 58
58-#[inline]
59-fn clamp255(v: i32) -> i32 {
60- v.clamp(0, 255)
61-}
62-
63 /// Extends the visible `vis_w` x `vis_h` region of `plane` into the `border`59 /// Extends the visible `vis_w` x `vis_h` region of `plane` into the `border`
64 /// ring on all four sides by edge replication: every out-of-image sample60 /// ring on all four sides by edge replication: every out-of-image sample
65 /// becomes the nearest in-image sample.61 /// becomes the nearest in-image sample.