Search in sources :

Example 96 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, ColorRgba transparency) {
    Check.notNull(transparency);
    final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.BITMASK);
    final ImageBuffer buffer = new ImageBufferAwt(image);
    final Graphic g = buffer.createGraphic();
    g.setColor(transparency);
    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 97 with ImageBuffer

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

the class FactoryGraphicAwtTest method testRotate.

/*
     * FactoryGraphicTest
     */
@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 98 with ImageBuffer

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

the class ImageBufferAwtTest method testImage.

/**
 * Test image.
 */
@Test
void testImage() {
    final BufferedImage buffer = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    final ImageBuffer image = ToolsAwt.getImageBuffer(buffer);
    assertNotNull(image.createGraphic());
    image.prepare();
    assertEquals(buffer, image.getSurface());
    assertEquals(ColorRgba.BLACK.getRgba(), image.getRgb(0, 0));
    assertNotNull(image.getRgb(0, 0, 1, 1, new int[1], 0, 0));
    assertEquals(Transparency.OPAQUE, image.getTransparency());
    assertEquals(Transparency.OPAQUE, ToolsAwt.getImageBuffer(ToolsAwt.copyImage(buffer)).getTransparency());
    assertEquals(buffer.getWidth(), image.getWidth());
    assertEquals(buffer.getHeight(), image.getHeight());
    image.setRgb(0, 0, ColorRgba.BLUE.getRgba());
    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.jupiter.api.Test)

Example 99 with ImageBuffer

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

the class TextAwtTest method beforeTests.

/**
 * Setup tests.
 */
@BeforeAll
public static void beforeTests() {
    Graphics.setFactoryGraphic(new FactoryGraphicAwt());
    final ImageBuffer buffer = Graphics.createImageBuffer(320, 240);
    buffer.prepare();
    g = buffer.createGraphic();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 100 with ImageBuffer

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

the class SpriteDigitTest method testHashCode.

/**
 * Test hash code.
 */
@Test
void testHashCode() {
    final ImageBuffer surface = Graphics.createImageBuffer(64, 32);
    final SpriteDigit sprite = new SpriteDigitImpl(surface, 1, 1, 1);
    final Media media = Medias.create("image.png");
    final SpriteDigit spriteMedia = new SpriteDigitImpl(media, 1, 1, 1);
    assertHashEquals(sprite, new SpriteDigitImpl(surface, 1, 1, 1));
    assertHashNotEquals(sprite, new Object());
    assertHashNotEquals(spriteMedia, new SpriteDigitImpl(media, 1, 1, 1));
    assertHashNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(64, 32), 1, 1, 1));
    assertHashNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(32, 32), 1, 1, 1));
    assertHashNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(64, 64), 1, 1, 1));
    assertHashNotEquals(sprite, new SpriteDigitImpl(Graphics.createImageBuffer(32, 64), 1, 1, 1));
    sprite.dispose();
    spriteMedia.dispose();
    surface.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.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