mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 14:03:42 +02:00
Use custom version of image-rs (#210)
This is done to avoid a panic in the current version image rs
This commit is contained in:
Generated
+1
-2
@@ -1340,8 +1340,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "image"
|
name = "image"
|
||||||
version = "0.24.3"
|
version = "0.24.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/PhilipK/image?rev=cb66840dd42785c7283206cc9805240501695a61#cb66840dd42785c7283206cc9805240501695a61"
|
||||||
checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
|||||||
+4
-2
@@ -18,6 +18,7 @@ steam_shortcuts_util = "^1.1.8"
|
|||||||
steamgriddb_api = "^0.3.1"
|
steamgriddb_api = "^0.3.1"
|
||||||
sysinfo = "^0.25.2"
|
sysinfo = "^0.25.2"
|
||||||
|
|
||||||
|
|
||||||
[dependencies.dashmap]
|
[dependencies.dashmap]
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
version = "^5.3.4"
|
version = "^5.3.4"
|
||||||
@@ -32,8 +33,9 @@ version = "^0.19.0"
|
|||||||
version = "^0.3.23"
|
version = "^0.3.23"
|
||||||
|
|
||||||
[dependencies.image]
|
[dependencies.image]
|
||||||
features = ["png"]
|
features = ["png","webp","jpeg"]
|
||||||
version = "^0.24.3"
|
git = "https://github.com/PhilipK/image"
|
||||||
|
rev = "cb66840dd42785c7283206cc9805240501695a61"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
[dependencies.reqwest]
|
||||||
default_features = false
|
default_features = false
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
+25
-49
@@ -11,10 +11,6 @@ pub mod ui_colors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod ui_images {
|
pub mod ui_images {
|
||||||
use std::{
|
|
||||||
path::Path,
|
|
||||||
thread::{self, Thread},
|
|
||||||
};
|
|
||||||
|
|
||||||
use eframe::IconData;
|
use eframe::IconData;
|
||||||
use egui::{ColorImage, ImageData};
|
use egui::{ColorImage, ImageData};
|
||||||
@@ -46,53 +42,27 @@ pub mod ui_images {
|
|||||||
rgba: pixels.as_slice().to_vec(),
|
rgba: pixels.as_slice().to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn load_image_from_path(path: &Path) -> Option<ColorImage> {
|
|
||||||
if path.exists() {
|
|
||||||
if let Ok(data) = std::fs::read(path) {
|
|
||||||
let load_result = load_image_from_memory(&data);
|
|
||||||
if load_result.is_err() {
|
|
||||||
eprintln!("Could not load image at path {:?}", path);
|
|
||||||
}
|
|
||||||
return load_result.ok();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
|
pub fn load_image_from_path(path: &std::path::Path) -> Result<egui::ColorImage, image::ImageError> {
|
||||||
|
let image = image::io::Reader::open(path)?.decode()?;
|
||||||
|
let size = [image.width() as _, image.height() as _];
|
||||||
|
let image_buffer = image.to_rgba8();
|
||||||
|
let pixels = image_buffer.as_flat_samples();
|
||||||
|
Ok(egui::ColorImage::from_rgba_unmultiplied(
|
||||||
|
size,
|
||||||
|
pixels.as_slice(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_image_from_memory(image_data: &[u8]) -> Result<ColorImage, image::ImageError> {
|
||||||
let image = image::load_from_memory(image_data)?;
|
let image = image::load_from_memory(image_data)?;
|
||||||
let size = [image.width() as _, image.height() as _];
|
let size = [image.width() as _, image.height() as _];
|
||||||
let image_buffer = image.to_rgba8();
|
let image_buffer = image.to_rgba8();
|
||||||
let pixels = image_buffer.as_flat_samples();
|
let pixels = image_buffer.as_flat_samples();
|
||||||
thread::scope(|s| {
|
Ok(ColorImage::from_rgba_unmultiplied(
|
||||||
let rgba = pixels.as_slice();
|
size,
|
||||||
let is_valid = size[0] * size[1] * 4 == rgba.len();
|
pixels.as_slice(),
|
||||||
if is_valid {
|
))
|
||||||
//Wrapping this in a thread, since it has a tendency to panic
|
|
||||||
let thread_handle = s
|
|
||||||
.spawn(move || ColorImage::from_rgba_unmultiplied(size, rgba))
|
|
||||||
.join();
|
|
||||||
match thread_handle {
|
|
||||||
Ok(value) => Ok(value),
|
|
||||||
Err(e) => {
|
|
||||||
println!("Error loading image {:?}", e);
|
|
||||||
Err(image::ImageError::Decoding(
|
|
||||||
image::error::DecodingError::new(
|
|
||||||
image::error::ImageFormatHint::Unknown,
|
|
||||||
"Could not load image, it panicked while trying",
|
|
||||||
),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(image::ImageError::Decoding(
|
|
||||||
image::error::DecodingError::new(
|
|
||||||
image::error::ImageFormatHint::Unknown,
|
|
||||||
"Image did not have right amount of pixels",
|
|
||||||
),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -104,18 +74,24 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
pub fn test_image_load_that_is_broken() {
|
pub fn test_image_load_that_is_broken() {
|
||||||
let res = load_image_from_path(std::path::Path::new("src/testdata/brokenimage.webp"));
|
let res = load_image_from_path(std::path::Path::new("src/testdata/brokenimage.webp"));
|
||||||
assert!(res.is_none());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_image_load_that_works_png() {
|
pub fn test_image_load_that_works_png() {
|
||||||
let res = load_image_from_path(std::path::Path::new("src/testdata/smallpng.png"));
|
let res = load_image_from_path(std::path::Path::new("src/testdata/smallpng.png"));
|
||||||
assert!(res.is_some());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_image_load_that_works_webp() {
|
pub fn test_image_load_that_works_webp() {
|
||||||
let res = load_image_from_path(std::path::Path::new("src/testdata/spider.webp"));
|
let res = load_image_from_path(std::path::Path::new("src/testdata/spider.webp"));
|
||||||
assert!(res.is_some());
|
assert!(res.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_image_load_animated_webp() {
|
||||||
|
let res = load_image_from_path(std::path::Path::new("src/testdata/hollow.webp"));
|
||||||
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ impl MyEguiApp {
|
|||||||
TextureState::Downloaded => {
|
TextureState::Downloaded => {
|
||||||
//Need to load
|
//Need to load
|
||||||
let image_data = load_image_from_path(&image.thumbnail_path);
|
let image_data = load_image_from_path(&image.thumbnail_path);
|
||||||
if let Some(image_data) = image_data {
|
if let Ok(image_data) = image_data {
|
||||||
let handle = ui.ctx().load_texture(
|
let handle = ui.ctx().load_texture(
|
||||||
&image_key,
|
&image_key,
|
||||||
image_data,
|
image_data,
|
||||||
@@ -481,7 +481,7 @@ impl MyEguiApp {
|
|||||||
let loaded = state.image_handles.contains_key(&key);
|
let loaded = state.image_handles.contains_key(&key);
|
||||||
if !loaded && path.exists() {
|
if !loaded && path.exists() {
|
||||||
let image = load_image_from_path(&path);
|
let image = load_image_from_path(&path);
|
||||||
if let Some(image) = image {
|
if let Ok(image) = image {
|
||||||
let texture = ui
|
let texture = ui
|
||||||
.ctx()
|
.ctx()
|
||||||
.load_texture(&key, image, egui::TextureFilter::Linear);
|
.load_texture(&key, image, egui::TextureFilter::Linear);
|
||||||
@@ -607,7 +607,7 @@ impl MyEguiApp {
|
|||||||
for image_type in ImageType::all() {
|
for image_type in ImageType::all() {
|
||||||
let (path, key) = shortcut.key(image_type, Path::new(&user.steam_user_data_folder));
|
let (path, key) = shortcut.key(image_type, Path::new(&user.steam_user_data_folder));
|
||||||
let image = load_image_from_path(&path);
|
let image = load_image_from_path(&path);
|
||||||
if let Some(image) = image {
|
if let Ok(image) = image {
|
||||||
let texture = ui
|
let texture = ui
|
||||||
.ctx()
|
.ctx()
|
||||||
.load_texture(&key, image, egui::TextureFilter::Linear);
|
.load_texture(&key, image, egui::TextureFilter::Linear);
|
||||||
|
|||||||
Reference in New Issue
Block a user