Tambe Salome has been working to add write support to ocaml-tiff; and we are well on the way to having good support. Writing TIFF files is no easy business. Unlike many formats, TIFF files have an internal metadata-data split, with values sometimes being place nowhere near the metadata describing the values in the file. In practice, it means if you do not wish to read the whole file into memory, then your IO layer must support seeking to file offsets. This means when you come to write the file, you might need to write at different offsets too.
This becomes particularly complicated when you do not know ahead of time how you are going to layout the file (e.g. how many strips will the raw data be separated into). For now, we are doing the sane first step and assuming we are copying a TIFF file we have access to but pushing all the copying via the OCaml values we read from our source TIFF. And Salome has made excellent progress:
$ exiftool test/data/uniform.tiff > input.exif
$ dune exec -- example/copy.exe test/data/uniform.tiff example.tiff
$ exiftool example.tiff > output.exif
$ patdiff input.exif output.exif
------ input.exif
++++++ output.exif
@|-1,23 +1,23 ============================================================
|ExifTool Version Number : 13.39
-|File Size : 66 kB
+|File Size : 118 bytes
|File Permissions : -rw-r--r--
|File Type : TIFF
|File Type Extension : tif
|MIME Type : image/tiff
|Exif Byte Order : Little-endian (Intel, II)
|Image Width : 256
|Image Height : 256
|Bits Per Sample : 8
|Compression : Uncompressed
|Photometric Interpretation : BlackIsZero
|Strip Offsets : 122
|Rows Per Strip : 256
|Strip Byte Counts : 65536
|Planar Configuration : Chunky
|Image Size : 256x256
|Megapixels : 0.066
From this slightly edited output, we can see that the OCaml libary is doing a good job at preserving the metadata. The file size discrepancy is because we have not tackled writing the raw data to the file yet! This is next on our TODOs, write data to a file given a strip-offset plan. Once we do that we can then start to think how might we come up with such a plan if we did not have one.