Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Image::convertToBufferedImage is indeterministic #4

Description

@kahlep

This behavior seems to result from ImageIO internals and can be reproduced with images where only specific readers (from those that claim to be able to read the source) work as expected, e.g. on JPEG compressed images with "tif" filename extensions. See eu.transkribus.interfaces.types.ImageTest::testFromUrlToBufferedImage

Findings so far:

  • ImageIO registers Reader/Writer plugins internally in a HashMap and the order of the entry set may thus change over time
  • ImageIO::read iterates readers, takes the first one that returns true when calling ImageReaderSpi::.canDecodeInput and if the actual read operation fails throws an IIOException
  • IIORegistry::register returns false if a reader of the given type is already registered, according to its JavaDoc. BUT: acutally it deregisters the old instance and puts the new instance into the map, altering the order of the entry set. Subsequent registering of the same plugin will therefore change the behavior of ImageIO::read for certain images.

Steps taken so far:

  • Image type does not contain a static block registering Readers and Writers anymore. This was needed by web applications in Tomcat so far but is solved with a context listener that registers plugins on the classpath automatically.
  • ImageUtils has an alternative implementation of ImageIO::read that tries other candidate-readers first if one reader fails.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions