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

Add required parameters in _flipPixels function #6726

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

mohitbalwani
Copy link
Contributor

@mohitbalwani mohitbalwani commented Jan 10, 2024

Resolves #6724

Changes:

The flipPixels function don't has access to width and height so it will give undefined error whenever we call it.

Screenshots of the change:

PR Checklist

Copy link

welcome bot commented Jan 10, 2024

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@@ -375,7 +375,7 @@ p5.prototype.saveGif = async function(
pixels
);

data = _flipPixels(pixels);
data = _flipPixels(pixels, this.width, this.height);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix! Does this still work correctly when you've set pixelDensity(2) in setup? I wonder if we need to be multiplying by the density here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried using pixelDensity() in setup but nothing was being rendered. Am I missing something in this code?

let sketch = function(p) {
  p.setup = function() {
    pixelDensity(2);
    p.createCanvas(500, 500, p.WEBGL);
  };

  p.draw = function() {
  };

  p.keyPressed = function() {
    if (p.key === 's') {
      p.saveGif('test', 5);
    }
  }
};

let myp5 = new p5(sketch);

Copy link
Contributor

Choose a reason for hiding this comment

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

In instance mode I think you need p.pixelDensity(2).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ya. Thanks!

The current fix works as expected when setting different densities of pixels.

I also checked the behaviour by multiplying the dimensions with density while passing in function call but I was getting another console error saying : offset is out of bounds. So, looks like some calculations go wrong inside flipPixels function in the case when we multiply dimensions with density.

I saw a similar implementation in readPixelsWebGL() function and stackoverflow answers (https://stackoverflow.com/questions/41969562/how-can-i-flip-the-result-of-webglrenderingcontext-readpixels) so looks like we should not consider multiplying by density here? Or maybe we need to recalculate the flip pixels logic considering density (I tried that but wasn't able to figure out).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, wait, logically it should have it, but we just set it to 1 here while exporting:

this.pixelDensity(1);

So I think width/height on its own is fine!

@davepagurek davepagurek merged commit d04d3b2 into processing:main Jan 17, 2024
2 checks passed
Copy link
Contributor

@davepagurek

I've put up a pull request to add @mohitbalwani! 🎉

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

Successfully merging this pull request may close these issues.

Error when using saveGif() in instance mode and WEBGL mode
2 participants