Bug 1420 : images copied have alpha channel set to FE
Last modified: 2010-02-18 06:00



Assigned To:

Attachment Type Created Size Actions
img.copy() changes alpha from 255 to 254 application/x-zip-compressed 2010-02-18 03:54 2.71 KB

Description:   Opened: 2009-12-27 15:27
My sketch requests images, on loading filters them THRESHOLD and then
copies the new image over an old one with img.copy(...)

The sketch later reads pixels from the image. Unlike the starting image,
that comes from the data directory and is a b/w png, alpha in newly fetched
images becomes FE and black becomes in hex() not FF000000 but FE000000. The
OPAQUE filter does not help.
Additional Comment #1 From fry 2010-02-17 20:02
can you post a very short example that shows the problem?
Additional Comment #2 From hungerburg 2010-02-18 03:54
img.copy() changes alpha from 255 to 254

Hello fry!

My report was a little confusing. I created a minimal sketch, its clearer now.
There is just one image that is copied over itself. Look at the console output,
press shift for a second, after the image is swapped, alpha goes from 255 to
254. filtering does not help. loadPixels neither.

PImage img; // image we want to track
PImage nimg; // next image
color c; // under mouse

void setup()
size (200, 200);
img = loadImage("some.jpg");
nimg = loadImage("some.jpg");

void draw()
image(img, 0, 0, width, height);
if(keyPressed && keyCode == SHIFT) {
img.copy(nimg, 0, 0, nimg.width, nimg.height, 0, 0, width, height);
println("image swapped.");
c = img.pixels[mouseY*img.width+mouseX];
println(mouseX+", "+mouseY+", "+alpha(c));
Additional Comment #3 From fry 2010-02-18 06:00
k, the problem is just that the image functions (like copy) aren't super
accurate. they sacrifice accuracy for speed, so there's some rounding error
as things are transferred. unfortunately that's what you're seeing here.
there's not much we can do about it short of making the image copy() method
far slower, so i think we're mostly stuck with it.

thanks for the report, i'll keep this around in case we can move to a
better solution in the future.
This bug is now being tracked here.