mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-08 05:48:46 +08:00
Add tlg decode support (v5 only)
This commit is contained in:
1
src/scripts/kirikiri/image/mod.rs
Normal file
1
src/scripts/kirikiri/image/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod tlg;
|
||||
93
src/scripts/kirikiri/image/tlg.rs
Normal file
93
src/scripts/kirikiri/image/tlg.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use crate::ext::io::*;
|
||||
use crate::scripts::base::*;
|
||||
use crate::types::*;
|
||||
use anyhow::Result;
|
||||
use libtlg_rs::*;
|
||||
use std::io::{Read, Seek};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TlgImageBuilder {}
|
||||
|
||||
impl TlgImageBuilder {
|
||||
pub const fn new() -> Self {
|
||||
TlgImageBuilder {}
|
||||
}
|
||||
}
|
||||
|
||||
impl ScriptBuilder for TlgImageBuilder {
|
||||
fn default_encoding(&self) -> Encoding {
|
||||
Encoding::Cp932
|
||||
}
|
||||
|
||||
fn build_script(
|
||||
&self,
|
||||
data: Vec<u8>,
|
||||
_filename: &str,
|
||||
_encoding: Encoding,
|
||||
_archive_encoding: Encoding,
|
||||
config: &ExtraConfig,
|
||||
) -> Result<Box<dyn Script>> {
|
||||
Ok(Box::new(TlgImage::new(MemReader::new(data), config)?))
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &'static [&'static str] {
|
||||
&["tlg", "tlg5", "tlg6"]
|
||||
}
|
||||
|
||||
fn script_type(&self) -> &'static ScriptType {
|
||||
&ScriptType::KirikiriTlg
|
||||
}
|
||||
|
||||
fn is_image(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
|
||||
if buf_len >= 11 {
|
||||
if is_valid_tlg(buf) {
|
||||
return Some(255);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TlgImage {
|
||||
data: Tlg,
|
||||
}
|
||||
|
||||
impl TlgImage {
|
||||
pub fn new<T: Read + Seek>(data: T, _config: &ExtraConfig) -> Result<Self> {
|
||||
let tlg = load_tlg(data)?;
|
||||
Ok(TlgImage { data: tlg })
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for TlgImage {
|
||||
fn default_output_script_type(&self) -> OutputScriptType {
|
||||
OutputScriptType::Json
|
||||
}
|
||||
|
||||
fn default_format_type(&self) -> FormatOptions {
|
||||
FormatOptions::None
|
||||
}
|
||||
|
||||
fn is_image(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn export_image(&self) -> Result<ImageData> {
|
||||
Ok(ImageData {
|
||||
width: self.data.width,
|
||||
height: self.data.height,
|
||||
color_type: match self.data.color {
|
||||
TlgColorType::Bgr24 => ImageColorType::Bgr,
|
||||
TlgColorType::Bgra32 => ImageColorType::Bgra,
|
||||
TlgColorType::Grayscale8 => ImageColorType::Grayscale,
|
||||
},
|
||||
depth: 8,
|
||||
data: self.data.data.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
pub mod image;
|
||||
pub mod ks;
|
||||
pub mod scn;
|
||||
pub mod simple_crypt;
|
||||
|
||||
@@ -54,6 +54,8 @@ lazy_static::lazy_static! {
|
||||
Box::new(kirikiri::simple_crypt::SimpleCryptBuilder::new()),
|
||||
#[cfg(feature = "kirikiri")]
|
||||
Box::new(kirikiri::ks::KsBuilder::new()),
|
||||
#[cfg(feature = "kirikiri-img")]
|
||||
Box::new(kirikiri::image::tlg::TlgImageBuilder::new()),
|
||||
];
|
||||
pub static ref ALL_EXTS: Vec<String> =
|
||||
BUILDER.iter().flat_map(|b| b.extensions()).map(|s| s.to_string()).collect();
|
||||
|
||||
Reference in New Issue
Block a user