Search in sources :

Example 56 with ImageBuffer

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

the class RasterImage method loadRasters.

/**
 * Load rasters.
 *
 * @param imageHeight The local image height.
 * @param save <code>true</code> to save generated (if) rasters, <code>false</code> else.
 * @param prefix The folder prefix, if save is <code>true</code> (must not be <code>null</code>).
 * @throws LionEngineException If the raster data from the media are invalid.
 */
public void loadRasters(int imageHeight, boolean save, String prefix) {
    Check.notNull(prefix);
    final Raster raster = Raster.load(rasterFile);
    final int max = UtilConversion.boolToInt(rasterSmooth) + 1;
    for (int m = 0; m < max; m++) {
        for (int i = 1; i <= RasterColor.MAX_RASTERS; i++) {
            final String folder = prefix + Constant.UNDERSCORE + UtilFile.removeExtension(rasterFile.getName());
            final String file = String.valueOf(i + m * RasterColor.MAX_RASTERS) + Constant.DOT + ImageFormat.PNG;
            final Media rasterMedia = Medias.create(rasterFile.getParentPath(), folder, file);
            final ImageBuffer rasterBuffer = createRaster(rasterMedia, raster, m, i, imageHeight, save);
            rasters.add(rasterBuffer);
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Raster(com.b3dgs.lionengine.graphic.Raster) Media(com.b3dgs.lionengine.Media)

Example 57 with ImageBuffer

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

the class FilterBlur method filter.

/*
     * Filter
     */
@Override
public ImageBuffer filter(ImageBuffer source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    if (width < MIN_SIZE || height < MIN_SIZE) {
        return source;
    }
    final int[] inPixels = new int[width * height];
    final int[] outPixels = new int[width * height];
    source.getRgb(0, 0, width, height, inPixels, 0, width);
    final Kernel kernel = createKernel(radius, width, height);
    compute(kernel, inPixels, outPixels, width, height, alpha, edge);
    compute(kernel, outPixels, inPixels, height, width, alpha, edge);
    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 58 with ImageBuffer

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

the class GraphicsTest method testCreateImageBuffer.

/**
 * Test create image buffer.
 */
@Test
public void testCreateImageBuffer() {
    final ImageBuffer imageBuffer = Graphics.createImageBuffer(16, 32);
    Assert.assertEquals(16, imageBuffer.getWidth());
    Assert.assertEquals(32, imageBuffer.getHeight());
    imageBuffer.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) GraphicTest(com.b3dgs.lionengine.graphic.GraphicTest) Test(org.junit.Test)

Example 59 with ImageBuffer

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

the class GraphicsTest method testGetImageBufferFromMedia.

/**
 * Test get image buffer from media.
 */
@Test
public void testGetImageBufferFromMedia() {
    final ImageBuffer imageA = Graphics.getImageBuffer(mediaImage);
    final ImageBuffer imageB = Graphics.getImageBuffer(mediaImage);
    Assert.assertNotEquals(imageA, imageB);
    Assert.assertEquals(imageB.getWidth(), imageA.getWidth());
    Assert.assertEquals(imageB.getHeight(), imageA.getHeight());
    imageA.dispose();
    imageB.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) GraphicTest(com.b3dgs.lionengine.graphic.GraphicTest) Test(org.junit.Test)

Example 60 with ImageBuffer

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

the class GraphicsTest method testGetImageBufferFromImage.

/**
 * Test get image buffer from image.
 */
@Test
public void testGetImageBufferFromImage() {
    final ImageBuffer imageBuffer = Graphics.createImageBuffer(16, 32);
    final ImageBuffer copy = Graphics.getImageBuffer(imageBuffer);
    Assert.assertEquals(imageBuffer.getWidth(), copy.getWidth());
    Assert.assertEquals(imageBuffer.getHeight(), copy.getHeight());
    imageBuffer.dispose();
    copy.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) GraphicTest(com.b3dgs.lionengine.graphic.GraphicTest) 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