Skip to content

Commit 5436e84

Browse files
committed
Remove obsolete workaround for Java 8 ImageIO not supporting PNGs with RGB and a single transparent color.
1 parent f7e4584 commit 5436e84

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

chunky/src/java/se/llbit/resources/ImageLoader.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ public final class ImageLoader {
4343
*/
4444
public final static BitmapImage missingImage;
4545

46-
/**
47-
* ImageIO doesn't support PNGs with RGB and a transparent color before JDK 11. Since Chunky only
48-
* supports Java 8 and 11+, this is a reasonable check.
49-
* https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6788458
50-
*/
51-
private static final boolean IMAGEIO_PNG_TRANSPARENT_COLOR_SUPPORTED = !System.getProperty("java.version").startsWith("1.");
52-
5346
static {
5447
missingImage = new BitmapImage(16, 16);
5548
for (int y = 0; y < 16; ++y) {
@@ -92,24 +85,6 @@ public static BitmapImage read(URL url) throws IOException {
9285
}
9386

9487
public static BitmapImage read(InputStream in) throws IOException {
95-
// TODO remove this when java 8 support is dropped
96-
if (!IMAGEIO_PNG_TRANSPARENT_COLOR_SUPPORTED) {
97-
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
98-
int nRead;
99-
byte[] data = new byte[4096];
100-
while ((nRead = in.read(data, 0, data.length)) != -1) {
101-
buffer.write(data, 0, nRead);
102-
}
103-
104-
byte[] imgData = buffer.toByteArray();
105-
try {
106-
Image img = Toolkit.getDefaultToolkit().createImage(imgData);
107-
return fromAwtImage(img);
108-
} catch (Exception e) {
109-
Log.info("Failed to load image with AWT. Trying with ImageIO.");
110-
return fromBufferedImage(ImageIO.read(new ByteArrayInputStream(imgData)));
111-
}
112-
}
11388
return fromBufferedImage(ImageIO.read(in));
11489
}
11590

@@ -171,11 +146,12 @@ private static BitmapImage fromAwtImage(Image newImage) {
171146
Mutable<Boolean> stop = new Mutable<>(false);
172147
ImageObserver observer = (img, infoflags, x, y, width, height) -> {
173148
boolean fail = (infoflags &
174-
(ImageObserver.ERROR | ImageObserver.ABORT)) != 0;
149+
(ImageObserver.ERROR | ImageObserver.ABORT)) != 0;
175150
stop.set(fail);
176151
return !fail;
177152
};
178-
while (!stop.get() && !g.drawImage(newImage, 0, 0, observer)) {}
153+
while (!stop.get() && !g.drawImage(newImage, 0, 0, observer)) {
154+
}
179155
g.dispose();
180156
if (stop.get()) {
181157
throw new IllegalArgumentException("Invalid image.");

0 commit comments

Comments
 (0)