1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/02/05 01:37:09 $
7 Version: $Revision: 1.42 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 #include "gdcmDebug.h"
22 #include "gdcmDictSet.h"
29 // a lot of troubles expected with TS : 1.2.840.113619.5.2
30 // Implicit VR - Big Endian
31 // see : http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
36 //-----------------------------------------------------------------------------
37 static const char *SpecialStrings[] = {
38 // Implicit VR Little Endian
40 // Implicit VR Big Endian DLX (G.E Private)
42 // Explicit VR Little Endian
43 "1.2.840.10008.1.2.1",
44 // Deflated Explicit VR Little Endian
45 "1.2.840.10008.1.2.1.99",
46 // Explicit VR Big Endian
47 "1.2.840.10008.1.2.2",
48 // JPEG Baseline (Process 1)
49 "1.2.840.10008.1.2.4.50",
50 // JPEG Extended (Process 2 & 4)
51 "1.2.840.10008.1.2.4.51",
52 // JPEG Extended (Process 3 & 5)
53 "1.2.840.10008.1.2.4.52",
54 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
55 "1.2.840.10008.1.2.4.53",
56 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
57 "1.2.840.10008.1.2.4.55",
58 // JPEG Lossless, Non-Hierarchical (Process 14)
59 "1.2.840.10008.1.2.4.57",
60 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1])
61 "1.2.840.10008.1.2.4.70",
62 // JPEG-LS Lossless Image Compression
63 "1.2.840.10008.1.2.4.80",
64 // JPEG-LS Lossy (Near-Lossless) Image Compression
65 "1.2.840.10008.1.2.4.81",
67 "1.2.840.10008.1.2.4.90",
69 "1.2.840.10008.1.2.4.91",
71 "1.2.840.10008.1.2.5",
73 "Unknown Transfer Syntax"
76 //-----------------------------------------------------------------------------
77 void FillDefaultTSDict(TSHT &ts);
79 //-----------------------------------------------------------------------------
80 // Constructor / Destructor
83 std::string filename = DictSet::BuildDictPath() + DICT_TS;
84 std::ifstream from(filename.c_str());
87 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
88 FillDefaultTSDict( TsMap );
99 std::getline(from, name);
115 //-----------------------------------------------------------------------------
117 int TS::Count(TSKey const &key)
119 return TsMap.count(key);
122 TSAtr const &TS::GetValue(TSKey const &key)
124 // First thing clean up the string sometime the transfer syntax is padded with spaces
125 std::string copy = key;
126 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
128 copy.erase(copy.size()-1, 1);
131 TSHT::const_iterator it = TsMap.find(copy);
132 if (it == TsMap.end())
139 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
140 * as defined in DICOM (and stored in gdcm::TS class)
141 * @return True when key is an actual 'Transfer Syntax'. False in all
144 bool TS::IsTransferSyntax(TSKey const &key)
146 TSHT::const_iterator it = TsMap.find(key);
147 return it != TsMap.end();
151 * \brief Determines if the Transfer Syntax was already encountered
152 * and if it corresponds to a Run Length Encoding Lossless one
153 * @return True when Run Length Encoding Lossless found. False in all
156 bool TS::IsRLELossless(TSKey const &key)
159 // First check this is an actual transfer syntax
160 if( IsTransferSyntax(key) )
162 if ( key == SpecialStrings[RLELossless] )
171 * \brief Determines if the Transfer Syntax was already encountered
172 * and if it corresponds to a 'classical' JPEG Lossless one
173 * @return True when 'classical' Lossless found. False in all
176 bool TS::IsJPEGLossless(TSKey const &key)
179 // First check this is an actual transfer syntax
180 if( IsTransferSyntax(key) )
182 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
183 || key == SpecialStrings[JPEGLosslessProcess14]
184 || key == SpecialStrings[JPEGLosslessProcess14_1] )
193 * \brief Determines if the Transfer Syntax was already encountered
194 * and if it corresponds to a 'classical' JPEG Lossy one
195 * @return True when 'classical' Lossy found. False in all
198 bool TS::IsJPEGLossy(TSKey const &key)
201 // First check this is an actual transfer syntax
202 if( IsTransferSyntax(key) )
204 if ( key == SpecialStrings[JPEGBaselineProcess1]
205 || key == SpecialStrings[JPEGExtendedProcess2_4]
206 || key == SpecialStrings[JPEGExtendedProcess3_5]
207 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
216 * \brief Determines if the Transfer Syntax was already encountered
217 * and if it corresponds to a JPEG2000 one
218 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
221 bool TS::IsJPEG2000(TSKey const &key)
224 // First check this is an actual transfer syntax
225 if( IsTransferSyntax(key) )
227 if ( key == SpecialStrings[JPEG2000Lossless]
228 || key == SpecialStrings[JPEG2000] )
237 * \brief Determines if the Transfer Syntax corresponds to
238 * 'classical' Jpeg Lossless or Jpeg lossy.
239 * @return True when any form of JPEG found. False otherwise.
241 bool TS::IsJPEG(TSKey const &key)
244 // First check this is an actual transfer syntax
245 if( IsTransferSyntax(key) )
247 if ( IsJPEGLossy( key )
248 || IsJPEGLossless( key )
258 * \brief Determines if the Transfer Syntax corresponds to any form
259 * of Jpeg-LS encoded Pixel data.
260 * @return True when any form of JPEG-LS found. False otherwise.
262 bool TS::IsJPEGLS(TSKey const &key)
265 // First check this is an actual transfer syntax
266 if( IsTransferSyntax(key) )
268 if ( key == SpecialStrings[JPEGLSLossless]
269 || key == SpecialStrings[JPEGLSNearLossless] )
277 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
279 for (int i = 0; SpecialStrings[i] != NULL; i++)
281 if ( SpecialStrings[i] == key )
283 return SpecialType(i);
290 const char* TS::GetSpecialTransferSyntax(SpecialType t)
292 return SpecialStrings[t];
295 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------
301 //-----------------------------------------------------------------------------
305 * @param os The output stream to be written to.
307 void TS::Print(std::ostream &os)
309 std::ostringstream s;
311 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
313 s << "TS : " << it->first << " = " << it->second << std::endl;
318 //-----------------------------------------------------------------------------
319 } // end namespace gdcm