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

Add support for fractional tiff values (eg. 10 or 12 bits per pixel) #3948

Open
tpendragon opened this issue Apr 24, 2024 · 6 comments
Open

Comments

@tpendragon
Copy link

Not sure what's going on here - first time we've run into this issue, but we have a whole run of images with this problem and wonder if we could get some advice on if this is a bug or what, as the images appear to open in viewers fine.

Tiffinfo:

TIFFReadDirectory: Warning, Unknown field with tag 41728 (0xa300) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 42016 (0xa420) encountered.
=== TIFF directory 0 ===
TIFF Directory at offset 0x8 (8)
  Image Width: 4336 Image Length: 5840
  Resolution: 320, 320 pixels/inch
  Bits/Sample: 12
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 161
  Planar Configuration: single image plane
  Page Number: 0-0
  DocumentName: S01054_reel_76
  Make: nextScan,Inc.
  Model: FlexScan, SN# 1005092
  Software: nextStar v4.4
  DateTime: 2024:04:11 11:36:33
  Artist: Firestone Library
  Tag 41728: Microfilm
  Tag 42016: 14

Tiffsave:

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 41728 (0xa300) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 42016 (0xa420) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 41728 (0xa300) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 42016 (0xa420) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 41728 (0xa300) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 42016 (0xa420) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 41728 (0xa300) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 42016 (0xa420) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 41728 (0xa300) encountered

(vips:94695): VIPS-WARNING **: 11:44:36.510: Unknown field with tag 42016 (0xa420) encountered
tiff2vips: samples_per_pixel not a whole number of bytes

Image: https://figgy-high-traffic-downloads.s3.us-east-2.amazonaws.com/00000014.tif

@jcupitt
Copy link
Member

jcupitt commented Apr 25, 2024

Hi @tpendragon,

libvips tiffload supports sub-byte values (1, 2, 4 bits) plus whole byte values (8, 16, 32, 64 bits), but not fractional values (eg. 10, 12, etc.).

It wouldn't be so difficult to add, but some poor schmuck would have to sit down and do the work.

@jcupitt
Copy link
Member

jcupitt commented Apr 25, 2024

I've tagged this as an enhancement issue so it doesn't get lost.

@jcupitt jcupitt changed the title Tiffsave samples_per_pixel not a whole number of bytes Add support for fractional tiff values (eg. 10 or 12 bits per pixel) Apr 25, 2024
@tpendragon
Copy link
Author

tpendragon commented Apr 25, 2024

@jcupitt Ah I'm so happy to have an expert weigh in, thank you! Do you know if there's a workaround? Like can I identify that it has fractional values and use some other library you might know about to convert it and then feed that converted thing into vips?

@jcupitt
Copy link
Member

jcupitt commented Apr 25, 2024

🤦 sorry, I should have offered a workaround.

You can load via imagemagick using magickload. In python:

$ python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> x = pyvips.Image.magickload("00000014.tif")
>>> x
<pyvips.Image 4336x5840 ushort, 1 bands, grey16>
>>> 

It'll be a lot slower than the usual libvips tiff loader, but it will work.

@tpendragon
Copy link
Author

Great! Do you happen to know how to make a really small version of this kind of file so I can put it in my test suite? I really appreciate all the help here.

@jcupitt
Copy link
Member

jcupitt commented Apr 25, 2024

ImageMagick's convert can do this, eg.:

$ convert 00000014.tif -crop 100x100+0+0 -depth 10 x.tif
convert-im6.q16: Unknown field with tag 41728 (0xa300) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/985.
convert-im6.q16: Unknown field with tag 42016 (0xa420) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/985.
$ tiffinfo x.tif
=== TIFF directory 0 ===
TIFF Directory at offset 0x30dc (12508)
  Image Width: 100 Image Length: 100
  Resolution: 320, 320 pixels/inch
  Bits/Sample: 10
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 100
  Planar Configuration: single image plane
  Page Number: 0-1
  White Point: 0.3127-0.329
  PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
$ ls -l x.tif
-rw-r--r-- 1 john john 12810 Apr 25 16:02 x.tif

A 100x100 pixel 10 bit image, 12kb.

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