@Override public TextureData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException { try (InputStream inStream = inputs.get(0).openStream()) { final BufferedImage img = ImageIO.read(inStream); return convertToTextureData(img, defaultFilterMode); } catch (UnsupportedOperationException e) { throw new IOException(e); } }
private void loadPreviewImages(final GameInfo gameInfo) { List<Texture> textures = new ArrayList<>(); if (gameInfo != null && gameInfo.getSavePath() != null) { final List<BufferedImage> bufferedImages = GamePreviewImageProvider.getAllPreviewImages(gameInfo.getSavePath()); textures = bufferedImages .stream() .map(buffImage -> { TextureData textureData; try { textureData = AWTTextureFormat.convertToTextureData(buffImage, Texture.FilterMode.LINEAR); } catch (IOException e) { logger.error("Converting preview image to texture data {} failed", e); return null; } return Assets.generateAsset(new ResourceUrn(PREVIEW_IMAGE_URI_PATTERN + bufferedImages.indexOf(buffImage)), textureData, Texture.class); }) .filter(Objects::nonNull) .collect(Collectors.toList()); } if (textures.isEmpty()) { textures.add(Assets.getTexture(DEFAULT_PREVIEW_IMAGE_URI).get()); } previewSlideshow.clean(); textures.forEach(tex -> { UIImage image = new UIImage(null, tex, true); previewSlideshow.addImage(image); }); }
@Test public void invalidImageTypeTest() { BufferedImage image = createBufferedImage(1, 2, BufferedImage.TYPE_BYTE_GRAY); try { AWTTextureFormat.convertToTextureData(image, Texture.FilterMode.LINEAR); Assert.fail("IOException should be thrown"); } catch (IOException ex) { Assert.assertEquals("Unsupported AWT format: " + image.getType(), ex.getMessage()); } }
@Test public void successTest() throws IOException { BufferedImage image = createBufferedImage(2, 3, BufferedImage.TYPE_3BYTE_BGR); TextureData textureData = AWTTextureFormat.convertToTextureData(image, Texture.FilterMode.LINEAR); Assert.assertNotNull(textureData); Assert.assertEquals(2, textureData.getWidth()); Assert.assertEquals(3, textureData.getHeight()); Assert.assertEquals(Texture.FilterMode.LINEAR, textureData.getFilterMode()); }