-
Notifications
You must be signed in to change notification settings - Fork 21
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
Range Error in tests #20
Comments
As mentioned in the other thread, I can't support 3.2.0. It looks like blurhash_dart has updated to the 4.x image version, so make sure you run pub upgrade to get the latest versions of libraries. You also posted in the other thread which was specifically related to encoding to the BMP format. It's not clear here that your issues has anything to do with the BMP format. So without more information, there's nothing I can do to help. |
Hi, please provide a minimal but complete reproducible example, |
Hi @justacid and @brendan-duncan, first thank you for your availability. As requested, below is my example code. • https://github.com/felipecastrosales/image_blurhash Explaning about the example above, I have a What perhaps made a test not pass was precisely this differentiation of assets. As the pixel is based on the image, and consequently the blurhash calculation as well, this impacted the tests. A modification I made to the package so that my tests passed with the previous assets was to make the modification below: for (var i = 0; i < width; ++i) {
for (var j = 0; j < height; ++j) {
final basis = normalisation *
cos((pi * x * i) / width) *
cos((pi * y * j) / height);
// Before
// r += basis *
// sRgbToLinear(pixels[channelOrderLength * i + 0 + j * bytesPerRow]);
// g += basis *
// sRgbToLinear(pixels[channelOrderLength * i + 1 + j * bytesPerRow]);
// b += basis *
// sRgbToLinear(pixels[channelOrderLength * i + 2 + j * bytesPerRow]);
// After - with the modification
final channelOrderLengthbytesPerRow =
channelOrderLength * i + 0 + j * bytesPerRow;
final fixedChannelOrderLengthbytesPerRow =
channelOrderLengthbytesPerRow >= pixels.length
? pixels.length - 3
: channelOrderLengthbytesPerRow;
r += basis * sRgbToLinear(pixels[fixedChannelOrderLengthbytesPerRow]);
g += basis *
sRgbToLinear(pixels[fixedChannelOrderLengthbytesPerRow + 1]);
b += basis *
sRgbToLinear(pixels[fixedChannelOrderLengthbytesPerRow + 2]);
}
}
} I'm not sure what the impacts of that would be, but that's what worked. Given this, what could be the best option to be followed here? |
Is pixels an img.Image? If so, with 4.x, you should a pixel iterator: for (final p in pixels) {
final basis = normalisation *
cos((pi * x * p.x) / width) *
cos((pi * y * p.y) / height);
r += basis * sRgbToLinear(p.r);
g += basis * sRgbToLinear(p.g);
b += basis * sRgbToLinear(p.b);
} In Image 4.x, Image data is stored in Pixels, not raw data, to be able to accommodate many different types of image formats. Your fixelChannelOrderLengthbytesPerRow is indexing into the raw data ad assumes the image image an 8-bit rgb/rgba image. You can use the Image.getPixel(x, y) to get the pixel at a specific coordinate. |
Pixels wasn't an img.Image... yet. Thanks for the pointer to the pixel iterator @brendan-duncan. I opened a PR with a fix (#21) and tested with the reproducible example from above. If you confirm it works (@felipecastrosales) I'll merge and push a new release asap. |
Hey guys! @justacid, it really worked! The tests ran normally and successfully. Now everyone is successful. And I made a push in case anyone wants to test it, here. Thank you very much for the quick response and solution. 🚀 We thank you too, @brendan-duncan. |
Glad I could help - version 1.2.1 is published on pub.dev. 👍🏻 |
Hi, @justacid.
I have this error in some tests and it shows me this.
RangeError (index): Index out of range: index should be less than 57600: 57600
In project, with this versions:
Everything worked normally.
What could it have been?
The text was updated successfully, but these errors were encountered: