use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class SpriteTiledTest method testHashCode.
/**
* Test hash code.
*/
@Test
public void testHashCode() {
final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
final int sprite = new SpriteTiledImpl(surface, 16, 8).hashCode();
final SpriteTiled spriteMedia = new SpriteTiledImpl(media, 16, 8);
spriteMedia.load();
Assert.assertEquals(sprite, new SpriteTiledImpl(surface, 16, 8).hashCode());
Assert.assertNotEquals(sprite, new Object().hashCode());
Assert.assertNotEquals(spriteMedia.hashCode(), new SpriteTiledImpl(media, 16, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(32, 32), 16, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(64, 64), 16, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(32, 64), 16, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 8, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 16).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(32, 32), 8, 8).hashCode());
Assert.assertNotEquals(sprite, new SpriteTiledImpl(Graphics.createImageBuffer(64, 64), 16, 16).hashCode());
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class TilesExtractor method isExtracted.
/**
* Check if tile has already been extracted regarding the current tile on level rip.
*
* @param level The level rip reference.
* @param x The current level rip horizontal location.
* @param y The current level rip vertical location.
* @param tiles The current extracted tiles.
* @return <code>true</code> if already extracted, <code>false</code> else.
*/
private static boolean isExtracted(SpriteTiled level, int x, int y, Collection<ImageBuffer> tiles) {
final int tw = level.getTileWidth();
final int th = level.getTileHeight();
final ImageBuffer surface = level.getSurface();
for (final ImageBuffer tile : tiles) {
if (compareTile(tw, th, surface, x, y, tile, 0, 0)) {
return true;
}
}
return false;
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class TilesExtractor method extract.
/**
* Start using specified output file. Listeners are cleared once ended.
*
* @param canceler The canceler reference (can be <code>null</code>).
* @param tw The tile width.
* @param th The tile height.
* @param levelRips The levels rip used.
* @return The extracted tile sheets.
* @throws LionEngineException If an error occurred when computing sheet.
*/
public Collection<ImageBuffer> extract(Canceler canceler, int tw, int th, Collection<Media> levelRips) {
final int tilesNumber = getTilesNumber(tw, th, levelRips);
final Collection<ImageBuffer> tiles = new ArrayList<>();
int checkedTiles = 0;
for (final Media levelRip : levelRips) {
final SpriteTiled level = Drawable.loadSpriteTiled(levelRip, tw, th);
level.load();
level.prepare();
checkedTiles = extract(canceler, level, tilesNumber, tiles, checkedTiles);
level.getSurface().dispose();
if (checkedTiles < 0) {
break;
}
}
listeners.clear();
return tiles;
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class TilesExtractor method extract.
/**
* Extract the tile from level.
*
* @param level The level image reference.
* @param number The tile number on level.
* @return The extracted tile image from level.
*/
private static ImageBuffer extract(SpriteTiled level, int number) {
final ColorRgba transparency = level.getSurface().getTransparentColor();
final ImageBuffer tile = Graphics.createImageBuffer(level.getTileWidth(), level.getTileHeight(), transparency);
final Graphic g = tile.createGraphic();
level.setTile(number);
level.render(g);
g.dispose();
final ImageBuffer copy = Graphics.getImageBuffer(tile);
tile.dispose();
return copy;
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class LevelRipConverter method start.
/**
* Run the converter.
*
* @param levelrip The file containing the levelrip as an image.
* @param map The destination map reference.
* @param listener The progress listener.
* @param canceler The canceler reference.
* @return The total number of not found tiles.
* @throws LionEngineException If media is <code>null</code> or image cannot be read.
*/
public static int start(Media levelrip, MapTile map, ProgressListener listener, Canceler canceler) {
final Sprite imageMap = Drawable.loadSprite(levelrip);
imageMap.load();
imageMap.prepare();
final int imageTilesInX = imageMap.getWidth() / map.getTileWidth();
final int imageTilesInY = imageMap.getHeight() / map.getTileHeight();
map.create(map.getTileWidth(), map.getTileHeight(), imageTilesInX, imageTilesInY);
final double progressMax = imageTilesInX * (double) imageTilesInY;
long progress = 0L;
int lastPercent = 0;
int errors = 0;
final ImageBuffer tileRef = imageMap.getSurface();
for (int progressTileY = 0; progressTileY < imageTilesInY; progressTileY++) {
for (int progressTileX = 0; progressTileX < imageTilesInX; progressTileX++) {
if (!checkPixel(map, tileRef, progressTileX, progressTileY)) {
Verbose.warning("Tile missing at: " + progressTileX + " " + progressTileY);
errors++;
}
final int percent = (int) Math.round(progress / progressMax * 100);
if (listener != null && percent != lastPercent) {
listener.notifyProgress(percent, progressTileX, progressTileY);
}
lastPercent = percent;
progress++;
if (canceler != null && canceler.isCanceled()) {
tileRef.dispose();
return errors;
}
}
}
tileRef.dispose();
return errors;
}
Aggregations