From 7111bef57ca39b4fa4317c5ac2809061c0ecc886 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Sat, 4 Nov 2006 15:00:40 +0000 Subject: [PATCH] 2006-11-04 Pierre-Luc Paour (1.5.1-b25) * Refactored image loading code, now using ImageIO for better performance and lower memory consumption. --- ChangeLog | 5 ++ com/gallery/GalleryRemote/CoreUtils.java | 12 ++- com/gallery/GalleryRemote/GRAppletMini.java | 3 +- com/gallery/GalleryRemote/GRScreenSaver.java | 2 +- .../GalleryRemote/GalleryRemoteCore.java | 4 +- .../GalleryRemoteScreenSaver.java | 5 +- com/gallery/GalleryRemote/MainFrame.java | 7 +- .../GalleryRemote/PictureInspector.java | 23 +++-- com/gallery/GalleryRemote/PreviewFrame.java | 13 +-- com/gallery/GalleryRemote/SlideshowFrame.java | 24 +++--- com/gallery/GalleryRemote/ThumbnailCache.java | 54 ++++++++---- .../GalleryRemote/util/ImageLoaderUtil.java | 27 +++--- .../GalleryRemote/util/ImageUtils.java | 86 ++++++++++--------- defaults.properties | 4 +- 14 files changed, 161 insertions(+), 108 deletions(-) diff --git a/ChangeLog b/ChangeLog index f617817..abfbe2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-11-04 Pierre-Luc Paour (1.5.1-b25) + + * Refactored image loading code, now using ImageIO for + better performance and lower memory consumption. + 2006-10-24 Pierre-Luc Paour (1.5.1-b24) * Added Norwegian translation (thanks Sverre M. Vikan) diff --git a/com/gallery/GalleryRemote/CoreUtils.java b/com/gallery/GalleryRemote/CoreUtils.java index 4fd9f41..9fec377 100644 --- a/com/gallery/GalleryRemote/CoreUtils.java +++ b/com/gallery/GalleryRemote/CoreUtils.java @@ -6,6 +6,7 @@ import javax.swing.*; import java.util.Arrays; import java.awt.*; +import java.awt.image.BufferedImage; import java.io.File; /** @@ -170,10 +171,15 @@ public Component getListCellRendererComponent( } if (GalleryRemote._().properties.getShowThumbnails()) { - ImageIcon icon = core.getThumbnail(p); + Image icon = core.getThumbnail(p); if (icon != null) { - setIcon(icon); - setIconTextGap(4 + GalleryRemote._().properties.getThumbnailSize().width - icon.getIconWidth()); + Icon iicon = getIcon(); + if (iicon == null || ! (iicon instanceof ImageIcon)) { + setIcon((iicon = new ImageIcon())); + } + ((ImageIcon) iicon).setImage(icon); + + setIconTextGap(4 + GalleryRemote._().properties.getThumbnailSize().width - icon.getWidth(this)); } } diff --git a/com/gallery/GalleryRemote/GRAppletMini.java b/com/gallery/GalleryRemote/GRAppletMini.java index 0955598..80981df 100644 --- a/com/gallery/GalleryRemote/GRAppletMini.java +++ b/com/gallery/GalleryRemote/GRAppletMini.java @@ -18,6 +18,7 @@ import java.util.Iterator; import java.util.Arrays; import java.awt.*; +import java.awt.image.BufferedImage; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; @@ -123,7 +124,7 @@ public void flushMemory() {} public void preloadThumbnails(Iterator pictures) {} - public ImageIcon getThumbnail(Picture p) { + public Image getThumbnail(Picture p) { return null; } diff --git a/com/gallery/GalleryRemote/GRScreenSaver.java b/com/gallery/GalleryRemote/GRScreenSaver.java index cb0973b..17ed1cb 100644 --- a/com/gallery/GalleryRemote/GRScreenSaver.java +++ b/com/gallery/GalleryRemote/GRScreenSaver.java @@ -91,7 +91,7 @@ public void paint(Graphics g) { Log.log(Log.LEVEL_TRACE, MODULE, "Really Paint!"); Component c = getContext().getComponent(); - Image img = grss.loader.imageShowNow.getImage(); + Image img = grss.loader.imageShowNow; int width = (int) c.getBounds().getWidth(); int height = (int) c.getBounds().getHeight(); diff --git a/com/gallery/GalleryRemote/GalleryRemoteCore.java b/com/gallery/GalleryRemote/GalleryRemoteCore.java index 908eb0c..cef0577 100644 --- a/com/gallery/GalleryRemote/GalleryRemoteCore.java +++ b/com/gallery/GalleryRemote/GalleryRemoteCore.java @@ -6,6 +6,8 @@ import javax.swing.*; import java.util.Iterator; import java.io.File; +import java.awt.image.BufferedImage; +import java.awt.*; /** * Created by IntelliJ IDEA. @@ -20,7 +22,7 @@ public interface GalleryRemoteCore { public void flushMemory(); public void preloadThumbnails(Iterator pictures); - public ImageIcon getThumbnail(Picture p); + public Image getThumbnail(Picture p); public StatusUpdate getMainStatusUpdate(); public void thumbnailLoadedNotify(); diff --git a/com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java b/com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java index b0ce803..2c0db99 100644 --- a/com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java +++ b/com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java @@ -12,6 +12,7 @@ import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; import java.awt.*; +import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.*; @@ -174,7 +175,7 @@ public void flushMemory() {} public void preloadThumbnails(Iterator pictures) {} - public ImageIcon getThumbnail(Picture p) { + public Image getThumbnail(Picture p) { return null; } @@ -234,7 +235,7 @@ public void run() { }.start(); } - public boolean blockPictureReady(ImageIcon image, Picture picture) { + public boolean blockPictureReady(BufferedImage image, Picture picture) { return false; } diff --git a/com/gallery/GalleryRemote/MainFrame.java b/com/gallery/GalleryRemote/MainFrame.java index 68ec7b6..f63ff7e 100644 --- a/com/gallery/GalleryRemote/MainFrame.java +++ b/com/gallery/GalleryRemote/MainFrame.java @@ -40,6 +40,7 @@ import javax.swing.filechooser.FileFilter; import javax.swing.tree.*; import java.awt.*; +import java.awt.image.BufferedImage; import java.awt.event.*; import java.io.*; import java.lang.reflect.Method; @@ -853,17 +854,17 @@ public void setShowPreview(boolean show) { * @param p picture whose thumbnail is to be fetched * @return The thumbnail value */ - public ImageIcon getThumbnail(Picture p) { + public Image getThumbnail(Picture p) { if (p == null) { return null; } - ImageIcon thumb = thumbnailCache.getThumbnail(p); + Image thumb = thumbnailCache.getThumbnail(p); if (thumb == null) { thumb = ImageUtils.defaultThumbnail; } else { - thumb = ImageUtils.rotateImageIcon(thumb, p.getAngle(), p.isFlipped(), getGlassPane()); + thumb = ImageUtils.rotateImage(thumb, p.getAngle(), p.isFlipped(), getGlassPane()); } return thumb; diff --git a/com/gallery/GalleryRemote/PictureInspector.java b/com/gallery/GalleryRemote/PictureInspector.java index af21e60..307ba65 100644 --- a/com/gallery/GalleryRemote/PictureInspector.java +++ b/com/gallery/GalleryRemote/PictureInspector.java @@ -29,6 +29,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.awt.*; +import java.awt.image.BufferedImage; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; @@ -42,7 +43,6 @@ * Bean inspector for Pictures * * @author paour - * @created August 16, 2002 */ public class PictureInspector extends JPanel implements ActionListener, DocumentListener { @@ -346,13 +346,13 @@ public void textUpdate(DocumentEvent e) { */ public void setMainFrame(MainFrame mf) { this.mf = mf; - jIcon.setIcon(ImageUtils.defaultThumbnail); + replaceIcon(jIcon, ImageUtils.defaultThumbnail); } /** * Sets the picture attribute of the PictureInspector object * - * @param p The new picture value + * @param pictures The new picture value */ public void setPictures(Object[] pictures) { //Log.log(Log.TRACE, MODULE, "setPictures " + pictures); @@ -367,7 +367,7 @@ public void setPictures(Object[] pictures) { if (pictures == null || pictures.length == 0) { jIcon.setText(GRI18n.getString(MODULE, "noPicSel")); - jIcon.setIcon(ImageUtils.defaultThumbnail); + replaceIcon(jIcon, ImageUtils.defaultThumbnail); jPath.setText(""); jAlbum.setText(""); @@ -388,7 +388,7 @@ public void setPictures(Object[] pictures) { } else if (pictures.length == 1) { Picture p = (Picture) pictures[0]; - jIcon.setIcon(mf.getThumbnail(p)); + replaceIcon(jIcon, mf.getThumbnail(p)); if (p.isOnline()) { jPath.setText(GRI18n.getString(MODULE, "onServer")); jIcon.setText(p.getName()); @@ -418,7 +418,7 @@ public void setPictures(Object[] pictures) { Object[] params = {new Integer(pictures.length)}; jIcon.setText(GRI18n.getString(MODULE, "countElemSel", params)); - jIcon.setIcon(ImageUtils.defaultThumbnail); + replaceIcon(jIcon, ImageUtils.defaultThumbnail); jPath.setText(""); jAlbum.setText(p.getParentAlbum().getTitle()); jCaption.setText(""); @@ -540,5 +540,16 @@ public void actionPerformed(ActionEvent evt) { CoreUtils.selectPrevPicture(); } }; + + public void replaceIcon(JLabel label, Image icon) { + Icon i = label.getIcon(); + + if (i == null || !(i instanceof ImageIcon)) { + i = new ImageIcon(); + label.setIcon(i); + } + + ((ImageIcon) i).setImage(icon); + } } diff --git a/com/gallery/GalleryRemote/PreviewFrame.java b/com/gallery/GalleryRemote/PreviewFrame.java index 3ea3a6b..fdfd486 100755 --- a/com/gallery/GalleryRemote/PreviewFrame.java +++ b/com/gallery/GalleryRemote/PreviewFrame.java @@ -29,6 +29,7 @@ import javax.swing.*; import java.awt.*; +import java.awt.image.BufferedImage; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.NoninvertibleTransformException; @@ -99,7 +100,7 @@ public void pictureReady() { repaint(); } - public boolean blockPictureReady(ImageIcon image, Picture picture) { + public boolean blockPictureReady(BufferedImage image, Picture picture) { return false; } @@ -129,14 +130,14 @@ public void paintComponent(Graphics g) { if (loader.imageShowNow != null && loader.pictureShowWant != null) { Log.log(Log.LEVEL_TRACE, MODULE, "New image: " + loader.imageShowNow); - ImageIcon tmpImage = ImageUtils.rotateImageIcon(loader.imageShowNow, loader.pictureShowWant.getAngle(), + Image tmpImage = ImageUtils.rotateImage(loader.imageShowNow, loader.pictureShowWant.getAngle(), loader.pictureShowWant.isFlipped(), this); - currentRect = new Rectangle(getLocation().x + (getWidth() - tmpImage.getIconWidth()) / 2, - getLocation().y + (getHeight() - tmpImage.getIconHeight()) / 2, - tmpImage.getIconWidth(), tmpImage.getIconHeight()); + currentRect = new Rectangle(getLocation().x + (getWidth() - tmpImage.getWidth(this)) / 2, + getLocation().y + (getHeight() - tmpImage.getHeight(this)) / 2, + tmpImage.getWidth(this), tmpImage.getHeight(this)); - g2.drawImage(tmpImage.getImage(), currentRect.x, currentRect.y, getContentPane()); + g2.drawImage(tmpImage, currentRect.x, currentRect.y, getContentPane()); } } } diff --git a/com/gallery/GalleryRemote/SlideshowFrame.java b/com/gallery/GalleryRemote/SlideshowFrame.java index 6b3e657..b5b2aa0 100644 --- a/com/gallery/GalleryRemote/SlideshowFrame.java +++ b/com/gallery/GalleryRemote/SlideshowFrame.java @@ -338,7 +338,7 @@ public boolean next(boolean user) { loader.preparePicture(picture, false, true); // and cache the one after it - if (wantIndex + 1< pictures.size() && (loader.imageIcons.get(picture = (Picture) pictures.get(wantIndex + 1))) == null) { + if (wantIndex + 1< pictures.size() && (loader.images.get(picture = (Picture) pictures.get(wantIndex + 1))) == null) { wantDownloaded.add(picture); loader.imageLoader.loadPicture(picture, false); } @@ -392,7 +392,7 @@ public boolean previous(boolean user) { loader.preparePicture(picture, false, true); // and cache the one after it - if (wantIndex - 1 > 0 && (loader.imageIcons.get(picture = (Picture) pictures.get(wantIndex - 1))) == null) { + if (wantIndex - 1 > 0 && (loader.images.get(picture = (Picture) pictures.get(wantIndex - 1))) == null) { wantDownloaded.add(picture); loader.imageLoader.loadPicture(picture, false); } @@ -400,7 +400,7 @@ public boolean previous(boolean user) { return true; } - public boolean blockPictureReady(ImageIcon image, Picture picture) { + public boolean blockPictureReady(BufferedImage image, Picture picture) { Log.log(Log.LEVEL_TRACE, MODULE, "blockPictureReady: " + picture + " - pictureShowWant: " + loader.pictureShowWant); if (picture == userPicture) { @@ -612,9 +612,9 @@ class SlideshowPane extends JPanel implements ActionListener { BufferedImage[] previousInfoCache = new BufferedImage[4]; Point[] previousInfoLocation = new Point[4]; - ImageIcon currentImage = null; - ImageIcon currentImageSrc = null; - ImageIcon previousImage = null; + Image currentImage = null; + Image currentImageSrc = null; + Image previousImage = null; Rectangle previousRect = null; Timer timer = new Timer(1000/60, this); @@ -680,12 +680,12 @@ public void paintPicture(Graphics2D g) { previousImage = currentImage; previousRect = currentRect; - currentImage = ImageUtils.rotateImageIcon(loader.imageShowNow, loader.pictureShowWant.getAngle(), + currentImage = ImageUtils.rotateImage(loader.imageShowNow, loader.pictureShowWant.getAngle(), loader.pictureShowWant.isFlipped(), this); - currentRect = new Rectangle(getLocation().x + (getWidth() - currentImage.getIconWidth()) / 2, - getLocation().y + (getHeight() - currentImage.getIconHeight()) / 2, - currentImage.getIconWidth(), currentImage.getIconHeight()); + currentRect = new Rectangle(getLocation().x + (getWidth() - currentImage.getWidth(this)) / 2, + getLocation().y + (getHeight() - currentImage.getHeight(this)) / 2, + currentImage.getWidth(this), currentImage.getHeight(this)); currentImageSrc = loader.imageShowNow; @@ -702,12 +702,12 @@ public void paintPicture(Graphics2D g) { if (imageAlpha != 1 && previousImage != null) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - imageAlpha)); - g.drawImage(previousImage.getImage(), previousRect.x, previousRect.y, getContentPane()); + g.drawImage(previousImage, previousRect.x, previousRect.y, getContentPane()); } if (imageAlpha != 0) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, imageAlpha)); - g.drawImage(currentImage.getImage(), currentRect.x, currentRect.y, getContentPane()); + g.drawImage(currentImage, currentRect.x, currentRect.y, getContentPane()); } g.setComposite(composite); diff --git a/com/gallery/GalleryRemote/ThumbnailCache.java b/com/gallery/GalleryRemote/ThumbnailCache.java index d3d3a40..530e5e2 100644 --- a/com/gallery/GalleryRemote/ThumbnailCache.java +++ b/com/gallery/GalleryRemote/ThumbnailCache.java @@ -25,10 +25,16 @@ import com.gallery.GalleryRemote.util.ImageUtils; import javax.swing.*; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.IIOException; +import javax.imageio.stream.ImageInputStream; import java.awt.*; +import java.awt.image.BufferedImage; import java.util.HashMap; import java.util.Iterator; import java.util.Stack; +import java.io.IOException; /** * Thumbnail cache loads and resizes images in the background for display in @@ -53,21 +59,37 @@ public void run() { //Log.log(Log.TRACE, MODULE, "Starting " + iFilename); while (!toLoad.isEmpty()) { Picture p = (Picture) toLoad.pop(); - ImageIcon i = null; + Image i = null; if (!thumbnails.containsKey(p)) { if (p.isOnline()) { Log.log(Log.LEVEL_TRACE, MODULE, "Fetching thumbnail " + p.getUrlThumbnail()); - i = new ImageIcon(p.getUrlThumbnail()); - - Image scaled = null; - Dimension newD = ImageUtils.getSizeKeepRatio( - new Dimension(i.getIconWidth(), i.getIconHeight()), - GalleryRemote._().properties.getThumbnailSize(), true); - if (newD != null) { - scaled = i.getImage().getScaledInstance(newD.width, newD.height, Image.SCALE_FAST); - i.getImage().flush(); - i.setImage(scaled); + try { + ImageReader reader = (ImageReader) ImageIO.getImageReadersByFormatName("jpeg").next(); + ImageInputStream inputStream = ImageIO.createImageInputStream(p.getUrlThumbnail().openStream()); + reader.setInput(inputStream); + + i = reader.read(0); + + reader.dispose(); + } catch (IIOException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } catch (IOException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } + + if (i != null) { + Image scaled; + Dimension newD = ImageUtils.getSizeKeepRatio( + new Dimension(((BufferedImage) i).getWidth(), ((BufferedImage) i).getHeight()), + GalleryRemote._().properties.getThumbnailSize(), true); + if (newD != null) { + scaled = i.getScaledInstance(newD.width, newD.height, Image.SCALE_FAST); + i.flush(); + i = scaled; + } + } else { + i = ImageUtils.unrecognizedThumbnail; } } else { i = ImageUtils.load( @@ -135,9 +157,9 @@ public void reload() { public void flushMemory() { Iterator it = thumbnails.values().iterator(); while (it.hasNext()) { - ImageIcon i = (ImageIcon) it.next(); - if (i.getImage() != null) { - i.getImage().flush(); + Image i = (Image) it.next(); + if (i != null) { + i.flush(); } } @@ -162,8 +184,8 @@ void cancelLoad() { * * @return The thumbnail object */ - public ImageIcon getThumbnail(Picture p) { - return (ImageIcon) thumbnails.get(p); + public Image getThumbnail(Picture p) { + return (Image) thumbnails.get(p); } } diff --git a/com/gallery/GalleryRemote/util/ImageLoaderUtil.java b/com/gallery/GalleryRemote/util/ImageLoaderUtil.java index 35b561d..b6b6802 100644 --- a/com/gallery/GalleryRemote/util/ImageLoaderUtil.java +++ b/com/gallery/GalleryRemote/util/ImageLoaderUtil.java @@ -8,6 +8,7 @@ import javax.swing.*; import java.awt.*; +import java.awt.image.BufferedImage; import java.awt.geom.Rectangle2D; import java.util.*; import java.util.regex.Matcher; @@ -17,8 +18,8 @@ public class ImageLoaderUtil implements PreferenceNames { public static final String MODULE = "ImgLoadrUtil"; - public SmartHashtable imageIcons = new SmartHashtable(); - public ImageIcon imageShowNow = null; + public SmartHashtable images = new SmartHashtable(); + public BufferedImage imageShowNow = null; public Picture pictureShowWant = null; public Picture pictureShowNow = null; public ImageLoader imageLoader = new ImageLoader(); @@ -43,7 +44,7 @@ public void setTransferListener(CancellableTransferListener transferListener) { } public void flushMemory() { - imageIcons.clear(); + images.clear(); if (pictureShowNow != null) { pictureShowWant = null; imageShowNow = null; @@ -52,7 +53,7 @@ public void flushMemory() { } } - public void pictureReady(ImageIcon image, Picture picture) { + public void pictureReady(BufferedImage image, Picture picture) { if (!imageLoaderUser.blockPictureReady(image, picture)) { imageShowNow = image; pictureShowNow = picture; @@ -73,7 +74,7 @@ public void preparePicture(Picture picture, boolean async, boolean notify) { if (picture != pictureShowWant) { pictureShowWant = picture; - ImageIcon r = (ImageIcon) imageIcons.get(picture); + BufferedImage r = (BufferedImage) images.get(picture); if (r != null) { Log.log(Log.LEVEL_TRACE, MODULE, "Cache hit: " + picture); if (notify) { @@ -84,7 +85,7 @@ public void preparePicture(Picture picture, boolean async, boolean notify) { if (async) { imageLoader.loadPicture(picture, true); } else { - ImageIcon sizedIcon = getSizedIconForce(picture); + BufferedImage sizedIcon = getSizedIconForce(picture); if (sizedIcon != null) { if (notify) { pictureReady(sizedIcon, picture); @@ -96,8 +97,8 @@ public void preparePicture(Picture picture, boolean async, boolean notify) { } } - public ImageIcon getSizedIconForce(Picture picture) { - ImageIcon r = (ImageIcon) imageIcons.get(picture); + public BufferedImage getSizedIconForce(Picture picture) { + BufferedImage r = (BufferedImage) images.get(picture); if (r == null) { synchronized(picture) { @@ -130,7 +131,7 @@ public ImageIcon getSizedIconForce(Picture picture) { } Log.log(Log.LEVEL_TRACE, MODULE, "Adding to cache: " + picture); - imageIcons.put(picture, r); + images.put(picture, r); } } @@ -313,7 +314,7 @@ public class ImageLoader implements Runnable { public void run() { Log.log(Log.LEVEL_TRACE, MODULE, "Starting " + picture); Picture tmpPicture = null; - ImageIcon tmpImage = null; + BufferedImage tmpImage = null; while (picture != null) { synchronized (picture) { tmpPicture = picture; @@ -431,9 +432,9 @@ public void shrink() { Object key = touchOrder.get(0); touchOrder.remove(0); - ImageIcon i = (ImageIcon) get(key, false); + Image i = (Image) get(key, false); if (i != null) { - i.getImage().flush(); + i.flush(); } remove(key); @@ -446,7 +447,7 @@ public void shrink() { public interface ImageLoaderUser { public void pictureReady(); - public boolean blockPictureReady(ImageIcon image, Picture picture); + public boolean blockPictureReady(BufferedImage image, Picture picture); public Dimension getImageSize(); public void nullRect(); public void pictureStartDownloading(Picture picture); diff --git a/com/gallery/GalleryRemote/util/ImageUtils.java b/com/gallery/GalleryRemote/util/ImageUtils.java index 9748c84..05ebf04 100644 --- a/com/gallery/GalleryRemote/util/ImageUtils.java +++ b/com/gallery/GalleryRemote/util/ImageUtils.java @@ -86,23 +86,23 @@ public class ImageUtils { public final static String DEFAULT_RESOURCE = "/default.gif"; public final static String UNRECOGNIZED_RESOURCE = "/default.gif"; - public static ImageIcon defaultThumbnail = null; - public static ImageIcon unrecognizedThumbnail = null; + public static BufferedImage defaultThumbnail = null; + public static BufferedImage unrecognizedThumbnail = null; public static boolean deferredStopUsingIM = false; public static boolean deferredStopUsingJpegtran = false; public static boolean deferredStopUsingJpegtranCrop = false; - public static ImageIcon load(String filename, Dimension d, int usage) { + public static BufferedImage load(String filename, Dimension d, int usage) { return load(filename, d, usage, false); } - public static ImageIcon load(String filename, Dimension d, int usage, boolean ignoreFailure) { + public static BufferedImage load(String filename, Dimension d, int usage, boolean ignoreFailure) { if (!new File(filename).exists()) { return null; } - ImageIcon r = null; + BufferedImage r = null; long start = System.currentTimeMillis(); if (!GalleryFileFilter.canManipulate(filename)) { @@ -147,10 +147,18 @@ public static ImageIcon load(String filename, Dimension d, int usage, boolean ig stopUsingIM(); } } else { - r = new ImageIcon(temp.getPath()); + try { + r = ImageIO.read(temp); + } catch (IOException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } } } else { - r = new ImageIcon(temp.getPath()); + try { + r = ImageIO.read(temp); + } catch (IOException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } } } @@ -166,47 +174,41 @@ public static ImageIcon load(String filename, Dimension d, int usage, boolean ig return r; } - public static ImageIcon loadJava(URL url, Dimension d, boolean noStretch) { - ImageIcon r = new ImageIcon(url); - - return loadJavaInternal(r, d, noStretch); - /*try { - ImageInputStream iis = ImageIO.createImageInputStream(url.openStream()); - return loadJavaInternal(iis, d); + public static BufferedImage loadJava(URL url, Dimension d, boolean noStretch) { + try { + BufferedImage r = ImageIO.read(url); + return loadJavaInternal(r, d, noStretch); } catch (IOException e) { - Log.logException(Log.LEVEL_ERROR, MODULE, e); - return null; - }*/ + Log.logException(Log.LEVEL_ERROR, MODULE, e); + return null; + } } - public static ImageIcon loadJava(String filename, Dimension d, boolean noStretch) { - ImageIcon r = new ImageIcon(filename); - - return loadJavaInternal(r, d, noStretch); - /*try { - ImageInputStream iis = ImageIO.createImageInputStream(new File(filename)); - return loadJavaInternal(iis, d); + public static BufferedImage loadJava(String filename, Dimension d, boolean noStretch) { + try { + BufferedImage r = ImageIO.read(new File(filename)); + return loadJavaInternal(r, d, noStretch); } catch (IOException e) { - Log.logException(Log.LEVEL_ERROR, MODULE, e); - return null; - }*/ + Log.logException(Log.LEVEL_ERROR, MODULE, e); + return null; + } } - private static ImageIcon loadJavaInternal(ImageIcon r, Dimension d, boolean noStretch) { - Image scaled = null; + private static BufferedImage loadJavaInternal(BufferedImage r, Dimension d, boolean noStretch) { + BufferedImage scaled = null; Dimension newD = getSizeKeepRatio( - new Dimension(r.getIconWidth(), r.getIconHeight()), + new Dimension(r.getWidth(), r.getHeight()), d, noStretch); if (newD == null) { return r; } - scaled = r.getImage().getScaledInstance(newD.width, newD.height, Image.SCALE_FAST); + scaled = (BufferedImage) r.getScaledInstance(newD.width, newD.height, Image.SCALE_FAST); - r.getImage().flush(); - r.setImage(scaled); - return r; + r.flush(); + + return scaled; /*Iterator iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { return null; @@ -550,15 +552,15 @@ private static File jpegtranExec(String filename, String arg1, String arg2, bool return r; } - public static ImageIcon rotateImageIcon(ImageIcon thumb, int angle, boolean flipped, Component c) { + public static Image rotateImage(Image thumb, int angle, boolean flipped, Component c) { if (angle != 0 || flipped) { int width; int height; int width1; int height1; - width = thumb.getImage().getWidth(c); - height = thumb.getImage().getHeight(c); + width = thumb.getWidth(c); + height = thumb.getHeight(c); if (angle % 2 == 0) { width1 = width; @@ -568,15 +570,15 @@ public static ImageIcon rotateImageIcon(ImageIcon thumb, int angle, boolean flip height1 = width; } - Image vImg = c.createImage(width1, height1); + BufferedImage vImg = (BufferedImage) c.createImage(width1, height1); Graphics2D g = (Graphics2D) vImg.getGraphics(); AffineTransform transform = getRotationTransform(width, height, angle, flipped); - g.drawImage(thumb.getImage(), transform, c); + g.drawImage(thumb, transform, c); - thumb = new ImageIcon(vImg); + thumb = vImg; } return thumb; @@ -673,7 +675,6 @@ public static LocalInfo getLocalFilenameForPicture(Picture p, boolean full) { } static class LocalInfo { - //String name; String ext; String filename; File file; @@ -681,7 +682,6 @@ static class LocalInfo { Dimension size; public LocalInfo(String ext, String filename, File file, URL url, Dimension size) { - //this.name = name; this.ext = ext; this.filename = filename; this.file = file; @@ -748,6 +748,8 @@ public static File download(Picture p, Dimension d, StatusUpdate su, Cancellable conn.addRequestProperty("Cookie", cookies[i].toString()); } + conn.connect(); + int size = conn.getContentLength(); su.startProgress(StatusUpdate.LEVEL_BACKGROUND, 0, size, diff --git a/defaults.properties b/defaults.properties index f4f89d4..55a4e9c 100644 --- a/defaults.properties +++ b/defaults.properties @@ -314,6 +314,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p # # --- Do not edit below this line --- # -version=1.5.1-b24 -releaseDate=2006/10/24 +version=1.5.1-b25 +releaseDate=2006/11/04 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\nSaverBeans