Don't assume we have an image manager or that we care about "compatible"
images. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3632 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -54,6 +54,7 @@ import com.threerings.resource.ResourceManager;
|
|||||||
* Provides a single point of access for image retrieval and caching.
|
* Provides a single point of access for image retrieval and caching.
|
||||||
*/
|
*/
|
||||||
public class ImageManager
|
public class ImageManager
|
||||||
|
implements ImageUtil.ImageCreator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Used to identify an image for caching and reconstruction.
|
* Used to identify an image for caching and reconstruction.
|
||||||
|
|||||||
@@ -50,6 +50,15 @@ import com.samskivert.swing.Label;
|
|||||||
*/
|
*/
|
||||||
public class ImageUtil
|
public class ImageUtil
|
||||||
{
|
{
|
||||||
|
public static interface ImageCreator
|
||||||
|
{
|
||||||
|
/** Used by routines that need to create new images to allow the
|
||||||
|
* caller to dictate the format (which may mean using
|
||||||
|
* createCompatibleImage). */
|
||||||
|
public BufferedImage createImage (
|
||||||
|
int width, int height, int transparency);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new buffered image with the same sample model and color
|
* Creates a new buffered image with the same sample model and color
|
||||||
* model as the source image but with the new width and height.
|
* model as the source image but with the new width and height.
|
||||||
@@ -273,9 +282,9 @@ public class ImageUtil
|
|||||||
* traced with the given color and thickness.
|
* traced with the given color and thickness.
|
||||||
*/
|
*/
|
||||||
public static BufferedImage createTracedImage (
|
public static BufferedImage createTracedImage (
|
||||||
ImageManager imgr, BufferedImage src, Color tcolor, int thickness)
|
ImageCreator isrc, BufferedImage src, Color tcolor, int thickness)
|
||||||
{
|
{
|
||||||
return createTracedImage(imgr, src, tcolor, thickness, 1.0f, 1.0f);
|
return createTracedImage(isrc, src, tcolor, thickness, 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -283,12 +292,12 @@ public class ImageUtil
|
|||||||
* traced with the given color, thickness and alpha transparency.
|
* traced with the given color, thickness and alpha transparency.
|
||||||
*/
|
*/
|
||||||
public static BufferedImage createTracedImage (
|
public static BufferedImage createTracedImage (
|
||||||
ImageManager imgr, BufferedImage src, Color tcolor, int thickness,
|
ImageCreator isrc, BufferedImage src, Color tcolor, int thickness,
|
||||||
float startAlpha, float endAlpha)
|
float startAlpha, float endAlpha)
|
||||||
{
|
{
|
||||||
// create the destination image
|
// create the destination image
|
||||||
int wid = src.getWidth(), hei = src.getHeight();
|
int wid = src.getWidth(), hei = src.getHeight();
|
||||||
BufferedImage dest = imgr.createImage(
|
BufferedImage dest = isrc.createImage(
|
||||||
wid, hei, Transparency.TRANSLUCENT);
|
wid, hei, Transparency.TRANSLUCENT);
|
||||||
return createTracedImage(
|
return createTracedImage(
|
||||||
src, dest, tcolor, thickness, startAlpha, endAlpha);
|
src, dest, tcolor, thickness, startAlpha, endAlpha);
|
||||||
@@ -408,7 +417,7 @@ public class ImageUtil
|
|||||||
* values from the second.
|
* values from the second.
|
||||||
*/
|
*/
|
||||||
public static BufferedImage composeMaskedImage (
|
public static BufferedImage composeMaskedImage (
|
||||||
ImageManager imgr, BufferedImage mask, BufferedImage base)
|
ImageCreator isrc, BufferedImage mask, BufferedImage base)
|
||||||
{
|
{
|
||||||
int wid = base.getWidth();
|
int wid = base.getWidth();
|
||||||
int hei = base.getHeight();
|
int hei = base.getHeight();
|
||||||
@@ -437,7 +446,7 @@ public class ImageUtil
|
|||||||
} else {
|
} else {
|
||||||
// otherwise composite them by rendering them with an alpha
|
// otherwise composite them by rendering them with an alpha
|
||||||
// rule
|
// rule
|
||||||
BufferedImage target = imgr.createImage(
|
BufferedImage target = isrc.createImage(
|
||||||
wid, hei, Transparency.TRANSLUCENT);
|
wid, hei, Transparency.TRANSLUCENT);
|
||||||
Graphics2D g2 = target.createGraphics();
|
Graphics2D g2 = target.createGraphics();
|
||||||
try {
|
try {
|
||||||
@@ -458,7 +467,7 @@ public class ImageUtil
|
|||||||
* clear.
|
* clear.
|
||||||
*/
|
*/
|
||||||
public static BufferedImage composeMaskedImage (
|
public static BufferedImage composeMaskedImage (
|
||||||
ImageManager imgr, Shape mask, BufferedImage base)
|
ImageCreator isrc, Shape mask, BufferedImage base)
|
||||||
{
|
{
|
||||||
int wid = base.getWidth();
|
int wid = base.getWidth();
|
||||||
int hei = base.getHeight();
|
int hei = base.getHeight();
|
||||||
@@ -475,7 +484,7 @@ public class ImageUtil
|
|||||||
// But it's something to consider)
|
// But it's something to consider)
|
||||||
|
|
||||||
// composite them by rendering them with an alpha rule
|
// composite them by rendering them with an alpha rule
|
||||||
BufferedImage target = imgr.createImage(
|
BufferedImage target = isrc.createImage(
|
||||||
wid, hei, Transparency.TRANSLUCENT);
|
wid, hei, Transparency.TRANSLUCENT);
|
||||||
Graphics2D g2 = target.createGraphics();
|
Graphics2D g2 = target.createGraphics();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user