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

set(0, 0, image) does not set alpha channel to opaque in P2D/P3D #2125

Closed
benfry opened this Issue Oct 9, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@benfry
Member

benfry commented Oct 9, 2013

Using set(0, 0, image) to set the background doesn't set the alpha channel opaque for the pixels that it covers.

As a result, calling get() or saveFrame() on that PGraphics will leave out the pixels written with set().

@ghost ghost assigned codeanticode Oct 9, 2013

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Oct 11, 2013

Member

Done properly, an RGB image should be completely opaque, so the pixels may need |= 0xFF000000 so that they're set properly. An ARGB image should retain the transparency of the A channel.

set() is quite literal about setting the pixels to those that are found in the image, but the assumption needs to be that an RGB format image will have its high bits set when drawn into an ARGB surface.

Member

benfry commented Oct 11, 2013

Done properly, an RGB image should be completely opaque, so the pixels may need |= 0xFF000000 so that they're set properly. An ARGB image should retain the transparency of the A channel.

set() is quite literal about setting the pixels to those that are found in the image, but the assumption needs to be that an RGB format image will have its high bits set when drawn into an ARGB surface.

@codeanticode

This comment has been minimized.

Show comment
Hide comment
@codeanticode

codeanticode Oct 25, 2013

Member

@benfry In which cases the background is not set to opaque? I tried the following code:

PImage img;

void setup() {
  size(300, 300, P2D);
  img = loadImage("berlin-1.jpg");
  println(img.format);
}

void draw() {
  set(0, 0, img);

  int c = get(mouseX, mouseY);
  println(alpha(c));
}

with both an jpg image and a png with transparency. In the first case, all the pixels report to have an alpha of 255, in the second, the appropriate alpha for each pixel is printed out.

Member

codeanticode commented Oct 25, 2013

@benfry In which cases the background is not set to opaque? I tried the following code:

PImage img;

void setup() {
  size(300, 300, P2D);
  img = loadImage("berlin-1.jpg");
  println(img.format);
}

void draw() {
  set(0, 0, img);

  int c = get(mouseX, mouseY);
  println(alpha(c));
}

with both an jpg image and a png with transparency. In the first case, all the pixels report to have an alpha of 255, in the second, the appropriate alpha for each pixel is printed out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment