Search in sources :

Example 6 with ImageBuffer

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

the class FilterBlurTest method testSinglePixel.

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

Example 7 with ImageBuffer

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

the class FilterHq3xTest method testHq3x.

/**
 * Test filter.
 */
@Test
public void testHq3x() {
    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 FilterHq3x hq3x = new FilterHq3x();
    final ImageBuffer filtered = hq3x.filter(image);
    Assert.assertNotEquals(image, filtered);
    Assert.assertNotNull(hq3x.getTransform(1.0, 1.0));
    Assert.assertEquals(image.getWidth() * 3, filtered.getWidth());
    Assert.assertEquals(image.getHeight() * 3, filtered.getHeight());
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.Test)

Example 8 with ImageBuffer

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

the class FactoryGraphicAwt method splitImage.

@Override
public ImageBuffer[] splitImage(ImageBuffer image, int h, int v) {
    Check.notNull(image);
    final BufferedImage surface = image.getSurface();
    final BufferedImage[] images = ToolsAwt.splitImage(surface, h, v);
    final ImageBuffer[] imageBuffers = new ImageBuffer[h * v];
    for (int i = 0; i < imageBuffers.length; i++) {
        imageBuffers[i] = new ImageBufferAwt(images[i]);
    }
    return imageBuffers;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BufferedImage(java.awt.image.BufferedImage)

Example 9 with ImageBuffer

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

the class FactoryGraphicAwt method createImageBuffer.

@Override
public ImageBuffer createImageBuffer(int width, int height) {
    final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.OPAQUE);
    final ImageBuffer buffer = new ImageBufferAwt(image);
    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) BufferedImage(java.awt.image.BufferedImage)

Example 10 with ImageBuffer

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

the class ImageBufferAwtTest method testImage.

/**
 * Test image.
 */
@Test
public void testImage() {
    final BufferedImage buffer = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    final ImageBuffer image = ToolsAwt.getImageBuffer(buffer);
    Assert.assertNotNull(image.createGraphic());
    image.prepare();
    Assert.assertEquals(buffer, image.getSurface());
    Assert.assertEquals(ColorRgba.BLACK.getRgba(), image.getRgb(0, 0));
    Assert.assertNotNull(image.getRgb(0, 0, 1, 1, new int[1], 0, 0));
    Assert.assertEquals(Transparency.OPAQUE, image.getTransparency());
    Assert.assertEquals(Transparency.OPAQUE, ToolsAwt.getImageBuffer(ToolsAwt.copyImage(buffer)).getTransparency());
    Assert.assertEquals(buffer.getWidth(), image.getWidth());
    Assert.assertEquals(buffer.getHeight(), image.getHeight());
    image.setRgb(0, 0, ColorRgba.BLUE.getRgba());
    Assert.assertEquals(ColorRgba.BLUE.getRgba(), image.getRgb(0, 0));
    image.setRgb(0, 0, 0, 0, new int[1], 0, 0);
    image.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BufferedImage(java.awt.image.BufferedImage) 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