From d2dd29fe47e24116504ca091fdcd6371bdaa0e5a Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Sat, 6 Aug 2005 05:28:43 +0000 Subject: [PATCH] 2005-08-06 Pierre-Luc Paour (1.4.2-b24) * GR can now find ImageMagick on its own on Windows, by looking in the registry. Using a newer version of IM can speed up image operations by a factor of 2! It is now recommended to install IM independantly of GR to get this benefit. This is all the more important for the applet. --- ChangeLog | 8 ++++ .../GalleryRemote/util/ImageUtils.java | 45 ++++++++++++++++--- defaults.properties | 4 +- imagemagick/im.properties.applet | 2 +- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67013b7..164dc4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-08-06 Pierre-Luc Paour (1.4.2-b24) + + * GR can now find ImageMagick on its own on Windows, by looking in + the registry. Using a newer version of IM can speed up image + operations by a factor of 2! It is now recommended to + install IM independantly of GR to get this benefit. + This is all the more important for the applet. + 2005-07-30 Pierre-Luc Paour (1.4.2-b23) * Now using the new format for the remote controller URL in G2. diff --git a/com/gallery/GalleryRemote/util/ImageUtils.java b/com/gallery/GalleryRemote/util/ImageUtils.java index e1a0047..7bcb807 100644 --- a/com/gallery/GalleryRemote/util/ImageUtils.java +++ b/com/gallery/GalleryRemote/util/ImageUtils.java @@ -41,6 +41,8 @@ import java.net.URLConnection; import java.util.*; import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.Matcher; import org.w3c.dom.Node; import org.w3c.dom.NamedNodeMap; @@ -617,7 +619,7 @@ public static LocalInfo getLocalFilenameForPicture(Picture p, boolean full) { URL u = null; Dimension d = null; - if (full == false && p.getSizeResized() == null) { + if (!full && p.getSizeResized() == null) { // no resized version return null; } @@ -854,7 +856,27 @@ public static Dimension getPictureDimension(Picture p) { imIgnoreErrorCode = p.getBooleanProperty("im.ignoreErrorCode", imIgnoreErrorCode); Log.log(Log.LEVEL_INFO, MODULE, "imIgnoreErrorCode: " + imIgnoreErrorCode); - if (imPath.indexOf("/") == -1 && imPath.indexOf("\\") == -1) { + if (imPath.indexOf('/') == -1 && imPath.indexOf('\\') == -1 + && System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { + // we're on Windows with an abbreviated path: look up IM in the registry + StringBuffer output = new StringBuffer(); + exec("reg query HKLM\\Software\\ImageMagick\\Current /v BinPath", output); + + Pattern pat = Pattern.compile("^\\s*BinPath\\s*REG_SZ\\s*(.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + //Pattern pat = Pattern.compile("BinPath", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + Matcher m = pat.matcher(output.toString()); + if (m.find()) { + imPath = m.group(1) + "\\" + imPath; + + if (!imPath.endsWith(".exe")) { + imPath += ".exe"; + } + + Log.log(Log.LEVEL_INFO, MODULE, "Found ImageMagick in registry. imPath is now " + imPath); + } + } + + if (imPath.indexOf('/') == -1 && imPath.indexOf('\\') == -1) { Log.log(Log.LEVEL_CRITICAL, MODULE, "ImageMagick path is not fully qualified, " + "presence won't be tested until later"); } else if (!new File(imPath).exists()) { @@ -915,7 +937,7 @@ public static Dimension getPictureDimension(Picture p) { jpegtranIgnoreErrorCode = p.getBooleanProperty("jp.ignoreErrorCode", jpegtranIgnoreErrorCode); Log.log(Log.LEVEL_INFO, MODULE, "jpegtranIgnoreErrorCode: " + jpegtranIgnoreErrorCode); - if (jpegtranPath.indexOf("/") == -1 && jpegtranPath.indexOf("\\") == -1) { + if (jpegtranPath.indexOf('/') == -1 && jpegtranPath.indexOf('\\') == -1) { Log.log(Log.LEVEL_CRITICAL, MODULE, "jpegtran path is not fully qualified, " + "presence won't be tested until later"); } @@ -1094,12 +1116,16 @@ public static java.util.List listFilesRecursive(File dir) } public static int exec(String cmdline) { + return exec(cmdline, null); + } + + public static int exec(String cmdline, StringBuffer output) { Log.log(Log.LEVEL_TRACE, MODULE, "Executing " + cmdline); try { Process p = Runtime.getRuntime().exec(cmdline); - return pumpExec(p); + return pumpExec(p, output); } catch (InterruptedException e) { Log.logException(Log.LEVEL_ERROR, MODULE, e); return -1; @@ -1111,12 +1137,16 @@ public static int exec(String cmdline) { } public static int exec(String[] cmd) { + return exec(cmd, null); + } + + public static int exec(String[] cmd, StringBuffer output) { Log.log(Log.LEVEL_TRACE, MODULE, "Executing " + Arrays.asList(cmd)); try { Process p = Runtime.getRuntime().exec(cmd); - return pumpExec(p); + return pumpExec(p, output); } catch (InterruptedException e) { Log.logException(Log.LEVEL_ERROR, MODULE, e); return -1; @@ -1127,7 +1157,7 @@ public static int exec(String[] cmd) { return 1; } - private static int pumpExec(Process p) throws InterruptedException, IOException { + private static int pumpExec(Process p, StringBuffer output) throws InterruptedException, IOException { DataInputStream out = new DataInputStream(new BufferedInputStream(p.getInputStream())); DataInputStream err = new DataInputStream(new BufferedInputStream(p.getErrorStream())); @@ -1136,6 +1166,9 @@ private static int pumpExec(Process p) throws InterruptedException, IOException String line = null; while ((line = out.readLine()) != null) { Log.log(Log.LEVEL_TRACE, MODULE, "Out: " + line); + if (output != null) { + output.append(line).append("\n"); + } } while ((line = err.readLine()) != null) { diff --git a/defaults.properties b/defaults.properties index ea7beae..5a254eb 100644 --- a/defaults.properties +++ b/defaults.properties @@ -245,6 +245,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p # # --- Do not edit below this line --- # -version=1.4.2-b23 -releaseDate=2005/07/30 +version=1.4.2-b24 +releaseDate=2005/08/06 aboutText=Gallery Remote\n \n \nA part of the Gallery Open-Source Project\nhttp://gallery.sourceforge.net\n \n \nMaintained by:\n \nPierre-Luc Paour\n \n \nInitial version by Chris Smith\n \n \nContributors:\n \nTim Miller\nDolan Halbrook\nMarkus Cozowicz\nScott Gartner\nAmedeo Paglione\nChris Schwerdt\nSeth Ladd\n \n \nArtwork by Ross A. Reyman\n \n \nBundled software:\n \nImageMagick\nJava look and feel Graphics Repository icons\njpegtran, Guido Vollbeding's version\nMetadataExtractor diff --git a/imagemagick/im.properties.applet b/imagemagick/im.properties.applet index d5cc5ac..0f61f3c 100644 --- a/imagemagick/im.properties.applet +++ b/imagemagick/im.properties.applet @@ -42,7 +42,7 @@ im.thumbnailResizeFormat=gif im.previewResizeFormat=jpg # jpeg quality -im.jpegQuality=80 +im.jpegQuality=90 # ignore error code sent back by the executable # there's a bug in the Linux Java VM that returns a failed code