Skip to content

Commit 1a32b5a

Browse files
committed
ported fixes from RC
1 parent 3e70df9 commit 1a32b5a

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

core/src/processing/core/PImage.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ public Object clone() throws CloneNotSupportedException { // ignore
373373
* Use 0 for wide or high to make that dimension scale proportionally.
374374
*/
375375
public void resize(int w, int h) { // ignore
376+
if (bitmap == null) {
377+
return; // Cannot resize an image not backed by a bitmap
378+
}
379+
376380
if (w <= 0 && h <= 0) {
377381
throw new IllegalArgumentException("width or height must be > 0 for resize");
378382
}
@@ -385,11 +389,15 @@ public void resize(int w, int h) { // ignore
385389
h = (int) (height * diff);
386390
}
387391
bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
392+
if (pixels != null) {
393+
// Resize pixels array, if in use.
394+
pixels = new int[w * h];
395+
bitmap.getPixels(pixels, 0, w, 0, 0, w, h);
396+
}
388397
this.width = w;
389398
this.height = h;
390-
391-
// Mark the pixels array as altered
392-
updatePixels();
399+
this.pixelWidth = w * pixelDensity;
400+
this.pixelHeight = h * pixelDensity;
393401
}
394402

395403

@@ -513,6 +521,8 @@ public PImage get(int x, int y, int w, int h) {
513521
target.parent = parent; // parent may be null so can't use createImage()
514522
if (w > 0 && h > 0) {
515523
getImpl(x, y, w, h, target, targetX, targetY);
524+
Bitmap nat = Bitmap.createBitmap(target.pixels, targetWidth, targetHeight, Config.ARGB_8888);
525+
target.setNative(nat);
516526
}
517527
return target;
518528
}
@@ -527,11 +537,11 @@ public PImage get(int x, int y, int w, int h) {
527537
protected void getImpl(int sourceX, int sourceY,
528538
int sourceWidth, int sourceHeight,
529539
PImage target, int targetX, int targetY) {
530-
if (pixels == null) {
540+
if (bitmap != null) {
531541
bitmap.getPixels(target.pixels,
532542
targetY*target.width + targetX, target.width,
533543
sourceX, sourceY, sourceWidth, sourceHeight);
534-
} else {
544+
} else if (pixels != null) {
535545
int sourceIndex = sourceY*width + sourceX;
536546
int targetIndex = targetY*target.width + targetX;
537547
for (int row = 0; row < sourceHeight; row++) {
@@ -2863,4 +2873,4 @@ public boolean save(String path) { // ignore
28632873
}
28642874
return success;
28652875
}
2866-
}
2876+
}

core/src/processing/opengl/PGL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ protected Texture wrapBackTexture(Texture texture) {
544544
glColorTex.get(backTex), TEXTURE_2D, RGBA,
545545
fboWidth, fboHeight, NEAREST, NEAREST,
546546
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
547-
texture.invertedY(graphics.cameraUp);
547+
texture.invertedY(!graphics.cameraUp);
548548
texture.colorBuffer(true);
549549
graphics.setCache(graphics, texture);
550550
} else {
@@ -561,7 +561,7 @@ protected Texture wrapFrontTexture(Texture texture) {
561561
glColorTex.get(frontTex), TEXTURE_2D, RGBA,
562562
fboWidth, fboHeight, NEAREST, NEAREST,
563563
CLAMP_TO_EDGE, CLAMP_TO_EDGE);
564-
texture.invertedY(graphics.cameraUp);
564+
texture.invertedY(!graphics.cameraUp);
565565
texture.colorBuffer(true);
566566
} else {
567567
texture.glName = glColorTex.get(frontTex);
@@ -3330,4 +3330,4 @@ public void bindFramebuffer(int target, int framebuffer) {
33303330
public abstract void renderbufferStorageMultisample(int target, int samples, int format, int width, int height);
33313331
public abstract void readBuffer(int buf);
33323332
public abstract void drawBuffer(int buf);
3333-
}
3333+
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6075,7 +6075,7 @@ protected void loadTextureImpl(int sampling, boolean mipmap) {
60756075
Texture.Parameters params = new Texture.Parameters(ARGB,
60766076
sampling, mipmap);
60776077
texture = new Texture(this, pixelWidth, pixelHeight, params);
6078-
texture.invertedY(cameraUp);
6078+
texture.invertedY(!cameraUp);
60796079
texture.colorBuffer(true);
60806080
setCache(this, texture);
60816081
}
@@ -6086,7 +6086,7 @@ protected void createPTexture() {
60866086
updatePixelSize();
60876087
if (texture != null) {
60886088
ptexture = new Texture(this, pixelWidth, pixelHeight, texture.getParameters());
6089-
ptexture.invertedY(cameraUp);
6089+
ptexture.invertedY(!cameraUp);
60906090
ptexture.colorBuffer(true);
60916091
}
60926092
}
@@ -6226,7 +6226,7 @@ public void filter(PShader shader) {
62266226
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62276227
filterTexture = new Texture(this, texture.width, texture.height,
62286228
texture.getParameters());
6229-
filterTexture.invertedY(cameraUp);
6229+
filterTexture.invertedY(!cameraUp);
62306230
filterImage = wrapTexture(filterTexture);
62316231
}
62326232
filterTexture.set(texture);
@@ -6296,7 +6296,7 @@ public void copy(int sx, int sy, int sw, int sh,
62966296
loadTexture();
62976297
if (filterTexture == null || filterTexture.contextIsOutdated()) {
62986298
filterTexture = new Texture(this, texture.width, texture.height, texture.getParameters());
6299-
filterTexture.invertedY(cameraUp);
6299+
filterTexture.invertedY(!cameraUp);
63006300
filterImage = wrapTexture(filterTexture);
63016301
}
63026302
filterTexture.put(texture, sx, height - (sy + sh), sw, height - sy);
@@ -6616,7 +6616,7 @@ protected Texture addTexture(PImage img, Texture.Parameters params) {
66166616
img.parent = parent;
66176617
}
66186618
Texture tex = new Texture(this, img.pixelWidth, img.pixelHeight, params);
6619-
tex.invertedY(!cameraUp); // Pixels are read upside down
6619+
tex.invertedY(cameraUp); // Pixels are read upside down if camera us pointing up
66206620
setCache(img, tex);
66216621
return tex;
66226622
}
@@ -13782,4 +13782,4 @@ static void rotateRight(int[] array, int i1, int i2) {
1378213782

1378313783
}
1378413784

13785-
}
13785+
}

0 commit comments

Comments
 (0)