use ruisa::*;

#[test]
fn decode_grayscale() {
    let pixmap = Canvas::from_image_file("tests/images/pngs/grayscale.png").unwrap();
    assert_eq!(pixmap.pixel(10, 10).unwrap(), ColorU8::from_rgba(255, 255, 255, 255).premultiply());
    assert_eq!(pixmap.pixel(50, 50).unwrap(), ColorU8::from_rgba(0, 0, 0, 255).premultiply());
}

#[test]
fn decode_grayscale_alpha() {
    let pixmap = Canvas::from_image_file("tests/images/pngs/grayscale-alpha.png").unwrap();
    assert_eq!(pixmap.pixel(10, 10).unwrap(), ColorU8::from_rgba(0, 0, 0, 0).premultiply());
    assert_eq!(pixmap.pixel(50, 50).unwrap(), ColorU8::from_rgba(0, 0, 0, 255).premultiply());
}

#[test]
fn decode_rgb() {
    let pixmap = Canvas::from_image_file("tests/images/pngs/rgb.png").unwrap();
    assert_eq!(pixmap.pixel(10, 10).unwrap(), ColorU8::from_rgba(255, 255, 255, 255).premultiply());
    assert_eq!(pixmap.pixel(50, 50).unwrap(), ColorU8::from_rgba(36, 191, 49, 255).premultiply());
}

fn decode_rgba() {
    let pixmap = Canvas::from_image_file("tests/images/pngs/rgba.png").unwrap();
    pixmap.dump();
    assert_eq!(pixmap.pixel(10, 10).unwrap(), ColorU8::from_rgba(0, 0, 0, 0).premultiply());
    assert_eq!(pixmap.pixel(25, 25).unwrap(), ColorU8::from_rgba(161, 227, 165, 108).premultiply());
    assert_eq!(pixmap.pixel(50, 50).unwrap(), ColorU8::from_rgba(33, 190, 47, 252).premultiply());
}

// TODO: test encoding, somehow
