Skip to content

Commit

Permalink
more efficient implementation of setImpl()
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed May 31, 2015
1 parent 6789f4d commit f322547
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions core/src/processing/opengl/PGraphicsOpenGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -5733,20 +5733,21 @@ protected void setImpl(PImage sourceImage,
int sourceX, int sourceY,
int sourceWidth, int sourceHeight,
int targetX, int targetY) {
// Copies the pixels
loadPixels();
super.setImpl(sourceImage, sourceX, sourceY, sourceWidth, sourceHeight,
targetX, targetY);
// do we need this?
// see https://github.com/processing/processing/issues/2125
// if (sourceImage.format == RGB) {
// int targetOffset = targetY * width + targetX;
// for (int y = sourceY; y < sourceY + sourceHeight; y++) {
// for (int x = targetOffset; x < targetOffset + sourceWidth; x++) {
// pixels[x] |= 0xff000000;
// }
// targetOffset += width;
// }
// }
int sourceOffset = sourceY * sourceImage.pixelWidth + sourceX;
int targetOffset = targetY * pixelWidth + targetX;
for (int y = sourceY; y < sourceY + sourceHeight; y++) {
System.arraycopy(sourceImage.pixels, sourceOffset, pixels, targetOffset, sourceWidth);
sourceOffset += sourceImage.pixelWidth;
targetOffset += pixelWidth;
}

// Draws the texture, copy() is very efficient because it simply renders
// the texture cache of sourceImage using OpenGL.
copy(sourceImage,
sourceX, sourceY, sourceWidth, sourceHeight,
targetX, targetY, sourceWidth, sourceHeight);
}


Expand Down Expand Up @@ -5893,7 +5894,8 @@ protected void drawTexture(int x, int y, int w, int h) {
// Processing Y axis is inverted with respect to OpenGL, so we need to
// invert the y coordinates of the screen rectangle.
pgl.disable(PGL.BLEND);
pgl.drawTexture(texture.glTarget, texture.glName, texture.glWidth, texture.glHeight,
pgl.drawTexture(texture.glTarget, texture.glName,
texture.glWidth, texture.glHeight,
0, 0, width, height,
x, y, x + w, y + h,
x, height - (y + h), x + w, height - y);
Expand Down

0 comments on commit f322547

Please sign in to comment.