aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/encode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lvc/src/encode.rs')
-rw-r--r--lvc/src/encode.rs37
1 files changed, 20 insertions, 17 deletions
diff --git a/lvc/src/encode.rs b/lvc/src/encode.rs
index 4ec72cf..030e882 100644
--- a/lvc/src/encode.rs
+++ b/lvc/src/encode.rs
@@ -2,15 +2,18 @@ use crate::diff::{diff, pixel_diff};
use crate::split::split;
use crate::{Block, Frame, Pixel, Ref, View, P2};
+#[derive(Debug, Clone)]
pub struct EncodeConfig {
- pub threshold: u32,
+ pub threshold: f32,
pub max_block_size: usize,
- pub iters: usize,
+ pub attention_split: u32,
}
pub fn encode(last_frame: &Frame, frame: &Frame, view: View, config: &EncodeConfig) -> Block {
let view_area = view.size().area();
- if view_area > config.max_block_size {
+ if view_area > config.max_block_size
+ || (view_area > 64 && attention(frame, view) > config.attention_split)
+ {
let [av, bv] = split(view);
let (ab, bb) = rayon::join(
|| Box::new(encode(last_frame, frame, av, config)),
@@ -22,12 +25,13 @@ pub fn encode(last_frame: &Frame, frame: &Frame, view: View, config: &EncodeConf
let mut r = Ref::default();
let mut d = diff([last_frame, frame], view, r);
- let att = 1. - attention(frame, view) as f32 * 0.000001;
- let thres = (config.threshold as f32 * att.clamp(0.2, 1.0)) as u32;
+ // let att = 1. - attention(frame, view) as f32 * 0.000001;
+ // let thres = (config.threshold as f32 * att.clamp(0.2, 1.0)) as u32;
+ let thres = (config.threshold * view_area as f32) as u32;
let target_average = average_color(frame, view);
- for granularity in [8, 8, 4, 2, 1, 1, 1] {
+ for granularity in [2, 1, 2, 1, 2, 1, 2, 1] {
let (nd, nrp) = optimize_ref(last_frame, frame, view, r, granularity, target_average);
if nd < d {
r = nrp;
@@ -52,6 +56,7 @@ pub fn optimize_ref(
g: i32,
target_average: Pixel,
) -> (u32, Ref) {
+ let g2 = g * 2;
[
Some(r.apply(|r| r.pos_off += P2 { x: g, y: 0 })),
Some(r.apply(|r| r.pos_off += P2 { x: g, y: g })),
@@ -61,6 +66,14 @@ pub fn optimize_ref(
Some(r.apply(|r| r.pos_off += P2 { x: -g, y: -g })),
Some(r.apply(|r| r.pos_off += P2 { x: 0, y: -g })),
Some(r.apply(|r| r.pos_off += P2 { x: g, y: -g })),
+ Some(r.apply(|r| r.pos_off += P2 { x: g2, y: 0 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: g2, y: g2 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: 0, y: g2 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: -g2, y: g2 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: -g2, y: 0 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: -g2, y: -g2 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: 0, y: -g2 })),
+ Some(r.apply(|r| r.pos_off += P2 { x: g2, y: -g2 })),
{
let mut r = r;
let last_avr = average_color(last_frame, view);
@@ -72,20 +85,10 @@ pub fn optimize_ref(
None
}
},
- // Some(r.apply(|r| r.color_off.r += (g as i16) << 2)),
- // Some(r.apply(|r| r.color_off.r -= (g as i16) << 2)),
- // Some(r.apply(|r| r.color_off.g += (g as i16) << 2)),
- // Some(r.apply(|r| r.color_off.g -= (g as i16) << 2)),
- // Some(r.apply(|r| r.color_off.b += (g as i16) << 2)),
- // Some(r.apply(|r| r.color_off.b -= (g as i16) << 2)),
]
.into_iter()
.flatten()
- .map(|r| {
- let d = diff([last_frame, frame], view, r);
-
- (d, r)
- })
+ .map(|r| (diff([last_frame, frame], view, r), r))
.min_by_key(|e| e.0)
.unwrap()
}