use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class SpriteTest method testHashCode.
/**
* Test hash code.
*/
@Test
public void testHashCode() {
final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
final int sprite = new SpriteImpl(surface).hashCode();
final Sprite spriteMedia = new SpriteImpl(media);
spriteMedia.load();
Assert.assertEquals(sprite, new SpriteImpl(surface).hashCode());
Assert.assertNotEquals(sprite, new Object().hashCode());
Assert.assertNotEquals(spriteMedia.hashCode(), new SpriteImpl(media).hashCode());
Assert.assertNotEquals(sprite, new SpriteImpl(Graphics.createImageBuffer(64, 32)).hashCode());
Assert.assertNotEquals(sprite, new SpriteImpl(Graphics.createImageBuffer(32, 32)).hashCode());
Assert.assertNotEquals(sprite, new SpriteImpl(Graphics.createImageBuffer(64, 64)).hashCode());
Assert.assertNotEquals(sprite, new SpriteImpl(Graphics.createImageBuffer(32, 64)).hashCode());
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class FactoryGraphicHeadless method createImageBuffer.
@Override
public ImageBuffer createImageBuffer(int width, int height) {
final ImageBuffer buffer = new ImageBufferHeadless(width, height, Transparency.OPAQUE);
final Graphic g = buffer.createGraphic();
g.setColor(ColorRgba.BLACK);
g.drawRect(0, 0, width, height, true);
g.dispose();
return buffer;
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class FactoryGraphicHeadlessTest method testRotate.
/*
* FactoryGraphicTest
*/
/**
* Test rotate.
*/
@Test
@Override
protected void testRotate() {
final ImageBuffer image = Graphics.getImageBuffer(Medias.create("image.png"));
final ImageBuffer rotate = Graphics.rotate(image, 90);
assertNotEquals(image, rotate);
assertEquals(image.getWidth(), rotate.getHeight());
assertEquals(image.getHeight(), rotate.getWidth());
rotate.dispose();
image.dispose();
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class ImageBufferHeadlessTest method testImageTransparency.
/**
* Test image transparency
*/
@Test
void testImageTransparency() {
final ImageBuffer image = Graphics.createImageBuffer(100, 100, ColorRgba.RED);
assertEquals(Transparency.BITMASK, image.getTransparency());
assertEquals(ColorRgba.TRANSPARENT, image.getTransparentColor());
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class RasterImage method loadFromPalette.
/**
* Load raster from palette image.
*
* @param save <code>true</code> to save generated (if) rasters, <code>false</code> else.
* @param suffix The folder suffix, if save is <code>true</code> (must not be <code>null</code>).
* @param allowed The ignored raster indexes.
*/
private void loadFromPalette(boolean save, String suffix, Collection<Integer> allowed) {
final String folder = UtilFile.removeExtension(rasterFile.getName()) + Constant.UNDERSCORE + suffix;
int rastersNumber = getRasterNumber(folder);
ImageBuffer rasterPalette = null;
ImageBuffer[] rastersBuffer = null;
for (int i = 0; i < rastersNumber; i++) {
if (allowed == null || allowed.isEmpty() || allowed.contains(Integer.valueOf(i))) {
final String file = i + Constant.DOT + ImageFormat.PNG;
final Media rasterMedia = Medias.create(rasterFile.getParentPath(), folder, file);
final ImageBuffer rasterBuffer;
if (rasterMedia.exists()) {
rasterBuffer = Graphics.getImageBuffer(rasterMedia);
rasterBuffer.prepare();
} else {
// CHECKSTYLE IGNORE LINE: NestedIfDepth
if (rastersBuffer == null) {
surface.prepare();
rasterPalette = Graphics.getImageBuffer(rasterFile);
rastersBuffer = Graphics.getRasterBuffer(surface, rasterPalette);
rastersNumber = rasterPalette.getHeight() - 1;
}
rasterBuffer = rastersBuffer[i];
// CHECKSTYLE IGNORE LINE: NestedIfDepth
if (save) {
Graphics.saveImage(rasterBuffer, rasterMedia);
}
}
rasters.add(rasterBuffer);
} else {
rasters.add(surface);
}
}
}
Aggregations