1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/01/23 10:12:34 $
7 Version: $Revision: 1.38 $
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 void FillDefaultTSDict(TSHT &ts);
77 //-----------------------------------------------------------------------------
78 // Constructor / Destructor
81 std::string filename = DictSet::BuildDictPath() + DICT_TS;
82 std::ifstream from(filename.c_str());
85 gdcmVerboseMacro("Can't open dictionary" << filename.c_str());
86 FillDefaultTSDict( TsMap );
97 std::getline(from, name);
108 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
118 * @param os The output stream to be written to.
120 void TS::Print(std::ostream &os)
122 std::ostringstream s;
124 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
126 s << "TS : " << it->first << " = " << it->second << std::endl;
131 //-----------------------------------------------------------------------------
133 int TS::Count(TSKey const &key)
135 return TsMap.count(key);
138 TSAtr const & TS::GetValue(TSKey const &key)
140 // First thing clean up the string sometime the transfer syntax is padded with spaces
141 std::string copy = key;
142 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
144 copy.erase(copy.size()-1, 1);
147 TSHT::const_iterator it = TsMap.find(copy);
148 if (it == TsMap.end())
155 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
156 * as defined in DICOM (and stored in gdcm::TS class)
157 * @return True when key is an actual 'Transfer Syntax'. False in all
160 bool TS::IsTransferSyntax(TSKey const &key)
162 TSHT::const_iterator it = TsMap.find(key);
163 return it != TsMap.end();
167 * \brief Determines if the Transfer Syntax was already encountered
168 * and if it corresponds to a Run Length Encoding Lossless one
169 * @return True when Run Length Encoding Lossless found. False in all
172 bool TS::IsRLELossless(TSKey const &key)
175 // First check this is an actual transfer syntax
176 if( IsTransferSyntax(key) )
178 if ( key == SpecialStrings[RLELossless] )
187 * \brief Determines if the Transfer Syntax was already encountered
188 * and if it corresponds to a 'classical' JPEG Lossless one
189 * @return True when 'classical' Lossless found. False in all
192 bool TS::IsJPEGLossless(TSKey const &key)
195 // First check this is an actual transfer syntax
196 if( IsTransferSyntax(key) )
198 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
199 || key == SpecialStrings[JPEGLosslessProcess14]
200 || key == SpecialStrings[JPEGLosslessProcess14_1] )
209 * \brief Determines if the Transfer Syntax was already encountered
210 * and if it corresponds to a 'classical' JPEG Lossy one
211 * @return True when 'classical' Lossy found. False in all
214 bool TS::IsJPEGLossy(TSKey const &key)
217 // First check this is an actual transfer syntax
218 if( IsTransferSyntax(key) )
220 if ( key == SpecialStrings[JPEGBaselineProcess1]
221 || key == SpecialStrings[JPEGExtendedProcess2_4]
222 || key == SpecialStrings[JPEGExtendedProcess3_5]
223 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
231 * \brief Determines if the Transfer Syntax was already encountered
232 * and if it corresponds to a JPEG2000 one
233 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
236 bool TS::IsJPEG2000(TSKey const &key)
239 // First check this is an actual transfer syntax
240 if( IsTransferSyntax(key) )
242 if ( key == SpecialStrings[JPEG2000Lossless]
243 || key == SpecialStrings[JPEG2000] )
252 * \brief Determines if the Transfer Syntax corresponds to
253 * 'classical' Jpeg Lossless or Jpeg lossy.
254 * @return True when any form of JPEG found. False otherwise.
256 bool TS::IsJPEG(TSKey const &key)
259 // First check this is an actual transfer syntax
260 if( IsTransferSyntax(key) )
262 if ( IsJPEGLossy( key )
263 || IsJPEGLossless( key )
273 * \brief Determines if the Transfer Syntax corresponds to any form
274 * of Jpeg-LS encoded Pixel data.
275 * @return True when any form of JPEG-LS found. False otherwise.
277 bool TS::IsJPEGLS(TSKey const &key)
280 // First check this is an actual transfer syntax
281 if( IsTransferSyntax(key) )
283 if ( key == SpecialStrings[JPEGLSLossless]
284 || key == SpecialStrings[JPEGLSNearLossless] )
292 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
294 for (int i = 0; SpecialStrings[i] != NULL; i++)
296 if ( SpecialStrings[i] == key )
298 return SpecialType(i);
305 const char* TS::GetSpecialTransferSyntax(SpecialType t)
307 return SpecialStrings[t];
310 //-----------------------------------------------------------------------------
313 //-----------------------------------------------------------------------------
316 //-----------------------------------------------------------------------------
318 } // end namespace gdcm