#include <gdcmUtil.h>
Public Member Functions | |
void | hifpswap (double *a, double *b) |
void | hNoifpswap (double *a, double *b) |
void | hfpswap (double *a, double *b) |
Static Public Member Functions | |
static std::string | Format (const char *format,...) |
Provide a better 'c++' approach for sprintf For example c code is: char result[2048]; // hope 2048 is enough sprintf(result, "%04x|%04x", group , elem);. | |
static void | Tokenize (const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ") |
Because not available in C++ (?). | |
static int | CountSubstring (const std::string &str, const std::string &subStr) |
Because not available in C++ (?) Counts the number of occurences of a substring within a string. | |
static std::string | CreateCleanString (std::string const &s) |
Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing). | |
static std::string | CreateCleanString (uint8_t *s, int l) |
Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing). | |
static bool | IsCleanString (std::string const &s) |
Checks whether a 'string' is printable or not (in order to avoid corrupting the terminal of invocation when printing). | |
static bool | IsCleanArea (uint8_t *s, int l) |
Checks whether an 'area' is printable or not (in order to avoid corrupting the terminal of invocation when printing). | |
static std::string | NormalizePath (std::string const &name) |
Add a SEPARATOR to the end of the name if necessary. | |
static std::string | GetPath (std::string const &fullName) |
Get the (directory) path from a full path file name. | |
static std::string | GetName (std::string const &fullName) |
Get the (last) name of a full path file name. | |
static std::string | GetCurrentDate () |
Get the current date of the system in a dicom string. | |
static std::string | GetCurrentTime () |
Get the current time of the system in a dicom string. | |
static std::string | GetCurrentDateTime () |
Get both the date and time at the same time to avoid problem around midnight where the two calls could be before and after midnight. | |
static std::string | GetVersion () |
Provides a simple static GetVersion() function. | |
static unsigned int | GetCurrentThreadID () |
static unsigned int | GetCurrentProcessID () |
static bool | IsCurrentProcessorBigEndian () |
tells us whether the processor we are working with is BigEndian or not | |
static std::string | DicomString (const char *s, size_t l) |
Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want. | |
static std::string | DicomString (const char *s) |
Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want. This function is similar to DicomString(const char*), except it doesn't take a length. It only pad with a null character if length is odd. | |
static bool | DicomStringEqual (const std::string &s1, const char *s2) |
Safely check the equality of two Dicom String:
| |
static bool | CompareDicomString (const std::string &s1, const char *s2, int op) |
Safely compare two Dicom String:
| |
static std::string | GetMACAddress () |
Encode the mac address on a fixed length string of 15 characters. we save space this way. | |
static std::string | CreateUniqueUID (const std::string &root="") |
Creates a new UID. As stipulated in the DICOM ref each time a DICOM image is created it should have a unique identifier (URI). | |
static void | SetRootUID (const std::string &root="") |
static const std::string & | GetRootUID () |
static const uint8_t * | GetFileMetaInformationVersion () |
static void | SetFileMetaInformationVersion (uint16_t fmiv) |
static void | sthifpswap (double *a, double *b) |
static void | sthNoifpswap (double *a, double *b) |
static std::string | ConvertToMD5 (std::string &stringToCrypt) |
Private Types | |
typedef GDCM_NAME_SPACE::Util::md5_state_s | md5_state_t |
Static Private Member Functions | |
static std::string | GetIPAddress () |
Return the IP adress of the machine writting the DICOM image. | |
static void | md5_process (md5_state_t *pms, const uint8_t *data) |
static void | md5_init (md5_state_t *pms) |
static void | md5_append (md5_state_t *pms, const uint8_t *data, int nbytes) |
static void | md5_finish (md5_state_t *pms, uint8_t digest[16]) |
Static Private Attributes | |
static std::string | RootUID = GDCM_UID |
static const std::string | GDCM_UID = "1.2.826.0.1.3680043.2.1143" |
static uint8_t * | FileMetaInformationVersion = (uint8_t *)&FMIV |
static const uint16_t | FMIV = 0x0100 |
static std::string | GDCM_MAC_ADRESS = GetMACAddress() |
Classes | |
struct | md5_state_s |
Definition at line 36 of file gdcmUtil.h.
|
|
|
Safely compare two Dicom String:
Definition at line 521 of file gdcmUtil.cxx. References DicomString(). Referenced by GDCM_NAME_SPACE::SerieHelper::AddFile(). 00522 { 00523 // s2 is the string from the DICOM reference e.g. : 'MONOCHROME1' 00524 std::string s1_even = s1; //Never change input parameter 00525 std::string s2_even = DicomString( s2 ); 00526 if ( s1_even[s1_even.size()-1] == ' ' ) 00527 { 00528 s1_even[s1_even.size()-1] = '\0'; //replace space character by null 00529 } 00530 switch (op) 00531 { 00532 case GDCM_EQUAL : 00533 return s1_even == s2_even; 00534 case GDCM_DIFFERENT : 00535 return s1_even != s2_even; 00536 case GDCM_GREATER : 00537 return s1_even > s2_even; 00538 case GDCM_GREATEROREQUAL : 00539 return s1_even >= s2_even; 00540 case GDCM_LESS : 00541 return s1_even < s2_even; 00542 case GDCM_LESSOREQUAL : 00543 return s1_even <= s2_even; 00544 default : 00545 gdcmDebugMacro(" Wrong operator : " << op); 00546 return false; 00547 } 00548 }
|
|
Definition at line 1129 of file gdcmUtil.cxx. References md5_append(), md5_finish(), and md5_init(). 01130 { 01131 char *szChar = new char[ inPszToCrypt.size()+1 ]; 01132 char *szHexOutput = new char[ 16 * 2 + 1 ]; 01133 int nLen,nDi; 01134 strcpy( szChar, inPszToCrypt.c_str() ); 01135 // création du code md5 01136 nLen = strlen( szChar ); 01137 md5_state_t state; 01138 uint8_t digest[ 16 ]; 01139 md5_init ( &state ); 01140 md5_append ( &state, (const uint8_t *)szChar, nLen); 01141 md5_finish ( &state, digest ); 01142 for ( nDi = 0; nDi < 16; nDi++) 01143 sprintf( szHexOutput + nDi * 2, "%02x", digest[ nDi ] ); 01144 szHexOutput[16 * 2]=0; 01145 delete [] szChar; 01146 std::string md5String=szHexOutput; 01147 delete [] szHexOutput; 01148 return md5String; 01149 }
|
|
Because not available in C++ (?) Counts the number of occurences of a substring within a string.
Definition at line 170 of file gdcmUtil.cxx. Referenced by GDCM_NAME_SPACE::CheckVM(). 00172 { 00173 int count = 0; // counts how many times it appears 00174 std::string::size_type x = 0; // The index position in the string 00175 00176 do 00177 { 00178 x = str.find(subStr,x); // Find the substring 00179 if (x != std::string::npos) // If present 00180 { 00181 count++; // increase the count 00182 x += subStr.length(); // Skip this word 00183 } 00184 } 00185 while (x != std::string::npos);// Carry on until not present 00186 00187 return count; 00188 }
|
|
Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).
Definition at line 261 of file gdcmUtil.cxx. 00262 { 00263 std::string str; 00264 00265 for( int i=0; i<l; i++) 00266 { 00267 if (!isprint((unsigned char)s[i]) ) 00268 { 00269 str = str + '.'; 00270 } 00271 else 00272 { 00273 str = str + (char )s[i]; 00274 } 00275 } 00276 00277 return str; 00278 }
|
|
Weed out a string from the non-printable characters (in order to avoid corrupting the terminal of invocation when printing).
Definition at line 229 of file gdcmUtil.cxx. Referenced by GDCM_NAME_SPACE::DataEntry::Print(). 00230 { 00231 std::string str = s; 00232 00233 for(unsigned int i=0; i<str.size(); i++) 00234 { 00235 if (!isprint((unsigned char)str[i]) ) 00236 { 00237 str[i] = '.'; 00238 } 00239 } 00240 00241 if (str.size() > 0 ) 00242 { 00243 if (!isprint((unsigned char)s[str.size()-1]) ) 00244 { 00245 if (s[str.size()-1] == 0 ) 00246 { 00247 str[str.size()-1] = ' '; 00248 } 00249 } 00250 } 00251 00252 return str; 00253 }
|
|
Creates a new UID. As stipulated in the DICOM ref each time a DICOM image is created it should have a unique identifier (URI).
Definition at line 933 of file gdcmUtil.cxx. References RootUID. Referenced by GDCM_NAME_SPACE::FileHelper::CheckMandatoryElements(), and GDCM_NAME_SPACE::DicomDirMeta::WriteContent(). 00934 { 00935 std::string prefix; 00936 std::string append; 00937 if ( root.empty() ) 00938 { 00939 // gdcm UID prefix, as supplied by http://www.medicalconnections.co.uk 00940 prefix = RootUID; 00941 } 00942 else 00943 { 00944 prefix = root; 00945 } 00946 00947 // A root was specified use it to forge our new UID: 00948 append += "."; 00949 //append += Util::GetMACAddress(); // to save CPU time 00950 append += Util::GDCM_MAC_ADRESS; 00951 append += "."; 00952 append += Util::GetCurrentDateTime(); 00953 append += "."; 00954 //Also add a mini random number just in case: 00955 char tmp[10]; 00956 int r = (int) (100.0*rand()/RAND_MAX); 00957 // Don't use Util::Format to accelerate the execution 00958 sprintf(tmp,"%02d", r); 00959 append += tmp; 00960 00961 // If append is too long we need to rehash it 00962 if ( (prefix + append).size() > 64 ) 00963 { 00964 gdcmStaticErrorMacro( "Size of UID is too long." ); 00965 // we need a hash function to truncate this number 00966 // if only md5 was cross plateform 00967 // MD5(append); 00968 } 00969 00970 return prefix + append; 00971 }
|
|
Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want. This function is similar to DicomString(const char*), except it doesn't take a length. It only pad with a null character if length is odd.
Definition at line 485 of file gdcmUtil.cxx. References gdcmAssertMacro. 00486 { 00487 size_t l = strlen(s); 00488 if ( l%2 ) 00489 { 00490 l++; 00491 } 00492 std::string r(s, s+l); 00493 gdcmAssertMacro( !(r.size() % 2) ); 00494 return r; 00495 }
|
|
Create a /DICOM/ string: It should a of even length (no odd length ever) It can contain as many (if you are reading this from your editor the following character is backslash followed by zero that needed to be escaped with an extra backslash for doxygen) \0 as you want.
Definition at line 467 of file gdcmUtil.cxx. References gdcmAssertMacro. Referenced by CompareDicomString(), DicomStringEqual(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToExplicitVR(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToImplicitVR(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToJPEG(), GDCM_NAME_SPACE::FileHelper::SetWriteFileTypeToJPEG2000(), and GDCM_NAME_SPACE::File::Write(). 00468 { 00469 std::string r(s, s+l); 00470 gdcmAssertMacro( !(r.size() % 2) ); // == basically 'l' is even 00471 return r; 00472 }
|
|
Safely check the equality of two Dicom String:
Definition at line 503 of file gdcmUtil.cxx. References DicomString(). Referenced by GDCM_NAME_SPACE::File::GetNumberOfScalarComponents(), GDCM_NAME_SPACE::File::GetXSpacing(), GDCM_NAME_SPACE::File::GetYSpacing(), GDCM_NAME_SPACE::File::IsMonochrome(), and GDCM_NAME_SPACE::File::IsMonochrome1(). 00504 { 00505 // s2 is the string from the DICOM reference e.g. : 'MONOCHROME1' 00506 std::string s1_even = s1; //Never change input parameter 00507 std::string s2_even = DicomString( s2 ); 00508 if ( s1_even[s1_even.size()-1] == ' ' ) 00509 { 00510 s1_even[s1_even.size()-1] = '\0'; //replace space character by null 00511 } 00512 return s1_even == s2_even; 00513 }
|
|
Provide a better 'c++' approach for sprintf For example c code is: char result[2048]; // hope 2048 is enough sprintf(result, "%04x|%04x", group , elem);. c++ code is std::ostringstream buf; buf << std::right << std::setw(4) << std::setfill('0') << std::hex << group << "|" << std::right << std::setw(4) << std::setfill('0') << std::hex << elem; buf.str(); gdcm style code is string result; result = gdcm::Util::Format("%04x|%04x", group , elem); Definition at line 129 of file gdcmUtil.cxx. Referenced by GetIPAddress(), GDCM_NAME_SPACE::DocEntry::Print(), and GDCM_NAME_SPACE::File::Write(). 00130 { 00131 char buffer[2048]; // hope 2048 is enough 00132 va_list args; 00133 va_start(args, format); 00134 vsprintf(buffer, format, args); //might be a security flaw 00135 va_end(args); // Each invocation of va_start should be matched 00136 // by a corresponding invocation of va_end 00137 // args is then 'undefined' 00138 return buffer; 00139 }
|
|
Get the current date of the system in a dicom string.
Definition at line 358 of file gdcmUtil.cxx. 00359 { 00360 char tmp[512]; 00361 time_t tloc; 00362 time (&tloc); 00363 strftime(tmp,512,"%Y%m%d", localtime(&tloc) ); 00364 return tmp; 00365 }
|
|
Get both the date and time at the same time to avoid problem around midnight where the two calls could be before and after midnight.
Definition at line 383 of file gdcmUtil.cxx. 00384 { 00385 char tmp[40]; 00386 long milliseconds; 00387 time_t timep; 00388 00389 // We need implementation specific functions to obtain millisecond precision 00390 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) 00391 struct timeb tb; 00392 ::ftime(&tb); 00393 timep = tb.time; 00394 milliseconds = tb.millitm; 00395 #else 00396 struct timeval tv; 00397 gettimeofday (&tv, NULL); 00398 timep = tv.tv_sec; 00399 // Compute milliseconds from microseconds. 00400 milliseconds = tv.tv_usec / 1000; 00401 #endif 00402 // Obtain the time of day, and convert it to a tm struct. 00403 struct tm *ptm = localtime (&timep); 00404 // Format the date and time, down to a single second. 00405 strftime (tmp, sizeof (tmp), "%Y%m%d%H%M%S", ptm); 00406 00407 // Add milliseconds 00408 // Don't use Util::Format to accelerate execution of code 00409 char tmpAll[80]; 00410 sprintf(tmpAll,"%s%03ld",tmp,milliseconds); 00411 00412 return tmpAll; 00413 }
|
|
Definition at line 436 of file gdcmUtil.cxx. 00437 { 00438 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) 00439 // NOTE: There is also a _getpid()... 00440 return (unsigned int)GetCurrentProcessId(); 00441 #else 00442 // get process identification, POSIX 00443 return (unsigned int)getpid(); 00444 #endif 00445 }
|
|
Definition at line 415 of file gdcmUtil.cxx. 00416 { 00417 // FIXME the implementation is far from complete 00418 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) 00419 return (unsigned int)GetCurrentThreadId(); 00420 #else 00421 #ifdef __linux__ 00422 return 0; 00423 // Doesn't work on fedora, but is in the man page... 00424 //return (unsigned int)gettid(); 00425 #else 00426 #ifdef __sun 00427 return (unsigned int)thr_self(); 00428 #else 00429 //default implementation 00430 return 0; 00431 #endif // __sun 00432 #endif // __linux__ 00433 #endif // Win32 00434 }
|
|
Get the current time of the system in a dicom string.
Definition at line 370 of file gdcmUtil.cxx. 00371 { 00372 char tmp[512]; 00373 time_t tloc; 00374 time (&tloc); 00375 strftime(tmp,512,"%H%M%S", localtime(&tloc) ); 00376 return tmp; 00377 }
|
|
Definition at line 74 of file gdcmUtil.h. Referenced by GDCM_NAME_SPACE::FileHelper::CheckMandatoryElements(). 00075 { return FileMetaInformationVersion;}
|
|
Return the IP adress of the machine writting the DICOM image.
Definition at line 1159 of file gdcmUtil.cxx. References Format(), and HOST_NAME_MAX. 01160 { 01161 // This is a rip from 01162 // http://www.codeguru.com/Cpp/I-N/internet/network/article.php/c3445/ 01163 #ifndef HOST_NAME_MAX 01164 // SUSv2 guarantees that `Host names are limited to 255 bytes'. 01165 // POSIX 1003.1-2001 guarantees that `Host names (not including the 01166 // terminating NUL) are limited to HOST_NAME_MAX bytes'. 01167 #define HOST_NAME_MAX 255 01168 // In this case we should maybe check the string was not truncated. 01169 // But I don't known how to check that... 01170 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) 01171 // with WinSock DLL we need to initialize the WinSock before using gethostname 01172 WORD wVersionRequested = MAKEWORD(1,0); 01173 WSADATA WSAData; 01174 int err = WSAStartup(wVersionRequested,&WSAData); 01175 if (err != 0) 01176 { 01177 // Tell the user that we could not find a usable 01178 // WinSock DLL. 01179 WSACleanup(); 01180 return "127.0.0.1"; 01181 } 01182 #endif 01183 01184 #endif //HOST_NAME_MAX 01185 01186 std::string str; 01187 char szHostName[HOST_NAME_MAX+1]; 01188 int r = gethostname(szHostName, HOST_NAME_MAX); 01189 01190 if ( r == 0 ) 01191 { 01192 // Get host adresses 01193 struct hostent *pHost = gethostbyname(szHostName); 01194 01195 for( int i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ ) 01196 { 01197 for( int j = 0; j<pHost->h_length; j++ ) 01198 { 01199 if ( j > 0 ) str += "."; 01200 01201 str += Util::Format("%u", 01202 (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]); 01203 } 01204 // str now contains one local IP address 01205 01206 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) 01207 WSACleanup(); 01208 #endif 01209 01210 } 01211 } 01212 // If an error occur r == -1 01213 // Most of the time it will return 127.0.0.1... 01214 return str; 01215 }
|
|
Encode the mac address on a fixed length string of 15 characters. we save space this way.
Definition at line 892 of file gdcmUtil.cxx. References gdcmStaticWarningMacro, GDCM_NAME_SPACE::getlastdigit(), and GDCM_NAME_SPACE::GetMacAddrSys(). 00893 { 00894 // This code is the result of a long internet search to find something 00895 // as compact as possible (not OS independant). We only have to separate 00896 // 3 OS: Win32, SunOS and 'real' POSIX 00897 // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be 00898 // http://bdn.borland.com/article/0,1410,26040,00.html 00899 unsigned char addr[6]; 00900 00901 int stat = GetMacAddrSys(addr); 00902 if (stat == 0) 00903 { 00904 // We need to convert a 6 digit number from base 256 to base 10, using integer 00905 // would requires a 48bits one. To avoid this we have to reimplement the div + modulo 00906 // with string only 00907 bool zero = false; 00908 int res; 00909 std::string sres; 00910 while(!zero) 00911 { 00912 res = getlastdigit(addr); 00913 sres.insert(sres.begin(), '0' + res); 00914 zero = (addr[0] == 0) && (addr[1] == 0) && (addr[2] == 0) 00915 && (addr[3] == 0) && (addr[4] == 0) && (addr[5] == 0); 00916 } 00917 00918 return sres; 00919 } 00920 else 00921 { 00922 gdcmStaticWarningMacro("Problem in finding the MAC Address"); 00923 return ""; 00924 } 00925 }
|
|
Get the (last) name of a full path file name.
Definition at line 334 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::GDCM_FILESEPARATOR. Referenced by GDCM_NAME_SPACE::DicomDir::SetElement(). 00335 { 00336 std::string filename = fullName; 00337 /* 00338 std::string::size_type slash_pos = filename.rfind("/"); 00339 std::string::size_type backslash_pos = filename.rfind("\\"); 00340 // At least with my gcc4.0.1, unfound char results in pos =4294967295 ... 00341 //slash_pos = slash_pos > backslash_pos ? slash_pos : backslash_pos; 00342 slash_pos = slash_pos < backslash_pos ? slash_pos : backslash_pos; 00343 */ 00344 std::string::size_type slash_pos = filename.rfind(GDCM_FILESEPARATOR); 00345 if (slash_pos != std::string::npos ) 00346 { 00347 return filename.substr(slash_pos + 1); 00348 } 00349 else 00350 { 00351 return filename; 00352 } 00353 }
|
|
Get the (directory) path from a full path file name.
Definition at line 309 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::GDCM_FILESEPARATOR. 00310 { 00311 std::string res = fullName; 00312 /* 00313 00314 int pos1 = res.rfind("/"); 00315 int pos2 = res.rfind("\\"); 00316 if ( pos1 > pos2 ) 00317 { 00318 res.resize(pos1); 00319 } 00320 else 00321 { 00322 res.resize(pos2); 00323 } 00324 */ 00325 int pos = res.rfind(GDCM_FILESEPARATOR); 00326 res.resize(pos); 00327 return res; 00328 }
|
|
Definition at line 981 of file gdcmUtil.cxx. References RootUID. 00982 { 00983 return RootUID; 00984 }
|
|
Provides a simple static GetVersion() function.
Definition at line 57 of file gdcmUtil.h. Referenced by GDCM_NAME_SPACE::FileHelper::CheckMandatoryElements().
|
|
Definition at line 1217 of file gdcmUtil.cxx.
|
|
Definition at line 85 of file gdcmUtil.h.
|
|
Definition at line 92 of file gdcmUtil.h.
|
|
Checks whether an 'area' is printable or not (in order to avoid corrupting the terminal of invocation when printing).
Definition at line 213 of file gdcmUtil.cxx. Referenced by GDCM_NAME_SPACE::DataEntry::Print(). 00214 { 00215 for( int i=0; i<l; i++) 00216 { 00217 if (!isprint((unsigned char)s[i]) ) 00218 { 00219 return false; 00220 } 00221 } 00222 return true; 00223 }
|
|
Checks whether a 'string' is printable or not (in order to avoid corrupting the terminal of invocation when printing).
Definition at line 195 of file gdcmUtil.cxx. 00196 { 00197 for(unsigned int i=0; i<s.size(); i++) 00198 { 00199 if (!isprint((unsigned char)s[i]) ) 00200 { 00201 return false; 00202 } 00203 } 00204 return true; 00205 }
|
|
tells us whether the processor we are working with is BigEndian or not
Definition at line 450 of file gdcmUtil.cxx. Referenced by GDCM_NAME_SPACE::Document::CheckSwap(), and GDCM_NAME_SPACE::RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(). 00451 { 00452 #if defined(GDCM_WORDS_BIGENDIAN) 00453 return true; 00454 #else 00455 return false; 00456 #endif 00457 }
|
|
Definition at line 1553 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::Util::md5_state_s::buf, GDCM_NAME_SPACE::Util::md5_state_s::count, and md5_process(). Referenced by ConvertToMD5(), and md5_finish(). 01554 { 01555 const uint8_t *p = data; 01556 int left = nbytes; 01557 int offset = (pms->count[0] >> 3) & 63; 01558 uint16_t nbits = (uint16_t)(nbytes << 3); 01559 if (nbytes <= 0) 01560 return; 01561 /* Update the message length. */ 01562 pms->count[1] += nbytes >> 29; 01563 pms->count[0] += nbits; 01564 if (pms->count[0] < nbits) 01565 pms->count[1]++; 01566 /* Process an initial partial block. */ 01567 if (offset) { 01568 int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); 01569 memcpy(pms->buf + offset, p, copy); 01570 if (offset + copy < 64) 01571 return; 01572 p += copy; 01573 left -= copy; 01574 md5_process(pms, pms->buf); 01575 } 01576 /* Process full blocks. */ 01577 for (; left >= 64; p += 64, left -= 64) 01578 md5_process(pms, p); 01579 /* Process a final partial block. */ 01580 if (left) 01581 memcpy(pms->buf, p, left); 01582 }
|
|
Definition at line 1584 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::Util::md5_state_s::abcd, GDCM_NAME_SPACE::Util::md5_state_s::count, and md5_append(). Referenced by ConvertToMD5(). 01585 { 01586 static const uint8_t pad[64] = { 01587 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 01588 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 01589 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 01590 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 01591 }; 01592 01593 uint8_t data[8]; 01594 int i; 01595 /* Save the length before padding. */ 01596 for (i = 0; i < 8; ++i) 01597 data[i] = (uint8_t)(pms->count[i >> 2] >> ((i & 3) << 3)); 01598 /* Pad to 56 bytes mod 64. */ 01599 md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); 01600 /* Append the length. */ 01601 md5_append(pms, data, 8); 01602 for (i = 0; i < 16; ++i) 01603 digest[i] = (uint8_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); 01604 }
|
|
Definition at line 1542 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::Util::md5_state_s::abcd, GDCM_NAME_SPACE::Util::md5_state_s::count, and T_MASK. Referenced by ConvertToMD5(). 01543 { 01544 pms->count[0] = pms->count[1] = 0; 01545 pms->abcd[0] = 0x67452301; 01546 pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; 01547 pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; 01548 pms->abcd[3] = 0x10325476; 01549 }
|
|
Definition at line 1361 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::Util::md5_state_s::abcd, SET, T1, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T2, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T3, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T4, T40, T41, T42, T43, T44, T45, T46, T47, T48, T49, T5, T50, T51, T52, T53, T54, T55, T56, T57, T58, T59, T6, T60, T61, T62, T63, T64, T7, T8, and T9. Referenced by md5_append(). 01362 { 01363 uint16_t 01364 a = pms->abcd[0], b = pms->abcd[1], 01365 c = pms->abcd[2], d = pms->abcd[3]; 01366 uint16_t t; 01367 01368 #if BYTE_ORDER > 0 01369 /* Define storage only for big-endian CPUs. */ 01370 uint16_t X[16]; 01371 #else 01372 /* Define storage for little-endian or both types of CPUs. */ 01373 uint16_t xbuf[16]; 01374 const uint16_t *X; 01375 #endif 01376 { 01377 #if BYTE_ORDER == 0 01378 /* 01379 * Determine dynamically whether this is a big-endian or 01380 * little-endian machine, since we can use a more efficient 01381 * algorithm on the latter. 01382 */ 01383 static const int w = 1; 01384 01385 if (*((const uint8_t *)&w)) /* dynamic little-endian */ 01386 #endif 01387 #if BYTE_ORDER <= 0 /* little-endian */ 01388 { 01389 /* 01390 * On little-endian machines, we can process properly aligned 01391 * data without copying it. 01392 */ 01393 if (!((data - (const uint8_t *)0) & 3)) { 01394 /* data are properly aligned */ 01395 X = (const uint16_t *)data; 01396 } else { 01397 /* not aligned */ 01398 memcpy(xbuf, data, 64); 01399 X = xbuf; 01400 } 01401 } 01402 #endif 01403 #if BYTE_ORDER == 0 01404 else /* dynamic big-endian */ 01405 #endif 01406 #if BYTE_ORDER >= 0 /* big-endian */ 01407 { 01408 /* 01409 * On big-endian machines, we must arrange the bytes in the 01410 * right order. 01411 */ 01412 const uint8_t *xp = data; 01413 int i; 01414 01415 # if BYTE_ORDER == 0 01416 X = xbuf; /* (dynamic only) */ 01417 # else 01418 # define xbuf /* (static only) */ 01419 # endif 01420 for (i = 0; i < 16; ++i, xp += 4) 01421 xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); 01422 } 01423 #endif 01424 } 01425 01426 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 01427 01428 /* Round 1. */ 01429 /* Let [abcd k s i] denote the operation 01430 a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ 01431 01432 #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) 01433 #define SET(a, b, c, d, k, s, Ti) \ 01434 t = a + F(b,c,d) + X[k] + Ti;\ 01435 a = ROTATE_LEFT(t, s) + b 01436 /* Do the following 16 operations. */ 01437 SET(a, b, c, d, 0, 7, T1); 01438 SET(d, a, b, c, 1, 12, T2); 01439 SET(c, d, a, b, 2, 17, T3); 01440 SET(b, c, d, a, 3, 22, T4); 01441 SET(a, b, c, d, 4, 7, T5); 01442 SET(d, a, b, c, 5, 12, T6); 01443 SET(c, d, a, b, 6, 17, T7); 01444 SET(b, c, d, a, 7, 22, T8); 01445 SET(a, b, c, d, 8, 7, T9); 01446 SET(d, a, b, c, 9, 12, T10); 01447 SET(c, d, a, b, 10, 17, T11); 01448 SET(b, c, d, a, 11, 22, T12); 01449 SET(a, b, c, d, 12, 7, T13); 01450 SET(d, a, b, c, 13, 12, T14); 01451 SET(c, d, a, b, 14, 17, T15); 01452 SET(b, c, d, a, 15, 22, T16); 01453 #undef SET 01454 /* Round 2. */ 01455 /* Let [abcd k s i] denote the operation 01456 a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ 01457 01458 #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) 01459 #define SET(a, b, c, d, k, s, Ti)\ 01460 t = a + G(b,c,d) + X[k] + Ti; \ 01461 a = ROTATE_LEFT(t, s) + b 01462 /* Do the following 16 operations. */ 01463 SET(a, b, c, d, 1, 5, T17); 01464 SET(d, a, b, c, 6, 9, T18); 01465 SET(c, d, a, b, 11, 14, T19); 01466 SET(b, c, d, a, 0, 20, T20); 01467 SET(a, b, c, d, 5, 5, T21); 01468 SET(d, a, b, c, 10, 9, T22); 01469 SET(c, d, a, b, 15, 14, T23); 01470 SET(b, c, d, a, 4, 20, T24); 01471 SET(a, b, c, d, 9, 5, T25); 01472 SET(d, a, b, c, 14, 9, T26); 01473 SET(c, d, a, b, 3, 14, T27); 01474 SET(b, c, d, a, 8, 20, T28); 01475 SET(a, b, c, d, 13, 5, T29); 01476 SET(d, a, b, c, 2, 9, T30); 01477 SET(c, d, a, b, 7, 14, T31); 01478 SET(b, c, d, a, 12, 20, T32); 01479 #undef SET 01480 /* Round 3. */ 01481 /* Let [abcd k s t] denote the operation 01482 a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ 01483 #define H(x, y, z) ((x) ^ (y) ^ (z)) 01484 #define SET(a, b, c, d, k, s, Ti)\ 01485 t = a + H(b,c,d) + X[k] + Ti; \ 01486 a = ROTATE_LEFT(t, s) + b 01487 01488 /* Do the following 16 operations. */ 01489 SET(a, b, c, d, 5, 4, T33); 01490 SET(d, a, b, c, 8, 11, T34); 01491 SET(c, d, a, b, 11, 16, T35); 01492 SET(b, c, d, a, 14, 23, T36); 01493 SET(a, b, c, d, 1, 4, T37); 01494 SET(d, a, b, c, 4, 11, T38); 01495 SET(c, d, a, b, 7, 16, T39); 01496 SET(b, c, d, a, 10, 23, T40); 01497 SET(a, b, c, d, 13, 4, T41); 01498 SET(d, a, b, c, 0, 11, T42); 01499 SET(c, d, a, b, 3, 16, T43); 01500 SET(b, c, d, a, 6, 23, T44); 01501 SET(a, b, c, d, 9, 4, T45); 01502 SET(d, a, b, c, 12, 11, T46); 01503 SET(c, d, a, b, 15, 16, T47); 01504 SET(b, c, d, a, 2, 23, T48); 01505 #undef SET 01506 /* Round 4. */ 01507 /* Let [abcd k s t] denote the operation 01508 a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ 01509 #define I(x, y, z) ((y) ^ ((x) | ~(z))) 01510 #define SET(a, b, c, d, k, s, Ti)\ 01511 t = a + I(b,c,d) + X[k] + Ti; \ 01512 a = ROTATE_LEFT(t, s) + b 01513 01514 /* Do the following 16 operations. */ 01515 SET(a, b, c, d, 0, 6, T49); 01516 SET(d, a, b, c, 7, 10, T50); 01517 SET(c, d, a, b, 14, 15, T51); 01518 SET(b, c, d, a, 5, 21, T52); 01519 SET(a, b, c, d, 12, 6, T53); 01520 SET(d, a, b, c, 3, 10, T54); 01521 SET(c, d, a, b, 10, 15, T55); 01522 SET(b, c, d, a, 1, 21, T56); 01523 SET(a, b, c, d, 8, 6, T57); 01524 SET(d, a, b, c, 15, 10, T58); 01525 SET(c, d, a, b, 6, 15, T59); 01526 SET(b, c, d, a, 13, 21, T60); 01527 SET(a, b, c, d, 4, 6, T61); 01528 SET(d, a, b, c, 11, 10, T62); 01529 SET(c, d, a, b, 2, 15, T63); 01530 SET(b, c, d, a, 9, 21, T64); 01531 01532 #undef SET 01533 /* Then perform the following additions. (That is increment each 01534 of the four registers by the value it had before this block 01535 was started.) */ 01536 pms->abcd[0] += a; 01537 pms->abcd[1] += b; 01538 pms->abcd[2] += c; 01539 pms->abcd[3] += d; 01540 }
|
|
Add a SEPARATOR to the end of the name if necessary.
Definition at line 283 of file gdcmUtil.cxx. References GDCM_NAME_SPACE::GDCM_FILESEPARATOR. Referenced by GDCM_NAME_SPACE::DirList::Explore(). 00284 { 00285 /* 00286 const char SEPARATOR_X = '/'; 00287 const char SEPARATOR_WIN = '\\'; 00288 #ifdef _WIN32 00289 const std::string SEPARATOR = "\\"; 00290 #else 00291 const std::string SEPARATOR = "/"; 00292 #endif 00293 */ 00294 std::string name = pathname; 00295 int size = name.size(); 00296 00297 // if ( name[size-1] != SEPARATOR_X && name[size-1] != SEPARATOR_WIN ) 00298 if ( name[size-1] != GDCM_FILESEPARATOR ) 00299 { 00300 name += GDCM_FILESEPARATOR; 00301 } 00302 return name; 00303 }
|
|
Definition at line 76 of file gdcmUtil.h. 00077 { FileMetaInformationVersion = (uint8_t *)&fmiv; }
|
|
Definition at line 973 of file gdcmUtil.cxx. References GDCM_UID, and RootUID. 00974 { 00975 if ( root.empty() ) 00976 RootUID = GDCM_UID; 00977 else 00978 RootUID = root; 00979 }
|
|
Definition at line 100 of file gdcmUtil.h.
|
|
Definition at line 107 of file gdcmUtil.h.
|
|
Because not available in C++ (?).
Definition at line 149 of file gdcmUtil.cxx. Referenced by GDCM_NAME_SPACE::DataEntry::GetDSValue(), GDCM_NAME_SPACE::File::GetLUTNbits(), and GDCM_NAME_SPACE::DataEntry::SetString(). 00152 { 00153 std::string::size_type lastPos = str.find_first_not_of(delimiters,0); 00154 std::string::size_type pos = str.find_first_of (delimiters,lastPos); 00155 while (std::string::npos != pos || std::string::npos != lastPos) 00156 { 00157 tokens.push_back(str.substr(lastPos, pos - lastPos)); 00158 lastPos = str.find_first_not_of(delimiters, pos); 00159 pos = str.find_first_of (delimiters, lastPos); 00160 } 00161 }
|
|
Definition at line 124 of file gdcmUtil.h. |
|
Definition at line 125 of file gdcmUtil.h. |
|
Definition at line 126 of file gdcmUtil.h. |
|
Definition at line 123 of file gdcmUtil.h. Referenced by SetRootUID(). |
|
Definition at line 122 of file gdcmUtil.h. Referenced by CreateUniqueUID(), GetRootUID(), and SetRootUID(). |