A whole lot of widening, refactoring, thinking, rethinking and fiddling around
for what ultimately boils down adding this method to BundledComponentRepository:
@Override // from IMImageProvider
public Mirage getTileImage (String path, Rectangle bounds, Colorization[] zations)
{
// we don't need our images prepared for screen rendering
BufferedImage src = _imgr.getImage(getImageKey(path), zations);
if (bounds != null) {
src = src.getSubimage(bounds.x, bounds.y, bounds.width, bounds.height);
}
return new BufferedMirage(src);
}
So much fun to revisit code I wrote six years ago.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@283 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -30,8 +30,8 @@ import com.threerings.media.image.Colorization;
|
||||
import com.threerings.media.tile.util.TileSetTrimmer;
|
||||
|
||||
/**
|
||||
* Contains the necessary information to create a set of trimmed tiles
|
||||
* from a base image and the associated trim metrics.
|
||||
* Contains the necessary information to create a set of trimmed tiles from a base image and the
|
||||
* associated trim metrics.
|
||||
*/
|
||||
public class TrimmedTileSet extends TileSet
|
||||
{
|
||||
@@ -42,9 +42,10 @@ public class TrimmedTileSet extends TileSet
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected Rectangle computeTileBounds (int tileIndex)
|
||||
public Rectangle computeTileBounds (int tileIndex, Rectangle bounds)
|
||||
{
|
||||
return _obounds[tileIndex];
|
||||
bounds.setBounds(_obounds[tileIndex]);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -61,14 +62,12 @@ public class TrimmedTileSet extends TileSet
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a trimmed tileset from the supplied source tileset. The
|
||||
* image path must be set by hand to the appropriate path based on
|
||||
* where the image data that is written to the <code>destImage</code>
|
||||
* parameter is actually stored on the file system. See {@link
|
||||
* Creates a trimmed tileset from the supplied source tileset. The image path must be set by
|
||||
* hand to the appropriate path based on where the image data that is written to the
|
||||
* <code>destImage</code> parameter is actually stored on the file system. See {@link
|
||||
* TileSetTrimmer#trimTileSet} for further information.
|
||||
*/
|
||||
public static TrimmedTileSet trimTileSet (
|
||||
TileSet source, OutputStream destImage)
|
||||
public static TrimmedTileSet trimTileSet (TileSet source, OutputStream destImage)
|
||||
throws IOException
|
||||
{
|
||||
final TrimmedTileSet tset = new TrimmedTileSet();
|
||||
@@ -79,36 +78,32 @@ public class TrimmedTileSet extends TileSet
|
||||
|
||||
// grab the dimensions of the original tiles
|
||||
for (int ii = 0; ii < tcount; ii++) {
|
||||
tset._tbounds[ii] = source.computeTileBounds(ii);
|
||||
tset._tbounds[ii] = source.computeTileBounds(ii, new Rectangle());
|
||||
}
|
||||
|
||||
// create the trimmed tileset image
|
||||
TileSetTrimmer.TrimMetricsReceiver tmr =
|
||||
new TileSetTrimmer.TrimMetricsReceiver() {
|
||||
public void trimmedTile (int tileIndex, int imageX, int imageY,
|
||||
int trimX, int trimY,
|
||||
int trimWidth, int trimHeight) {
|
||||
tset._tbounds[tileIndex].x = trimX;
|
||||
tset._tbounds[tileIndex].y = trimY;
|
||||
tset._obounds[tileIndex] =
|
||||
new Rectangle(imageX, imageY, trimWidth, trimHeight);
|
||||
}
|
||||
};
|
||||
TileSetTrimmer.TrimMetricsReceiver tmr = new TileSetTrimmer.TrimMetricsReceiver() {
|
||||
public void trimmedTile (int tileIndex, int imageX, int imageY,
|
||||
int trimX, int trimY, int trimWidth, int trimHeight) {
|
||||
tset._tbounds[tileIndex].x = trimX;
|
||||
tset._tbounds[tileIndex].y = trimY;
|
||||
tset._obounds[tileIndex] = new Rectangle(imageX, imageY, trimWidth, trimHeight);
|
||||
}
|
||||
};
|
||||
TileSetTrimmer.trimTileSet(source, destImage, tmr);
|
||||
|
||||
return tset;
|
||||
}
|
||||
|
||||
/** The width and height of the trimmed tile, and the x and y offset
|
||||
* of the trimmed image within our tileset image. */
|
||||
/** The width and height of the trimmed tile, and the x and y offset of the trimmed image
|
||||
* within our tileset image. */
|
||||
protected Rectangle[] _obounds;
|
||||
|
||||
/** The width and height of the untrimmed image and the x and y offset
|
||||
* within the untrimmed image at which the trimmed image should be
|
||||
* rendered. */
|
||||
/** The width and height of the untrimmed image and the x and y offset within the untrimmed
|
||||
* image at which the trimmed image should be rendered. */
|
||||
protected Rectangle[] _tbounds;
|
||||
|
||||
/** Increase this value when object's serialized state is impacted by
|
||||
* a class change (modification of fields, inheritance). */
|
||||
/** Increase this value when object's serialized state is impacted by a class change
|
||||
* (modification of fields, inheritance). */
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user