Skip to content

Commit 487e897

Browse files
GDCM Upstreamblowekamp
authored andcommitted
GDCM 2026-06-18 (2b923808)
Code extracted from: https://github.com/malaterre/GDCM.git at commit 2b9238088772254f66b2764b7e4a18e011c63926 (v3.2.8).
1 parent 51fda44 commit 487e897

18 files changed

Lines changed: 1862 additions & 59 deletions

CMakeLists.txt

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ endif()
1010
#----------------------------------------------------------------------------
1111

1212
project(GDCM
13-
VERSION 3.3.0
13+
VERSION 3.2.8
1414
LANGUAGES CXX C
1515
)
1616
## NOTE: the "DESCRIPTION" feature of project() was introduced in cmake 3.10.0
@@ -86,7 +86,10 @@ if(GDCM_VERSION_MINOR MATCHES "[02468]$")
8686
# So unless the user *specifically* requested a particular cmake_build_type
8787
# do the work internally and append the NDEBUG def flag (hopefully portable)
8888
if(NOT CMAKE_BUILD_TYPE)
89-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
89+
get_cmake_property(is_multi_config_generator GENERATOR_IS_MULTI_CONFIG)
90+
if (NOT is_multi_config_generator)
91+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
92+
endif()
9093
endif()
9194
# Since we are on a release branch, chance is that people don't care about testing
9295
# let's disable it for them
@@ -334,8 +337,7 @@ option(GDCM_USE_SYSTEM_JSON "Use system json" OFF)
334337
option(GDCM_USE_SYSTEM_PAPYRUS3 "Use system papyrus3" OFF)
335338
option(GDCM_USE_SYSTEM_SOCKETXX "Use system socket++" OFF)
336339
option(GDCM_USE_SYSTEM_LJPEG "Use system ljpeg (ijg lib)" OFF)
337-
option(GDCM_USE_SYSTEM_OPENJPEG "Use system openjpeg" OFF)
338-
option(GDCM_USE_SYSTEM_CHARLS "Use system charls" OFF)
340+
option(GDCM_USE_JPEGTURBO "Use libjpeg-turbo instead of IJG for JPEG codec" OFF)
339341
mark_as_advanced(
340342
GDCM_USE_SYSTEM_ZLIB
341343
GDCM_USE_SYSTEM_OPENSSL
@@ -347,6 +349,7 @@ mark_as_advanced(
347349
GDCM_USE_SYSTEM_LJPEG
348350
GDCM_USE_SYSTEM_OPENJPEG
349351
GDCM_USE_SYSTEM_CHARLS
352+
GDCM_USE_JPEGTURBO
350353
)
351354
option(GDCM_USE_SYSTEM_POPPLER "Use system poppler (pdf)" OFF)
352355
if(GDCM_USE_SYSTEM_POPPLER)
@@ -360,7 +363,41 @@ if(GDCM_USE_SYSTEM_LIBXML2)
360363
endif()
361364
mark_as_advanced(GDCM_USE_SYSTEM_LIBXML2)
362365

363-
if(GDCM_USE_SYSTEM_LJPEG)
366+
if(GDCM_USE_JPEGTURBO)
367+
# libjpeg-turbo >= 3.0 is required for lossless JPEG and 12/16-bit support
368+
set(_gdcm_jpegturbo_min_version "3.0")
369+
find_package(libjpeg-turbo ${_gdcm_jpegturbo_min_version} QUIET)
370+
if(libjpeg-turbo_FOUND)
371+
set(GDCM_JPEGTURBO_INCLUDE_DIRS ${libjpeg-turbo_INCLUDE_DIRS})
372+
set(GDCM_JPEGTURBO_LIBRARIES ${libjpeg-turbo_LIBRARIES})
373+
# Modern config uses imported targets for libraries
374+
if(NOT GDCM_JPEGTURBO_LIBRARIES AND TARGET libjpeg-turbo::jpeg)
375+
set(GDCM_JPEGTURBO_LIBRARIES libjpeg-turbo::jpeg)
376+
endif()
377+
else()
378+
# Fall back to CMake's FindJPEG which works with system libjpeg-turbo
379+
find_package(JPEG REQUIRED)
380+
include(CheckSymbolExists)
381+
set(CMAKE_REQUIRED_INCLUDES ${JPEG_INCLUDE_DIRS})
382+
check_symbol_exists(LIBJPEG_TURBO_VERSION "jconfig.h" JPEG_IS_TURBO)
383+
if(NOT JPEG_IS_TURBO)
384+
message(FATAL_ERROR "GDCM_USE_JPEGTURBO requires libjpeg-turbo, but found plain libjpeg")
385+
endif()
386+
# Verify version >= 3.0 by checking for jpeg_enable_lossless (added in 3.0)
387+
include(CheckSymbolExists)
388+
set(CMAKE_REQUIRED_INCLUDES ${JPEG_INCLUDE_DIRS})
389+
set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
390+
check_symbol_exists(jpeg12_read_scanlines "jpeglib.h" JPEG_HAS_12BIT_API)
391+
if(NOT JPEG_HAS_12BIT_API)
392+
message(FATAL_ERROR
393+
"GDCM_USE_JPEGTURBO requires libjpeg-turbo >= ${_gdcm_jpegturbo_min_version} "
394+
"(for lossless JPEG and 12/16-bit support), but the installed version is too old.")
395+
endif()
396+
set(GDCM_JPEGTURBO_INCLUDE_DIRS ${JPEG_INCLUDE_DIRS})
397+
set(GDCM_JPEGTURBO_LIBRARIES JPEG::JPEG)
398+
endif()
399+
set(GDCM_LJPEG_LIBRARIES "")
400+
elseif(GDCM_USE_SYSTEM_LJPEG)
364401
find_package(LJPEG REQUIRED)
365402
set(GDCM_LJPEG_LIBRARIES ${LJPEG_LIBRARIES})
366403
else()
@@ -375,6 +412,9 @@ else()
375412
set(GDCM_CHARLS_LIBRARIES gdcmcharls)
376413
endif()
377414

415+
option(GDCM_USE_SYSTEM_OPENJPEG "Use system openjpeg" OFF)
416+
option(GDCM_USE_SYSTEM_CHARLS "Use system charls" OFF)
417+
378418
if(GDCM_USE_SYSTEM_OPENJPEG)
379419
find_package(OpenJPEG 2.0.0 REQUIRED)
380420
set(GDCM_OPENJPEG_LIBRARIES ${OPENJPEG_LIBRARIES})
@@ -814,9 +854,11 @@ include(CMake/InstallRequiredVTKLibraries.cmake)
814854
endif()
815855
endif()
816856

817-
# Make sure to run doxygen after everything else (in particular vtkgdcm):
818-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/doxygen)
819-
add_subdirectory(Utilities/doxygen)
857+
if(GDCM_DOCUMENTATION)
858+
# Make sure to run doxygen after everything else (in particular vtkgdcm):
859+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/doxygen)
860+
add_subdirectory(Utilities/doxygen)
861+
endif()
820862
endif()
821863

822864
#-----------------------------------------------------------------------------

Source/DataDictionary/gdcmPrivateDefaultDicts.cxx

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,104 @@ using DICT_ENTRY = struct
3838
};
3939

4040
static const DICT_ENTRY DICOMV3DataDict [] = {
41+
// Major MRI vendors typically use identifiable creator names for a good reason...
42+
// BEGIN UIH
43+
// See https://github.com/rordenlab/dcm2niix/issues/225
44+
{0x0019,0x0018,"EPI Private Header",VR::IS,VM::VM1,"?",false },
45+
{0x0019,0x0028,"EPI Private Header",VR::FD,VM::VM1,"?",false },
46+
{0x0051,0x0011,"EPI Private Header",VR::LO,VM::VM1,"?",false },
47+
{0x0061,0x0002,"DB Dicom Private Creator",VR::US,VM::VM1,"Generate Private",false },
48+
{0x0061,0x0004,"EditStatus",VR::US,VM::VM1,"?",false },
49+
{0x0061,0x0001,"Common Private Header",VR::SH,VM::VM1,"?",false },
50+
{0x0061,0x0002,"Common Private Header",VR::SH,VM::VM1,"FOV",false },
51+
{0x0061,0x0003,"Common Private Header",VR::SH,VM::VM1,"?",false },
52+
{0x0061,0x0006,"PrivateCreator16",VR::ST,VM::VM1,"Radiopharmaceutical Information JSON",false },
53+
{0x0065,0x0000,"Image Private Header",VR::UL,VM::VM1,"MeasurmentUID",false },
54+
{0x0065,0x0002,"Image Private Header",VR::LO,VM::VM1,"ImageOrientationDisplayed",false },
55+
{0x0065,0x0003,"Image Private Header",VR::LO,VM::VM1,"ReceiveCoil",false },
56+
{0x0065,0x0004,"Image Private Header",VR::SH,VM::VM1,"Interpolation",false },
57+
{0x0065,0x0005,"Image Private Header",VR::SH,VM::VM1,"PE Direction Displayed",false },
58+
{0x0065,0x0006,"Image Private Header",VR::IS,VM::VM1,"Slice Group ID",false },
59+
{0x0065,0x0007,"Image Private Header",VR::OB,VM::VM1,"Uprotocol",false },
60+
{0x0065,0x0009,"Image Private Header",VR::FD,VM::VM1,"BActualValue",false },
61+
{0x0065,0x000a,"Image Private Header",VR::FD,VM::VM1,"BUserValue",false },
62+
{0x0065,0x000d,"Image Private Header",VR::SH,VM::VM1,"Parallel Information",false },
63+
{0x0065,0x000f,"Image Private Header",VR::SH,VM::VM1,"Slice Position",false },
64+
{0x0065,0x0011,"Image Private Header",VR::SH,VM::VM1,"Sections",false },
65+
{0x0065,0x0012,"Image Private Header",VR::LO,VM::VM1,"?",false },
66+
{0x0065,0x0013,"Image Private Header",VR::FD,VM::VM1,"InPlaneRotAngle",false },
67+
{0x0065,0x0014,"Image Private Header",VR::DS,VM::VM3,"SliceNormalVector",false },
68+
{0x0065,0x0015,"Image Private Header",VR::DS,VM::VM3,"SliceCenterPosition",false },
69+
{0x0065,0x0016,"Image Private Header",VR::UL,VM::VM1,"PixelRotateModel",false },
70+
{0x0065,0x0017,"Image Private Header",VR::LO,VM::VM1,"SAR Model",false },
71+
{0x0065,0x0018,"Image Private Header",VR::LO,VM::VM1,"dB/dt Model",false },
72+
{0x0065,0x0021,"Image Private Header",VR::SH,VM::VM1,"?",false },
73+
{0x0065,0x0023,"Image Private Header",VR::LO,VM::VM1,"TablePosition",false },
74+
{0x0065,0x0025,"Image Private Header",VR::DS,VM::VM1,"Slice Gap",false },
75+
{0x0065,0x0029,"Image Private Header",VR::SH,VM::VM1,"AcquisitionDuration",false },
76+
{0x0065,0x002b,"Image Private Header",VR::LT,VM::VM1,"ApplicationCategory",false },
77+
{0x0065,0x002c,"Image Private Header",VR::IS,VM::VM1,"RepeatitionIndex",false },
78+
{0x0065,0x002d,"Image Private Header",VR::ST,VM::VM1,"SequenceDisplayName",false },
79+
{0x0065,0x002e,"Image Private Header",VR::LO,VM::VM1,"NoiseDecovarFlag",false },
80+
{0x0065,0x002f,"Image Private Header",VR::FL,VM::VM1,"ScaleFactor",false },
81+
{0x0065,0x0030,"Image Private Header",VR::LO,VM::VM1,"?Customer?",false },
82+
{0x0065,0x0031,"Image Private Header",VR::SH,VM::VM1,"MRSequenceVariant",false },
83+
{0x0065,0x0032,"Image Private Header",VR::SH,VM::VM1,"MRKSpaceFilter",false },
84+
{0x0065,0x0033,"Image Private Header",VR::SH,VM::VM1,"MRTableMode",false },
85+
{0x0065,0x0036,"Image Private Header",VR::OB,VM::VM1,"MRDiscoParameter",false },
86+
{0x0065,0x0037,"Image Private Header",VR::FD,VM::VM3,"MRDiffusionGradOrientation",false },
87+
{0x0065,0x0038,"Image Private Header",VR::FD,VM::VM1,"MRPerfusionNoiseLevel",false },
88+
{0x0065,0x0039,"Image Private Header",VR::SH,VM::VM6,"MRGradRange",false },
89+
{0x0065,0x0040,"Image Private Header",VR::LO,VM::VM1,"?",false },
90+
{0x0065,0x0041,"Image Private Header",VR::LT,VM::VM1,"?NIN?",false },
91+
{0x0065,0x0048,"Image Private Header",VR::OB,VM::VM1,"?",false },
92+
{0x0065,0x0049,"Image Private Header",VR::DS,VM::VM3,"?",false },
93+
{0x0065,0x0050,"Image Private Header",VR::DS,VM::VM1,"MR Number Of Slice In Volume",false },
94+
{0x0065,0x0051,"Image Private Header",VR::SQ,VM::VM1,"MR VFrame Sequence",false },
95+
{0x0065,0x0052,"Image Private Header",VR::LO,VM::VM1_n,"?",false },
96+
{0x0065,0x0053,"Image Private Header",VR::DS,VM::VM3,"?",false },
97+
{0x0065,0x0055,"Image Private Header",VR::DS,VM::VM1,"?",false },
98+
{0x0065,0x0058,"Image Private Header",VR::IS,VM::VM1,"?",false },
99+
{0x0065,0x0059,"Image Private Header",VR::LO,VM::VM1,"?",false },
100+
{0x0065,0x0060,"Image Private Header",VR::LO,VM::VM1,"?",false },
101+
{0x0065,0x006a,"Image Private Header",VR::LO,VM::VM1,"?",false },
102+
{0x0065,0x006c,"Image Private Header",VR::OB,VM::VM1,"UIH serialized protocol",false },
103+
{0x0065,0x0071,"Image Private Header",VR::US,VM::VM1,"?",false },
104+
{0x0065,0x0073,"Image Private Header",VR::OB,VM::VM1,"?",false },
105+
{0x0065,0x0076,"Image Private Header",VR::SH,VM::VM1,"?",false },
106+
{0x0065,0x0077,"Image Private Header",VR::LO,VM::VM1,"?",false },
107+
{0x0065,0x0078,"Image Private Header",VR::LO,VM::VM1,"?",false },
108+
{0x0067,0x0004,"PrivateCreator10",VR::FD,VM::VM1,"?",false },
109+
{0x0067,0x0005,"PrivateCreator10",VR::FD,VM::VM2,"?",false },
110+
{0x0067,0x0007,"PrivateCreator10",VR::CS,VM::VM3,"?",false },
111+
{0x0067,0x0008,"PrivateCreator10",VR::LO,VM::VM1,"?",false },
112+
{0x0067,0x0009,"PrivateCreator10",VR::IS,VM::VM1,"?",false },
113+
{0x0067,0x000a,"PrivateCreator10",VR::IS,VM::VM1,"?",false },
114+
{0x0067,0x000b,"PrivateCreator10",VR::IS,VM::VM1,"?",false },
115+
{0x0067,0x000d,"PrivateCreator10",VR::SH,VM::VM1,"?",false },
116+
{0x0067,0x0010,"PrivateCreator10",VR::DT,VM::VM1,"?",false },
117+
{0x0067,0x0012,"PrivateCreator10",VR::DT,VM::VM1,"?",false },
118+
{0x0067,0x0014,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
119+
{0x0067,0x0015,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
120+
{0x0067,0x0017,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
121+
{0x0067,0x0019,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
122+
{0x0067,0x001a,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
123+
{0x0067,0x001b,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
124+
{0x0067,0x001c,"PrivateCreator10",VR::CS,VM::VM1,"?",false },
125+
{0x0067,0x001d,"PrivateCreator10",VR::IS,VM::VM1,"?",false },
126+
{0x0067,0x0020,"PrivateCreator10",VR::UT,VM::VM1,"?",false },
127+
{0x0067,0x0021,"PrivateCreator10",VR::SQ,VM::VM1,"?",false },
128+
{0x0067,0x002c,"PrivateCreator10",VR::ST,VM::VM1,"?",false },
129+
{0x0067,0x002f,"PrivateCreator10",VR::DS,VM::VM1,"?",false },
130+
{0x0067,0x0031,"PrivateCreator10",VR::UT,VM::VM1,"?",false },
131+
{0x0067,0x0001,"PrivateCreator11",VR::TM,VM::VM1,"?",false },
132+
{0x0067,0x0002,"PrivateCreator11",VR::DA,VM::VM1,"?",false },
133+
{0x0067,0x0003,"PrivateCreator11",VR::DS,VM::VM1,"?",false },
134+
{0x0067,0x0004,"PrivateCreator11",VR::TM,VM::VM1,"?",false },
135+
{0x0067,0x0005,"PrivateCreator11",VR::DA,VM::VM1,"?",false },
136+
{0x0067,0x0006,"PrivateCreator11",VR::DS,VM::VM1,"?",false },
137+
{0x0067,0x0007,"PrivateCreator11",VR::LO,VM::VM1,"?",false },
138+
// END UIH
41139
{0x0033,0x0001,"KONICA MINOLTA QA 1.4",VR::SQ,VM::VM1,"?Possibly PHI?",false },
42140
{0x0033,0x0004,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false },
43141
{0x0033,0x0006,"KONICA MINOLTA QA 1.4",VR::SS,VM::VM1,"?",false },
@@ -1296,7 +1394,7 @@ static const DICT_ENTRY DICOMV3DataDict [] = {
12961394
{0x0021,0x008e,"SIEMENS MR SDI 02",VR::ST,VM::VM1,"?",false},
12971395
{0x0021,0x00fe,"SIEMENS MR SDI 02",VR::SQ,VM::VM1,"??",false},
12981396
{0x0021,0x00fe,"SIEMENS MR SDS 01",VR::SQ,VM::VM1,"Series Data Sequence",false},
1299-
{0x0089,0x0054,"SYNGO_IMAGING",VR::OW,VM::VM1,"??",false},
1397+
{0x0089,0x0054,"SYNGO_IMAGING",VR::OB,VM::VM1,"??",false},
13001398
{0x0095,0x00fa,"SIENET",VR::PN,VM::VM1,"?Some kind of Patient Name?",false},
13011399
{0x8ff1,0x0010,"SSI Image enhancement Group",VR::LO,VM::VM1,"SSI Image enhancement Group Version",false },
13021400
{0x8ff1,0x0020,"SSI Image enhancement Group",VR::IS,VM::VM256,"RGB LUT",false },

Source/InformationObjectDefinition/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ include_directories(
3737
"${GDCM_SOURCE_DIR}/Source/DataStructureAndEncodingDefinition"
3838
"${GDCM_SOURCE_DIR}/Source/DataDictionary"
3939
"${GDCM_SOURCE_DIR}/Utilities"
40-
"${GDCM_BINARY_DIR}/Utilities/gdcmexpat" # expat_mangle.h
4140
)
42-
if(GDCM_USE_SYSTEM_EXPAT)
41+
if(NOT GDCM_USE_SYSTEM_EXPAT) # only needed _without_ find_package
4342
include_directories(
44-
${EXPAT_INCLUDE_DIRS}
43+
"${GDCM_BINARY_DIR}/Utilities/gdcmexpat" # expat_mangle.h
4544
)
4645
endif()
4746

Source/MediaStorageAndFileFormat/CMakeLists.txt

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(MSFF_SRCS
4242
gdcmDICOMDIR.cxx
4343
gdcmSpectroscopy.cxx
4444
gdcmEncapsulatedDocument.cxx
45+
gdcmSplitGridFilter.cxx
4546
gdcmSplitMosaicFilter.cxx
4647
gdcmFiducials.cxx
4748
gdcmWaveform.cxx
@@ -67,13 +68,10 @@ set(MSFF_SRCS
6768
gdcmImage.cxx
6869
gdcmImageConverter.cxx
6970
gdcmImageCodec.cxx
70-
gdcmJPEG12Codec.cxx
7171
gdcmRLECodec.cxx
7272
gdcmPDFCodec.cxx
7373
gdcmAudioCodec.cxx
74-
gdcmJPEG16Codec.cxx
7574
gdcmJPEGLSCodec.cxx
76-
gdcmJPEG8Codec.cxx
7775
gdcmJPEGCodec.cxx
7876
gdcmPVRGCodec.cxx
7977
gdcmKAKADUCodec.cxx
@@ -102,6 +100,19 @@ set(MSFF_SRCS
102100
gdcmJPEG2000Codec.cxx
103101
)
104102

103+
# Per-bitdepth IJG codecs or single libjpeg-turbo codec
104+
if(GDCM_USE_JPEGTURBO)
105+
list(APPEND MSFF_SRCS
106+
gdcmJPEGTurboCodec.cxx
107+
)
108+
else()
109+
list(APPEND MSFF_SRCS
110+
gdcmJPEG8Codec.cxx
111+
gdcmJPEG12Codec.cxx
112+
gdcmJPEG16Codec.cxx
113+
)
114+
endif()
115+
105116
list(APPEND MSFF_SRCS
106117
${GDCM_SOURCE_DIR}/Utilities/gdcmrle/rle.cxx
107118
${GDCM_SOURCE_DIR}/Utilities/gdcmrle/info.cxx
@@ -178,6 +189,10 @@ endif()
178189
if(GDCM_USE_SYSTEM_LJPEG)
179190
include_directories(${LJPEG_INCLUDE_DIRS} )
180191
endif()
192+
if(GDCM_USE_JPEGTURBO)
193+
include_directories(${GDCM_JPEGTURBO_INCLUDE_DIRS})
194+
add_definitions(-DGDCM_USE_JPEGTURBO)
195+
endif()
181196
if(NOT GDCM_USE_SYSTEM_ZLIB)
182197
include_directories(
183198
"${GDCM_BINARY_DIR}/Utilities/gdcmzlib"
@@ -211,6 +226,9 @@ endif()
211226
# main libs:
212227
target_link_libraries(gdcmMSFF LINK_PUBLIC gdcmIOD gdcmDSED gdcmDICT)
213228
target_link_libraries(gdcmMSFF LINK_PRIVATE ${GDCM_LJPEG_LIBRARIES} ${GDCM_OPENJPEG_LIBRARIES})
229+
if(GDCM_USE_JPEGTURBO)
230+
target_link_libraries(gdcmMSFF LINK_PRIVATE ${GDCM_JPEGTURBO_LIBRARIES})
231+
endif()
214232
if(GDCM_USE_JPEGLS)
215233
target_link_libraries(gdcmMSFF LINK_PRIVATE ${GDCM_CHARLS_LIBRARIES})
216234
endif()

Source/MediaStorageAndFileFormat/gdcmBitmap.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -888,13 +888,13 @@ bool Bitmap::TryJPEG2000Codec(char *buffer, bool &lossyflag) const
888888
DataElement out;
889889
bool r = codec.Decode(PixelData, out);
890890
if(!r) return false;
891-
gdcm_assert( r );
892891
const ByteValue *outbv = out.GetByteValue();
893-
gdcm_assert( outbv );
894-
unsigned long check = outbv->GetLength(); // FIXME
895-
(void)check;
896-
gdcm_assert( len <= outbv->GetLength() );
897-
memcpy(buffer, outbv->GetPointer(), len /*outbv->GetLength()*/ ); // FIXME
892+
// A missing or short decoded buffer is a runtime condition (e.g. an
893+
// allocation failed while decoding), not a logic invariant: fail gracefully
894+
// rather than throwing out of GetBuffer, which is uncatchable across the
895+
// SWIG language bindings and aborts the host process.
896+
if( !outbv || outbv->GetLength() < len ) return false;
897+
memcpy(buffer, outbv->GetPointer(), len);
898898

899899
lossyflag = codec.IsLossy();
900900
if( codec.IsLossy() && !ts.IsLossy() )

Source/MediaStorageAndFileFormat/gdcmDirectionCosines.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ static inline double NormImpl(const double x[3])
103103
return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
104104
}
105105

106+
double DirectionCosines::Distance(const double x[3], const double y[3])
107+
{
108+
const double dx = x[0] - y[0];
109+
const double dy = x[1] - y[1];
110+
const double dz = x[2] - y[2];
111+
return std::sqrt(dx * dx + dy * dy + dz * dz);
112+
}
113+
106114
double DirectionCosines::Norm(const double v[3])
107115
{
108116
return NormImpl(v);

Source/MediaStorageAndFileFormat/gdcmDirectionCosines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class GDCM_EXPORT DirectionCosines
4343
/// Compute Dot
4444
static double Dot(const double x[3], const double y[3]);
4545

46+
/// Compute Distance
47+
static double Distance(const double x[3], const double y[3]);
48+
4649
/// Normalize in-place
4750
void Normalize();
4851

0 commit comments

Comments
 (0)