vtkTIFFReader assumes incorrect default orientation
The TIFF spec 6.0 (at https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf) lists the default value for the Orientation tag as 1, i.e. ORIENTATION_TOPLEFT in /usr/include/tiff.h. However, vtkTIFFReader assumes a default of ORIENTATION_BOTLEFT when no Orientation tag is found in a TIFF file, which is incorrect.
I'm trying to load the attached TIFF file 3DAtlas_CS07-8752-labels-v2016-01.tif, which doesn't have an orientation tag (it actually is a multi-directory tiff, each of which lack the orientation tag). The above incorrect default causes readings error in VTK (git master of a few hours ago) this case. It fails on a call to TIFFReadScanline() as the compression used doesn't allow random access and the assumed orientation in the reader causes the rows to be read in the reverse order compared to the file order.
Below is a patch to correct the default orientation value. This fixes the reading errors. I do need to check if the multi-page image is read correctly into a 3D image, as something strange seems to be going on (but that's probably not related to the issue here).
diff --git a/IO/Image/vtkTIFFReader.cxx b/IO/Image/vtkTIFFReader.cxx
index 91c857a..7bf9da6 100644
--- a/IO/Image/vtkTIFFReader.cxx
+++ b/IO/Image/vtkTIFFReader.cxx
@@ -334,13 +335,13 @@ bool vtkTIFFReader::vtkTIFFReaderInternal::Initialize()
}
// TIFFTAG_ORIENTATION tag from the image data and use it if available.
- // If the tag is not found in the image data, use ORIENTATION_BOTLEFT by
+ // If the tag is not found in the image data, use ORIENTATION_TOPLEFT by
// default.
int status = TIFFGetField(this->Image, TIFFTAG_ORIENTATION,
&this->Orientation);
if (!status)
{
- this->Orientation = ORIENTATION_BOTLEFT;
+ this->Orientation = ORIENTATION_TOPLEFT;
}
TIFFGetFieldDefaulted(this->Image, TIFFTAG_SAMPLESPERPIXEL,