2008.08.08 13:29 "Re: [Tiff] Writing custom fields with big counts.", by Edward Lam
I agree with Andy. Having said that, the TIFF6 spec says that tags have 32-bit value count. Looking at this page and the code, I think it's possible to do that with application tags in libtiff as well. First, make sure that you've defined your tags appropriately as per: http://www.remotesensing.org/libtiff/addingtags.html
Now, what that page doesn't seem to explain is how to set your tag values. :) First note how to set up your tag in the Default Tag Auto-registration in the link above. In particular, field_passcount should be set to true. Looking at the code in tif_dir.c, if field_passcount is set to true, then you must include the value count as the first argument after your tag type, then followed by a pointer to your data.
eg. TIFFSetField(my_fp, my_tag, my_int_count, my_buffer_ptr);
Finally, note that "my_buffer_ptr" should point to a chunk of memory that contains my_int_count * sizeof(my_tiff_value_type) number of bytes.
Are you doing anything wrong. Yes:
Why invent something non-standard, when TIFF provides the facility to do exactly what you want. You have two options:
- Put multiple images in a single file. Your main first image would be the RGB data that most applications will view and your second image would be your scientific data. This is all spec'd in the TIFF documentation -see page 16 to start with (Multiple Images per TIFF File) and then page 26 and later.
- Make your image an RGB image with extra samples (which are your scientific data), where these are marked as "unspecified". See page 31 for details on this.
- Personally, I'd go for the second option (assuming most readers work with it), as this keeps (preserves) your scientific data with the equivalent RGB data.
- Alternatively and even simpler, just create two TIFF files with similar names but one being slightly different to indicates it's the scientific data.
I am playing with an idea to add arbitrary extra fields to a vanilla RGB TIFF, these extra tags will hold the source image that was used to create the RGB image. I want to do this so tht I have data files from a scientific intrument that contain all sorts of strange data, but to the users look like normal multi-image 24 bit RGB files.
I can add the extra field OK, but I find that although the spec allows 4 bytes for the count, libtiff only seems to use 2 bytes, so the maximum count is 65535. The TIFFFieldInfo struct only uses shorts for field_readcount & field_writecount, so I suppose this is why. However, even if I have -1 for these values (indicating that the number of values is set in the call to TIFFSetField), the maximum count that I seem to be able to write is 65535. Tiffdump will only report the field count as correct if it is less than 32768, any more and it gives me a count of zero, even though inspecting a hex dump of the tiff file shows the correct count.
Am I doing something wrong?
I was hoping to save my private data as an array of 1024*1024*4 unsigned shorts, but it looks like this will not work with libtiff. Perhaps I should be looking at writing a table of offsets to data in strips (exactly how images are saved at present).
Tom Harris <celephicus(AT)gmail(DOT)com>