Skip to content

Commit

Permalink
more dither tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
exoticorn committed Jul 23, 2016
1 parent 26f27ca commit 45fc0a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/colormap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ impl ColorMap {
neighbor
}

pub fn closest_neighbor(&self, index: usize, target: FloatColor) -> usize {
let color = self.colors[index];
let to_target = target - color;
let mut neighbor = index;
let mut best = ::std::f64::MAX;
for &i in &self.neighbors[index] {
let c = self.colors[i];
let d = (c - target).abs();
if d > 0.0 && d < best && (c - color).dot(&to_target) >= 0.0 {
neighbor = i;
best = d;
}
}
neighbor
}

pub fn float_color(&self, index: usize) -> FloatColor {
self.colors[index]
}
Expand Down
5 changes: 3 additions & 2 deletions src/remapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ impl Remapper for RemapperOrdered2 {
}
let dir = diff * (1.0 / d);
let j = self.map.neighbor_in_dir(i, dir);
// let j = self.map.closest_neighbor(i, color);
let c2 = self.map.float_color(j);
let d2 = (c2 - color).abs();
let f = d / (d + d2);
let span = c2 - c;
let f = (color - c).dot(&span) / span.dot(&span);
let offset = if f > 0.375 {
2
} else if f > 0.125 {
Expand Down

0 comments on commit 45fc0a0

Please sign in to comment.