com.threerings.media.tile
Class TrimmedObjectTileSet

java.lang.Object
  extended by com.threerings.media.tile.TileSet
      extended by com.threerings.media.tile.TrimmedObjectTileSet
All Implemented Interfaces:
BaseSizableTileSet, RecolorableTileSet, Serializable, Cloneable

public class TrimmedObjectTileSet
extends TileSet
implements RecolorableTileSet, BaseSizableTileSet

An object tileset in which the objects have been trimmed to the smallest possible images that still contain all of their non-transparent pixels. The objects' origins are adjusted so that the objects otherwise behave exactly as the untrimmed objects and are thus interchangeable (and more memory efficient).

See Also:
Serialized Form

Nested Class Summary
protected static class TrimmedObjectTileSet.Bits
          Extra bits related to object tiles.
 
Nested classes/interfaces inherited from class com.threerings.media.tile.TileSet
TileSet.Colorizer
 
Field Summary
protected  TrimmedObjectTileSet.Bits[] _bits
          Extra bits relating to our objects.
protected  Rectangle[] _bounds
          Contains the width and height of each object tile and the offset into the tileset image of their image data.
protected  Rectangle[] _ometrics
          Contains the origin offset for each object tile and the object footprint width and height (in tile units).
protected  String[] _zations
          Colorization classes that apply to our objects.
 
Fields inherited from class com.threerings.media.tile.TileSet
_atiles, _cacheStatThrottle, _imagePath, _improv, _key, _name
 
Constructor Summary
TrimmedObjectTileSet()
           
 
Method Summary
 Rectangle computeTileBounds(int tileIndex, Rectangle bounds)
          Computes and fills in the bounds for the specified tile based on the mechanism used by the derived class to do such things.
protected  Tile createTile()
          Creates a blank tile of the appropriate type for this tileset.
 int getBaseHeight(int tileIdx)
          Returns the base height for the specified object index.
 int getBaseWidth(int tileIdx)
          Returns the base width for the specified object index.
 String[] getColorizations()
          Returns the colorization classes that should be used to recolor objects in this tileset.
protected  Colorization[] getColorizations(int tileIndex, TileSet.Colorizer rizer)
          Returns colorizations for the specified tile image.
 String[] getConstraints(int tileIdx)
          Returns the constraints associated with the specified tile index, or null if the object has no associated constraints.
 int getSpotOrient(int tileIdx)
          Returns the orientation of the spot associated with the specified tile index, or -1 if the object has no associated spot.
 int getTileCount()
          Returns the number of tiles in the tileset.
 int getXSpot(int tileIdx)
          Returns the x coordinate of the spot associated with the specified tile index.
 int getYSpot(int tileIdx)
          Returns the y coordinate of the spot associated with the specified tile index.
 boolean hasConstraint(int tileIdx, String constraint)
          Checks whether the tile at the specified index has the given constraint.
protected  void initTile(Tile tile, int tileIndex, Colorization[] zations)
          Initializes the supplied tile.
protected  void toString(StringBuilder buf)
          Derived classes can override this, calling super.toString(buf) and then appending additional information to the buffer.
static TrimmedObjectTileSet trimObjectTileSet(ObjectTileSet source, OutputStream destImage)
          Convenience function to trim the tile set to a file using FastImageIO.
static TrimmedObjectTileSet trimObjectTileSet(ObjectTileSet source, OutputStream destImage, String imgFormat)
          Creates a trimmed object tileset from the supplied source object tileset.
 
Methods inherited from class com.threerings.media.tile.TileSet
checkTileIndex, clone, clone, getImagePath, getName, getRawTileImage, getRawTileSetImage, getTile, getTile, getTile, getTileMirage, getTileMirage, getTileMirages, reportCachePerformance, setImagePath, setImageProvider, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_bounds

protected Rectangle[] _bounds
Contains the width and height of each object tile and the offset into the tileset image of their image data.


_ometrics

protected Rectangle[] _ometrics
Contains the origin offset for each object tile and the object footprint width and height (in tile units).


_bits

protected TrimmedObjectTileSet.Bits[] _bits
Extra bits relating to our objects.


_zations

protected String[] _zations
Colorization classes that apply to our objects.

Constructor Detail

TrimmedObjectTileSet

public TrimmedObjectTileSet()
Method Detail

getTileCount

public int getTileCount()
Description copied from class: TileSet
Returns the number of tiles in the tileset.

Specified by:
getTileCount in class TileSet

computeTileBounds

public Rectangle computeTileBounds(int tileIndex,
                                   Rectangle bounds)
Description copied from class: TileSet
Computes and fills in the bounds for the specified tile based on the mechanism used by the derived class to do such things. The width and height of the bounds should be the size of the tile image and the x and y offset should be the offset in the tileset image for the image data of the specified tile.

Specified by:
computeTileBounds in class TileSet
Parameters:
tileIndex - the index of the tile whose bounds are to be computed.
bounds - the rectangle object into which to fill the bounds.
Returns:
the rectangle passed into the bounds parameter.

getXSpot

public int getXSpot(int tileIdx)
Returns the x coordinate of the spot associated with the specified tile index.


getYSpot

public int getYSpot(int tileIdx)
Returns the y coordinate of the spot associated with the specified tile index.


getSpotOrient

public int getSpotOrient(int tileIdx)
Returns the orientation of the spot associated with the specified tile index, or -1 if the object has no associated spot.


getConstraints

public String[] getConstraints(int tileIdx)
Returns the constraints associated with the specified tile index, or null if the object has no associated constraints.


hasConstraint

public boolean hasConstraint(int tileIdx,
                             String constraint)
Checks whether the tile at the specified index has the given constraint.


getColorizations

public String[] getColorizations()
Description copied from interface: RecolorableTileSet
Returns the colorization classes that should be used to recolor objects in this tileset.

Specified by:
getColorizations in interface RecolorableTileSet

getBaseWidth

public int getBaseWidth(int tileIdx)
Returns the base width for the specified object index.

Specified by:
getBaseWidth in interface BaseSizableTileSet

getBaseHeight

public int getBaseHeight(int tileIdx)
Returns the base height for the specified object index.

Specified by:
getBaseHeight in interface BaseSizableTileSet

getColorizations

protected Colorization[] getColorizations(int tileIndex,
                                          TileSet.Colorizer rizer)
Description copied from class: TileSet
Returns colorizations for the specified tile image. The default is to return any colorizations associated with the tileset via a call to TileSet.clone(Colorization[]), however derived classes may have dynamic colorization policies that look up colorization assignments from the supplied colorizer.

Overrides:
getColorizations in class TileSet

createTile

protected Tile createTile()
Description copied from class: TileSet
Creates a blank tile of the appropriate type for this tileset.

Overrides:
createTile in class TileSet
Returns:
a blank tile ready to be populated with its image and metadata.

initTile

protected void initTile(Tile tile,
                        int tileIndex,
                        Colorization[] zations)
Description copied from class: TileSet
Initializes the supplied tile. Derived classes can override this method to add in their own tile information, but should be sure to call super.initTile().

Overrides:
initTile in class TileSet
Parameters:
tile - the tile to initialize.
tileIndex - the index of the tile.
zations - the colorizations to be used when generating the tile image.

toString

protected void toString(StringBuilder buf)
Description copied from class: TileSet
Derived classes can override this, calling super.toString(buf) and then appending additional information to the buffer.

Overrides:
toString in class TileSet

trimObjectTileSet

public static TrimmedObjectTileSet trimObjectTileSet(ObjectTileSet source,
                                                     OutputStream destImage)
                                              throws IOException
Convenience function to trim the tile set to a file using FastImageIO.

Throws:
IOException

trimObjectTileSet

public static TrimmedObjectTileSet trimObjectTileSet(ObjectTileSet source,
                                                     OutputStream destImage,
                                                     String imgFormat)
                                              throws IOException
Creates a trimmed object tileset from the supplied source object tileset. The image path must be set by hand to the appropriate path based on where the image data that is written to the destImage parameter is actually stored on the file system. If imgFormat is null, uses FastImageIO to save the file. See TileSetTrimmer.trimTileSet(com.threerings.media.tile.TileSet, java.io.OutputStream, com.threerings.media.tile.util.TileSetTrimmer.TrimMetricsReceiver) for further information.

Throws:
IOException