Search in sources :

Example 46 with ImageBuffer

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

the class WorldTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Context() {

        @Override
        public int getX() {
            return 0;
        }

        @Override
        public int getY() {
            return 0;
        }

        @Override
        public int getWidth() {
            return 0;
        }

        @Override
        public int getHeight() {
            return 0;
        }

        @Override
        public <T extends InputDevice> T getInputDevice(Class<T> type) {
            return null;
        }

        @Override
        public Config getConfig() {
            return config;
        }
    });
    services.add(new SourceResolutionProvider() {

        @Override
        public int getWidth() {
            return output.getWidth();
        }

        @Override
        public int getHeight() {
            return output.getHeight();
        }

        @Override
        public int getRate() {
            return output.getRate();
        }
    });
    services.add(new Sequencer() {

        @Override
        public void end(Class<? extends Sequencable> nextSequenceClass, Object... arguments) {
        // Mock
        }

        @Override
        public void end() {
        // Mock
        }

        @Override
        public void load(Class<? extends Sequencable> nextSequenceClass, Object... arguments) {
        // Mock
        }

        @Override
        public void setSystemCursorVisible(boolean visible) {
        // Mock
        }
    });
    services.add(new Rasterbar() {

        @Override
        public void setRasterbarY(int y1, int y2) {
        // Mock
        }

        @Override
        public void setRasterbarOffset(int offsetY, int factorY) {
        // Mock
        }

        @Override
        public void renderRasterbar() {
        // Mock
        }

        @Override
        public void clearRasterbarColor() {
        // Mock
        }

        @Override
        public void addRasterbarColor(ImageBuffer buffer) {
        // Mock
        }
    });
}
Also used : Context(com.b3dgs.lionengine.Context) Sequencer(com.b3dgs.lionengine.graphic.engine.Sequencer) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Config(com.b3dgs.lionengine.Config) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) Rasterbar(com.b3dgs.lionengine.graphic.engine.Rasterbar) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 47 with ImageBuffer

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

the class FilterBilinearTest method testBilinear.

/**
 * Test bilinear filter
 */
@Test
void testBilinear() {
    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 FilterBilinear bilinear = new FilterBilinear();
    final ImageBuffer filtered = bilinear.filter(image);
    assertNotEquals(image, filtered);
    assertNotNull(bilinear.getTransform(1.0, 1.0));
    assertEquals(image.getWidth(), filtered.getWidth());
    assertEquals(image.getHeight(), 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 48 with ImageBuffer

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

the class Scene method load.

@Override
public void load() {
    final Media levelrip = Medias.create("level.png");
    final TilesExtractor tilesExtractor = new TilesExtractor();
    final AtomicInteger p = new AtomicInteger();
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    Collection<ImageBuffer> buffers = tilesExtractor.extract(16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(100, p.get());
    p.set(0);
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    buffers = tilesExtractor.extract(() -> true, 16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(0, p.get());
    tilesExtractor.addListener((percent, tiles) -> p.set(percent));
    buffers = tilesExtractor.extract(() -> false, 16, 16, Arrays.asList(levelrip));
    map.loadSheets(SheetsExtractor.extract(buffers, 16));
    buffers.forEach(ImageBuffer::dispose);
    assertEquals(100, p.get());
    p.set(0);
    LevelRipConverter.start(levelrip, map, (percent, progressTileX, progressTileY) -> p.set(percent));
    assertEquals(100, p.get());
    mapViewer.prepare(map);
    minimap.load();
    minimap.automaticColor();
    minimap.prepare();
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    camera.setLimits(map);
    tick.start();
}
Also used : TilesExtractor(com.b3dgs.lionengine.game.feature.tile.TilesExtractor) ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Media(com.b3dgs.lionengine.Media)

Example 49 with ImageBuffer

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

the class FilterBlurTest method testParam.

/**
 * Test with single pixel.
 *
 * @param width The width.
 * @param height The height.
 */
@ParameterizedTest
@CsvSource({ "5,5", "5,8", "8,5" })
void testParam(int width, int height) {
    final FilterBlur blur = new FilterBlur();
    final ImageBuffer image = Graphics.createImageBuffer(width, height);
    final ImageBuffer filtered = blur.filter(image);
    assertNotEquals(image, filtered);
    image.dispose();
    filtered.dispose();
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with ImageBuffer

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

the class FilterHq3xTest method testHq3x.

/**
 * Test filter.
 */
@Test
void testHq3x() {
    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 FilterHq3x hq3x = new FilterHq3x();
    final ImageBuffer filtered = hq3x.filter(image);
    assertNotEquals(image, filtered);
    assertNotNull(hq3x.getTransform(1.0, 1.0));
    assertEquals(image.getWidth() * 3, filtered.getWidth());
    assertEquals(image.getHeight() * 3, 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)

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