@Nonnull private ByteBuffer convertToOpenGlFormat( @Nonnull final BufferedImage originalImage, final boolean shouldFlipVertically, final boolean shouldUseARGB) { ImageProperties originalImageProperties = new ImageProperties( originalImage.getWidth(), originalImage.getHeight(), shouldFlipVertically); imageProperties = originalImageProperties; BufferedImage openGlImage = createImageWithProperties(originalImageProperties); Graphics2D openGlImageGraphics = (Graphics2D) openGlImage.getGraphics(); blankImageForMacOsXCompatibility(openGlImageGraphics, originalImageProperties); copyImage(originalImage, openGlImageGraphics, originalImageProperties); byte[] rawOpenGlImageData = getRawImageData(openGlImage); if (shouldUseARGB) { convertImageToARGB(rawOpenGlImageData); } ByteBuffer openGlImageByteBuffer = createByteBuffer(rawOpenGlImageData); // We can't dispose of openGlImage any earlier because it would destroy rawOpenGlImageData. disposeImage(openGlImageGraphics); return openGlImageByteBuffer; }
@Override @Nonnull public ByteBuffer loadAsByteBufferRGBA(@Nonnull @WillNotClose final InputStream imageStream) throws IOException { return convertToOpenGlFormat(loadImageFromStream(imageStream), false, false); }
@Nonnull private BufferedImage createImageWithProperties(@Nonnull final ImageProperties imageProperties) { return new BufferedImage( imageProperties.getColorModel(), createRasterWithProperties(imageProperties), false, null); }
public static ImageLoader createImageLoader(@Nonnull final String imageFilename) { return imageFilename.endsWith(".tga") ? new TGAImageLoader() : new DefaultImageLoader(); } }
@Nonnull @Override public ByteBuffer loadAsByteBufferARGB( @Nonnull @WillNotClose final InputStream imageStream, final boolean shouldFlipVertically) throws IOException { try { return convertToOpenGlFormat(loadImageFromStream(imageStream), shouldFlipVertically, true); } catch (IOException e) { throw new IOException("Could not load mouse cursor image!", e); } }