Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Support fake alpha for BMP files #728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,14 @@ public ImageTypeSpecifier getRawImageType(int pImageIndex) throws IOException {
);
}

// TODO: use some heuristic to determine if we should treat the extra byte as an alpha channel
//
// According to https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html some BMP decoders
// will treat the unused bits in a 32 bit representation as an alpha channel if any of the unused bits is non-zero
// but that potentially requires doing a full pass over all the pizels (in that case that it doesn't use fake alpha).

// Default if no mask
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
return ImageTypeSpecifiers.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB);

case 0:
if (header.getCompression() == DIB.COMPRESSION_JPEG || header.getCompression() == DIB.COMPRESSION_PNG) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,23 @@ public void testMetadataEqualsJRE() throws IOException {
}
}

@Test
public void testFakeAlpha() throws IOException {
final ImageReader reader = createReader();
TestData data = new TestData(getClassLoaderResource("/bmpsuite/q/rgb32fakealpha.bmp"), new Dimension(127, 64));
reader.setInput(data.getInputStream());
try {
reader.read(0);
}
catch (IOException e) {
fail("Could not read image");
}

ImageTypeSpecifier rawType = reader.getRawImageType(0);
assertNotNull(rawType);
assertTrue("BMP with fake alpha should support the alpha channel", rawType.getColorModel().hasAlpha());
}

private void assertNodeEquals(final String message, final Node expected, final Node actual) {
assertEquals(message + " class differs", expected.getClass(), actual.getClass());

Expand Down Expand Up @@ -473,4 +490,4 @@ private String toString(final NodeList list) {

return builder.toString();
}
}
}