Skip to content

Commit

Permalink
2006-11-04 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b25)
Browse files Browse the repository at this point in the history
	* Refactored image loading code, now using ImageIO for
	  better performance and lower memory consumption.
  • Loading branch information
Pierre-Luc Paour committed Nov 4, 2006
1 parent f061964 commit 7111bef
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 108 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2006-11-04 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b25)

* Refactored image loading code, now using ImageIO for
better performance and lower memory consumption.

2006-10-24 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b24)

* Added Norwegian translation (thanks Sverre M. Vikan)
Expand Down
12 changes: 9 additions & 3 deletions com/gallery/GalleryRemote/CoreUtils.java
Expand Up @@ -6,6 +6,7 @@
import javax.swing.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
Expand Down Expand Up @@ -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));
}
}

Expand Down
3 changes: 2 additions & 1 deletion com/gallery/GalleryRemote/GRAppletMini.java
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +124,7 @@ public void flushMemory() {}

public void preloadThumbnails(Iterator pictures) {}

public ImageIcon getThumbnail(Picture p) {
public Image getThumbnail(Picture p) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion com/gallery/GalleryRemote/GRScreenSaver.java
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion com/gallery/GalleryRemote/GalleryRemoteCore.java
Expand Up @@ -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.
Expand All @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java
Expand Up @@ -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.*;
Expand Down Expand Up @@ -174,7 +175,7 @@ public void flushMemory() {}

public void preloadThumbnails(Iterator pictures) {}

public ImageIcon getThumbnail(Picture p) {
public Image getThumbnail(Picture p) {
return null;
}

Expand Down Expand Up @@ -234,7 +235,7 @@ public void run() {
}.start();
}

public boolean blockPictureReady(ImageIcon image, Picture picture) {
public boolean blockPictureReady(BufferedImage image, Picture picture) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 17 additions & 6 deletions com/gallery/GalleryRemote/PictureInspector.java
Expand Up @@ -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;
Expand All @@ -42,7 +43,6 @@
* Bean inspector for Pictures
*
* @author paour
* @created August 16, 2002
*/
public class PictureInspector extends JPanel
implements ActionListener, DocumentListener {
Expand Down Expand Up @@ -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);
Expand All @@ -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("");

Expand All @@ -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());
Expand Down Expand Up @@ -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("");
Expand Down Expand Up @@ -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);
}
}

13 changes: 7 additions & 6 deletions com/gallery/GalleryRemote/PreviewFrame.java
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void pictureReady() {
repaint();
}

public boolean blockPictureReady(ImageIcon image, Picture picture) {
public boolean blockPictureReady(BufferedImage image, Picture picture) {
return false;
}

Expand Down Expand Up @@ -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());
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions com/gallery/GalleryRemote/SlideshowFrame.java
Expand Up @@ -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);
}
Expand Down Expand Up @@ -392,15 +392,15 @@ 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);
}

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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 7111bef

Please sign in to comment.