-
Notifications
You must be signed in to change notification settings - Fork 239
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
copy function not working correctly for Java2D renderer #169
Comments
Interesting - when I replace the Are you suggesting a fix would be to check the results of the I'm happy to try this out and submit a PR, but want to know if this is the right approach. |
import processing.awt.PGraphicsJava2D;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.ImageObserver;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
PGraphicsJava2D renderer;
PImage image;
BufferedImage imgNative;
int sx = 0, sy = 0, sw = 512, sh = 512;
int dx = 32, dy = 64, dw = 256, dh = 256;
void settings() {
size(512, 512, JAVA2D);
}
void setup() {
renderer = (PGraphicsJava2D)getGraphics();
image = createImage(512, 512, ARGB);
rgb(image);
imgNative = new BufferedImage(
image.pixelWidth,
image.pixelHeight,
image.format == RGB ? BufferedImage.TYPE_INT_RGB :
BufferedImage.TYPE_INT_ARGB);
WritableRaster wr = imgNative.getRaster();
wr.setDataElements(
0, 0,
image.pixelWidth, image.pixelHeight,
image.pixels);
}
void draw() {
renderer.g2.drawImage(
imgNative,
dx, dy, dx + dw, dy + dh,
sx, sy, sx + sw, sy + sh,
(Color)null,
(ImageObserver)null);
}
PImage rgb ( PImage target ) {
target.loadPixels();
int[] px = target.pixels;
int len = px.length;
int w = target.width;
float hInv = 255.0 / ( target.height - 1.0 );
float wInv = 255.0 / ( w - 1.0 );
for ( int i = 0; i < len; ++i ) {
px[i] = 0xff000080 | ( int ) ( 0.5 + wInv * ( i % w ) ) << 0x10
| ( int ) ( 255.5 - hInv * ( i / w ) ) << 0x8;
}
target.updatePixels();
return target;
}
I'm not a Processing dev, so you'd have to ask them about the right approach, whether now is a good time to work on a PR, etc. |
This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs. |
Description
For this code:
When using the P2D renderer I see two red squares. When using the default renderer I see one. The
copy
function does not work correctly when the first parameter is a PImage object and I use the JAVA2D renderer.Expected Behavior
I expect the copy function to work the same for the JAVA2D and P2D renderers.
Current Behavior
This bug appears in 4.0a3 but not in 3.5.4.
Steps to Reproduce
Your Environment
Linux main 5.10.9-201.fc33.x86_64 Java 11, OpenJDK, ANTLR 4, and Travis #1 SMP Wed Jan 20 16:56:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Fedora release 33 (Thirty Three)
Possible Causes / Solutions
Not sure, the relevant code in PGraphicsJava2D did not change from 3.5.4 to 4.0a3:
The text was updated successfully, but these errors were encountered: