Skip to content

Commit

Permalink
textile: add vtf conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
khanghugo committed Sep 20, 2024
1 parent 2437bc1 commit aee5188
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/gui/programs/textile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ pub struct TexTileGui {
impl Default for TexTileGui {
fn default() -> Self {
let options = TexTileOptions::default();
let extensions = options.extensions.join(" ");

Self {
items: vec![],
options,
extensions: String::from("png jpeg jpg"),
extensions,
sync: TexTileSync::default(),
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/modules/textile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use eyre::eyre;
use image::RgbaImage;

use rayon::prelude::*;
use vtf::Vtf;

use crate::utils::img_stuffs::{
eight_bpp_transparent_img, rgba8_to_8bpp, tile_and_resize, write_8bpp_to_file, GoldSrcBmp,
Expand Down Expand Up @@ -36,7 +37,12 @@ pub struct TexTileOptions {
impl Default for TexTileOptions {
fn default() -> Self {
Self {
extensions: vec!["png".to_string(), "jpg".to_string(), "jpeg".to_string()],
extensions: vec![
"png".to_string(),
"jpg".to_string(),
"jpeg".to_string(),
"vtf".to_string(),
],
is_tiling: true,
tiling_scalar: 2,
is_transparent: false,
Expand Down Expand Up @@ -209,7 +215,13 @@ impl TexTileBuilder {
let rgba_images: Vec<eyre::Result<(PathBuf, RgbaImage)>> = work_items
.into_par_iter()
.map(|work_item| {
let new_img = image::open(&work_item);
// items are already checked so they should have the extensions we want
let ext = work_item.extension().unwrap().to_str().unwrap();

let new_img = match ext {
"vtf" => Vtf::from_file(&work_item)?.get_high_res_image(),
_ => image::open(&work_item).map_err(|err| eyre!(err)),
};

if new_img.is_err() {
let log = format!(
Expand Down

0 comments on commit aee5188

Please sign in to comment.