Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply mask throw RangeError on getting R color (Not in inclusive range 0..639999: 640000) #697

Open
g-apparence opened this issue Dec 13, 2024 · 3 comments

Comments

@g-apparence
Copy link

g-apparence commented Dec 13, 2024

file : pixel_uint8.dart line 146

ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (length): Invalid value: Not in inclusive range 0..639999: 640000
#0      Uint8List.[] (dart:typed_data-patch/typed_data_patch.dart)
#1      PixelUint8.index (package:image/src/image/pixel_uint8.dart:141:24)
pixel_uint8.dart:141
#2      PixelUint8.r (package:image/src/image/pixel_uint8.dart:148:13)
pixel_uint8.dart:148
#3      getLuminance (package:image/src/util/color_util.dart:129:40)
color_util.dart:129
#4      PixelUint8.luminance (package:image/src/image/pixel_uint8.dart:234:47)
pixel_uint8.dart:234
#5      PixelUint8.getChannel (package:image/src/image/pixel_uint8.dart:241:38)
pixel_uint8.dart:241
#6      PixelUint8.getChannelNormalized (package:image/src/image/pixel_uint8.dart:245:7)
pixel_uint8.dart:245
#7      drawPixel (package:image/src/draw/draw_pixel.dart:31:36)
draw_pixel.dart:31
#8      _composite (package:image/src/draw/composite_image.dart:136:7)
composite_image.dart:136
#9      compositeImage (package:image/src/draw/composite_image.dart:71:5)
@override
  num get r => palette == null
      ? numChannels > 0
          ? data[_index] // throws here 
          : 0
      : palette!.getRed(data[_index]);

Here is the code I used to do it

final maskImgRes = await rootBundle.load(preset.assetPath);
final maskImgBytes = maskImgRes.buffer.asUint8List();
final maskImg = img.decodeImage(maskImgBytes);
print("...mask loaded");

final imgBytes = await widget.drawable.image.toByteData(format: ui.ImageByteFormat.png);
final srcImg = img.decodeImage(imgBytes!.buffer.asUint8List());
print("...image loaded");

// var dst = img.Image.from(srcImg!);
var dst = img.Image(width: widget.drawable.image.width, height: widget.drawable.image.height, numChannels: 4);
print("...dst image loaded");

dst = img.compositeImage(
  dst, 
  srcImg!,
  mask: maskImg,
  // maskChannel: img.Channel.luminance,
);
print("...image masked");
final encodedPng = img.encodePng(dst);
final resultImage = await decodeImageFromList(encodedPng);

Flutter image version 4.3.0
Device iOS simulator running on iOS 18.1 and impeller.

ps: really love the work you made on this. Thanks a lot.

@brendan-duncan
Copy link
Owner

Thanks for the report. I fixed it in git. Wasn't range checking the mask sample. I'll be doing a release soon.

@brendan-duncan
Copy link
Owner

Just published 4.5.0

@g-apparence
Copy link
Author

Thanks a lot! 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants