Add support to detect BGI sysgrp image

This commit is contained in:
2025-06-14 13:11:29 +08:00
parent c1269bdd3c
commit 1e70036d47
2 changed files with 34 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ impl ScriptBuilder for BgiArchiveBuilder {
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
if buf_len >= 12 && buf.starts_with(b"PackFile ") {
return Some(1);
return Some(10);
}
None
}

View File

@@ -3,6 +3,32 @@ use crate::scripts::base::*;
use crate::types::*;
use anyhow::Result;
fn try_parse(buf: &[u8]) -> Result<u8> {
let mut reader = MemReaderRef::new(buf);
let width = reader.read_u16()?;
let height = reader.read_u16()?;
let bpp = reader.read_u16()?;
let _flag = reader.read_u16()?;
let padding = reader.read_u64()?;
if padding != 0 {
return Err(anyhow::anyhow!("Invalid padding: {}", padding));
}
if width == 0 || height == 0 {
return Err(anyhow::anyhow!("Invalid dimensions: {}x{}", width, height));
}
if width > 4096 || height > 4096 {
return Err(anyhow::anyhow!(
"Dimensions too large: {}x{}",
width,
height
));
}
if bpp != 8 && bpp != 24 && bpp != 32 {
return Err(anyhow::anyhow!("Unsupported BPP: {}", bpp));
}
Ok(1)
}
#[derive(Debug)]
pub struct BgiImageBuilder {}
@@ -39,6 +65,13 @@ impl ScriptBuilder for BgiImageBuilder {
fn is_image(&self) -> bool {
true
}
fn is_this_format(&self, _filename: &str, buf: &[u8], buf_len: usize) -> Option<u8> {
if buf_len >= 0x10 {
return try_parse(&buf[0..0x10]).ok();
}
None
}
}
#[derive(Debug)]