1 /*=========================================================================
4 Module: $RCSfile: gdcmTS.cxx,v $
6 Date: $Date: 2005/02/11 15:22:18 $
7 Version: $Revision: 1.43 $
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 // http://www.gemedicalsystemseurope.com/euen/it_solutions/pdf/lsqxi_rev2.pdf
36 //-----------------------------------------------------------------------------
37 /// \brief Transfer Syntaxes gdcm deals with (internal use onky)
38 static const char *SpecialStrings[] = {
39 // Implicit VR Little Endian
41 // Implicit VR Big Endian DLX (G.E Private)
43 // Explicit VR Little Endian
44 "1.2.840.10008.1.2.1",
45 // Deflated Explicit VR Little Endian
46 "1.2.840.10008.1.2.1.99",
47 // Explicit VR Big Endian
48 "1.2.840.10008.1.2.2",
49 // JPEG Baseline (Process 1)
50 "1.2.840.10008.1.2.4.50",
51 // JPEG Extended (Process 2 & 4)
52 "1.2.840.10008.1.2.4.51",
53 // JPEG Extended (Process 3 & 5)
54 "1.2.840.10008.1.2.4.52",
55 // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8)
56 "1.2.840.10008.1.2.4.53",
57 // JPEG Full Progression, Non-Hierarchical (Process 10 & 12)
58 "1.2.840.10008.1.2.4.55",
59 // JPEG Lossless, Non-Hierarchical (Process 14)
60 "1.2.840.10008.1.2.4.57",
61 // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14,
62 // [Selection Value 1])
63 "1.2.840.10008.1.2.4.70",
64 // JPEG-LS Lossless Image Compression
65 "1.2.840.10008.1.2.4.80",
66 // JPEG-LS Lossy (Near-Lossless) Image Compression
67 "1.2.840.10008.1.2.4.81",
69 "1.2.840.10008.1.2.4.90",
71 "1.2.840.10008.1.2.4.91",
73 "1.2.840.10008.1.2.5",
75 "Unknown Transfer Syntax"
78 //-----------------------------------------------------------------------------
79 /// \brief auto generated function, to fill up the Dicom Dictionnary,
80 /// if relevant file is not found on user's disk
81 void FillDefaultTSDict(TSHT &ts);
83 //-----------------------------------------------------------------------------
84 // Constructor / Destructor
87 std::string filename = DictSet::BuildDictPath() + DICT_TS;
88 std::ifstream from(filename.c_str());
91 gdcmWarningMacro("Can't open dictionary" << filename.c_str());
92 FillDefaultTSDict( TsMap );
103 std::getline(from, name);
119 //-----------------------------------------------------------------------------
122 /// \brief returns occurence number of the given key
123 int TS::Count(TSKey const &key)
125 return TsMap.count(key);
128 /// \brief returns the human reabable value of a Transfer Synatx string
129 TSAtr const &TS::GetValue(TSKey const &key)
131 // First thing clean up the string
132 // (sometime the transfer syntax is padded with spaces)
133 std::string copy = key;
134 while ( copy.size() && !isdigit((unsigned char)copy[copy.size()-1]) )
136 copy.erase(copy.size()-1, 1);
139 TSHT::const_iterator it = TsMap.find(copy);
140 if (it == TsMap.end())
147 * \brief Determines if the key passed corresponds to a 'Transfer Syntax'
148 * as defined in DICOM (and stored in gdcm::TS class)
149 * @return True when key is an actual 'Transfer Syntax'. False in all
152 bool TS::IsTransferSyntax(TSKey const &key)
154 TSHT::const_iterator it = TsMap.find(key);
155 return it != TsMap.end();
159 * \brief Determines if the Transfer Syntax was already encountered
160 * and if it corresponds to a Run Length Encoding Lossless one
161 * @return True when Run Length Encoding Lossless found. False in all
164 bool TS::IsRLELossless(TSKey const &key)
167 // First check this is an actual transfer syntax
168 if( IsTransferSyntax(key) )
170 if ( key == SpecialStrings[RLELossless] )
179 * \brief Determines if the Transfer Syntax was already encountered
180 * and if it corresponds to a 'classical' JPEG Lossless one
181 * @return True when 'classical' Lossless found. False in all
184 bool TS::IsJPEGLossless(TSKey const &key)
187 // First check this is an actual transfer syntax
188 if( IsTransferSyntax(key) )
190 if ( key == SpecialStrings[JPEGFullProgressionProcess10_12]
191 || key == SpecialStrings[JPEGLosslessProcess14]
192 || key == SpecialStrings[JPEGLosslessProcess14_1] )
201 * \brief Determines if the Transfer Syntax was already encountered
202 * and if it corresponds to a 'classical' JPEG Lossy one
203 * @return True when 'classical' Lossy found. False in all
206 bool TS::IsJPEGLossy(TSKey const &key)
209 // First check this is an actual transfer syntax
210 if( IsTransferSyntax(key) )
212 if ( key == SpecialStrings[JPEGBaselineProcess1]
213 || key == SpecialStrings[JPEGExtendedProcess2_4]
214 || key == SpecialStrings[JPEGExtendedProcess3_5]
215 || key == SpecialStrings[JPEGSpectralSelectionProcess6_8] )
224 * \brief Determines if the Transfer Syntax was already encountered
225 * and if it corresponds to a JPEG2000 one
226 * @return True when JPEG2000 (Lossly or LossLess) found. False in all
229 bool TS::IsJPEG2000(TSKey const &key)
232 // First check this is an actual transfer syntax
233 if( IsTransferSyntax(key) )
235 if ( key == SpecialStrings[JPEG2000Lossless]
236 || key == SpecialStrings[JPEG2000] )
245 * \brief Determines if the Transfer Syntax corresponds to
246 * 'classical' Jpeg Lossless or Jpeg lossy.
247 * @return True when any form of JPEG found. False otherwise.
249 bool TS::IsJPEG(TSKey const &key)
252 // First check this is an actual transfer syntax
253 if( IsTransferSyntax(key) )
255 if ( IsJPEGLossy( key )
256 || IsJPEGLossless( key )
266 * \brief Determines if the Transfer Syntax corresponds to any form
267 * of Jpeg-LS encoded Pixel data.
268 * @return True when any form of JPEG-LS found. False otherwise.
270 bool TS::IsJPEGLS(TSKey const &key)
273 // First check this is an actual transfer syntax
274 if( IsTransferSyntax(key) )
276 if ( key == SpecialStrings[JPEGLSLossless]
277 || key == SpecialStrings[JPEGLSNearLossless] )
285 TS::SpecialType TS::GetSpecialTransferSyntax(TSKey const &key)
287 for (int i = 0; SpecialStrings[i] != NULL; i++)
289 if ( SpecialStrings[i] == key )
291 return SpecialType(i);
298 const char* TS::GetSpecialTransferSyntax(SpecialType t)
300 return SpecialStrings[t];
303 //-----------------------------------------------------------------------------
306 //-----------------------------------------------------------------------------
309 //-----------------------------------------------------------------------------
313 * @param os The output stream to be written to.
315 void TS::Print(std::ostream &os)
317 std::ostringstream s;
319 for (TSHT::const_iterator it = TsMap.begin(); it != TsMap.end(); ++it)
321 s << "TS : " << it->first << " = " << it->second << std::endl;
326 //-----------------------------------------------------------------------------
327 } // end namespace gdcm