From ea68ae87b504fa8f0b1a4600f3f8feabfeb612b8 Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 22 Nov 2005 18:10:45 +0000 Subject: [PATCH] fixes for openStream() and export properly handling subfolders on windows --- app/Sketch.java | 16 +++++++++++++++- core/PApplet.java | 42 +++++++++++++++++++++++------------------- core/todo.txt | 15 +++++++++++++++ 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/app/Sketch.java b/app/Sketch.java index c838dd4ea..a5a83393a 100644 --- a/app/Sketch.java +++ b/app/Sketch.java @@ -1817,7 +1817,11 @@ public class Sketch { //String dataFiles[] = dataFolder.list(); String dataFiles[] = Base.listFiles(dataFolder, false); int offset = folder.getAbsolutePath().length() + 1; + //int offset = dataFolder.getAbsolutePath().length() + 1; for (int i = 0; i < dataFiles.length; i++) { + if (PApplet.platform == PApplet.WINDOWS) { + dataFiles[i] = dataFiles[i].replace('\\', '/'); + } File dataFile = new File(dataFiles[i]); if (dataFile.isDirectory()) continue; @@ -1826,10 +1830,20 @@ public class Sketch { //if (dataFiles[i].charAt(0) == '.') continue; if (dataFile.getName().charAt(0) == '.') continue; + //System.out.println("placing " + dataFiles[i].substring(offset)); + //if (dataFile.isDirectory()) { + //entry = new ZipEntry(dataFiles[i].substring(offset) + "/"); + //} else { entry = new ZipEntry(dataFiles[i].substring(offset)); + //} + //if (entry.isDirectory()) { + //System.out.println(entry + " is a dir"); + //} zos.putNextEntry(entry); //zos.write(Base.grabFile(new File(dataFolder, dataFiles[i]))); - zos.write(Base.grabFile(dataFile)); //new File(folder, dataFiles[i]))); + //if (!dataFile.isDirectory()) { + zos.write(Base.grabFile(dataFile)); + //} zos.closeEntry(); } } diff --git a/core/PApplet.java b/core/PApplet.java index cae98d608..12695bd5d 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -2741,18 +2741,22 @@ public class PApplet extends Applet // IMAGE I/O + /** + * Load an image from the data folder or a local directory. + * Supports .gif (including transparency), .tga, and .jpg images. + * In Java 1.2 or later, .png images are also supported. + *

+ * As of 0096, returns null if no image of that name is found. + */ public PImage loadImage(String filename) { if (filename.toLowerCase().endsWith(".tga")) { return loadImageTGA(filename); } - return loadImage(filename, true); - } + byte bytes[] = loadBytes(filename); + if (bytes == null) return null; - // returns null if no image of that name is found - public PImage loadImage(String filename, boolean force) { - Image awtImage = - Toolkit.getDefaultToolkit().createImage(loadBytes(filename)); + Image awtImage = Toolkit.getDefaultToolkit().createImage(bytes); MediaTracker tracker = new MediaTracker(this); tracker.addImage(awtImage, 0); @@ -2767,12 +2771,14 @@ public class PApplet extends Applet PImage image = new PImage(awtImage); // if it's a .gif image, test to see if it has transparency - if (filename.toLowerCase().endsWith(".gif")) { + 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; } } } @@ -2789,6 +2795,7 @@ public class PApplet extends Applet protected PImage loadImageTGA(String filename) { // load image file as byte array byte[] buffer = loadBytes(filename); + if (buffer == null) return null; // check if it's a TGA and has 8bits/colour channel //if (buffer[2] == 2 && buffer[17] == 8) { @@ -3183,6 +3190,9 @@ public class PApplet extends Applet * If the requested item doesn't exist, null is returned. * (Prior to 0096, die() would be called, killing the applet) *

+ * for 0096, the "data" folder is exported intact with subfolders + * Bug 218 + *

* The filename passed in can be: *