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
00028
00029
00030
00031
00032
00033
00034 namespace gdcm
00035 {
00036
00037 static const char *SpecialStrings[] = {
00038
00039 "1.2.840.10008.1.2",
00040
00041 "1.2.840.113619.5.2",
00042
00043 "1.2.840.10008.1.2.1",
00044
00045 "1.2.840.10008.1.2.1.99",
00046
00047 "1.2.840.10008.1.2.2",
00048
00049 "1.2.840.10008.1.2.4.50",
00050
00051 "1.2.840.10008.1.2.4.51",
00052
00053 "1.2.840.10008.1.2.4.52",
00054
00055 "1.2.840.10008.1.2.4.53",
00056
00057 "1.2.840.10008.1.2.4.55",
00058
00059 "1.2.840.10008.1.2.4.57",
00060
00061 "1.2.840.10008.1.2.4.70",
00062
00063 "1.2.840.10008.1.2.4.80",
00064
00065 "1.2.840.10008.1.2.4.81",
00066
00067 "1.2.840.10008.1.2.4.90",
00068
00069 "1.2.840.10008.1.2.4.91",
00070
00071 "1.2.840.10008.1.2.5",
00072
00073 "Unknown Transfer Syntax"
00074 };
00075
00076
00077 void FillDefaultTSDict(TSHT &ts);
00078
00079
00080
00081 TS::TS()
00082 {
00083 std::string filename = DictSet::BuildDictPath() + DICT_TS;
00084 std::ifstream from(filename.c_str());
00085 if( !from )
00086 {
00087 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
00088 FillDefaultTSDict( TsMap );
00089 }
00090 else
00091 {
00092 TSKey key;
00093 TSAtr name;
00094
00095 while (!from.eof())
00096 {
00097 from >> key;
00098 from >> std::ws;
00099 std::getline(from, name);
00100
00101 if(key != "")
00102 {
00103 TsMap[key] = name;
00104 }
00105 }
00106 from.close();
00107 }
00108 }
00109
00110 TS::~TS()
00111 {
00112 TsMap.clear();
00113 }
00114
00115
00116
00117 int TS::Count(TSKey const &key)
00118 {
00119 return TsMap.count(key);
00120 }
00121
00122 TSAtr const &TS::GetValue(TSKey const &key)
00123 {
00124
00125 std::string copy = key;
00126 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
00127 {
00128 copy.erase(copy.size()-1, 1);
00129 }
00130
00131 TSHT::const_iterator it = TsMap.find(copy);
00132 if (it == TsMap.end())
00133 {
00134 return GDCM_UNFOUND;
00135 }
00136 return it->second;
00137 }
00144 bool TS::IsTransferSyntax(TSKey const &key)
00145 {
00146 TSHT::const_iterator it = TsMap.find(key);
00147 return it != TsMap.end();
00148 }
00149
00156 bool TS::IsRLELossless(TSKey const &key)
00157 {
00158 bool r = false;
00159
00160 if( IsTransferSyntax(key) )
00161 {
00162 if ( key == SpecialStrings[RLELossless] )
00163 {
00164 r = true;
00165 }
00166 }
00167 return r;
00168 }
00169
00176 bool TS::IsJPEGLossless(TSKey const &key)
00177 {
00178 bool r = false;
00179
00180 if( IsTransferSyntax(key) )
00181 {
00182 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
00183 || key == SpecialStrings[JPEGLosslessProcess14]
00184 || key == SpecialStrings[JPEGLosslessProcess14_1] )
00185 {
00186 r = true;
00187 }
00188 }
00189 return r;
00190 }
00191
00198 bool TS::IsJPEGLossy(TSKey const &key)
00199 {
00200 bool r = false;
00201
00202 if( IsTransferSyntax(key) )
00203 {
00204 if ( key == SpecialStrings[JPEGBaselineProcess1]
00205 || key == SpecialStrings[JPEGExtendedProcess2_4]
00206 || key == SpecialStrings[JPEGExtendedProcess3_5]
00207 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
00208 {
00209 r = true;
00210 }
00211 }
00212 return r;
00213 }
00214
00221 bool TS::IsJPEG2000(TSKey const &key)
00222 {
00223 bool r = false;
00224
00225 if( IsTransferSyntax(key) )
00226 {
00227 if ( key == SpecialStrings[JPEG2000Lossless]
00228 || key == SpecialStrings[JPEG2000] )
00229 {
00230 r = true;
00231 }
00232 }
00233 return r;
00234 }
00235
00241 bool TS::IsJPEG(TSKey const &key)
00242 {
00243 bool r = false;
00244
00245 if( IsTransferSyntax(key) )
00246 {
00247 if ( IsJPEGLossy( key )
00248 || IsJPEGLossless( key )
00249 )
00250 {
00251 r = true;
00252 }
00253 }
00254 return r;
00255 }
00256
00262 bool TS::IsJPEGLS(TSKey const &key)
00263 {
00264 bool r = false;
00265
00266 if( IsTransferSyntax(key) )
00267 {
00268 if ( key == SpecialStrings[JPEGLSLossless]
00269 || key == SpecialStrings[JPEGLSNearLossless] )
00270 {
00271 r = true;
00272 }
00273 }
00274 return r;
00275 }
00276
00277 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
00278 {
00279 for (int i = 0; SpecialStrings[i] != NULL; i++)
00280 {
00281 if ( SpecialStrings[i] == key )
00282 {
00283 return SpecialType(i);
00284 }
00285 }
00286
00287 return UnknownTS;
00288 }
00289
00290 const char* TS::GetSpecialTransferSyntax(SpecialType t)
00291 {
00292 return SpecialStrings[t];
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00307 void TS::Print(std::ostream &os)
00308 {
00309 std::ostringstream s;
00310
00311 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
00312 {
00313 s << "TS : " << it->first << " = " << it->second << std::endl;
00314 }
00315 os << s.str();
00316 }
00317
00318
00319 }