Fix dpng may contains zero size image

Use better message for scn
This commit is contained in:
2026-01-30 00:16:16 +08:00
parent 736fe4d6a8
commit 59c40b451e
2 changed files with 16 additions and 5 deletions

View File

@@ -601,7 +601,8 @@ impl Script for ScnScript {
text[1][self.language_index][0].set_string(name);
} else {
return Err(anyhow::anyhow!(
"Name is missing for message. (text {j} at scene {i})"
"Name is missing for message. (text {j} at scene {i}, message: {})",
m.message
));
}
}

View File

@@ -120,16 +120,26 @@ impl Script for DpngImage {
}
fn export_image(&self) -> Result<ImageData> {
let mut base = load_png(MemReaderRef::new(&self.img.tiles[0].png_data))?;
let (idx, tile) = self
.img
.tiles
.iter()
.enumerate()
.find(|(_, t)| t.size != 0)
.ok_or_else(|| anyhow::anyhow!("DPNG image has no valid tiles with PNG data"))?;
let mut base = load_png(MemReaderRef::new(&tile.png_data))?;
convert_to_rgba(&mut base)?;
let mut base = draw_on_canvas(
base,
self.img.header.image_width,
self.img.header.image_height,
self.img.tiles[0].x,
self.img.tiles[0].y,
tile.x,
tile.y,
)?;
for tile in &self.img.tiles[1..] {
for tile in &self.img.tiles[idx + 1..] {
if tile.size == 0 {
continue;
}
let mut diff = load_png(MemReaderRef::new(&tile.png_data))?;
convert_to_rgba(&mut diff)?;
draw_on_image(&mut base, &diff, tile.x, tile.y)?;