changeset 326:9947e70cbcea

preparing padding of JPEG and PNG
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2024 17:24:56 +0200
parents a92bb720f90b
children 4e25eb77cd1d
files Applications/Dicomizer.cpp Framework/Inputs/PlainTiff.cpp Framework/Inputs/PlainTiff.h Framework/Inputs/SingleLevelDecodedPyramid.cpp Framework/Inputs/SingleLevelDecodedPyramid.h
diffstat 5 files changed, 44 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/Dicomizer.cpp	Wed Oct 16 21:08:58 2024 +0200
+++ b/Applications/Dicomizer.cpp	Thu Oct 17 17:24:56 2024 +0200
@@ -1064,22 +1064,26 @@
   OrthancWSI::ImageCompression format = OrthancWSI::DetectFormatFromFile(path);
   LOG(WARNING) << "File format of the input image: " << EnumerationToString(format);
 
+  std::unique_ptr<OrthancWSI::SingleLevelDecodedPyramid> plainImage;
+
   switch (format)
   {
     case OrthancWSI::ImageCompression_Png:
     {
       sourceCompression = OrthancWSI::ImageCompression_Unknown;
-      return new OrthancWSI::TiledPngImage(path, 
-                                           parameters.GetTargetTileWidth(512), 
-                                           parameters.GetTargetTileHeight(512));
+      plainImage.reset(new OrthancWSI::TiledPngImage(path,
+                                                     parameters.GetTargetTileWidth(512),
+                                                     parameters.GetTargetTileHeight(512)));
+      break;
     }
 
     case OrthancWSI::ImageCompression_Jpeg:
     {
       sourceCompression = OrthancWSI::ImageCompression_Unknown;
-      return new OrthancWSI::TiledJpegImage(path, 
-                                            parameters.GetTargetTileWidth(512), 
-                                            parameters.GetTargetTileHeight(512));
+      plainImage.reset(new OrthancWSI::TiledJpegImage(path,
+                                                      parameters.GetTargetTileWidth(512),
+                                                      parameters.GetTargetTileHeight(512)));
+      break;
     }
 
     case OrthancWSI::ImageCompression_Tiff:
@@ -1104,13 +1108,9 @@
       try
       {
         sourceCompression = OrthancWSI::ImageCompression_Unknown;
-        return new OrthancWSI::PlainTiff(path,
-                                         parameters.GetTargetTileWidth(512),
-                                         parameters.GetTargetTileHeight(512),
-                                         parameters.GetPadding(),
-                                         parameters.GetBackgroundColorRed(),
-                                         parameters.GetBackgroundColorGreen(),
-                                         parameters.GetBackgroundColorBlue());
+        plainImage.reset(new OrthancWSI::PlainTiff(path,
+                                                   parameters.GetTargetTileWidth(512),
+                                                   parameters.GetTargetTileHeight(512)));
       }
       catch (Orthanc::OrthancException&)
       {
@@ -1122,6 +1122,19 @@
       break;
   }
 
+  if (plainImage.get() != NULL)
+  {
+    if (parameters.GetPadding() > 1)
+    {
+      plainImage->SetPadding(parameters.GetPadding(),
+                             parameters.GetBackgroundColorRed(),
+                             parameters.GetBackgroundColorGreen(),
+                             parameters.GetBackgroundColorBlue());
+    }
+
+    return plainImage.release();
+  }
+
   try
   {
     LOG(WARNING) << "Trying to open the input pyramid with OpenSlide";
--- a/Framework/Inputs/PlainTiff.cpp	Wed Oct 16 21:08:58 2024 +0200
+++ b/Framework/Inputs/PlainTiff.cpp	Thu Oct 17 17:24:56 2024 +0200
@@ -39,11 +39,7 @@
 {
   PlainTiff::PlainTiff(const std::string& path,
                        unsigned int tileWidth,
-                       unsigned int tileHeight,
-                       unsigned int paddingAlignement,
-                       uint8_t paddingRed,
-                       uint8_t paddingGreen,
-                       uint8_t paddingBlue) :
+                       unsigned int tileHeight) :
     SingleLevelDecodedPyramid(tileWidth, tileHeight)
   {
     TiffReader reader(path);
@@ -113,17 +109,9 @@
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
     }
 
-    LOG(WARNING) << "Size of the source TIFF image: " << width << "x" << height;
+    LOG(INFO) << "Size of the source plain TIFF image: " << width << "x" << height;
 
-    const unsigned int paddedWidth = paddingAlignement * CeilingDivision(width, paddingAlignement);
-    const unsigned int paddedHeight = paddingAlignement * CeilingDivision(height, paddingAlignement);
-    assert(paddedWidth >= width &&
-           paddedHeight >= height);
-
-    LOG(WARNING) << "Size of the padded TIFF image: " << paddedWidth << "x" << paddedHeight;
-
-    decoded_.reset(new Orthanc::Image(pixelFormat, paddedWidth, paddedHeight, false));
-    Orthanc::ImageProcessing::Set(*decoded_, paddingRed, paddingGreen, paddingBlue, 255);
+    decoded_.reset(new Orthanc::Image(pixelFormat, width, height, false));
 
     std::string strip;
     strip.resize(TIFFStripSize(reader.GetTiff()));
--- a/Framework/Inputs/PlainTiff.h	Wed Oct 16 21:08:58 2024 +0200
+++ b/Framework/Inputs/PlainTiff.h	Thu Oct 17 17:24:56 2024 +0200
@@ -36,10 +36,6 @@
   public:
     PlainTiff(const std::string& path,
               unsigned int tileWidth,
-              unsigned int tileHeight,
-              unsigned int paddingAlignement,
-              uint8_t paddingRed,
-              uint8_t paddingGreen,
-              uint8_t paddingBlue);
+              unsigned int tileHeight);
   };
 }
--- a/Framework/Inputs/SingleLevelDecodedPyramid.cpp	Wed Oct 16 21:08:58 2024 +0200
+++ b/Framework/Inputs/SingleLevelDecodedPyramid.cpp	Thu Oct 17 17:24:56 2024 +0200
@@ -80,4 +80,13 @@
         throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
     }
   }
+
+
+  void SingleLevelDecodedPyramid::SetPadding(unsigned int paddingAlignement,
+                                             uint8_t paddingRed,
+                                             uint8_t paddingGreen,
+                                             uint8_t paddingBlue)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);  // TODO
+  }
 }
--- a/Framework/Inputs/SingleLevelDecodedPyramid.h	Wed Oct 16 21:08:58 2024 +0200
+++ b/Framework/Inputs/SingleLevelDecodedPyramid.h	Thu Oct 17 17:24:56 2024 +0200
@@ -79,5 +79,10 @@
     }
 
     virtual Orthanc::PhotometricInterpretation GetPhotometricInterpretation() const ORTHANC_OVERRIDE;
+
+    void SetPadding(unsigned int paddingAlignement,
+                    uint8_t paddingRed,
+                    uint8_t paddingGreen,
+                    uint8_t paddingBlue);
   };
 }