mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-07-08 01:31:53 +08:00
Add TLG encode support
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -673,9 +673,9 @@ checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libtlg-rs"
|
name = "libtlg-rs"
|
||||||
version = "0.1.4"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f65cb31779c2b9adeb55fccc033f911f117a459bb75808b907cd535c68c99602"
|
checksum = "59d57b48167296edc5ea37791e19c63031ae4341b44ddc7c8580a93e2d098164"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"overf",
|
"overf",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ flate2 = { version = "1.1", optional = true }
|
|||||||
int-enum = { version = "1.2", optional = true }
|
int-enum = { version = "1.2", optional = true }
|
||||||
json = { version = "0.12", optional = true }
|
json = { version = "0.12", optional = true }
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
libtlg-rs = { version = "0.1", optional = true }
|
libtlg-rs = { version = "0.2", optional = true, features = ["encode"] }
|
||||||
markup5ever = { version = "0.35", optional = true }
|
markup5ever = { version = "0.35", optional = true }
|
||||||
markup5ever_rcdom = { version = "0.35", optional = true }
|
markup5ever_rcdom = { version = "0.35", optional = true }
|
||||||
memchr = { version = "2.7", optional = true }
|
memchr = { version = "2.7", optional = true }
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ msg-tool create -t <script-type> <input> <output>
|
|||||||
|
|
||||||
| Image Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Create | Remarks |
|
| Image Type | Feature Name | Name | Export | Import | Export Multiple | Import Multiple | Create | Remarks |
|
||||||
|---|---|---|---|---|---|---|---|---|
|
|---|---|---|---|---|---|---|---|---|
|
||||||
| `kirikiri-tlg`/`kr-tlg` | `kirikiri-img` | Kirikiri TLG Image File (.tlg) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
| `kirikiri-tlg`/`kr-tlg` | `kirikiri-img` | Kirikiri TLG Image File (.tlg) | ✔️ | ✔️ | ❌ | ❌ | ✔️ | tlg6 is not supported when importing/creating image |
|
||||||
| `kirikiri-pimg`/`kr-pimg` | `kirikiri-img` | Kirikiri Multiple Image File (.pimg) | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
| `kirikiri-pimg`/`kr-pimg` | `kirikiri-img` | Kirikiri Multiple Image File (.pimg) | ❌ | ❌ | ✔️ | ❌ | ❌ | |
|
||||||
| `kirikiri-dref`/`kr-dref` | `kirikiri-img` | Kirikiri DPAK-referenced Image File (.dref) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
| `kirikiri-dref`/`kr-dref` | `kirikiri-img` | Kirikiri DPAK-referenced Image File (.dref) | ✔️ | ❌ | ❌ | ❌ | ❌ | |
|
||||||
### WillPlus / AdvHD
|
### WillPlus / AdvHD
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
use crate::ext::io::*;
|
use crate::ext::io::*;
|
||||||
use crate::scripts::base::*;
|
use crate::scripts::base::*;
|
||||||
use crate::types::*;
|
use crate::types::*;
|
||||||
|
use crate::utils::img::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use libtlg_rs::*;
|
use libtlg_rs::*;
|
||||||
use std::io::{Read, Seek};
|
use std::io::{Read, Seek};
|
||||||
@@ -54,6 +55,44 @@ impl ScriptBuilder for TlgImageBuilder {
|
|||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn can_create_image_file(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_image_file<'a>(
|
||||||
|
&'a self,
|
||||||
|
mut data: ImageData,
|
||||||
|
writer: Box<dyn WriteSeek + 'a>,
|
||||||
|
_options: &ExtraConfig,
|
||||||
|
) -> Result<()> {
|
||||||
|
if data.depth != 8 {
|
||||||
|
return Err(anyhow::anyhow!("Unsupported image depth: {}", data.depth));
|
||||||
|
}
|
||||||
|
let color_type = match data.color_type {
|
||||||
|
ImageColorType::Bgr => TlgColorType::Bgr24,
|
||||||
|
ImageColorType::Bgra => TlgColorType::Bgra32,
|
||||||
|
ImageColorType::Grayscale => TlgColorType::Grayscale8,
|
||||||
|
ImageColorType::Rgb => {
|
||||||
|
convert_rgb_to_bgr(&mut data)?;
|
||||||
|
TlgColorType::Bgr24
|
||||||
|
}
|
||||||
|
ImageColorType::Rgba => {
|
||||||
|
convert_rgba_to_bgra(&mut data)?;
|
||||||
|
TlgColorType::Bgra32
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let tlg = Tlg {
|
||||||
|
width: data.width,
|
||||||
|
height: data.height,
|
||||||
|
color: color_type,
|
||||||
|
data: data.data,
|
||||||
|
tags: Default::default(),
|
||||||
|
version: 5, // Currently only version 5 is supported
|
||||||
|
};
|
||||||
|
save_tlg(&tlg, writer)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -99,4 +138,37 @@ impl Script for TlgImage {
|
|||||||
data: self.data.data.clone(),
|
data: self.data.data.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn import_image<'a>(
|
||||||
|
&'a self,
|
||||||
|
mut data: ImageData,
|
||||||
|
file: Box<dyn WriteSeek + 'a>,
|
||||||
|
) -> Result<()> {
|
||||||
|
if data.depth != 8 {
|
||||||
|
return Err(anyhow::anyhow!("Unsupported image depth: {}", data.depth));
|
||||||
|
}
|
||||||
|
let color_type = match data.color_type {
|
||||||
|
ImageColorType::Bgr => TlgColorType::Bgr24,
|
||||||
|
ImageColorType::Bgra => TlgColorType::Bgra32,
|
||||||
|
ImageColorType::Grayscale => TlgColorType::Grayscale8,
|
||||||
|
ImageColorType::Rgb => {
|
||||||
|
convert_rgb_to_bgr(&mut data)?;
|
||||||
|
TlgColorType::Bgr24
|
||||||
|
}
|
||||||
|
ImageColorType::Rgba => {
|
||||||
|
convert_rgba_to_bgra(&mut data)?;
|
||||||
|
TlgColorType::Bgra32
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let tlg = Tlg {
|
||||||
|
width: data.width,
|
||||||
|
height: data.height,
|
||||||
|
color: color_type,
|
||||||
|
data: data.data,
|
||||||
|
tags: self.data.tags.clone(),
|
||||||
|
version: 5, // Currently only version 5 is supported
|
||||||
|
};
|
||||||
|
save_tlg(&tlg, file)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user