Skip to content

copy function not working correctly for Java2D renderer #169

Closed
@processing-bot

Description

@processing-bot

Created by: hx2A

Description

For this code:

void setup() {
  size(400, 400, P2D);

  // create a simple image with only red pixels
  PImage red_img = createImage(50, 50, RGB);
  color red = color(255, 0, 0);
  red_img.loadPixels();
  for (int i = 0; i < red_img.pixels.length; i++) {
    red_img.pixels[i] = red;
  }
  red_img.updatePixels();
  
  // first red square
  image(red_img, 50, 50);
  // second red square, but only appears for P2D renderer
  copy(red_img, 0, 0, 50, 50, 250, 250, 50, 50);
}

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

  1. Run the above code
  2. Change the above code to use the default renderer
  3. Run code again, observing the difference

Your Environment

Possible Causes / Solutions

Not sure, the relevant code in PGraphicsJava2D did not change from 3.5.4 to 4.0a3:

  public void copy(PImage src,
                   int sx, int sy, int sw, int sh,
                   int dx, int dy, int dw, int dh) {
    g2.drawImage((Image) src.getNative(),
                 dx, dy, dx + dw, dy + dh,
                 sx, sy, sx + sw, sy + sh, null);
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions