Search in sources :

Example 86 with ImageBuffer

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

the class FilterBilinear method filter.

/*
     * Filter
     */
@Override
public ImageBuffer filter(ImageBuffer source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final int[] inPixels = new int[width * height];
    final int[] outPixels = new int[width * height];
    source.getRgb(0, 0, width, height, inPixels, 0, width);
    compute(inPixels, outPixels, width, height, 1);
    compute(outPixels, inPixels, height, width, 1);
    final ImageBuffer dest = Graphics.createImageBuffer(width, height, source.getTransparentColor());
    dest.setRgb(0, 0, width, height, inPixels, 0, width);
    return dest;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Example 87 with ImageBuffer

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

the class FilterHq2xTest method testHq2x.

/**
 * Test filter.
 */
@Test
void testHq2x() {
    final Media media = Medias.create("image.png");
    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 FilterHq2x hq2x = new FilterHq2x();
    final ImageBuffer filtered = hq2x.filter(image);
    assertNotEquals(image, filtered);
    assertNotNull(hq2x.getTransform(1.0, 1.0));
    assertEquals(image.getWidth() * 2, filtered.getWidth());
    assertEquals(image.getHeight() * 2, filtered.getHeight());
    image.dispose();
    filtered.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 88 with ImageBuffer

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

the class FilterBlurTest method testNoPixel.

/**
 * Test without pixel.
 */
@Test
void testNoPixel() {
    final FilterBlur blur = new FilterBlur();
    final ImageBuffer image = Graphics.createImageBuffer(5, 5);
    final ImageBuffer filtered = blur.filter(image);
    assertNotNull(filtered);
    assertEquals(image.getWidth(), filtered.getWidth());
    assertEquals(image.getHeight(), filtered.getHeight());
    image.dispose();
    filtered.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with ImageBuffer

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

the class FilterBlurTest method testBlur.

/**
 * Test blur filter
 */
@Test
void testBlur() {
    final Media media = Medias.create("image.png");
    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);
    assertNotEquals(image, filtered);
    assertNotNull(blur.getTransform(1.0, 1.0));
    assertEquals(image.getWidth(), filtered.getWidth());
    assertEquals(image.getHeight(), filtered.getHeight());
    blur.setAlpha(false);
    assertNotNull(blur.filter(image));
    blur.setEdgeMode(FilterBlur.WRAP_EDGES);
    assertNotNull(blur.filter(image));
    blur.setRadius(1.0f);
    assertNotNull(blur.filter(image));
    image.dispose();
    filtered.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with ImageBuffer

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

the class MapTileGame method create.

/**
 * Create a map from a level rip which should be an image file (*.PNG, *.BMP) that represents the full map.
 * The file will be read pixel by pixel to recognize tiles and their location. Data structure will be created (
 * {@link #create(int, int, int, int)}).
 *
 * @param levelrip The file describing the levelrip as a single image.
 * @param tileWidth The tile width.
 * @param tileHeight The tile height.
 * @param horizontalTiles The number of horizontal tiles on sheets.
 * @throws LionEngineException If error when importing map.
 * @see TilesExtractor
 * @see LevelRipConverter
 */
public void create(Media levelrip, int tileWidth, int tileHeight, int horizontalTiles) {
    final TilesExtractor tilesExtractor = new TilesExtractor();
    final Collection<ImageBuffer> buffers = tilesExtractor.extract(tileWidth, tileHeight, Arrays.asList(levelrip));
    loadSheets(SheetsExtractor.extract(buffers, horizontalTiles));
    for (final ImageBuffer tileBuffer : buffers) {
        tileBuffer.dispose();
    }
    LevelRipConverter.start(levelrip, mapSurface);
}
Also used : TilesExtractor(com.b3dgs.lionengine.game.feature.tile.TilesExtractor) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

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