Raster (@NotNull IIOImage image) { boolean rasterOnly = image.hasRaster(); if (rasterOnly) { return image.getRaster(); } else { RenderedImage renderedImage = image.getRenderedImage(); if (renderedImage instanceof BufferedImage bufferedImage) { // Convert indexed to RGB if (renderedImage.getColorModel() instanceof IndexColorModel) { //noinspection UndesirableClassUsage BufferedImage rgb = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = rgb.createGraphics(); graphics.drawImage(bufferedImage, 0, 0, null); graphics.dispose(); return rgb.getRaster(); } return bufferedImage.getRaster(); } else if (renderedImage.getNumXTiles() == 1 && renderedImage.getNumYTiles() == 1) { Raster raster = renderedImage.getTile(renderedImage.getMinTileX(), renderedImage.getMinTileY()); if (raster.getWidth() != renderedImage.getWidth() || raster.getHeight() != renderedImage.getHeight()) { raster = raster.createChild(raster.getMinX(), raster.getMinY(), renderedImage.getWidth(), renderedImage.getHeight(), raster.getMinX(), raster.getMinY(), null); } return raster; } else { return renderedImage.getData(); } } }