Search in sources :

Example 81 with ImageBuffer

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());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Sprite(com.b3dgs.lionengine.graphic.Sprite) Test(org.junit.Test)

Example 82 with ImageBuffer

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;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic)

Example 83 with ImageBuffer

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();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test) FactoryGraphicTest(com.b3dgs.lionengine.graphic.FactoryGraphicTest)

Example 84 with ImageBuffer

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());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test)

Example 85 with ImageBuffer

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);
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Media(com.b3dgs.lionengine.Media)

Aggregations

ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)110 Test (org.junit.Test)34 Test (org.junit.jupiter.api.Test)28 Media (com.b3dgs.lionengine.Media)16 Graphic (com.b3dgs.lionengine.graphic.Graphic)12 GraphicTest (com.b3dgs.lionengine.graphic.GraphicTest)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 BufferedImage (java.awt.image.BufferedImage)9 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)6 SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)5 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)3 FactoryGraphicTest (com.b3dgs.lionengine.graphic.FactoryGraphicTest)3 Image (com.b3dgs.lionengine.graphic.Image)3 Sprite (com.b3dgs.lionengine.graphic.Sprite)3 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TilesExtractor (com.b3dgs.lionengine.game.feature.tile.TilesExtractor)2 ArrayList (java.util.ArrayList)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Config (com.b3dgs.lionengine.Config)1