chinedufn / psd

A Rust API for parsing and working with PSD files.
https://chinedufn.github.io/psd
Apache License 2.0
265 stars 40 forks source link

index out of bounds #57

Open Smooth-Zhao opened 4 months ago

Smooth-Zhao commented 4 months ago

Hi, I'm trying to convert my PSD image to PNG, and when using psd.rgba() I always get the same error

thread 'tokio-runtime-worker' panicked at xxx\psd-0.3.5\src\psd_channel.rs:130:29:
index out of bounds: the len is 96641024 but the index is 96641025

96641024 looks like a maximum value. I tried a few other files and it seems the size cannot exceed a certain value, looking at my image size in Photoshop it is 6016*4016.

Here is my code:

let psd = Psd::from_bytes(std::fs::read(path).unwrap().as_bytes()).unwrap();
metadata.image_width = psd.width();
metadata.image_height = psd.height();
println!("{}*{}",metadata.image_width,metadata.image_height);

let final_image = psd.rgba();

what should I do :)

Smooth-Zhao commented 4 months ago

I cloned the source code, and the problem seems to be that when converting 16-bit color to 8-bit color, only the Red channel is converted. What is the reason for doing this.