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

Feature scanIterator #781

Merged
merged 3 commits into from Sep 6, 2019
Merged

Feature scanIterator #781

merged 3 commits into from Sep 6, 2019

Conversation

ghost
Copy link

@ghost ghost commented Aug 31, 2019

What's Changing and Why

Currently with image.scan it's possible to iterate over the image with a callback

But on some cases it's better if it would possible to iterate with a for loop, like:

for (const { x, y, idx, image } of image.scanIterator(0, 0, image.bitmap.width, image.bitmap.height)) {
    ...
}

An advantage would be too, it's possible to abort the scan with break;, with the callback this is not possible (currently)

What else might be affected

I also change image.scan to use internal the new scanIterator and call the callback

Tasks

  • Add tests
  • Update Documentation
  • Update jimp.d.ts
  • Add SemVer Label

@hipstersmoothie hipstersmoothie added the minor Increment the minor version when merged label Sep 3, 2019
@hipstersmoothie
Copy link
Collaborator

Does this have any performance implications? I'd be hesitant to make this the default if it makes things slower since scan is used by almost every function.

@ghost
Copy link
Author

ghost commented Sep 3, 2019

@hipstersmoothie Thanks for your hint

I made some measuring tests (10000px x 10000px Jimp image) and I take values like:

Measure scanCallback: 500ms
Measure scanCallbackWithIterator: 2933ms
Measure scanIterator: 2338ms

So you're right and the iterator is very slow and I revert the scan function change

Copy link
Collaborator

@hipstersmoothie hipstersmoothie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some docs to the jimp package's README? Please make sure to note the performance implication.

@hipstersmoothie hipstersmoothie merged commit b2f8dfb into jimp-dev:master Sep 6, 2019
@hipstersmoothie
Copy link
Collaborator

🚀 PR was released in v0.7.0 🚀

@hipstersmoothie hipstersmoothie added the released This issue/pull request has been released. label Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant