changeset 296:559499b80da8

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 06:45:44 +0200
parents 92b88fa3e631
children c1687b8fc800
files Framework/Inputs/HierarchicalTiff.cpp Framework/Inputs/HierarchicalTiff.h
diffstat 2 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Inputs/HierarchicalTiff.cpp	Thu Jul 13 18:18:21 2023 +0200
+++ b/Framework/Inputs/HierarchicalTiff.cpp	Tue Jul 18 06:45:44 2023 +0200
@@ -99,10 +99,13 @@
   }
 
 
-  bool HierarchicalTiff::GetCurrentCompression(ImageCompression& compression)
+  bool HierarchicalTiff::GetCurrentDirectoryInformation(TIFF* tiff,
+                                                        ImageCompression& compression,
+                                                        Orthanc::PixelFormat& pixelFormat,
+                                                        Orthanc::PhotometricInterpretation& photometric)
   {
     uint16_t c;
-    if (!TIFFGetField(tiff_, TIFFTAG_COMPRESSION, &c))
+    if (!TIFFGetField(tiff, TIFFTAG_COMPRESSION, &c))
     {
       return false;
     }
@@ -111,30 +114,24 @@
     {
       case COMPRESSION_NONE:
         compression = ImageCompression_None;
-        return true;
+        break;
 
       case COMPRESSION_JPEG:
         compression = ImageCompression_Jpeg;
-        return true;
+        break;
 
       default:
         return false;
     }
-  }
 
-
-  bool HierarchicalTiff::GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat,
-                                               Orthanc::PhotometricInterpretation& photometric,
-                                               ImageCompression compression)
-  {
     // http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
 
     uint16_t channels, photometricTiff, bpp, planar;
-    if (!TIFFGetField(tiff_, TIFFTAG_SAMPLESPERPIXEL, &channels) ||
+    if (!TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &channels) ||
         channels == 0 ||
-        !TIFFGetField(tiff_, TIFFTAG_PHOTOMETRIC, &photometricTiff) ||
-        !TIFFGetField(tiff_, TIFFTAG_BITSPERSAMPLE, &bpp) ||
-        !TIFFGetField(tiff_, TIFFTAG_PLANARCONFIG, &planar))
+        !TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometricTiff) ||
+        !TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &bpp) ||
+        !TIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &planar))
     {
       return false;
     }
@@ -161,6 +158,15 @@
           return false;
       }
     }
+    else if (compression == ImageCompression_None &&
+             channels == 3 &&     // This is a color image
+             bpp == 8 &&
+             planar == PLANARCONFIG_CONTIG)  // This is interleaved RGB
+    {
+      pixelFormat = Orthanc::PixelFormat_RGB24;
+      photometric = Orthanc::PhotometricInterpretation_RGB;
+      return true;
+    }
     else if (compression == ImageCompression_Jpeg &&
              channels == 1 &&     // This is a grayscale image
              bpp == 8)
@@ -198,8 +204,7 @@
           h > 0 &&
           tw > 0 &&
           th > 0 &&
-          GetCurrentCompression(compression) &&
-          GetCurrentPixelFormat(pixelFormat, photometric, compression))
+          GetCurrentDirectoryInformation(tiff_, compression, pixelFormat, photometric))
       {
         if (first)
         {
--- a/Framework/Inputs/HierarchicalTiff.h	Thu Jul 13 18:18:21 2023 +0200
+++ b/Framework/Inputs/HierarchicalTiff.h	Tue Jul 18 06:45:44 2023 +0200
@@ -62,12 +62,6 @@
 
     void CheckLevel(unsigned int level) const;
 
-    bool GetCurrentCompression(ImageCompression& compression);
-
-    bool GetCurrentPixelFormat(Orthanc::PixelFormat& pixelFormat,
-                               Orthanc::PhotometricInterpretation& photometric,
-                               ImageCompression compression);
-
     bool Initialize();
 
   public:
@@ -117,5 +111,10 @@
     {
       return compression_;
     }
+
+    static bool GetCurrentDirectoryInformation(TIFF* tiff,
+                                               ImageCompression& compression,
+                                               Orthanc::PixelFormat& pixelFormat,
+                                               Orthanc::PhotometricInterpretation& photometric);
   };
 }