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;
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class FilterHq2xTest method testHq2x.
/**
* Test filter.
*/
@Test
void testHq2x() {
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 FilterHq2x hq2x = new FilterHq2x();
final ImageBuffer filtered = hq2x.filter(image);
assertNotEquals(image, filtered);
assertNotNull(hq2x.getTransform(1.0, 1.0));
assertEquals(image.getWidth() * 2, filtered.getWidth());
assertEquals(image.getHeight() * 2, filtered.getHeight());
image.dispose();
filtered.dispose();
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class FilterBlurTest method testNoPixel.
/**
* Test without pixel.
*/
@Test
void testNoPixel() {
final FilterBlur blur = new FilterBlur();
final ImageBuffer image = Graphics.createImageBuffer(5, 5);
final ImageBuffer filtered = blur.filter(image);
assertNotNull(filtered);
assertEquals(image.getWidth(), filtered.getWidth());
assertEquals(image.getHeight(), filtered.getHeight());
image.dispose();
filtered.dispose();
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class FilterBlurTest method testBlur.
/**
* Test blur filter
*/
@Test
void testBlur() {
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 FilterBlur blur = new FilterBlur();
final ImageBuffer filtered = blur.filter(image);
assertNotEquals(image, filtered);
assertNotNull(blur.getTransform(1.0, 1.0));
assertEquals(image.getWidth(), filtered.getWidth());
assertEquals(image.getHeight(), filtered.getHeight());
blur.setAlpha(false);
assertNotNull(blur.filter(image));
blur.setEdgeMode(FilterBlur.WRAP_EDGES);
assertNotNull(blur.filter(image));
blur.setRadius(1.0f);
assertNotNull(blur.filter(image));
image.dispose();
filtered.dispose();
}
use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.
the class MapTileGame method create.
/**
* Create a map from a level rip which should be an image file (*.PNG, *.BMP) that represents the full map.
* The file will be read pixel by pixel to recognize tiles and their location. Data structure will be created (
* {@link #create(int, int, int, int)}).
*
* @param levelrip The file describing the levelrip as a single image.
* @param tileWidth The tile width.
* @param tileHeight The tile height.
* @param horizontalTiles The number of horizontal tiles on sheets.
* @throws LionEngineException If error when importing map.
* @see TilesExtractor
* @see LevelRipConverter
*/
public void create(Media levelrip, int tileWidth, int tileHeight, int horizontalTiles) {
final TilesExtractor tilesExtractor = new TilesExtractor();
final Collection<ImageBuffer> buffers = tilesExtractor.extract(tileWidth, tileHeight, Arrays.asList(levelrip));
loadSheets(SheetsExtractor.extract(buffers, horizontalTiles));
for (final ImageBuffer tileBuffer : buffers) {
tileBuffer.dispose();
}
LevelRipConverter.start(levelrip, mapSurface);
}
Aggregations