X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmedia%2Fimage%2FImageMagickImageProcessor.java;h=bb9a3dccb49fff1ab0b1063c3a66cc61ab5b1bf1;hb=881863484ff95a2a7e395987156120ab0f7943c8;hp=c538d1845d8757a3ab0d0b7e8690004d9b3303dc;hpb=a183ca30262564a8a190ad0bb8f7829b76dfa002;p=mir.git diff --git a/source/mir/media/image/ImageMagickImageProcessor.java b/source/mir/media/image/ImageMagickImageProcessor.java index c538d184..bb9a3dcc 100755 --- a/source/mir/media/image/ImageMagickImageProcessor.java +++ b/source/mir/media/image/ImageMagickImageProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2005 The Mir-coders group * * This file is part of Mir. * @@ -18,16 +18,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this + * the code of this program with any library licensed under the Apache Software License. + * You must obey the GNU General Public License in all respects for all of the code used + * other than the above mentioned libraries. If you modify this file, you may extend this * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ - package mir.media.image; import mir.log.LoggerWrapper; @@ -37,7 +33,15 @@ import mir.util.StreamCopier; import mir.util.ShellRoutines; import mir.config.MirPropertiesConfiguration; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.StringTokenizer; @@ -79,6 +83,8 @@ public class ImageMagickImageProcessor implements ImageProcessor { */ int width; int height; + int fileSize; + /** * Image type as returned by identify %m : "PNG", "GIF", ... */ @@ -150,13 +156,28 @@ public class ImageMagickImageProcessor implements ImageProcessor { checkFile(); String infoString = ShellRoutines.execIntoString (getImageMagickPath() + - "identify " + "-format \"%w %h %m %n \" " + + "identify " + "-format \"%w %h %m %n %b \" " + file.getAbsolutePath()); // extra space, for multiframe (animations) StringTokenizer st = new StringTokenizer(infoString); width = Integer.parseInt(st.nextToken()); height = Integer.parseInt(st.nextToken()); type = st.nextToken(); isAnimation = Integer.parseInt(st.nextToken()) > 1; + // yoss: different versions of ImageMagick produce different formatted output file sizes + // for example, Version: ImageMagick 6.2.4 (Ubuntu Dapper 6.06) produces a byte value, i.e. 67013 + // Version: ImageMagick 6.0.6 (Debian Sarge) produces output like 67kb or 500mb. + // Trying to do an int.parse in Sarge fails for obvious reasons. + /*String sFileSize = st.nextToken(); + if (sFileSize.endsWith("kb") || sFileSize.endsWith("Kb") || sFileSize.endsWith("KB") || sFileSize.endsWith("kB")){ + sFileSize = sFileSize.substring(0, sFileSize.length() - 2); + fileSize = 1024 * Integer.parseInt(sFileSize); + } else if (sFileSize.endsWith("mb") || sFileSize.endsWith("Mb") || sFileSize.endsWith("MB") || sFileSize.endsWith("mB")){ + sFileSize = sFileSize.substring(0, sFileSize.length() - 2); + fileSize = 1048576 * Integer.parseInt(sFileSize); + } else { + fileSize = Integer.parseInt(sFileSize); + }*/ + fileSize = (int)file.length(); } public ImageFile scale(float aScalingFactor) throws IOException { @@ -264,15 +285,16 @@ public class ImageMagickImageProcessor implements ImageProcessor { if (1 - scale > aMinDescale) { scaleImage(scale); + + return; } - } else { - logger.debug("descaleImage: image size is ok, not scaling image"); - try { - scaledImage = new ImageFile(sourceImage.file); - } - catch (IOException e) { - throw new MediaExc(e.toString()); - } + } + logger.debug("descaleImage: image size is ok, not scaling image"); + try { + scaledImage = new ImageFile(sourceImage.file); + } + catch (IOException e) { + throw new MediaExc(e.toString()); } } @@ -305,6 +327,14 @@ public class ImageMagickImageProcessor implements ImageProcessor { public int getHeight() { return sourceImage.height; } + + public int getSourceFileSize() { + return sourceImage.fileSize; + } + + public int getScaledFileSize() { + return scaledImage.fileSize; + } public int getScaledWidth() { return scaledImage.width; @@ -360,11 +390,15 @@ public class ImageMagickImageProcessor implements ImageProcessor { stream.close(); } catch (Throwable t) { + logger.debug("Unable to close stream when writing scaled data."); } } } catch (FileNotFoundException f) { throw new MediaFailure(f); } + catch (Exception e) { + logger.debug("Exception caught while trying to write scaled data: " + e.toString()); + } } }