aboutsummaryrefslogtreecommitdiff
path: root/evc/src/codec/encode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'evc/src/codec/encode.rs')
-rw-r--r--evc/src/codec/encode.rs41
1 files changed, 35 insertions, 6 deletions
diff --git a/evc/src/codec/encode.rs b/evc/src/codec/encode.rs
index 7322fea..13df17d 100644
--- a/evc/src/codec/encode.rs
+++ b/evc/src/codec/encode.rs
@@ -1,4 +1,6 @@
-use crate::{block::Block, frame::Frame, vec2::Vec2, view::View};
+use crate::{
+ block::Block, frame::Frame, pixel::Pixel, threading::both_par, vec2::Vec2, view::View,
+};
#[derive(Debug, Clone)]
pub struct EncodeConfig {
@@ -6,9 +8,13 @@ pub struct EncodeConfig {
pub ref_thres: f64,
pub max_diff_size: isize,
pub min_block_size: isize,
+ // pub importance_k: f64,
+ // pub importance_scale: f64,
}
pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfig) -> Block {
+ // let importance = importance(&view);
+
let (diff, translation) = if view.area() > config.max_diff_size {
(f64::INFINITY, Vec2::ZERO)
} else if config.translate {
@@ -29,16 +35,23 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi
} else {
(View::diff(&view, &prev) / view.area() as f64, Vec2::ZERO)
};
- if diff < config.ref_thres {
+ // config.importance_k)
+ // / (config.importance_k + importance * config.importance_scale)
+ if diff < (config.ref_thres) {
Block::Reference { translation }
} else {
if view.size.x < config.min_block_size {
Block::Literal(view.pixels())
} else {
- let [av, bv] = view.split();
- let [ap, bp] = prev.split();
- let a = encode_block(av, ap, config);
- let b = encode_block(bv, bp, config);
+ let [av, bv] =
+ unsafe { std::mem::transmute::<_, [View<&'static Frame>; 2]>(view.split()) };
+ let [ap, bp] =
+ unsafe { std::mem::transmute::<_, [View<&'static Frame>; 2]>(prev.split()) };
+ let config = unsafe { std::mem::transmute::<_, &'static EncodeConfig>(config) };
+ let (a, b) = both_par(
+ || encode_block(av, ap, config),
+ || encode_block(bv, bp, config),
+ );
if a.is_literal() && b.is_literal() {
Block::Literal(view.pixels())
} else {
@@ -47,3 +60,19 @@ pub fn encode_block(view: View<&Frame>, prev: View<&Frame>, config: &EncodeConfi
}
}
}
+
+pub fn importance(view: &View<&Frame>) -> f64 {
+ let mut acc = 0;
+ for x in 0..view.size.x {
+ for y in 0..view.size.y {
+ let p = Vec2 { x, y };
+ if x > 0 {
+ acc += Pixel::distance(view[p], view[p + Vec2::LEFT]);
+ }
+ if y > 0 {
+ acc += Pixel::distance(view[p], view[p + Vec2::UP]);
+ }
+ }
+ }
+ (acc / view.area() as usize) as f64
+}