remove image crate dependency from gam Bitmap

This commit is contained in:
nworbnhoj 2022-06-04 10:23:13 +10:00
parent 66b0665d08
commit 767461fa16
2 changed files with 4 additions and 8 deletions

View file

@ -36,8 +36,6 @@ qrcode = { version = "0.12", default-features = false }
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28 #dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true } dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
# note: image version is matched to version used by dither
image = { version = "0.23", default-features = false, features = ["png"], optional = true }
[target.'cfg(not(any(windows,unix)))'.dependencies] [target.'cfg(not(any(windows,unix)))'.dependencies]
utralib = {path = "../../utralib"} utralib = {path = "../../utralib"}
@ -45,6 +43,6 @@ utralib = {path = "../../utralib"}
[features] [features]
debugprint = [] debugprint = []
tts = [] tts = []
ditherpunk = ["dither", "image"] ditherpunk = ["dither"]
# default = ["debugprint"] # "debugprint" # default = ["debugprint"] # "debugprint"
default = [] default = []

View file

@ -236,11 +236,9 @@ impl From<[Option<Tile>; 6]> for Bitmap {
} }
} }
impl From<&image::RgbImage> for Bitmap { impl From<Img<RGB<u8>>> for Bitmap {
fn from(image: &image::RgbImage) -> Self { fn from(image: Img<RGB<u8>>) -> Self {
let pixels: Vec<RGB<u8>> = image.pixels().map(|p| RGB::from(p.0)).collect(); let img = image.convert_with(|rgb: RGB<u8>| rgb.convert_with(f64::from));
let img = Img::new(pixels, image.width()).expect("failed to create dither Img");
let img = img.convert_with(|rgb: RGB<u8>| rgb.convert_with(f64::from));
let bit_depth = 1; let bit_depth = 1;
let quantize = dither::create_quantize_n_bits_func(bit_depth).unwrap(); let quantize = dither::create_quantize_n_bits_func(bit_depth).unwrap();
let bw_img = img.convert_with(|rgb| rgb.to_chroma_corrected_black_and_white()); let bw_img = img.convert_with(|rgb| rgb.to_chroma_corrected_black_and_white());