brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.17k stars 265 forks source link

PSD: Can't read RLE - Index out of range #656

Open ServOKio opened 3 months ago

ServOKio commented 3 months ago
Image img = decodePsd(fileBytes);
flutter: Exception RangeError (index): Index out of range: index should be less than 1859584: 1859584
flutter: K:\pictures\sd\outputs\txt2img-images\2024-06-15\00033-3613106575.psd
flutter: StackTrace #0      _typedDataIndexCheck (dart:typed_data-patch/typed_data_patch.dart:5215:5)
#1      Uint8List.[]= (dart:typed_data-patch/typed_data_patch.dart:2263:13)
#2      PsdChannel._decodeRLE (package:image/src/formats/psd/psd_channel.dart:110:14)
#3      PsdChannel._readPlaneRleCompressed (package:image/src/formats/psd/psd_channel.dart:98:7)
#4      PsdChannel.readPlane (package:image/src/formats/psd/psd_channel.dart:49:9)
#5      PsdLayer.readImageData (package:image/src/formats/psd/psd_layer.dart:396:19)
#6      PsdImage._readLayerAndMaskData (package:image/src/formats/psd/psd_image.dart:465:17)
#7      PsdImage.decode (package:image/src/formats/psd/psd_image.dart:90:5)
#8      PsdImage.decodeImage (package:image/src/formats/psd/psd_image.dart:104:10)

2022-10-05_23-03 psd.zip

brendan-duncan commented 3 months ago

Fix is in git. I'll have to plan a release at some point in the near future, but might not be for a couple weeks due to a vacation.

ServOKio commented 3 months ago

It looks like I've run into two more new problems

  1. Exception RangeError (index): Index out of range: index should be less than... index should be less than 28926027: 28926027 index should be less than 11570024: 11570024

  2. Exception ImageException: Unsupported compression: *** 33024, 2569, 5374, 4125, 3856... a huge number of "methods"

The files come out too big, so I had to use google drive

brendan-duncan commented 3 months ago

I took out the code that tries to read the actual layers from the PSD, and it will just read the merged image now. PSD is too weird of a proprietary format to handle all those cases, but at least it always provides the merged image. The changes are in git, those images can be read now.