Search in sources :

Example 1 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class Minimap method computeSheet.

/**
 * Compute the current sheet.
 *
 * @param colors The colors data.
 * @param sheet The sheet number.
 */
private void computeSheet(Map<TileRef, ColorRgba> colors, Integer sheet) {
    final SpriteTiled tiles = map.getSheet(sheet);
    final ImageBuffer tilesSurface = tiles.getSurface();
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    int number = 0;
    for (int i = 0; i < tilesSurface.getWidth(); i += tw) {
        for (int j = 0; j < tilesSurface.getHeight(); j += th) {
            final int h = number * tw % tiles.getWidth();
            final int v = number / tiles.getTilesHorizontal() * th;
            final ColorRgba color = UtilColor.getWeightedColor(tilesSurface, h, v, tw, th);
            if (!(NO_TILE.equals(color) || color.getAlpha() == 0)) {
                colors.put(new TileRef(sheet, number), color);
            }
            number++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 2 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class SpriteTiledTest method testConstructorSurface.

/**
 * Test constructor with surface.
 */
@Test
public void testConstructorSurface() {
    final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
    final SpriteTiled sprite = new SpriteTiledImpl(surface, 16, 8);
    Assert.assertTrue(sprite.isLoaded());
    Assert.assertEquals(surface, sprite.getSurface());
    Assert.assertEquals(64, sprite.getWidth());
    Assert.assertEquals(32, sprite.getHeight());
    Assert.assertEquals(16, sprite.getTileWidth());
    Assert.assertEquals(8, sprite.getTileHeight());
    Assert.assertEquals(4, sprite.getTilesHorizontal());
    Assert.assertEquals(4, sprite.getTilesVertical());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

Example 3 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FilterBlurTest method testLowHeight.

/**
 * Test with low height.
 */
@Test
public void testLowHeight() {
    final FilterBlur blur = new FilterBlur();
    final ImageBuffer image = Graphics.createImageBuffer(3, 1);
    final ImageBuffer filtered = blur.filter(image);
    Assert.assertEquals(image, filtered);
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.Test)

Example 4 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FilterBlurTest method testLowWidth.

/**
 * Test with low width.
 */
@Test
public void testLowWidth() {
    final FilterBlur blur = new FilterBlur();
    final ImageBuffer image = Graphics.createImageBuffer(1, 3);
    final ImageBuffer filtered = blur.filter(image);
    Assert.assertEquals(image, filtered);
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.Test)

Example 5 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FilterBlurTest method testBlur.

/**
 * Test blur filter
 */
@Test
public void testBlur() {
    final ImageBuffer image = Graphics.getImageBuffer(media);
    int i = 0;
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            i++;
            if (y < 10) {
                image.setRgb(x, y, i % 2);
            } else if (y < 20) {
                image.setRgb(x, y, i % 3);
            } else if (y < 32) {
                image.setRgb(x, y, i % 5);
            }
        }
    }
    final FilterBlur blur = new FilterBlur();
    final ImageBuffer filtered = blur.filter(image);
    Assert.assertNotEquals(image, filtered);
    Assert.assertNotNull(blur.getTransform(1.0, 1.0));
    Assert.assertEquals(image.getWidth(), filtered.getWidth());
    Assert.assertEquals(image.getHeight(), filtered.getHeight());
    blur.setAlpha(false);
    Assert.assertNotNull(blur.filter(image));
    blur.setEdgeMode(FilterBlur.WRAP_EDGES);
    Assert.assertNotNull(blur.filter(image));
    blur.setRadius(1.0f);
    Assert.assertNotNull(blur.filter(image));
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.Test)

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