00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmTS.h"
00020 #include "gdcmDebug.h"
00021 #include "gdcmUtil.h"
00022 #include "gdcmDictSet.h"
00023
00024 #include <fstream>
00025 #include <string>
00026 #include <iostream>
00027 #include <ctype.h>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 namespace gdcm
00040 {
00041
00043 static const char *SpecialStrings[] = {
00044
00045 "1.2.840.10008.1.2",
00046
00047 "1.2.840.113619.5.2",
00048
00049 "1.2.840.10008.1.2.1",
00050
00051 "1.2.840.10008.1.2.1.99",
00052
00053 "1.2.840.10008.1.2.2",
00054
00055 "1.2.840.10008.1.2.4.50",
00056
00057 "1.2.840.10008.1.2.4.51",
00058
00059 "1.2.840.10008.1.2.4.52",
00060
00061 "1.2.840.10008.1.2.4.53",
00062
00063 "1.2.840.10008.1.2.4.55",
00064
00065 "1.2.840.10008.1.2.4.57",
00066
00067
00068 "1.2.840.10008.1.2.4.70",
00069
00070 "1.2.840.10008.1.2.4.80",
00071
00072 "1.2.840.10008.1.2.4.81",
00073
00074 "1.2.840.10008.1.2.4.90",
00075
00076 "1.2.840.10008.1.2.4.91",
00077
00078 "1.2.840.10008.1.2.5",
00079
00080 "1.2.840.10008.1.2.4.100",
00081
00082 "Unknown Transfer Syntax",
00083 NULL
00084 };
00085
00086
00089 void FillDefaultTSDict(TSHT &ts);
00090
00091
00092
00093 TS::TS()
00094 {
00095 std::string filename = DictSet::BuildDictPath() + DICT_TS;
00096 std::ifstream from(filename.c_str());
00097 if ( !from )
00098 {
00099 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00100 FillDefaultTSDict( TsMap );
00101 }
00102 else
00103 {
00104 TSKey key;
00105 TSAtr name;
00106
00107 while (!from.eof())
00108 {
00109 from >> key;
00110 from >> std::ws;
00111 std::getline(from, name);
00112
00113 if (key != "")
00114 {
00115 TsMap[key] = name;
00116 }
00117 }
00118 from.close();
00119 }
00120 }
00121
00122 TS::~TS()
00123 {
00124 TsMap.clear();
00125 }
00126
00127
00128
00129
00131 int TS::Count(TSKey const &key)
00132 {
00133 return TsMap.count(key);
00134 }
00135
00137 TSAtr const &TS::GetValue(TSKey const &key)
00138 {
00139
00140
00141 std::string copy = key;
00142 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
00143 {
00144 copy.erase(copy.size()-1, 1);
00145 }
00146
00147 TSHT::const_iterator it = TsMap.find(copy);
00148 if (it == TsMap.end())
00149 {
00150 return GDCM_UNFOUND;
00151 }
00152 return it->second;
00153 }
00160 bool TS::IsTransferSyntax(TSKey const &key)
00161 {
00162 TSHT::const_iterator it = TsMap.find(key);
00163 return it != TsMap.end();
00164 }
00165
00172 bool TS::IsRLELossless(TSKey const &key)
00173 {
00174 bool r = false;
00175
00176 if ( IsTransferSyntax(key) )
00177 {
00178 if ( key == SpecialStrings[RLELossless] )
00179 {
00180 r = true;
00181 }
00182 }
00183 return r;
00184 }
00185
00192 bool TS::IsJPEGLossless(TSKey const &key)
00193 {
00194 bool r = false;
00195
00196 if ( IsTransferSyntax(key) )
00197 {
00198 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
00199 || key == SpecialStrings[JPEGLosslessProcess14]
00200 || key == SpecialStrings[JPEGLosslessProcess14_1] )
00201 {
00202 r = true;
00203 }
00204 }
00205 return r;
00206 }
00207
00214 bool TS::IsJPEGLossy(TSKey const &key)
00215 {
00216 bool r = false;
00217
00218 if ( IsTransferSyntax(key) )
00219 {
00220 if ( key == SpecialStrings[JPEGBaselineProcess1]
00221 || key == SpecialStrings[JPEGExtendedProcess2_4]
00222 || key == SpecialStrings[JPEGExtendedProcess3_5]
00223 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
00224 {
00225 r = true;
00226 }
00227 }
00228 return r;
00229 }
00230
00237 bool TS::IsJPEG2000(TSKey const &key)
00238 {
00239 bool r = false;
00240
00241 if ( IsTransferSyntax(key) )
00242 {
00243 if ( key == SpecialStrings[JPEG2000Lossless]
00244 || key == SpecialStrings[JPEG2000] )
00245 {
00246 r = true;
00247 }
00248 }
00249 return r;
00250 }
00251
00257 bool TS::IsJPEG(TSKey const &key)
00258 {
00259 bool r = false;
00260
00261 if ( IsTransferSyntax(key) )
00262 {
00263 if ( IsJPEGLossy( key )
00264 || IsJPEGLossless( key )
00265 || IsJPEG2000( key )
00266 || IsJPEGLS( key )
00267 )
00268 {
00269 r = true;
00270 }
00271 }
00272 return r;
00273 }
00274
00280 bool TS::IsJPEGLS(TSKey const &key)
00281 {
00282 bool r = false;
00283
00284 if ( IsTransferSyntax(key) )
00285 {
00286 if ( key == SpecialStrings[JPEGLSLossless]
00287 || key == SpecialStrings[JPEGLSNearLossless] )
00288 {
00289 r = true;
00290 }
00291 }
00292 return r;
00293 }
00294
00300 bool TS::IsMPEG(TSKey const &key)
00301 {
00302 bool r = false;
00303
00304 if ( IsTransferSyntax(key) )
00305 {
00306 if ( key == SpecialStrings[MPEG2MainProfile] )
00307 {
00308 r = true;
00309 }
00310 }
00311 return r;
00312 }
00313
00319 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
00320 {
00321 for (int i = 0; SpecialStrings[i] != NULL; i++)
00322 {
00323 if ( SpecialStrings[i] == key )
00324 {
00325 return SpecialType(i);
00326 }
00327 }
00328 return UnknownTS;
00329 }
00330
00336 const char* TS::GetSpecialTransferSyntax(SpecialType t)
00337 {
00338 return SpecialStrings[t];
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00353 void TS::Print(std::ostream &os,std::string const &)
00354 {
00355 std::ostringstream s;
00356
00357 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
00358 {
00359 s << "TS : " << it->first << " = " << it->second << std::endl;
00360 }
00361 os << s.str();
00362 }
00363
00364
00365 }