diff Framework/Inputs/HierarchicalTiff.cpp @ 166:f0dac1e8f736

access to photometric interpretation of source pyramids
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 12 Jul 2019 09:06:54 +0200
parents 6b8ccfc02051
children 11413cc2b9d6
line wrap: on
line diff
--- a/Framework/Inputs/HierarchicalTiff.cpp	Fri Feb 22 14:28:40 2019 +0100
+++ b/Framework/Inputs/HierarchicalTiff.cpp	Fri Jul 12 09:06:54 2019 +0200
@@ -123,14 +123,15 @@
 
 
   bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat,
+                                               Orthanc::PhotometricInterpretation& photometric,
                                                ImageCompression compression)
   {
     // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
 
-    uint16_t channels, photometric, bpp, planar;
+    uint16_t channels, photometricTiff, bpp, planar;
     if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) ||
         channels == 0 ||
-        !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometric) ||
+        !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometricTiff) ||
         !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) ||
         !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar))
     {
@@ -140,10 +141,24 @@
     if (compression == ImageCompression_Jpeg &&
         channels == 3 &&     // This is a color image
         bpp == 8 &&
-        photometric == PHOTOMETRIC_YCBCR &&
         planar == PLANARCONFIG_CONTIG)  // This is interleaved RGB
     {
       pixelFormat = Orthanc::PixelFormat_RGB24;
+
+      switch (photometricTiff)
+      {
+        case PHOTOMETRIC_YCBCR:
+          photometric = Orthanc::PhotometricInterpretation_YBRFull422;
+          return true;
+          
+        case PHOTOMETRIC_RGB:
+          photometric = Orthanc::PhotometricInterpretation_RGB;
+          return true;
+
+        default:
+          LOG(ERROR) << "Unknown photometric interpretation in TIFF: " << photometricTiff;
+          return false;
+      }
     }
     else
     {
@@ -164,6 +179,7 @@
       uint32_t w, h, tw, th;
       ImageCompression compression;
       Orthanc::PixelFormat pixelFormat;
+      Orthanc::PhotometricInterpretation photometric;
 
       if (TIFFSetDirectory(tiff_, pos) &&
           TIFFGetField(tiff_, TIFFTAG_IMAGEWIDTH, &w) &&
@@ -175,7 +191,7 @@
           tw > 0 &&
           th > 0 &&
           GetCurrentCompression(compression) &&
-          GetCurrentPixelFormat(pixelFormat, compression))
+          GetCurrentPixelFormat(pixelFormat, photometric, compression))
       {
         if (first)
         {
@@ -183,12 +199,14 @@
           tileHeight_ = th;
           compression_ = compression;
           pixelFormat_ = pixelFormat;
+          photometric_ = photometric;
           first = false;
         }
         else if (tw != tileWidth_ ||
                  th != tileHeight_ ||
                  compression_ != compression ||
-                 pixelFormat_ != pixelFormat)
+                 pixelFormat_ != pixelFormat ||
+                 photometric_ != photometric)
         {
           LOG(ERROR) << "The tile size or compression of the TIFF file varies along levels, this is not supported";
           return false;