com.threerings.media.image
Class ImageManager

java.lang.Object
  extended by com.threerings.media.image.ImageManager
All Implemented Interfaces:
ImageUtil.ImageCreator
Direct Known Subclasses:
ClientImageManager

public class ImageManager
extends Object
implements ImageUtil.ImageCreator

Provides a single point of access for image retrieval and caching. This does not include any tie-in to runtime adjustments to control caching and mirage creation.


Nested Class Summary
protected static class ImageManager.CacheRecord
          Maintains a source image and a set of colorized versions in the image cache.
static class ImageManager.ImageKey
          Used to identify an image for caching and reconstruction.
static interface ImageManager.OptimalImageCreator
          This interface allows the image manager to create images that are in a format optimal for rendering to the screen.
 
Field Summary
protected  Throttle _cacheStatThrottle
          Throttle our cache status logging to once every 300 seconds.
protected  LRUHashMap<ImageManager.ImageKey,ImageManager.CacheRecord> _ccache
          A cache of loaded images.
protected  ImageDataProvider _defaultProvider
          Our default data provider.
protected  ImageManager.OptimalImageCreator _icreator
          We use this to create images optimized for rendering.
protected  HashSet<ImageManager.ImageKey> _keySet
          The set of all keys we've ever seen.
protected  Map<String,ImageDataProvider> _providers
          Data providers for different resource sets.
protected  ResourceManager _rmgr
          A reference to the resource manager via which we load image data by default.
protected static int DEFAULT_CACHE_SIZE
          Default amount of data we'll store in our image cache.
 
Constructor Summary
ImageManager(ResourceManager rmgr, Component context)
          A convenience constructor that creates an AWTImageCreator for use by the image manager.
ImageManager(ResourceManager rmgr, ImageManager.OptimalImageCreator icreator)
          Construct an image manager with the specified ResourceManager from which it will obtain its data.
 
Method Summary
 void clearCache()
          Clears all images out of the cache.
 BufferedImage createImage(int width, int height, int transparency)
          Creates a buffered image, optimized for display on our graphics device.
 int getCacheSize()
          Returns how much space we're willing to use for caching images.
protected  ImageDataProvider getDataProvider(String rset)
          Returns the data provider configured to obtain image data from the specified resource set.
 BufferedImage getImage(ImageManager.ImageKey key, Colorization[] zations)
          Obtains the image identified by the specified key, caching if possible.
 BufferedImage getImage(String path)
          Loads (and caches) the specified image from the resource manager using the supplied path to identify the image.
 BufferedImage getImage(String path, Colorization[] zations)
          Like getImage(String) but the specified colorizations are applied to the image before it is returned.
 BufferedImage getImage(String rset, String path)
          Like getImage(String) but the image is loaded from the specified resource set rathern than the default resource set.
 BufferedImage getImage(String rset, String path, Colorization[] zations)
          Like getImage(String,String) but the specified colorizations are applied to the image before it is returned.
 ImageManager.OptimalImageCreator getImageCreator()
          Returns the image creator that can be used to create buffered images optimized for rendering to the screen.
 ImageManager.ImageKey getImageKey(ImageDataProvider daprov, String path)
          Returns an image key that can be used to fetch the image identified by the specified data provider and image path.
 ImageManager.ImageKey getImageKey(String rset, String path)
          Returns an image key that can be used to fetch the image identified by the specified resource set and image path.
 Mirage getMirage(ImageManager.ImageKey key)
          Creates a mirage which is an image optimized for display on our current display device and which will be stored into video memory if possible.
 Mirage getMirage(ImageManager.ImageKey key, Colorization[] zations)
          Like getMirage(ImageKey) but the supplied colorizations are applied to the source image before creating the mirage.
 Mirage getMirage(ImageManager.ImageKey key, Rectangle bounds)
          Like getMirage(ImageKey) but that only the specified subimage of the source image is used to build the mirage.
 Mirage getMirage(ImageManager.ImageKey key, Rectangle bounds, Colorization[] zations)
          Like getMirage(ImageKey,Colorization[]) except that the mirage is created using only the specified subset of the original image.
 Mirage getMirage(String rsrcPath)
          Creates a mirage which is an image optimized for display on our current display device and which will be stored into video memory if possible.
 BufferedImage getPreparedImage(String path)
          Loads (and caches) the specified image from the resource manager using the supplied path to identify the image.
 BufferedImage getPreparedImage(String rset, String path)
          Loads (and caches) the specified image from the resource manager, obtaining the image from the supplied resource set.
 BufferedImage getPreparedImage(String rset, String path, Colorization[] zations)
          Loads (and caches) the specified image from the resource manager, obtaining the image from the supplied resource set and applying the using the supplied path to identify the image.
protected  BufferedImage loadImage(ImageManager.ImageKey key)
          Loads and returns the image with the specified key from the supplied data provider.
protected  void reportCachePerformance()
          Reports statistics detailing the image manager cache performance and the current size of the cached images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_rmgr

protected ResourceManager _rmgr
A reference to the resource manager via which we load image data by default.


_icreator

protected ImageManager.OptimalImageCreator _icreator
We use this to create images optimized for rendering.


_ccache

protected LRUHashMap<ImageManager.ImageKey,ImageManager.CacheRecord> _ccache
A cache of loaded images.


_keySet

protected HashSet<ImageManager.ImageKey> _keySet
The set of all keys we've ever seen.


_cacheStatThrottle

protected Throttle _cacheStatThrottle
Throttle our cache status logging to once every 300 seconds.


_defaultProvider

protected ImageDataProvider _defaultProvider
Our default data provider.


_providers

protected Map<String,ImageDataProvider> _providers
Data providers for different resource sets.


DEFAULT_CACHE_SIZE

protected static int DEFAULT_CACHE_SIZE
Default amount of data we'll store in our image cache.

Constructor Detail

ImageManager

public ImageManager(ResourceManager rmgr,
                    ImageManager.OptimalImageCreator icreator)
Construct an image manager with the specified ResourceManager from which it will obtain its data.


ImageManager

public ImageManager(ResourceManager rmgr,
                    Component context)
A convenience constructor that creates an AWTImageCreator for use by the image manager.

Method Detail

getCacheSize

public int getCacheSize()
Returns how much space we're willing to use for caching images.


clearCache

public void clearCache()
Clears all images out of the cache.


createImage

public BufferedImage createImage(int width,
                                 int height,
                                 int transparency)
Creates a buffered image, optimized for display on our graphics device.

Specified by:
createImage in interface ImageUtil.ImageCreator

getImage

public BufferedImage getImage(String path)
Loads (and caches) the specified image from the resource manager using the supplied path to identify the image.


getImage

public BufferedImage getImage(String path,
                              Colorization[] zations)
Like getImage(String) but the specified colorizations are applied to the image before it is returned.


getImage

public BufferedImage getImage(String rset,
                              String path)
Like getImage(String) but the image is loaded from the specified resource set rathern than the default resource set.


getImage

public BufferedImage getImage(String rset,
                              String path,
                              Colorization[] zations)
Like getImage(String,String) but the specified colorizations are applied to the image before it is returned.


getPreparedImage

public BufferedImage getPreparedImage(String path)
Loads (and caches) the specified image from the resource manager using the supplied path to identify the image.

Additionally the image is optimized for display in the current graphics configuration. Consider using getMirage(ImageKey) instead of prepared images as they (some day) will automatically use volatile images to increase performance.


getPreparedImage

public BufferedImage getPreparedImage(String rset,
                                      String path)
Loads (and caches) the specified image from the resource manager, obtaining the image from the supplied resource set.

Additionally the image is optimized for display in the current graphics configuration. Consider using getMirage(ImageKey) instead of prepared images as they (some day) will automatically use volatile images to increase performance.


getPreparedImage

public BufferedImage getPreparedImage(String rset,
                                      String path,
                                      Colorization[] zations)
Loads (and caches) the specified image from the resource manager, obtaining the image from the supplied resource set and applying the using the supplied path to identify the image.

Additionally the image is optimized for display in the current graphics configuration. Consider using getMirage(ImageKey,Colorization[]) instead of prepared images as they (some day) will automatically use volatile images to increase performance.


getImageKey

public ImageManager.ImageKey getImageKey(String rset,
                                         String path)
Returns an image key that can be used to fetch the image identified by the specified resource set and image path.


getImageKey

public ImageManager.ImageKey getImageKey(ImageDataProvider daprov,
                                         String path)
Returns an image key that can be used to fetch the image identified by the specified data provider and image path.


getImage

public BufferedImage getImage(ImageManager.ImageKey key,
                              Colorization[] zations)
Obtains the image identified by the specified key, caching if possible. The image will be recolored using the supplied colorizations if requested.


getMirage

public Mirage getMirage(String rsrcPath)
Creates a mirage which is an image optimized for display on our current display device and which will be stored into video memory if possible.


getMirage

public Mirage getMirage(ImageManager.ImageKey key)
Creates a mirage which is an image optimized for display on our current display device and which will be stored into video memory if possible.


getMirage

public Mirage getMirage(ImageManager.ImageKey key,
                        Rectangle bounds)
Like getMirage(ImageKey) but that only the specified subimage of the source image is used to build the mirage.


getMirage

public Mirage getMirage(ImageManager.ImageKey key,
                        Colorization[] zations)
Like getMirage(ImageKey) but the supplied colorizations are applied to the source image before creating the mirage.


getMirage

public Mirage getMirage(ImageManager.ImageKey key,
                        Rectangle bounds,
                        Colorization[] zations)
Like getMirage(ImageKey,Colorization[]) except that the mirage is created using only the specified subset of the original image.


getImageCreator

public ImageManager.OptimalImageCreator getImageCreator()
Returns the image creator that can be used to create buffered images optimized for rendering to the screen.


getDataProvider

protected ImageDataProvider getDataProvider(String rset)
Returns the data provider configured to obtain image data from the specified resource set.


loadImage

protected BufferedImage loadImage(ImageManager.ImageKey key)
Loads and returns the image with the specified key from the supplied data provider.


reportCachePerformance

protected void reportCachePerformance()
Reports statistics detailing the image manager cache performance and the current size of the cached images.