changeset 6828:13f0f6dda96d

using Constants.h throughout the source code
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 May 2026 08:54:11 +0200
parents 0aadb5a23a78
children 460330d630bc 4176eb41cf29
files OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp OrthancFramework/Sources/Images/JpegReader.cpp OrthancFramework/Sources/Images/PamReader.cpp OrthancFramework/Sources/Images/PngReader.cpp OrthancFramework/UnitTestsSources/ToolboxTests.cpp
diffstat 7 files changed, 40 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp	Thu May 21 08:54:11 2026 +0200
@@ -31,6 +31,7 @@
 #include "DicomImageInformation.h"
 
 #include "../Compatibility.h"
+#include "../Constants.h"
 #include "../Logging.h"
 #include "../OrthancException.h"
 #include "../SerializationToolbox.h"
@@ -43,8 +44,8 @@
 #include <memory>
 
 static const uint64_t MAX_FRAME_SIZE = (sizeof(void*) == 4
-                                        ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                        : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                        ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                        : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 
 namespace Orthanc
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp	Thu May 21 08:54:11 2026 +0200
@@ -70,13 +70,14 @@
   =========================================================================*/
 
 
-#include "../../Logging.h"
-#include "../../OrthancException.h"
+#include "../../Constants.h"
+#include "../../DicomFormat/DicomIntegerPixelAccessor.h"
 #include "../../Images/Image.h"
 #include "../../Images/ImageProcessing.h"
-#include "../../DicomFormat/DicomIntegerPixelAccessor.h"
+#include "../../Logging.h"
+#include "../../OrthancException.h"
+#include "../FromDcmtkBridge.h"
 #include "../ToDcmtkBridge.h"
-#include "../FromDcmtkBridge.h"
 
 #if ORTHANC_ENABLE_PNG == 1
 #  include "../../Images/PngWriter.h"
@@ -124,8 +125,8 @@
 #endif
 
 static const uint64_t MAX_DECODED_FRAME_SIZE = (sizeof(void*) == 4
-                                                ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                                : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                                ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                                : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 
 namespace Orthanc
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Thu May 21 08:54:11 2026 +0200
@@ -77,6 +77,7 @@
 #include "Internals/DicomImageDecoder.h"
 #include "ToDcmtkBridge.h"
 
+#include "../Constants.h"
 #include "../DicomFormat/DicomImageInformation.h"
 #include "../Images/Image.h"
 #include "../Images/ImageProcessing.h"
@@ -147,8 +148,8 @@
 #endif
 
 static const uint64_t MAX_OVERLAY_SIZE = (sizeof(void*) == 4
-                                          ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                          : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                          ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                          : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 
 namespace Orthanc
--- a/OrthancFramework/Sources/Images/JpegReader.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/Images/JpegReader.cpp	Thu May 21 08:54:11 2026 +0200
@@ -25,17 +25,18 @@
 #include "../PrecompiledHeaders.h"
 #include "JpegReader.h"
 
-#include "JpegErrorManager.h"
+#include "../Constants.h"
+#include "../Logging.h"
 #include "../OrthancException.h"
-#include "../Logging.h"
+#include "JpegErrorManager.h"
 
 #if ORTHANC_SANDBOXED == 0
 #  include "../SystemToolbox.h"
 #endif
 
 static const uint64_t MAX_DECODED_JPEG_IMAGE_SIZE = (sizeof(void*) == 4
-                                                     ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                                     : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                                     ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                                     : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 namespace Orthanc
 {
--- a/OrthancFramework/Sources/Images/PamReader.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/Images/PamReader.cpp	Thu May 21 08:54:11 2026 +0200
@@ -25,6 +25,7 @@
 #include "../PrecompiledHeaders.h"
 #include "PamReader.h"
 
+#include "../Constants.h"
 #include "../Endianness.h"
 #include "../Logging.h"
 #include "../OrthancException.h"
@@ -40,8 +41,8 @@
 #include <limits>
 
 static const uint64_t MAX_PAM_IMAGE_BUFFER_SIZE = (sizeof(void*) == 4
-                                                   ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                                   : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                                   ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                                   : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 
 namespace Orthanc
--- a/OrthancFramework/Sources/Images/PngReader.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/Sources/Images/PngReader.cpp	Thu May 21 08:54:11 2026 +0200
@@ -25,6 +25,7 @@
 #include "../PrecompiledHeaders.h"
 #include "PngReader.h"
 
+#include "../Constants.h"
 #include "../OrthancException.h"
 #include "../Toolbox.h"
 
@@ -39,8 +40,8 @@
 
 
 static const uint64_t MAX_DECODED_PNG_IMAGE_SIZE = (sizeof(void*) == 4
-                                                    ? 1ull * 1024ull * 1024ull * 1024ull   // 1 GB on 32 bits system
-                                                    : 4ull * 1024ull * 1024ull * 1024ull); // 4 GB on 64 bits system
+                                                    ? 1 * Orthanc::GIGABYTE   // 1 GB on 32 bits system
+                                                    : 4 * Orthanc::GIGABYTE); // 4 GB on 64 bits system
 
 
 namespace Orthanc
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Thu May 21 08:44:24 2026 +0200
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Thu May 21 08:54:11 2026 +0200
@@ -405,8 +405,8 @@
 TEST(Toolbox, GetHumanTransferSpeed)
 {
   ASSERT_EQ("8.00Mbps", Toolbox::GetHumanTransferSpeed(false, 1000, 1000000));
-  ASSERT_EQ("8.59Gbps", Toolbox::GetHumanTransferSpeed(false, 1024ull*1024*1024, 1000000000));
-  ASSERT_EQ("1.00GB in 1.00s = 8.59Gbps", Toolbox::GetHumanTransferSpeed(true, 1024ull*1024*1024, 1000000000));
+  ASSERT_EQ("8.59Gbps", Toolbox::GetHumanTransferSpeed(false, KILOBYTE*1024*1024, 1000000000));
+  ASSERT_EQ("1.00GB in 1.00s = 8.59Gbps", Toolbox::GetHumanTransferSpeed(true, KILOBYTE*1024*1024, 1000000000));
   ASSERT_EQ("976.56KB in 1.00s = 8.00Mbps", Toolbox::GetHumanTransferSpeed(true, 1000ull*1000, 1000000000));
 }
 
@@ -483,5 +483,19 @@
 {
   // Make sure that "16 * GIGABYTE" is not casted to a size_t on 32bit architectures
   ASSERT_EQ(static_cast<int16_t>(16) * GIGABYTE, 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(GIGABYTE * static_cast<int16_t>(16), 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(GIGABYTE * 16, 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(16 * GIGABYTE, 16ull * 1024ull * 1024ull * 1024ull);
+
+  ASSERT_EQ(static_cast<int16_t>(16 * 1024) * MEGABYTE, 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(MEGABYTE * static_cast<int16_t>(16 * 1024), 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(static_cast<int32_t>(16 * 1024 * 1024) * KILOBYTE, 16ull * 1024ull * 1024ull * 1024ull);
+  ASSERT_EQ(KILOBYTE * static_cast<int32_t>(16 * 1024 * 1024), 16ull * 1024ull * 1024ull * 1024ull);
+
   ASSERT_EQ(8, sizeof(static_cast<int16_t>(16) * GIGABYTE));
+  ASSERT_EQ(8, sizeof(GIGABYTE * static_cast<int16_t>(16)));
+  ASSERT_EQ(8, sizeof(static_cast<int16_t>(16 * 1024) * MEGABYTE));
+  ASSERT_EQ(8, sizeof(MEGABYTE * static_cast<int16_t>(16 * 1024)));
+  ASSERT_EQ(8, sizeof(static_cast<int32_t>(16 * 1024 * 1024) * KILOBYTE));
+  ASSERT_EQ(8, sizeof(KILOBYTE * static_cast<int32_t>(16 * 1024 * 1024)));
 }