Allow the ImageManager to function if we're running in headless mode. It

will create all images as 32-bit ARGB.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2674 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-06-23 17:59:04 +00:00
parent 13fba9919e
commit 28a9441143
2 changed files with 19 additions and 8 deletions
@@ -1,5 +1,5 @@
// //
// $Id: ImageManager.java,v 1.56 2003/05/31 00:56:38 mdb Exp $ // $Id: ImageManager.java,v 1.57 2003/06/23 17:59:04 mdb Exp $
package com.threerings.media.image; package com.threerings.media.image;
@@ -119,7 +119,12 @@ public class ImageManager
{ {
// DEBUG: override transparency for the moment on all images // DEBUG: override transparency for the moment on all images
transparency = Transparency.TRANSLUCENT; transparency = Transparency.TRANSLUCENT;
return _gc.createCompatibleImage(width, height, transparency); if (_gc != null) {
return _gc.createCompatibleImage(width, height, transparency);
} else {
// if we're running in headless mode, do everything in 24-bit
return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
} }
/** /**
@@ -1,5 +1,5 @@
// //
// $Id: ImageUtil.java,v 1.32 2003/05/07 19:14:38 mdb Exp $ // $Id: ImageUtil.java,v 1.33 2003/06/23 17:59:04 mdb Exp $
package com.threerings.media.image; package com.threerings.media.image;
@@ -10,6 +10,7 @@ import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice; import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image; import java.awt.Image;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Shape; import java.awt.Shape;
@@ -576,16 +577,21 @@ public class ImageUtil
} }
/** /**
* Obtains the default graphics configuration for this VM. * Obtains the default graphics configuration for this VM. If the JVM
* is in headless mode, this method will return null.
*/ */
protected static GraphicsConfiguration getDefGC () protected static GraphicsConfiguration getDefGC ()
{ {
if (_gc == null) { if (_gc == null) {
// obtain information on our graphics environment // obtain information on our graphics environment
GraphicsEnvironment env = try {
GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsEnvironment env =
GraphicsDevice gd = env.getDefaultScreenDevice(); GraphicsEnvironment.getLocalGraphicsEnvironment();
_gc = gd.getDefaultConfiguration(); GraphicsDevice gd = env.getDefaultScreenDevice();
_gc = gd.getDefaultConfiguration();
} catch (HeadlessException e) {
// no problem, just return null
}
} }
return _gc; return _gc;
} }