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

Java 11 fixes #2

Merged
merged 2 commits into from
Oct 31, 2019
Merged

Java 11 fixes #2

merged 2 commits into from
Oct 31, 2019

Conversation

tylerperyea
Copy link
Contributor

The pull request should fix an issue where some default java8 library, as far as I can tell, used to read in some PNGs in such a way that the alpha channel being "255" meant "transparent", but in java11 it now instead means "opaque". No doubt this confusion has to do with deep definitions of color models that can be inspected/analyzed, but that's beyond my attention span.

When MolVec reads in an image, it first flattens it to a single-channel grayscale image. To do this, it applies a certain transform if the colorspace is RGB, and a slightly different transform if it's RGBA. For the extra alpha channel, it tries to count alpha as just a multiplier to the underlying RGB transform, so an especially transparent pixel gets multiplied by 0, and an especially opaque pixel gets multiplied by 1. The alpha scale is now inverted for many images when run on a java11+ JRE, so this effectively ends up producing completely blank images since everything is viewed as transparent.

There are 4 fixes to help with this:

  1. 255 now always means "opaque" internally to MolVec when generating a flat grayscale image
  2. If there is an alpha channel but it has the same value for all pixels, it is explicitly set to be 255 for all pixels.
  3. If the alpha channel does vary, the alpha channel is rescaled to be between 0 and 255
  4. Also, if the alpha channel varies, and there are more >128 alpha pixels than <128 alpha pixels, invert the alpha channel to be 255-alpha. The assumption here is that if there's meaningful alpha, it's probably the negative space. There should be more negative space than positive space for chemical images with alpha.

None of these are "perfect" fixes. A safer thing to do is probably render any image with an alpha channel on both a white and black background first using standard abstraction layers, and then use the image which maintains the highest dynamic range. But the above fixes do make the tests work for both java8 and java11, so it seems sufficient for now.

@caodac caodac merged commit e2f914c into master Oct 31, 2019
@dkatzel-ncats dkatzel-ncats deleted the java11test branch November 4, 2019 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants