File: test.rs

package info (click to toggle)
rust-color-thief 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
extern crate image;
extern crate color_thief;

use std::path;

use color_thief::{Color, ColorFormat};

fn find_color(t: image::ColorType) -> ColorFormat {
    match t {
        image::ColorType::Rgb8 => ColorFormat::Rgb,
        image::ColorType::Rgba8 => ColorFormat::Rgba,
        _ => unreachable!(),
    }
}

#[test]
fn image1() {
    let img = image::open(&path::Path::new("images/photo1.jpg")).unwrap();
    let color_type = find_color(img.color());
    let colors = color_thief::get_palette(&img.as_bytes(), color_type, 10, 10).unwrap();

    assert_eq!(colors[0], Color::new( 54,  37,  28)); //  55,  37,  29
    assert_eq!(colors[1], Color::new(215, 195, 134)); // 213, 193, 136
    assert_eq!(colors[2], Color::new(109, 204, 223)); // 110, 204, 223
    assert_eq!(colors[3], Color::new(127, 119,  58)); // 131, 122,  58
    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
    assert_eq!(colors[4], Color::new( 42, 125, 149)); //  43, 124, 148
    #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
    assert_eq!(colors[4], Color::new( 43, 125, 149)); //  43, 124, 148
    assert_eq!(colors[5], Color::new(134, 123, 107)); // 156, 175, 121
    assert_eq!(colors[6], Color::new(160, 178, 120)); // 131, 121, 110
    assert_eq!(colors[7], Color::new(167, 199, 221)); // 167, 198, 220
    assert_eq!(colors[8], Color::new(212,  80,   7)); // 213,  75,   8
}