From fa4e115d9f0ad32d845e43ab53ba8a4711e2f550 Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 16 May 2006 15:22:49 +0000 Subject: [PATCH] fix transparency with new imageio (bug #350), add bug num to revisions.txt for lighting stuff --- build/shared/revisions.txt | 1 + core/PApplet.java | 32 ++++++++++++++++++++------------ core/PImage.java | 17 +++++++++++++++++ core/todo.txt | 17 +++++++++-------- todo.txt | 2 ++ 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 56f3c6bf1..1fe662389 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -140,6 +140,7 @@ Lots of OpenGL bug fixes, and some big OS X fixes too. http://dev.processing.org/bugs/show_bug.cgi?id=189 + Fix lighting issues with that were introduced in revision 0109. + http://dev.processing.org/bugs/show_bug.cgi?id=316 + Now checking maximum supported texture sizes for the video card when using OpenGL. It will now throw a RuntimeException to avoid diff --git a/core/PApplet.java b/core/PApplet.java index 506f178a7..440fa6ff0 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -3056,6 +3056,12 @@ public class PApplet extends Applet * println(javax.imageio.ImageIO.getReaderFormatNames()) */ public PImage loadImage(String filename) { + // it's not clear whether this method is more efficient for + // loading gif, jpeg, and png data than the standard toolkit function, + // in fact it may even be identical. but who knows, with any luck + // it may even fix the image loading problems from bug #279. + // http://dev.processing.org/bugs/show_bug.cgi?id=279 + // (if anyone reading this knows for certain, please post) if (PApplet.javaVersion >= 1.4f) { if (loadImageFormats == null) { //loadImageFormats = javax.imageio.ImageIO.getReaderFormatNames(); @@ -3112,21 +3118,15 @@ public class PApplet extends Applet // if it's a .gif image, test to see if it has transparency if ((filename.toLowerCase().endsWith(".gif")) || (filename.toLowerCase().endsWith(".png"))) { - for (int i = 0; i < image.pixels.length; i++) { - // since transparency is often at corners, hopefully this - // will find a non-transparent pixel quickly and exit - if ((image.pixels[i] & 0xff000000) != 0xff000000) { - image.format = ARGB; - break; - } - } + image.checkAlpha(); } return image; } /** - * + * Use Java 1.4 ImageIO methods to load an image. All done via reflection + * in order to maintain compatability with previous releases. */ protected PImage loadImageIO(String filename) { InputStream stream = openStream(filename); @@ -3150,14 +3150,17 @@ public class PApplet extends Applet Method getHeightMethod = biClass.getMethod("getHeight", (Class[]) null); Integer hi = (Integer) getHeightMethod.invoke(bimage, (Object[]) null); - //int h = hi.intValue(); Method getWidthMethod = biClass.getMethod("getWidth", (Class[]) null); Integer wi = (Integer) getWidthMethod.invoke(bimage, (Object[]) null); - //int w = wi.intValue(); - // need to call getType() on the image to see if RGB or ARGB + // was gonna call getType() on the image to see if RGB or ARGB, + // but it's not actually useful, since gif images will come through + // as TYPE_BYTE_INDEXED, which means it'll still have to check for + // the transparency. also, would have to iterate through all the other + // types and guess whether alpha was in there, so.. just gonna stick + // with the old method. PImage outgoing = new PImage(wi.intValue(), hi.intValue()); @@ -3171,6 +3174,11 @@ public class PApplet extends Applet new Integer(outgoing.width), new Integer(outgoing.height), outgoing.pixels, new Integer(0), new Integer(outgoing.width) }); + + // check the alpha for this image + outgoing.checkAlpha(); + + // return the image return outgoing; } catch (Exception e) { diff --git a/core/PImage.java b/core/PImage.java index 09a0339fc..4df244cde 100644 --- a/core/PImage.java +++ b/core/PImage.java @@ -144,6 +144,23 @@ public class PImage implements PConstants, Cloneable { } + /** + * Check the alpha on an image, using a really primitive loop. + */ + protected void checkAlpha() { + if (pixels == null) return; + + for (int i = 0; i < pixels.length; i++) { + // since transparency is often at corners, hopefully this + // will find a non-transparent pixel quickly and exit + if ((pixels[i] & 0xff000000) != 0xff000000) { + format = ARGB; + break; + } + } + } + + /** * Construct a new PImage from a java.awt.Image. This constructor assumes * that you've done the work of making sure a MediaTracker has been used diff --git a/core/todo.txt b/core/todo.txt index 5c01c4c0b..fdaafb5dd 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -16,6 +16,9 @@ X fix issue where processing applets would run extremely fast X after having been starved of resources where there framerate dropped X http://dev.processing.org/bugs/show_bug.cgi?id=336 X added color/stroke/tint/fill(#FF8800, 30); +X test imageio with images that have alpha (does it work?) +X nope, doesn't, didn't finish support +X http://dev.processing.org/bugs/show_bug.cgi?id=350 fixed in 0115 / quicktime 7.1 X color values on camera input flipped on intel macs @@ -57,15 +60,9 @@ _ http://dev.processing.org/bugs/show_bug.cgi?id=346 _ bring back the old P2D, rename PGraphics2 into PGraphicsJava _ remove POLYGON, LINE_LOOP, LINE_STRIP - _ an image marked RGB but with 0s for the alpha won't draw in JAVA2D - -_ test imageio with images that have alpha (does it work?) - -_ get tiff exporter for p5 to support argb and gray -_ would also need to modify the tiff loading code, -_ because the header would be different -_ http://dev.processing.org/bugs/show_bug.cgi?id=343 +_ also if transparency set but RGB is setting, still honors transparency +_ http://dev.processing.org/bugs/show_bug.cgi?id=351 _ this produces a dark blue background: colorMode(RGB, 100); @@ -705,6 +702,10 @@ _ specifically, which tags that were in the original image file _ perhaps something gets corrected? _ loadImage() using spaces in the name _ if loadImage() with spaces when online(), throw an error +_ get tiff exporter for p5 to support argb and gray +_ would also need to modify the tiff loading code, +_ because the header would be different +_ http://dev.processing.org/bugs/show_bug.cgi?id=343 CORE / Documentation diff --git a/todo.txt b/todo.txt index 64caabada..9d568eec9 100644 --- a/todo.txt +++ b/todo.txt @@ -103,6 +103,8 @@ X move 'how do i create large images' here _ move stuff about getting gl object and java2d stuff here _ explain how to integrate code with swing _ use a separate environment, call init(), use noLoop(), redraw() +_ use JPopupMenu.setDefaultLightWeightPopupEnabled(false); for zorder +_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1147670059 _ how do i add gui to a sketch? _ don't use awt components _ how to use swing and embed components inside p5