mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-07 13:28:47 +08:00
Add new arg
This commit is contained in:
@@ -169,6 +169,7 @@ pub struct CrxImage {
|
||||
zstd: bool,
|
||||
zstd_compression_level: i32,
|
||||
row_type: CircusCrxMode,
|
||||
canvas: bool,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for CrxImage {
|
||||
@@ -230,9 +231,15 @@ impl CrxImage {
|
||||
zstd: config.circus_crx_zstd,
|
||||
zstd_compression_level: config.zstd_compression_level,
|
||||
row_type: config.circus_crx_mode.for_importing(),
|
||||
canvas: config.circus_crx_canvas,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_canvas(mut self, canvas: bool) -> Self {
|
||||
self.canvas = canvas;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn draw_diff(&self, diff: &Self) -> Result<ImageData> {
|
||||
let base_header = &self.header;
|
||||
let diff_header = &diff.header;
|
||||
@@ -810,13 +817,29 @@ impl Script for CrxImage {
|
||||
data[i + 3] = a ^ alpha_flip;
|
||||
}
|
||||
}
|
||||
Ok(ImageData {
|
||||
let img = ImageData {
|
||||
width: self.header.width as u32,
|
||||
height: self.header.height as u32,
|
||||
depth: 8,
|
||||
color_type: self.color_type,
|
||||
data,
|
||||
})
|
||||
};
|
||||
if self.canvas {
|
||||
let (img_width, img_height) = if self.header.clips.is_empty() {
|
||||
(self.header.width as u32, self.header.height as u32)
|
||||
} else {
|
||||
let clip = &self.header.clips[0];
|
||||
(clip.img_width as u32, clip.img_height as u32)
|
||||
};
|
||||
return Ok(draw_on_canvas(
|
||||
img,
|
||||
img_width,
|
||||
img_height,
|
||||
self.header.inner_x as u32,
|
||||
self.header.inner_y as u32,
|
||||
)?);
|
||||
}
|
||||
Ok(img)
|
||||
}
|
||||
|
||||
fn import_image<'a>(
|
||||
|
||||
@@ -90,7 +90,8 @@ impl CrxdImage {
|
||||
nf.set_file_name(name);
|
||||
let f = std::fs::File::open(nf)?;
|
||||
CrxImage::new(std::io::BufReader::new(f), config)?
|
||||
};
|
||||
}
|
||||
.with_canvas(false);
|
||||
let mut typ = [0; 4];
|
||||
reader.read_exact(&mut typ)?;
|
||||
if typ == *b"CRXJ" {
|
||||
@@ -107,7 +108,7 @@ impl CrxdImage {
|
||||
return Ok(Self { base, diff });
|
||||
} else if typ == *b"CRXG" {
|
||||
let reader = StreamRegion::with_start_pos(reader, 0x20)?;
|
||||
let diff = CrxImage::new(reader, config)?;
|
||||
let diff = CrxImage::new(reader, config)?.with_canvas(false);
|
||||
return Ok(Self { base, diff });
|
||||
}
|
||||
Err(anyhow::anyhow!("Unsupported diff CRXD type: {:?}", typ))
|
||||
@@ -129,16 +130,17 @@ impl CrxdImage {
|
||||
if typ == *b"CRXJ" {
|
||||
reader.seek_relative(4)?;
|
||||
let offset = reader.read_u32()?;
|
||||
return Ok(CrxImage::new(
|
||||
return Self::read_diff(
|
||||
archive
|
||||
.ok_or(anyhow::anyhow!("No archive provided"))?
|
||||
.open_file_by_offset(offset as u64)?
|
||||
.to_data()?,
|
||||
archive,
|
||||
config,
|
||||
)?);
|
||||
);
|
||||
} else if typ == *b"CRXG" {
|
||||
let reader = StreamRegion::with_start_pos(reader, 0x20)?;
|
||||
return Ok(CrxImage::new(reader, config)?);
|
||||
return Ok(CrxImage::new(reader, config)?.with_canvas(false));
|
||||
}
|
||||
Err(anyhow::anyhow!("Unsupported diff CRXD type: {:?}", typ))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user