Skip to content

Commit

Permalink
psd update
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Nov 10, 2024
1 parent 6fe284d commit 227bc1e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/src/formats/psd/psd_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class PsdImage implements DecodeInfo {
//var di = (layer.top! + y) * width * 4 + layer.left! * 4;
final dy = layer.top! + y;
for (int? x = 0, sx = layer.left; x! < layer.width; ++x, ++sx) {
final srcP = src.getPixel(x, y);
final srcP = src!.getPixel(x, y);
final br = srcP.r.toInt();
final bg = srcP.g.toInt();
final bb = srcP.b.toInt();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/formats/psd/psd_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PsdLayer {
Map<String, PsdLayerData> additionalData = {};
List<PsdLayer> children = [];
PsdLayer? parent;
late Image layerImage;
Image? layerImage;
List<PsdEffect> effects = [];

static const signature = 0x3842494d; // '8BIM'
Expand Down
Binary file added test/_data/psd/rectangles.psd
Binary file not shown.
16 changes: 14 additions & 2 deletions test/formats/psd_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ void main() {
final files = dir.listSync();

group('psd', () {
for (var f in files.whereType<File>()) {
for (final f in files.whereType<File>()) {
if (!f.path.endsWith('.psd')) {
continue;
}

final name = f.uri.pathSegments.last;
test(name, () {
final psd = PsdDecoder().decode(f.readAsBytesSync());
final decoder = PsdDecoder();
final psd = decoder.decode(f.readAsBytesSync());
expect(psd, isNotNull);
File('$testOutputPath/psd/$name.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(psd!));

var li = 0;
for (final layer in decoder.info!.layers) {
final layerImg = layer.layerImage;
if (layerImg != null) {
File('$testOutputPath/psd/${name}_${li}_${layer.name}.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(layerImg!));
}
++li;
}
});
}
});
Expand Down

0 comments on commit 227bc1e

Please sign in to comment.