Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ rayon = { version = "1.10", optional = true }
dbpnoise = { version = "0.1.2", optional = true }
pathfinding = { version = "4.14", optional = true }
num-integer = { version = "0.1.46", optional = true }
dmi = { version = "0.4.0", optional = true }
dmi = { version = "0.5.0", optional = true }
tracy_full = { version = "1.12.0", optional = true }
ammonia = { version = "4.1", optional = true }
fast_poisson = { version = "1.0.2", optional = true, features = [
Expand Down
2 changes: 1 addition & 1 deletion src/dmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ struct DmiMetadata {
}

fn read_metadata(path: &str) -> Result<String> {
let dmi = Icon::load(File::open(path).map(BufReader::new)?)?;
let dmi = Icon::load_meta(File::open(path).map(BufReader::new)?)?;
let metadata = DmiMetadata {
width: dmi.width,
height: dmi.height,
Expand Down
23 changes: 11 additions & 12 deletions src/iconforge/gags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::{blending, icon_operations, image_cache::filepath_to_dmi};
use crate::error::Error;
use dashmap::DashMap;
use dmi::icon::{DmiVersion, Icon, IconState};
use image::DynamicImage;
use once_cell::sync::Lazy;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -217,10 +216,10 @@ fn gags_internal(
config_path: &str,
colors_vec: &Vec<String>,
icon_state: &String,
last_external_images: Option<Vec<DynamicImage>>,
last_external_images: Option<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>>,
first_matched_state: &mut Option<IconState>,
last_matched_state: &mut Option<IconState>,
) -> Result<Vec<DynamicImage>, String> {
) -> Result<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>, String> {
zone!("gags_internal");
let gags_data = match GAGS_CACHE.get(config_path) {
Some(config) => config,
Expand Down Expand Up @@ -270,12 +269,12 @@ fn generate_layer_groups_for_iconstate(
colors: &Vec<String>,
layer_groups: &Vec<GAGSLayerGroupOption>,
gags_data: &GAGSData,
last_external_images: Option<Vec<DynamicImage>>,
last_external_images: Option<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>>,
first_matched_state: &mut Option<IconState>,
last_matched_state: &mut Option<IconState>,
) -> Result<Vec<DynamicImage>, String> {
) -> Result<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>, String> {
zone!("generate_layer_groups_for_iconstate");
let mut new_images: Option<Vec<DynamicImage>> = None;
let mut new_images: Option<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>> = None;
for option in layer_groups {
zone!("process_gags_layergroup_option");
let (layer_images, blend_mode_result) = match option {
Expand Down Expand Up @@ -342,12 +341,12 @@ fn generate_layer_for_iconstate(
colors: &[String],
layer: &GAGSLayer,
gags_data: &GAGSData,
new_images: Option<Vec<DynamicImage>>,
new_images: Option<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>>,
first_matched_state: &mut Option<IconState>,
last_matched_state: &mut Option<IconState>,
) -> Result<Vec<DynamicImage>, String> {
) -> Result<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>, String> {
zone!("generate_layer_for_iconstate");
let images_result: Option<Vec<DynamicImage>> = match layer {
let images_result: Option<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>> = match layer {
GAGSLayer::IconState {
icon_state,
blend_mode: _,
Expand Down Expand Up @@ -459,16 +458,16 @@ fn generate_layer_for_iconstate(
}
}

pub fn map_cloned_images<F>(images: &Vec<DynamicImage>, do_fn: F) -> Vec<DynamicImage>
pub fn map_cloned_images<F>(images: &Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>, do_fn: F) -> Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>
where
F: Fn(&mut image::ImageBuffer<image::Rgba<u8>, Vec<u8>>) + Send + Sync,
{
images
.par_iter()
.map(|image| {
let mut new_image = image.clone().into_rgba8();
let mut new_image = image.clone();
do_fn(&mut new_image);
DynamicImage::ImageRgba8(new_image)
new_image
})
.collect()
}
38 changes: 19 additions & 19 deletions src/iconforge/icon_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::error::Error;
use dmi::{dirs::Dirs, icon::IconState};
use image::{imageops, DynamicImage, Rgba, RgbaImage};
use image::{imageops, Rgba, RgbaImage};
use ordered_float::OrderedFloat;
use rayon::{
iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator},
Expand Down Expand Up @@ -571,26 +571,26 @@ pub fn blend_images_other_universal(
)));
}
}
let images_out: Vec<DynamicImage> = if images_other.len() == 1 {
let images_out: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> = if images_other.len() == 1 {
// This is useful in the case where the something with 4+ dirs blends with 1dir
let first_image = images_other.first().unwrap().clone().into_rgba8();
let first_image = images_other.first().unwrap().clone();
images
.into_par_iter()
.map(|image| {
zone!("blend_image_other_simple");
let mut new_image = image.clone().into_rgba8();
let mut new_image = image.clone();
blend_icon(&mut new_image, &first_image, blend_mode, position);
DynamicImage::ImageRgba8(new_image)
new_image
})
.collect()
} else {
(images, images_other)
.into_par_iter()
.map(|(image, image2)| {
zone!("blend_image_other");
let mut new_image = image.clone().into_rgba8();
blend_icon(&mut new_image, &image2.into_rgba8(), blend_mode, position);
DynamicImage::ImageRgba8(new_image)
let mut new_image = image.clone();
blend_icon(&mut new_image, &image2, blend_mode, position);
new_image
})
.collect()
};
Expand All @@ -611,12 +611,12 @@ pub fn blend_images_other_universal(
/// Blends a set of images with another set of images.
/// The frame and dir counts of first_matched_state are mutated to match the new icon.
pub fn blend_images_other(
images: Vec<DynamicImage>,
images_other: Vec<DynamicImage>,
images: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>,
images_other: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>,
blend_mode: &blending::BlendMode,
first_matched_state: &mut Option<IconState>,
last_matched_state: &mut Option<IconState>,
) -> Result<Vec<DynamicImage>, Error> {
) -> Result<Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>, Error> {
zone!("blend_images_other");
let base_icon_state = match first_matched_state {
Some(state) => state,
Expand Down Expand Up @@ -709,26 +709,26 @@ pub fn blend_images_other(
)));
}
}
let images_out: Vec<DynamicImage> = if images_other.len() == 1 {
let images_out: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> = if images_other.len() == 1 {
// This is useful in the case where the something with 4+ dirs blends with 1dir
let first_image = images_other.first().unwrap().clone().into_rgba8();
let first_image = images_other.first().unwrap().clone();
images
.into_par_iter()
.map(|image| {
zone!("blend_image_other_simple");
let mut new_image = image.clone().into_rgba8();
let mut new_image = image.clone();
blend_icon(&mut new_image, &first_image, blend_mode, None);
DynamicImage::ImageRgba8(new_image)
new_image
})
.collect()
} else {
(images, images_other)
.into_par_iter()
.map(|(image, image2)| {
zone!("blend_image_other");
let mut new_image = image.clone().into_rgba8();
blend_icon(&mut new_image, &image2.into_rgba8(), blend_mode, None);
DynamicImage::ImageRgba8(new_image)
let mut new_image = image.clone();
blend_icon(&mut new_image, &image2, blend_mode, None);
new_image
})
.collect()
};
Expand All @@ -747,7 +747,7 @@ impl Transform {
flatten: bool,
) -> Result<UniversalIconData, String> {
zone!("transform_apply");
let images: Vec<DynamicImage>;
let images: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>;
let mut frames = image_data.frames;
let mut dirs = image_data.dirs;
let mut delay = image_data.delay.to_owned();
Expand Down
4 changes: 2 additions & 2 deletions src/iconforge/image_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dmi::{
dirs::{Dirs, ALL_DIRS, CARDINAL_DIRS},
icon::{dir_to_dmi_index, Icon, IconState},
};
use image::DynamicImage;
use image::ImageBuffer;
use once_cell::sync::Lazy;
use std::{fs::File, hash::BuildHasherDefault, io::BufReader, sync::Arc};
use tracy_full::zone;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl UniversalIcon {
frame_offset = 0;
}

let mut images: Vec<DynamicImage> = Vec::new();
let mut images: Vec<ImageBuffer<image::Rgba<u8>, Vec<u8>>> = Vec::new();

for frame_index in frame_offset..(frame_offset + frames) {
for dir_offset in dir_index..(dir_index + dirs) {
Expand Down
2 changes: 1 addition & 1 deletion src/iconforge/spritesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn create_png_image(
if image_data.images.len() > 1 {
return Err(format!("More than one image (non-flattened) sprite {sprite_name} in PNG spritesheet for icon {icon}!"));
}
let image = image_data.images.first().unwrap().to_rgba8();
let image = image_data.images.first().unwrap();
let base_x: u32 = base_width * idx as u32;
for x in 0..image.width() {
for y in 0..image.height() {
Expand Down
9 changes: 4 additions & 5 deletions src/iconforge/universal_icon.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dmi::icon::Looping;
use image::DynamicImage;
use ordered_float::OrderedFloat;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -112,7 +111,7 @@ pub enum Transform {

#[derive(Clone)]
pub struct UniversalIconData {
pub images: Vec<DynamicImage>,
pub images: Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>,
pub frames: u32,
pub dirs: u8,
pub delay: Option<Vec<f32>>,
Expand All @@ -121,16 +120,16 @@ pub struct UniversalIconData {
}

impl UniversalIconData {
pub fn map_cloned_images<F>(&self, do_fn: F) -> Vec<DynamicImage>
pub fn map_cloned_images<F>(&self, do_fn: F) -> Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>
where
F: Fn(&mut image::ImageBuffer<image::Rgba<u8>, Vec<u8>>) + Send + Sync,
{
self.images
.par_iter()
.map(|image| {
let mut new_image = image.clone().into_rgba8();
let mut new_image = image.clone();
do_fn(&mut new_image);
DynamicImage::ImageRgba8(new_image)
new_image
})
.collect()
}
Expand Down
5 changes: 2 additions & 3 deletions tests/iconforge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use dmi::{
error::DmiError,
icon::{Icon, IconState},
};
use image::{DynamicImage, GenericImageView};
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use std::{
fs::{read_dir, File},
Expand Down Expand Up @@ -211,8 +210,8 @@ fn compare_states(dm_state: &IconState, rustg_state: &IconState) -> Option<Strin

fn compare_images(
differences: &mut Vec<String>,
dm_images: &Vec<DynamicImage>,
rustg_images: &Vec<DynamicImage>,
dm_images: &Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>,
rustg_images: &Vec<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>>,
dirs: u8,
) {
let safe_diffs = Arc::new(Mutex::new(Vec::<String>::new()));
Expand Down
Loading