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

Reading a TIFF and then writing it back may loose BitsPerSample information #3516

Open
julienrf opened this issue Jul 25, 2023 · 0 comments
Open

Comments

@julienrf
Copy link

Describe the bug

BitsPerSample is modeled as an Int, although in multi-band TIFFs this tag contains as many values as SamplesPerPixel. This results in producing invalid multi-band TIFFs that cannot be consumed by third-party tools.

To Reproduce

Add a file read-and-write-back.scala to the project root directory with the following content:

//> using scala 3
//> using dep "org.locationtech.geotrellis:geotrellis-raster_2.13:3.7.0"

import geotrellis.raster.io.geotiff.MultibandGeoTiff

@main def run() =
  val originalTiff = MultibandGeoTiff("./raster/data/geotiff-test-files/overviews/multiband.tif")
  originalTiff.write("/tmp/multiband.tif")

Then, run the following commands from a shell, from within the project root directory:

scala-cli read-and-write-back.scala
exiftool -IFD0:BitsPerSample /tmp/multiband.tif
exiftool -IFD0:BitsPerSample ./raster/data/geotiff-test-files/overviews/multiband.tif

Actual output:

Bits Per Sample                 : 8
Bits Per Sample                 : 8 8 8 8

Note that the BitsPerSample tag of the written file /tmp/multiband.tif is 8, whereas the original file contained 8 8 8 8.

Expected output:

Bits Per Sample                 : 8 8 8 8
Bits Per Sample                 : 8 8 8 8

The BitsPerSample tag should be a collection.

Environment

  • GeoTrellis version: 3.7.0

Additional context

According to the following comment, this issue seems to be known from the project maintainers:

bitsPerSample: Int = 1, // This is written as an array per sample, but libtiff only takes one value, and so do we.

However, the comments refers to a lib libtiff which I am not sure to follow what it refers to. Is this comment legacy? If yes, would you consider changing the model of bitsPerSample to be an Array[Short] instead of an Int?

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

No branches or pull requests

2 participants