mirror of
https://github.com/G2-Games/lbee-utils.git
synced 2025-04-19 23:32:55 -05:00
Allow saving PNG files from CZs with bitmaps which are incorrectly sized
This commit is contained in:
parent
74ee617a04
commit
67700df6ef
3 changed files with 8 additions and 3 deletions
|
@ -408,9 +408,13 @@ pub fn indexed_gen_palette(
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
header: &CommonHeader,
|
header: &CommonHeader,
|
||||||
) -> Result<(Vec<u8>, Vec<image::Rgba<u8>>), CzError> {
|
) -> Result<(Vec<u8>, Vec<image::Rgba<u8>>), CzError> {
|
||||||
|
let size = (header.width() as u32 * header.height() as u32) * 4;
|
||||||
|
|
||||||
|
let mut buf = vec![0; size as usize];
|
||||||
|
buf[..input.len()].copy_from_slice(&input);
|
||||||
|
|
||||||
let image = Image::new(
|
let image = Image::new(
|
||||||
input,
|
&buf,
|
||||||
header.width() as usize,
|
header.width() as usize,
|
||||||
header.height() as usize
|
header.height() as usize
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl DynamicCz {
|
||||||
if bitmap.len() != image_size * (header_common.depth() >> 3) as usize {
|
if bitmap.len() != image_size * (header_common.depth() >> 3) as usize {
|
||||||
// If the bitmap is smaller or larger than the image size, it is likely wrong
|
// If the bitmap is smaller or larger than the image size, it is likely wrong
|
||||||
eprintln!("Image is wrong, length is {}, expected {}", bitmap.len(), image_size * (header_common.depth() >> 3) as usize);
|
eprintln!("Image is wrong, length is {}, expected {}", bitmap.len(), image_size * (header_common.depth() >> 3) as usize);
|
||||||
//return Err(CzError::Corrupt);
|
return Err(CzError::Corrupt);
|
||||||
}
|
}
|
||||||
|
|
||||||
match header_common.depth() {
|
match header_common.depth() {
|
||||||
|
|
|
@ -14,7 +14,8 @@ fn main() {
|
||||||
let mut gallery_cz = DynamicCz::open("24.cz2").unwrap();
|
let mut gallery_cz = DynamicCz::open("24.cz2").unwrap();
|
||||||
gallery_cz.save_as_png("24.png").unwrap();
|
gallery_cz.save_as_png("24.png").unwrap();
|
||||||
|
|
||||||
//gallery_cz.header_mut().set_depth(8);
|
gallery_cz.set_bitmap(new_bitmap.into_vec());
|
||||||
|
gallery_cz.header_mut().set_depth(8);
|
||||||
gallery_cz.remove_palette();
|
gallery_cz.remove_palette();
|
||||||
gallery_cz.header_mut().set_version(CzVersion::CZ2);
|
gallery_cz.header_mut().set_version(CzVersion::CZ2);
|
||||||
gallery_cz.save_as_cz("24-modified.cz2").unwrap();
|
gallery_cz.save_as_cz("24-modified.cz2").unwrap();
|
||||||
|
|
Loading…
Reference in a new issue