2024-04-14 16:55:47 +00:00
|
|
|
use lofty::picture::PictureInformation;
|
2021-11-22 22:14:02 +00:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-22 22:14:02 +00:00
|
|
|
fn read_png() {
|
|
|
|
// 640x628
|
|
|
|
let mut f = File::open("tests/picture/assets/png_640x628.png").unwrap();
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
f.read_to_end(&mut buf).unwrap();
|
|
|
|
|
2022-07-03 21:46:18 +00:00
|
|
|
let information = PictureInformation::from_png(&buf).unwrap();
|
2021-11-22 22:14:02 +00:00
|
|
|
|
|
|
|
assert_eq!(information.width, 640);
|
|
|
|
assert_eq!(information.height, 628);
|
2021-11-24 01:08:11 +00:00
|
|
|
assert_eq!(information.color_depth, 32);
|
2021-11-22 22:14:02 +00:00
|
|
|
|
|
|
|
// No PLTE chunk
|
|
|
|
assert_eq!(information.num_colors, 0);
|
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-22 22:14:02 +00:00
|
|
|
fn read_png_plte() {
|
|
|
|
// PNG image with a PLTE chunk (indexed color)
|
|
|
|
let mut f = File::open("tests/picture/assets/png_640x628_plte.png").unwrap();
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
f.read_to_end(&mut buf).unwrap();
|
|
|
|
|
2022-07-03 21:46:18 +00:00
|
|
|
let information = PictureInformation::from_png(&buf).unwrap();
|
2021-11-22 22:14:02 +00:00
|
|
|
|
|
|
|
assert_eq!(information.width, 640);
|
|
|
|
assert_eq!(information.height, 628);
|
|
|
|
assert_eq!(information.color_depth, 8);
|
|
|
|
|
|
|
|
// This field is actually filled since we
|
|
|
|
// have a PLTE chunk
|
|
|
|
assert_eq!(information.num_colors, 118);
|
|
|
|
}
|
|
|
|
|
2024-08-31 17:38:30 +00:00
|
|
|
#[test_log::test]
|
2021-11-22 22:14:02 +00:00
|
|
|
fn read_jpeg() {
|
|
|
|
let mut f = File::open("tests/picture/assets/jpeg_640x628.jpg").unwrap();
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
f.read_to_end(&mut buf).unwrap();
|
|
|
|
|
2022-07-03 21:46:18 +00:00
|
|
|
let information = PictureInformation::from_jpeg(&buf).unwrap();
|
2021-11-22 22:14:02 +00:00
|
|
|
|
|
|
|
assert_eq!(information.width, 640);
|
|
|
|
assert_eq!(information.height, 628);
|
|
|
|
assert_eq!(information.color_depth, 24);
|
|
|
|
|
|
|
|
// Always 0, not applicable for JPEG
|
|
|
|
assert_eq!(information.num_colors, 0);
|
|
|
|
}
|