-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Weird results on reading .pixels array #7763
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
Comments
Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you! |
I am able to see this bug as well, it's pretty weird that it happens only in private windows though. Will try to find some time to look into it. |
Just an initial report, the problem seems to stem from As for why that is the case, my current suspicion is that it has to do with image compression artefact and repeatedly modifying the image and then loading its pixels triggers image compression at some point that create subtle compression noise. As for why it happens only in private windows, I don't have an idea yet so still looking. As a fix, which is good practice anyway, is to only call |
Thanks! That's intressing... I though that i have to call the Also, i had notice that the values are not consistent between the bits and hex, so it maybe something on writing directly on DOM's element? The full implementation of the |
@limzykenneth "As a fix, which is good practice anyway, is to only call loadPixels() only once, we can possibly change the internal implementation to not run loadPixels()'s code again when it has been called before though." Should there be an FES warning (or error) for multiple calls? |
I think |
Here's a minimal reproduction if anyone wants to test: let img;
function setup() {
createCanvas(400, 400);
img = createImage(8, 8);
img.loadPixels();
for(let i=0; i<img.pixels.length; i++){
img.pixels[i] = 255;
}
img.updatePixels();
}
function draw() {
background(220);
image(img, 0, 0, 400, 400);
}
function mouseReleased(){
img.loadPixels();
img.pixels[0] = 0;
img.pixels[1] = 0;
img.pixels[2] = 0;
console.log(img.pixels);
img.updatePixels();
} I'm going to try replicating with native Canvas API and if I can also replicate it there (which I suspect likely to be the case), I might just file this against Firefox directly instead. Edit: Ok, it is the same with just native API so this just a bug on Firefox side and probably not something we can fix directly. const canvasEl = document.querySelector("#canvas");
const context = canvasEl.getContext("2d");
let imageData = context.getImageData(0, 0, 8, 8);
let data = imageData.data;
for(let i=0; i<data.length; i++){
data[i] = 255;
}
context.putImageData(imageData, 0, 0);
document.addEventListener("click", () => {
let imageData = context.getImageData(0, 0, 8, 8);
let data = imageData.data;
console.log(data);
data[0] = 0;
data[1] = 0;
data[2] = 0;
context.putImageData(imageData, 0, 0);
}); |
Great work! Marking as cause since is a Firefox bug. Thanks you all. |
Just an update that the Firefox issue has been logged here: https://bugzilla.mozilla.org/show_bug.cgi?id=1963094 The behavior is somewhat by design as an anti-fingerprinting technique. There may be room to explore the exact implementation but discussion will be in the Firefox issue instead of here since we won't be able to fix this behavior. |
Most appropriate sub-area of p5.js?
p5.js version
v1.11.1
Web browser and version
Mozilla Firefox 136.0 (and others)
Operating system
Linux (and others)
Steps to reproduce this
idw if is actually a bug, but i notice a very different behavior when running a simple sketch on normal and private mode of Firefox. in case im looping trough the
.pixel
array of a tiny image created with thecreateImage()
function and put them on a both DOM's paragraphs (after converting to binary and hexadecimal values). amousePressed()
function update the image and call the functions that update the paragraphs.the strange part is that even in the online editor, as in a version hosted locally on my computer, or hosted on a github page i notice the following: in a normal firefox window everything goes as expected. but on a private tab strange results appear in the paraphs.
links to the both online editor and github pages versions:
Steps:
the source on both versions are on the following links, but ill paste the related functions
Snippet:
The text was updated successfully, but these errors were encountered: