Search in sources :

Example 11 with ImageBuffer

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

the class SpriteParallaxedImpl method load.

/*
     * SpriteParallaxed
     */
@Override
public void load(boolean alpha) {
    ImageBuffer surface = Graphics.getImageBuffer(media);
    if (0 != Double.compare(factorH, 1.0) || 0 != Double.compare(factorV, 1.0)) {
        final int x = (int) (surface.getWidth() * factorH);
        final int y = (int) (surface.getHeight() * factorV);
        surface = Graphics.resize(surface, x, y);
    }
    lineWidth = (int) Math.floor(surface.getWidth() * sx / 100.0);
    lineHeight = (int) Math.floor(surface.getHeight() / (double) linesNumber * sy / 100.0);
    lines = Graphics.splitImage(surface, 1, linesNumber);
    final double factH = sx / 100.0 / AMPLITUDE_FACTOR;
    for (int i = 0; i < linesNumber; i++) {
        final int width = (int) Math.ceil(lines[i].getWidth() * (sx + i * 2 * factH) / 100);
        final int height = lines[i].getHeight() * sy / 100;
        lines[i] = Graphics.resize(lines[i], width, height);
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Example 12 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 13 with ImageBuffer

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

the class FilterHq2x method filter.

/*
     * Filter
     */
@Override
public ImageBuffer filter(ImageBuffer source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final int[] srcData = new int[width * height];
    source.getRgb(0, 0, width, height, srcData, 0, width);
    final RawScale2x scaler = new RawScale2x(width, height);
    final ImageBuffer image = Graphics.createImageBuffer(width * RawScale2x.SCALE, height * RawScale2x.SCALE, source.getTransparentColor());
    image.setRgb(0, 0, width * RawScale2x.SCALE, height * RawScale2x.SCALE, scaler.getScaledData(srcData), 0, width * RawScale2x.SCALE);
    return image;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Example 14 with ImageBuffer

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

the class FilterHq3x method filter.

/*
     * Filter
     */
@Override
public ImageBuffer filter(ImageBuffer source) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final int[] srcData = new int[width * height];
    source.getRgb(0, 0, width, height, srcData, 0, width);
    final RawScale3x scaler = new RawScale3x(width, height);
    final ImageBuffer image = Graphics.createImageBuffer(width * RawScale3x.SCALE, height * RawScale3x.SCALE, source.getTransparentColor());
    image.setRgb(0, 0, width * RawScale3x.SCALE, height * RawScale3x.SCALE, scaler.getScaledData(srcData), 0, width * RawScale3x.SCALE);
    return image;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Example 15 with ImageBuffer

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

the class GraphicsTest method testSplitImage.

/**
 * Test split image.
 */
@Test
public void testSplitImage() {
    final ImageBuffer[] split = Graphics.splitImage(image, 2, 2);
    for (final ImageBuffer img1 : split) {
        for (final ImageBuffer img2 : split) {
            Assert.assertEquals(img1.getWidth(), img2.getWidth());
            Assert.assertEquals(img1.getHeight(), img2.getHeight());
        }
    }
    Assert.assertEquals(image.getWidth() / 2, split[0].getWidth());
    Assert.assertEquals(image.getHeight() / 2, split[0].getHeight());
    for (final ImageBuffer image : split) {
        image.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