/** * Create a new big image by loading it from the specified reference * * @param ref The reference to the image to load * @param filter The image filter to apply (@see #Image.FILTER_NEAREST) * @param tileSize The maximum size of the tiles to use to build the bigger image * @throws SlickException Indicates we were unable to locate the resource */ private void build(String ref, int filter, int tileSize) throws SlickException { try { final LoadableImageData data = ImageDataFactory.getImageDataFor(ref); final ByteBuffer imageBuffer = data.loadImage(ResourceLoader.getResourceAsStream(ref), false, null); build(data, imageBuffer, filter, tileSize); } catch (IOException e) { throw new SlickException("Failed to load: "+ref, e); } }
@Override public void run() { // load image data into a ByteBuffer to use constructor Image(ImageData) LoadableImageData imageData = ImageDataFactory.getImageDataFor(file.getAbsolutePath()); try (BufferedInputStream in = this.in = new BufferedInputStream(new FileInputStream(file))) { ByteBuffer textureBuffer = imageData.loadImage(in, false, null); if (!isInterrupted()) data = new LoadedImageData(imageData, textureBuffer); } catch (Exception e) { if (!isInterrupted()) Log.warn(String.format("Failed to load background image '%s'.", file), e); } this.in = null; }
@Override public void run() { // load image data into a ByteBuffer to use constructor Image(ImageData) LoadableImageData imageData = ImageDataFactory.getImageDataFor(file.getAbsolutePath()); try (BufferedInputStream in = this.in = new BufferedInputStream(new FileInputStream(file))) { ByteBuffer textureBuffer = imageData.loadImage(in, false, null); if (!isInterrupted()) data = new LoadedImageData(imageData, textureBuffer); } catch (IOException e) { if (!isInterrupted()) Log.warn(String.format("Failed to load background image '%s'.", file), e); } this.in = null; }
@Override public Object[] work(String resourceKey) throws PromiseException { // avoid the resource cache, AsyncTextureLoader has its own cache InputStream in = db.getInputStreamSync(resourceKey); ResourceDB.FileEntry fileEntry = db.getFileEntry(resourceKey); if (in == null || fileEntry == null) { log.log(Level.SEVERE, "Unable to load texture, the given resource key ({0}) does not exist", resourceKey); throw new InvalidResourceKeyException(); } String fileName = fileEntry.zipEntry == null ? fileEntry.file.getName() : fileEntry.zipEntry; LoadableImageData imageData = ImageDataFactory.getImageDataFor(fileName); try { ByteBuffer textureBytes = imageData.loadImage(new BufferedInputStream(in), false, null); if (textureBytes == null) { throw new IOException("loadImage returned null"); } log.log(Level.INFO, "Texture data for {0} read. {1} {2} {3} {4} {5}", new Object[] { resourceKey, imageData.getWidth(), imageData.getHeight(), imageData.getDepth(), imageData.getTexWidth(), imageData.getTexHeight() }); return new Object[] { textureBytes, imageData.getWidth(), imageData.getHeight(), imageData.getDepth(), imageData.getTexWidth(), imageData.getTexHeight() }; } catch (IOException | UnsatisfiedLinkError | UnsupportedOperationException ex) { log.log(Level.SEVERE, "Exception while parsing image for texture " + resourceKey, ex); throw new PromiseException(ex); } }