Skip to content

TIFF: Colors brightened when reading and then writing a 32-bpc integer linear grayscale image #1136

@danielperano

Description

@danielperano

Describe the bug
When reading and then writing a 32-bit per channel grayscale TIFF image in linear colorspace, the written colors are brightened.

Version information

  1. The version of the TwelveMonkeys ImageIO library in use.
    imageio-tiff:3.12.0

  2. The exact output of java --version (or java -version for older Java releases).

openjdk 23 2024-09-17
OpenJDK Runtime Environment (build 23+37-2369)
OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)
  1. Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.

This is on a Linux Mint 21.3 desktop, running directly from a jar.

To Reproduce
Steps to reproduce the behavior:

  1. Compile the below sample code
  2. Download the sample image file
  3. Run the code with the sample file
  4. See error

Expected behavior
The output image is a 32-bit per channel integer grayscale image in linear colorspace with the same shade of grey as the input.

Example code

System.out.println("Is headless? " + System.getProperty("java.awt.headless"));
var image = ImageIO.read(new File("./Untitled_32bit.tif"));

System.out.println("Width: " + image.getWidth());
System.out.println("Height: " + image.getHeight());
System.out.println("Color model: " + image.getColorModel().toString());
System.out.println("Color space is sRGB: " + image.getColorModel().getColorSpace().isCS_sRGB());
System.out.println("Channels: " + image.getColorModel().getColorSpace().getNumComponents());
System.out.println("Channel size: " + image.getColorModel().getComponentSize()[0]);
            
var writer = ImageIO.getImageWritersBySuffix("tif").next();

var params = writer.getDefaultWriteParam();
params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
params.setCompressionType("Deflate");

writer.setOutput(ImageIO.createImageOutputStream(new File("./out.tif")));
writer.write(image);

Sample file(s)
Attach any sample files needed to reproduce the problem. Use a ZIP-file if the format is not directly supported by GitHub.

Untitled_32bit.tif.zip

Stak trace
No stack trace.

Screenshots
PNG of input image (totally different encoding, just for visual demo):

Image

PNG of output image:

Image

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions