Skip to content

Commit

Permalink
2006-11-14 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b26)
Browse files Browse the repository at this point in the history
	* Fixed multi-line caption alignment.
	* Now capturing out of memory errors and displaying message
	  when using Java resize (which leads to high
	  memory consumption).
	* Final fix for lower memory consumption while resizing
	  images in Java code.
  • Loading branch information
Pierre-Luc Paour committed Nov 14, 2006
1 parent dbab55b commit 5eaee01
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 103 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
2006-11-14 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b26)

* Fixed multi-line caption alignment.
* Now capturing out of memory errors and displaying message
when using Java resize (which leads to high
memory consumption).
* Final fix for lower memory consumption while resizing
images in Java code.

2006-11-04 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b25)

* Refactored image loading code, now using ImageIO for
Expand Down
3 changes: 3 additions & 0 deletions build.xml
Expand Up @@ -64,6 +64,7 @@
<target name="jar" depends="clean,compile"
description="create a jar of the source">

<delete file="GalleryRemote.jar" />
<jar destfile="GalleryRemote.jar">
<fileset dir="${build}" />
<fileset dir="." includes="*.properties" excludes="postchangelog.properties" />
Expand Down Expand Up @@ -91,6 +92,7 @@

<target name="applet_mini_jar" depends="compile" description="create a jar for the applet version of GR">

<delete file="GalleryRemoteAppletMini.jar" />
<jar destfile="GalleryRemoteAppletMini.jar" index="true" >
<fileset dir="${build}" excludes="HTTPClient/*" excludesfile="AppletMiniExcludes.txt" />
<fileset dir="." includes="*.properties" excludes="postchangelog.properties" />
Expand All @@ -105,6 +107,7 @@

<target name="httpclient_jar" depends="compile" description="create a jar for the HTTP library">

<delete file="GalleryRemoteHTTPClient.jar" />
<jar destfile="GalleryRemoteHTTPClient.jar" index="true" >
<fileset dir="${build}" includes="HTTPClient/*" />
<manifest>
Expand Down
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/GalleryRemoteScreenSaver.java
Expand Up @@ -249,4 +249,5 @@ public Dimension getImageSize() {
public void nullRect() {}
public void pictureStartDownloading(Picture picture) {}
public void pictureStartProcessing(Picture picture) {}
public void pictureLoadError(Picture picture) {}
}
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/PreviewFrame.java
Expand Up @@ -113,6 +113,7 @@ public void nullRect() {

public void pictureStartDownloading(Picture picture) {}
public void pictureStartProcessing(Picture picture) {}
public void pictureLoadError(Picture picture) {}

class ImageContentPane extends JPanel {
public void paintComponent(Graphics g) {
Expand Down
17 changes: 16 additions & 1 deletion com/gallery/GalleryRemote/SlideshowFrame.java
Expand Up @@ -46,6 +46,7 @@ public class SlideshowFrame extends PreviewFrame
public static final int STATE_NEXTREADY = 3;
public static final int STATE_SKIPPING = 4;
public static final int STATE_SHOWING = 5;
public static final int STATE_ERROR = 6;

public static final int FEEDBACK_NONE = 0;
public static final int FEEDBACK_HELP = 1;
Expand Down Expand Up @@ -135,6 +136,8 @@ public void hide() {
mainFrame.setVisible(true);
}
}

ImageUtils.deferredTasks();
}

public void initComponents() {
Expand Down Expand Up @@ -451,6 +454,14 @@ public void pictureStartProcessing(Picture picture) {
}
}

public void pictureLoadError(Picture picture) {
if (picture == loader.pictureShowWant || picture == userPicture) {
updateProgress(picture, STATE_ERROR);
}

loader.reduceMemory();
}

private void updateProgress(Picture picture, int state) {
if (picture == null) {
return;
Expand Down Expand Up @@ -485,6 +496,10 @@ private void updateProgress(Picture picture, int state) {
progress = GRI18n.getString(MODULE, "nextReady", params);
break;

case STATE_ERROR:
progress = GRI18n.getString(MODULE, "error", params);
break;

case STATE_SKIPPING:
progress = GRI18n.getString(MODULE, "skipping", params);
skipping = GRI18n.getString(MODULE, "skippingController", params);
Expand Down Expand Up @@ -878,7 +893,7 @@ public void paintInfo(Graphics2D g, int id, String text, int position, boolean t
Graphics2D g2 = (Graphics2D) infoCache[id].getGraphics();
g2.setFont(g.getFont());
infoLocation[id] = ImageLoaderUtil.paintAlignedOutline(
g2, text, x, y, 1, position, d.width, wrapInfo, true);
g2, x, y, 1, position, wrapInfo, true);
Log.log(Log.LEVEL_TRACE, MODULE, "Cached info " + id + " - " + text);
}

Expand Down
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/prefs/PreferenceNames.java
Expand Up @@ -84,6 +84,7 @@ public interface PreferenceNames {
public static final String SUPPRESS_WARNING_JPEGTRAN_CROP = "suppressWarningJpegtranCrop";
public static final String SUPPRESS_WARNING_CORRUPTED = "suppressWarningCorrupted";
public static final String SUPPRESS_WARNING_JAVA = "suppressWarningJava";
public static final String SUPPRESS_WARNING_OUT_OF_MEMORY = "suppressWarningOutOfMemory";
public static final String USE_JAVA_RESIZE = "useJavaResize";
public static final String FONT_OVERRIDE_NAME = "fontOverrideName";
public static final String FONT_OVERRIDE_STYLE = "fontOverrideStyle";
Expand Down
18 changes: 12 additions & 6 deletions com/gallery/GalleryRemote/resources/GRResources.properties
Expand Up @@ -482,24 +482,29 @@ ImageUtils.warningTextIM=<html>An optional part of Gallery Remote, <b>ImageMagic
or is malfunctioning. Gallery Remote will not be able to resize images before<br>\
uploading them, and loading thumbnails and previews will be much slower.<br>\
You can find out how to fix this by going to this page:
ImageUtils.warningUrlIM=http://codex.gallery2.org/index.php/Gallery_Remote:FAQ
ImageUtils.warningUrlTextIM=Gallery Remote Known Problems
ImageUtils.warningUrlIM=http://codex.gallery2.org/index.php/Gallery_Remote_Bundled
ImageUtils.warningUrlTextIM=Gallery Remote Bundled
ImageUtils.warningTextJpegtran=<html>An optional part of Gallery Remote, <b>jpegtran</b>, could not be found<br>\
or is malfunctioning. Gallery Remote will not be able to rotate images before<br>\
uploading them.<br>\
You can find out how to fix this by going to this page:
ImageUtils.warningUrlJpegtran=http://codex.gallery2.org/index.php/Gallery_Remote:FAQ
ImageUtils.warningUrlTextJpegtran=Gallery Remote Known Problems
ImageUtils.warningUrlJpegtran=http://codex.gallery2.org/index.php/Gallery_Remote_Bundled
ImageUtils.warningUrlTextJpegtran=Gallery Remote Bundled
ImageUtils.warningTextJpegtranCrop=<html>An optional part of Gallery Remote, <b>jpegtran</b>, could not be found<br>\
or is malfunctioning for the purpose of cropping pictures. Gallery Remote will not be able to losslessly crop images before<br>\
uploading them.<br>\
You can find out how to fix this by going to this page:
ImageUtils.warningUrlJpegtranCrop=http://codex.gallery2.org/index.php/Gallery_Remote:FAQ
ImageUtils.warningUrlTextJpegtranCrop=Gallery Remote Known Problems
ImageUtils.warningUrlJpegtranCrop=http://codex.gallery2.org/index.php/Gallery_Remote_Bundled
ImageUtils.warningUrlTextJpegtranCrop=Gallery Remote Bundled
ImageUtils.warningTextJava=<html>Using Java as a fallback to resize pictures will cause them to lose their EXIF data.<br>\
Do you want to resize with Gallery Remote anyway, or let the server perform the resize (longer upload time).
ImageUtils.useJava=Resize in GR
ImageUtils.dontUseJava=Don't resize in GR
ImageUtils.warningTextOutOfMemory=<html>Gallery Remote needs more memory to be able to correctly load images.<br>\
Some images may not display until you remedy the situation.<br>\
You can find out how to fix this by going to this page:
ImageUtils.warningUrlOutOfMemory=http://codex.gallery2.org/index.php/Gallery_Remote:FAQ#Out_of_memory_errors
ImageUtils.warningUrlTextOutOfMemory=Gallery Remote FAQ

# AppletMini
AppletMini.Upload = Upload
Expand All @@ -525,6 +530,7 @@ SlideFrame.paused = Showing {0} ({1, number, integer} / {2, number, integer}) (p
SlideFrame.downloading = Downloading picture {0} ({1, number, integer} / {2, number, integer})
SlideFrame.processing = Processing picture {0} ({1, number, integer} / {2, number, integer})
SlideFrame.skipping = Skipping to {0} ({1, number, integer} / {2, number, integer})
SlideFrame.error = Error loading {0} ({1, number, integer} / {2, number, integer})
SlideFrame.skippingController = {1, number, integer} / {2, number, integer}
SlideFrame.controller.left = Left arrow
SlideFrame.controller.right = Right arrow
Expand Down
Expand Up @@ -32,6 +32,7 @@ AppletMini.DefMessage=K\u00E9pek hozz\u00E1ad\u00E1sa a list\u00E1hoz...
AppletMini.Upload=F\u00F6lt\u00F6lt\u00E9s
AppletMini.pictures=Felt\u00F6ltend\u00F6 k\u00E9pek list\u00E1ja ("fogd \u00E9s vidd" vagy kattints az K\u00E9pek Hozz\u00E1ad\u00E1sa... gombra)
Common.Cancel=M\u00E9gsem
Common.translator=G\u00E1csi Zsolt
GEdiDlog.alias=R\u00F6vid n\u00E9v
GEdiDlog.passwd=Jelsz\u00F3
GEdiDlog.stndAln=Gal\u00E9ria C\u00EDme
Expand Down
93 changes: 66 additions & 27 deletions com/gallery/GalleryRemote/util/ImageLoaderUtil.java
Expand Up @@ -6,9 +6,7 @@
import com.gallery.GalleryRemote.Log;
import com.gallery.GalleryRemote.prefs.PreferenceNames;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.geom.Rectangle2D;
import java.util.*;
import java.util.regex.Matcher;
Expand All @@ -27,7 +25,7 @@ public class ImageLoaderUtil implements PreferenceNames {
public static final Color darkGray = new Color(64, 64, 64, 128);
public static Pattern breaker = Pattern.compile("<(br|BR)\\s?\\/?>");
public static Pattern stripper = Pattern.compile("<[^<>]*>");
//public static Pattern spacer = Pattern.compile("[\r\n]");
//public static Pattern mopper = Pattern.compile("\r");

int cacheSize = 10;
boolean ignoreIMFailure = false;
Expand All @@ -53,6 +51,19 @@ public void flushMemory() {
}
}

public void reduceMemory() {
Log.log(Log.LEVEL_TRACE, MODULE, "Free memory before reduction: " + Runtime.getRuntime().freeMemory());
Log.log(Log.LEVEL_TRACE, MODULE, "Current image cache: " + images.size() + " - cache size " + cacheSize);

if (images.size() > 1 && cacheSize > 1) {
cacheSize = images.size() - 1;
}

images.shrink();

Log.log(Log.LEVEL_TRACE, MODULE, "Free memory after reduction: " + Runtime.getRuntime().freeMemory());
}

public void pictureReady(Image image, Picture picture) {
if (!imageLoaderUser.blockPictureReady(image, picture)) {
imageShowNow = image;
Expand Down Expand Up @@ -130,6 +141,10 @@ public Image getSizedIconForce(Picture picture) {
ImageUtils.PREVIEW, ignoreIMFailure);
}

if (r == null) {
imageLoaderUser.pictureLoadError(picture);
}

Log.log(Log.LEVEL_TRACE, MODULE, "Adding to cache: " + picture);
images.put(picture, r);
}
Expand All @@ -145,63 +160,79 @@ public static void paintAlignedOutline(
int thickness,
int position,
int wrapWidth) {
paintAlignedOutline(g, s, textX, textY, thickness, position, wrapWidth, wrap((Graphics2D) g, s, wrapWidth), false);
paintAlignedOutline(g, textX, textY, thickness, position, wrap((Graphics2D) g, s, wrapWidth), false);
}

public static Point paintAlignedOutline(
Graphics g,
String s,
int textX, int textY,
int thickness,
int position,
int wrapWidth,
WrapInfo wrapInfo,
boolean paintOrigin) {
boolean paintAtOrigin) {
FontMetrics fm = g.getFontMetrics();
Rectangle2D bounds = fm.getStringBounds(s, g);

Point p = new Point();
Point boxPos = new Point();

switch (position / 10) {
case 1:
default:
p.y = textY;
boxPos.y = textY;
break;

case 2:
p.y = textY - wrapInfo.height / 2;
boxPos.y = textY - wrapInfo.height / 2;
break;

case 3:
p.y = textY - wrapInfo.height;
boxPos.y = textY - wrapInfo.height;
break;
}

switch (position % 10) {
case 2:
default:
boxPos.x = textX;
break;

case 0:
boxPos.x = textX - wrapInfo.width / 2;
break;

case 4:
boxPos.x = textX - wrapInfo.width;
break;
}

for (int i = 0; i < wrapInfo.lines.length; i++) {
Rectangle2D bounds1 = fm.getStringBounds(wrapInfo.lines[i], g);
Rectangle2D bounds = fm.getStringBounds(wrapInfo.lines[i], g);
Point linePos = new Point(boxPos);

if (paintAtOrigin) {
linePos.x = thickness;
linePos.y = thickness;
}

switch (position % 10) {
case 2:
default:
p.x = textX;
// nothing to do
break;

case 0:
p.x = textX - (int) bounds1.getWidth() / 2;
linePos.x += (wrapInfo.width - bounds.getWidth()) / 2;
break;

case 4:
p.x = textX - (int) bounds1.getWidth();
linePos.x += wrapInfo.width - bounds.getWidth();
break;
}

if (paintOrigin) {
paintOutline(g, wrapInfo.lines[i], thickness, fm.getAscent() + thickness, thickness);
} else {
paintOutline(g, wrapInfo.lines[i], p.x, p.y + fm.getAscent(), thickness);
}
paintOutline(g, wrapInfo.lines[i], linePos.x,
(int) (linePos.y + fm.getAscent() + bounds.getHeight() * i), thickness);
}

return p;
return boxPos;
}

public static WrapInfo wrap(
Expand Down Expand Up @@ -300,8 +331,8 @@ public static String stripTags(String text) {
m = stripper.matcher(text);
text = m.replaceAll("");

//m = spacer.matcher(m.replaceAll(""));
//text = m.replaceAll(" ");
//m = mopper.matcher(text);
//text = m.replaceAll("");

return text;
}
Expand Down Expand Up @@ -399,14 +430,16 @@ public void clear() {
while (it.hasNext()) {
Image i = (Image) it.next();
if (i != null) {
//i.getGraphics().dispose();
i.flush();
}
}

super.clear();
touchOrder.clear();

Runtime.getRuntime().gc();
System.runFinalization();
System.gc();

//Log.log(Log.LEVEL_TRACE, MODULE, Runtime.getRuntime().freeMemory() + " - " + Runtime.getRuntime().totalMemory());
}
Expand Down Expand Up @@ -434,14 +467,19 @@ public void shrink() {

Image i = (Image) get(key, false);
if (i != null) {
//i.getGraphics().dispose();
i.flush();
}

remove(key);

Runtime.getRuntime().gc();

Log.log(Log.LEVEL_TRACE, MODULE, "Shrunk " + key);
if (cacheSize > 0 && size() > cacheSize) {
shrink();
} else {
System.runFinalization();
System.gc();
}
}
}

Expand All @@ -452,5 +490,6 @@ public interface ImageLoaderUser {
public void nullRect();
public void pictureStartDownloading(Picture picture);
public void pictureStartProcessing(Picture picture);
public void pictureLoadError(Picture picture);
}
}

0 comments on commit 5eaee01

Please sign in to comment.