From 76ddb8926e08fab1c177fc63e3fd84ca7e796543 Mon Sep 17 00:00:00 2001 From: benfry Date: Mon, 4 Dec 2006 03:03:14 +0000 Subject: [PATCH] fix obscure image cache bugs when multiple renderers are used --- core/src/processing/core/PGraphicsJava2D.java | 43 ++++++++++++++----- core/todo.txt | 6 +++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 2bb6ca73a..fbbeacfe2 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -622,6 +622,14 @@ public class PGraphicsJava2D extends PGraphics { protected void imageImpl(PImage who, float x1, float y1, float x2, float y2, int u1, int v1, int u2, int v2) { + if (who.cache != null) { + if (!(who.cache instanceof ImageCache)) { + // this cache belongs to another renderer.. fix me later, + // because this is gonna make drawing *really* inefficient + //who.cache = null; + } + } + if (who.cache == null) { who.cache = new ImageCache(who); //who.updatePixels(); // mark the whole thing for update @@ -639,7 +647,7 @@ public class PGraphicsJava2D extends PGraphics { } if (who.modified) { - cash.update(); + cash.update(tint, tintColor); who.modified = false; } @@ -664,7 +672,14 @@ public class PGraphicsJava2D extends PGraphics { image = new BufferedImage(source.width, source.height, type); } - public void update() { //boolean t, int argb) { + // for rev 0124, passing the tintColor in here. the problem is that + // the 'parent' PGraphics object of this inner class may not be + // the same one that's used when drawing. for instance, if this + // is a font used by the main drawing surface, then it's later + // used in an offscreen PGraphics, the tintColor value from the + // original PGraphics will be used. + public void update(boolean tint, int tintColor) { + if ((source.format == ARGB) || (source.format == RGB)) { if (tint) { // create tintedPixels[] if necessary @@ -672,12 +687,10 @@ public class PGraphicsJava2D extends PGraphics { tintedPixels = new int[source.width * source.height]; } - //int argb2 = tintColor; int a2 = (tintColor >> 24) & 0xff; int r2 = (tintColor >> 16) & 0xff; int g2 = (tintColor >> 8) & 0xff; int b2 = (tintColor) & 0xff; - //System.out.println("a2 is " + a2); // multiply each of the color components into tintedPixels // if straight RGB image, don't bother multiplying @@ -717,14 +730,20 @@ public class PGraphicsJava2D extends PGraphics { tintedColor = tintColor; // finally, do a setRGB based on tintedPixels - image.setRGB(0, 0, source.width, source.height, - tintedPixels, 0, source.width); + //image.setRGB(0, 0, source.width, source.height, + // tintedPixels, 0, source.width); + WritableRaster raster = ((BufferedImage) image).getRaster(); + raster.setDataElements(0, 0, source.width, source.height, + tintedPixels); } else { // no tint // just do a setRGB like before // (and we'll just hope that the high bits are set) - image.setRGB(0, 0, source.width, source.height, - source.pixels, 0, source.width); + //image.setRGB(0, 0, source.width, source.height, + // source.pixels, 0, source.width); + WritableRaster raster = ((BufferedImage) image).getRaster(); + raster.setDataElements(0, 0, source.width, source.height, + tintedPixels); } } else if (source.format == ALPHA) { @@ -734,6 +753,7 @@ public class PGraphicsJava2D extends PGraphics { int lowbits = tintColor & 0x00ffffff; if (((tintColor >> 24) & 0xff) >= 254) { + //PApplet.println(" no alfa " + PApplet.hex(tintColor)); // no actual alpha to the tint, set the image's alpha // as the high 8 bits, and use the color as the low 24 bits for (int i = 0; i < tintedPixels.length; i++) { @@ -743,6 +763,7 @@ public class PGraphicsJava2D extends PGraphics { } } else { + //PApplet.println(" yes alfa " + PApplet.hex(tintColor)); // multiply each image alpha by the tint alpha int alphabits = (tintColor >> 24) & 0xff; for (int i = 0; i < tintedPixels.length; i++) { @@ -756,8 +777,10 @@ public class PGraphicsJava2D extends PGraphics { tintedColor = tintColor; // finally, do a setRGB based on tintedPixels - image.setRGB(0, 0, source.width, source.height, - tintedPixels, 0, source.width); + //image.setRGB(0, 0, source.width, source.height, + // tintedPixels, 0, source.width); + WritableRaster raster = ((BufferedImage) image).getRaster(); + raster.setDataElements(0, 0, source.width, source.height, tintedPixels); } } } diff --git a/core/todo.txt b/core/todo.txt index dc83a9780..fe143722f 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -4,6 +4,12 @@ X but on osx, apple defaults the image smoothing to true X http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1164753510 X http://developer.apple.com/documentation/Java/Conceptual/JavaPropVMInfoRef/Articles/JavaSystemProperties.html#//apple_ref/doc/uid/TP40001975-DontLinkElementID_6 X background(0, 0, 0, 0) was resetting stroke, smooth, etc. +X make imageImpl() use WritableRaster in an attempt to speed things up +X fix weird situation where fonts used in more than one renderer wouldn't show + +_ calling graphics.smooth(), graphics.colorMode() outside begin/endDraw +_ this causes everything to be reset once the draw occurs +_ kinda seems problematic and prone to errors? _ loadImage() requires an extension, maybe add a second version? _ loadImage("blah", "jpg");