Skip to content

Commit

Permalink
Fix error with drawPixel mask
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-duncan committed Dec 14, 2024
1 parent baa495d commit c6f2c4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/src/draw/draw_pixel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Image drawPixel(Image image, int x, int y, Color c,
}
}

final msk = mask?.getPixel(x, y).getChannelNormalized(maskChannel) ?? 1;
final maskPixel = mask?.getPixelSafe(x, y);
final msk = maskPixel?.getChannelNormalized(maskChannel) ?? 1;

var overlayR =
filter != null ? c.rNormalized * filter.rNormalized : c.rNormalized;
Expand Down
12 changes: 12 additions & 0 deletions test/draw/composite_image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import '../_test_util.dart';

void main() {
group('Draw', () {
test('compositeImage2', () async {
final mask = (await decodePngFile('test/_data/png/logo.png'))!;
final fg = (await decodePngFile('test/_data/png/colors.png'))!;
final bg = (await decodePngFile('test/_data/png/buck_24.png'))!;

compositeImage(bg, fg, mask: mask);

File('$testOutputPath/draw/compositeImage2.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(bg));
});

test('compositeImage', () async {
final i0 = Image(width: 256, height: 256);
final i1 = Image(width: 256, height: 256, numChannels: 4);
Expand Down

0 comments on commit c6f2c4e

Please sign in to comment.