Commit cb1b26dc authored by Shreevari SP's avatar Shreevari SP

Added an activity mask (indexing changes completed)

parent bb8d5690
......@@ -855,6 +855,8 @@ impl<T: Pixel> ContextInner<T> {
fi.set_quantizers(&qps);
let mut fs = FrameState::new_with_frame(fi, frame.clone());
fs.compute_activity_mask();
// TODO: Trial encoding for first frame of each type.
let data = encode_frame(fi, &mut fs);
self.maybe_prev_log_base_q = Some(qps.log_base_q);
......
......@@ -299,6 +299,7 @@ pub struct FrameState<T: Pixel> {
pub input: Arc<Frame<T>>,
pub input_hres: Plane<T>, // half-resolution version of input luma
pub input_qres: Plane<T>, // quarter-resolution version of input luma
pub activity_mask: Plane<T>,
pub rec: Frame<T>,
pub cdfs: CDFContext,
pub context_update_tile_id: usize, // tile id used for the CDFontext
......@@ -329,6 +330,7 @@ impl<T: Pixel> FrameState<T> {
input: frame,
input_hres: Plane::new(luma_width / 2, luma_height / 2, 1, 1, luma_padding_x / 2, luma_padding_y / 2),
input_qres: Plane::new(luma_width / 4, luma_height / 4, 2, 2, luma_padding_x / 4, luma_padding_y / 4),
activity_mask: Plane::new(luma_width / 8, luma_height / 8, 3, 3, luma_padding_x / 8, luma_padding_y / 8),
rec: Frame::new(luma_width, luma_height, fi.sequence.chroma_sampling),
cdfs: CDFContext::new(0),
context_update_tile_id: 0,
......@@ -347,6 +349,56 @@ impl<T: Pixel> FrameState<T> {
}
}
pub fn compute_activity_mask(&mut self) {
//activity mask is computed only for luma plane
let luma_plane = &self.input.planes[0];
let PlaneConfig { width, height, .. } = luma_plane.cfg;
let luma_stride = luma_plane.cfg.stride;
let luma = &luma_plane.data;
let PlaneConfig { xdec, ydec, .. } = self.activity_mask.cfg;
assert!(xdec==3);
assert!(ydec==3);
let mut act_mask = vec![0 as u32; (width >> xdec) * (height >> ydec) ];
for r in 0..(height >> ydec) {
for c in 0..(width >> xdec) {
let base = luma_plane.index(c << xdec, r << ydec);
//Calculate mean
let mut mean: u32 = 0;
for x_offset in 0..(1 << xdec) {
for y_offset in 0..(1 << ydec) {
let offset = x_offset + y_offset * luma_stride;
let temp: u32 = luma[base + offset].into();
mean += temp;
}
}
mean >>= xdec + ydec;
//Calculate variance
let mut var: i32 = 0;
for x_offset in 0..(1 << xdec) {
for y_offset in 0..(1 << ydec) {
let offset = x_offset + y_offset * luma_stride;
let temp: i32 = luma[base + offset].into();
var += (temp - mean as i32).pow(2);
}
}
var >>= xdec + ydec;
act_mask[r * (width >> xdec) + c] = var as u32;
}
}
let max = act_mask.iter().max().unwrap();
let activity_mask: &mut [T] = &mut *self.activity_mask.data;
activity_mask
.iter_mut()
.zip(act_mask.iter())
.map(|(var1, var2)| *var1 = T::cast_from(if *max!=0 {(256 * var2 / max)} else {0} as u8) )
.for_each(|_| {});
}
#[inline(always)]
pub fn as_tile_state_mut(&mut self) -> TileStateMut<'_, T> {
let PlaneConfig { width, height, .. } = self.rec.planes[0].cfg;
......
......@@ -298,7 +298,7 @@ impl<T: Pixel> Plane<T> {
}
#[inline]
fn index(&self, x: usize, y: usize) -> usize {
pub fn index(&self, x: usize, y: usize) -> usize {
(y + self.cfg.yorigin) * self.cfg.stride + (x + self.cfg.xorigin)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment