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

Range Error in tests #20

Closed
felipecastrosales opened this issue Feb 2, 2023 · 7 comments
Closed

Range Error in tests #20

felipecastrosales opened this issue Feb 2, 2023 · 7 comments

Comments

@felipecastrosales
Copy link

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:

image: ^3.2.0
blurhash_dart: ^1.1.0

Everything worked normally.

What could it have been?


@brendan-duncan
Copy link

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.

@justacid
Copy link
Owner

justacid commented Feb 2, 2023

Hi,

please provide a minimal but complete reproducible example,
otherwise there is pretty much nothing anyone can help you with,
thanks.

@felipecastrosales
Copy link
Author

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 mixin_a (my current test), and mixin_b (which only changes the assets used).

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?

@brendan-duncan
Copy link

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.

@justacid
Copy link
Owner

justacid commented Feb 4, 2023

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.

@felipecastrosales
Copy link
Author

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.
00:06 +8: All tests passed!

Thank you very much for the quick response and solution. 🚀

We thank you too, @brendan-duncan.

@justacid
Copy link
Owner

justacid commented Feb 4, 2023

Glad I could help - version 1.2.1 is published on pub.dev. 👍🏻

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

3 participants