+2005-01-11 Jean-Pierre Roux <jpr@creatis.univ-lyon1.fr>
+ * Replace confusing name SwitchSwapToBigEndian name by SwitchByteSwapCode
+ * Add the Document::HandleOutOfGroup0002(uint16_t group) method
+ to swap the Swap Code, at parsing time, when we come out of group 0002
+ and Transfer Syntax is Big Endian
+ We should be able to read now 'true DICOM" Big Endian coded images
+ * Add optional run time SetDebugOn (last param) for PrintHeader, PrintFile
+ * Replace the french 'Transfert Syntax' by the english 'Transfer Syntax'
+
2005-01-10 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
* Hopefully fix the bug on MacOSX and static global initialization.
This is the only -minor- patch I found that both please MacOSX and VS6.
Other patch would be to declare a const std::string & GDCM_UNFOUND() instead,
- but this would require a lot of change. Another approach wqould be that Global
+ but this would require a lot of change. Another approach would be that Global
create those string and GDCM_UNFOUND becomes a pointer to a string (which
gdcm::Global would destroy at exit).
2005-01-08 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
- * Fix bug on MacOSX with static initialization in a multui threaded
- environement. static const string in a header file used to be ill
+ * Fix bug on MacOSX with static initialization in a multy threaded
+ environment. static const string in a header file used to be ill
initialized provoquing the freeze of any tests. patch should solve this
issue.
images, without the need of the Cornwell lib, but we do read them properly now
* To reduce code (well to avoid code duplication), I defined a common place
for jpeg read/write: gdcmJpeg.cxx. Now gdcmJpeg[8,12 16] include this file and
- redefine symbols. This is not prefect but this the best solution I found for a
+ redefine symbols. This is not perfect but this the best solution I found for a
compilation time jpeg option.
2004-10-13 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
1.2.840.10008.1.2.4.91 JPEG 2000 Image Compression
1.2.840.10008.1.2.4.100 MPEG2 Main Profile @ Main Level
1.2.840.10008.1.2.5 RLE Lossless
+1.2.840.113619.5.2 Implicit VR - Big Endian (G.E Private)
1.2.840.10008.1.3.10 Media Storage Directory Storage
1.2.840.10008.1.4.1.1 Talairach Brain Atlas Frame of Reference
Program: gdcm
Module: $RCSfile: PrintDicomDir.cxx,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:57 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2005/01/11 11:37:12 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDicomDirSerie.h"
#include "gdcmDicomDirImage.h"
#include "gdcmTS.h"
+#include "gdcmDebug.h"
#include <fstream>
#include <iostream>
file += "/DICOMDIR";
}
+ if (argc > 3)
+ gdcm::Debug::SetDebugOn();
+
e1 = new gdcm::DicomDir( file );
if (argc > 2) {
Program: gdcm
Module: $RCSfile: PrintFile.cxx,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:57 $
- Version: $Revision: 1.19 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.20 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmHeader.h"
+#include "gdcmDebug.h"
#include "gdcmFile.h"
#include <iostream>
fileName += GDCM_DATA_ROOT;
fileName += "/test.acr";
}
+
+ if (argc > 3)
+ gdcm::Debug::SetDebugOn();
e1= new gdcm::Header( fileName.c_str() );
f1 = new gdcm::File(e1);
- f1->SetPrintLevel(2);
- f1->Print();
+ if (argc > 2)
+ {
+ int level = atoi(argv[2]);
+ e1->SetPrintLevel(level);
+ }
std::cout << "\n\n" << std::endl;
if ( e1->GetEntry(0x0002,0x0010) == gdcm::GDCM_NOTLOADED )
{
- std::cout << "Transfert Syntax not loaded. " << std::endl
+ std::cout << "Transfer Syntax not loaded. " << std::endl
<< "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
<< std::endl;
return 0;
}
- std::string transferSyntaxName = e1->GetTransfertSyntaxName();
+ std::string transferSyntaxName = e1->GetTransferSyntaxName();
std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
if(e1->IsReadable())
Program: gdcm
Module: $RCSfile: PrintHeader.cxx,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:57 $
- Version: $Revision: 1.13 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.14 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmHeader.h"
+#include "gdcmDebug.h"
+
#include <iostream>
int main(int argc, char* argv[])
if (argc == 1)
{
- std::cout << argv[0] << " fileName" << std::endl;
+ std::cout << argv[0] << " fileName printLevel" << std::endl;
}
if (argc > 1)
fileName += "/test.acr";
}
+ if (argc > 3)
+ gdcm::Debug::SetDebugOn();
+
gdcm::Header *e1 = new gdcm::Header( fileName.c_str() );
if (argc > 2)
if ( e1->GetEntry(0x0002,0x0010) == gdcm::GDCM_NOTLOADED )
{
- std::cout << "Transfert Syntax not loaded. " << std::endl
+ std::cout << "Transfer Syntax not loaded. " << std::endl
<< "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
<< std::endl;
return 0;
}
- std::string transferSyntaxName = e1->GetTransfertSyntaxName();
+ std::string transferSyntaxName = e1->GetTransferSyntaxName();
std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
if(e1->IsReadable())
Program: gdcm
Module: $RCSfile: TestWrite.cxx,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:57 $
- Version: $Revision: 1.13 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.14 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
- transferSyntaxName = e1->GetTransfertSyntaxName();
+ transferSyntaxName = e1->GetTransferSyntaxName();
std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
/* if ( transferSyntaxName != "Implicit VR - Little Endian"
Program: gdcm
Module: $RCSfile: Write.cxx,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:57 $
- Version: $Revision: 1.13 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.14 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
int numberOfScalarComponents=e1->GetNumberOfScalarComponents();
std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <<std::endl;
- transferSyntaxName = e1->GetTransfertSyntaxName();
+ transferSyntaxName = e1->GetTransferSyntaxName();
std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl;
/* if ( transferSyntaxName != "Implicit VR - Little Endian"
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2005/01/11 00:21:48 $
- Version: $Revision: 1.172 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.173 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
return;
}
+ Group0002Parsed = false;
+
gdcmVerboseMacro( "Starting parsing of file: " << Filename.c_str());
- Fp->seekg( 0, std::ios::beg);
+ // Fp->seekg( 0, std::ios::beg);
Fp->seekg(0, std::ios::end);
long lgt = Fp->tellg();
Initialise();
SwapCode = 0;
Filetype = ExplicitVR;
+ Group0002Parsed = false;
}
/**
*/
bool Document::IsDicomV3()
{
- // Checking if Transfert Syntax exists is enough
+ // Checking if Transfer Syntax exists is enough
// Anyway, it's to late check if the 'Preamble' was found ...
// And ... would it be a rich idea to check ?
// (some 'no Preamble' DICOM images exist !)
*/
std::ifstream *Document::OpenFile()
{
+
+ HasDCMPreamble = false;
if (Filename.length() == 0)
{
return 0;
if(Fp)
{
- gdcmVerboseMacro( "Is already opened when opening: " << Filename.c_str());
+ gdcmVerboseMacro( "File already open: " << Filename.c_str());
}
Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary);
}
if( memcmp(dicm, "DICM", 4) == 0 )
{
+ HasDCMPreamble = true;
return Fp;
}
return;
}
length16 = 4;
- SwitchSwapToBigEndian();
+ SwitchByteSwapCode();
// Restore the unproperly loaded values i.e. the group, the element
// and the dictionary entry depending on them.
// FIXME : FIXME:
// Sometimes (see : gdcmData/icone.dcm) group 0x0002 *is* Explicit VR,
- // but elem 0002,0010 (Transfert Syntax) tells us the file is
+ // but elem 0002,0010 (Transfer Syntax) tells us the file is
// *Implicit* VR. -and it is !-
if( memcmp(entCur, "UL", (size_t)2) == 0 ||
/**
- * \brief Restore the unproperly loaded values i.e. the group, the element
- * and the dictionary entry depending on them.
+ * \brief Change the Byte Swap code.
*/
-void Document::SwitchSwapToBigEndian()
+void Document::SwitchByteSwapCode()
{
- gdcmVerboseMacro( "Switching to BigEndian mode.");
+ gdcmVerboseMacro( "Switching Byte Swap code.");
if ( SwapCode == 0 )
{
SwapCode = 4321;
{
// start endian swap mark for group found
reversedEndian++;
- SwitchSwapToBigEndian();
+ SwitchByteSwapCode();
// fix the tag
group = 0xfffe;
elem = 0xe000;
{
// end of reversed endian group
reversedEndian--;
- SwitchSwapToBigEndian();
+ SwitchByteSwapCode();
+ }
+}
+
+/**
+ * \brief Group 0002 is always coded Little Endian
+ * whatever Transfer Syntax is
+ * @return no return
+ */
+void Document::HandleOutOfGroup0002(uint16_t group)
+{
+ // Endian reversion. Some files contain groups of tags with reversed endianess.
+ if ( !Group0002Parsed && group != 0x0002)
+ {
+ Group0002Parsed = true;
+ // we just came out of group 0002
+ // if Transfer syntax is Big Endian we have to change CheckSwap
+
+ TagKey key = DictEntry::TranslateToKey(0x0002, 0x0010);
+ if ( !TagHT.count(key))
+ {
+ gdcmVerboseMacro("True DICOM File, with NO Tansfer Syntax ?!?");
+ return;
+ }
+
+ // FIXME Strangely, this works with
+ //'Implicit VR Transfer Syntax (GE Private)
+
+ if ( ((ValEntry *)TagHT.find(key)->second)->GetValue()
+ == "Explicit VR - Big Endian" )
+ {
+ gdcmVerboseMacro("Tansfer Syntax = Explicit VR - Big Endian");
+ SwitchByteSwapCode();
+ }
}
}
/**
* \brief Read the next tag but WITHOUT loading it's value
* (read the 'Group Number', the 'Element Number',
- * gets the Dict Entry
+ * gets the Dict Entry
* gets the VR, gets the length, gets the offset value)
* @return On succes the newly created DocEntry, NULL on failure.
*/
return 0;
}
+ // Sometimes file contains groups of tags with reversed endianess.
HandleBrokenEndian(group, elem);
+
+// In 'true DICOM' files Group 0002 is allways little endian
+ if ( HasDCMPreamble )
+ HandleOutOfGroup0002(group);
+
std::string vr = FindDocEntryVR();
std::string realVR = vr;
<< " but instead we encountered tag ("
<< std::hex << itemTagGroup << "," << itemTagElement << ")"
<< std::dec
- << " at address: " << (unsigned int)currentPosition );
+ << " at address: " << (unsigned int)currentPosition
+ << std::hex
+ << " 0x(" << (unsigned int)currentPosition << ")"
+ ) ;
Fp->seekg(positionOnEntry, std::ios::beg);
return false;
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2005/01/08 15:03:59 $
- Version: $Revision: 1.78 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.79 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// what is written on disc.
int SwapCode;
+ ///\brief whether we already parsed group 0002
+ bool Group0002Parsed;
+
+ ///\brief whether file has a DCM Preamble
+ bool HasDCMPreamble;
+
/// File Pointer, opened during Header parsing.
std::ifstream *Fp;
void Initialise();
bool CheckSwap();
- void SwitchSwapToBigEndian();
+ void SwitchByteSwapCode();
void SetMaxSizeLoadEntry(long);
void SetMaxSizePrintEntry(long);
DocEntrySet* set );
void HandleBrokenEndian(uint16_t group, uint16_t elem);
+ void HandleOutOfGroup0002(uint16_t group);
// Variables
/// Public dictionary used to parse this header
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2005/01/11 00:21:48 $
- Version: $Revision: 1.188 $
+ Date: $Date: 2005/01/11 11:37:13 $
+ Version: $Revision: 1.189 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* the given value.
* @param content new value (string) to substitute with
* @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
+ * @param elem element number of the Dicom Element to modify
*/
bool File::SetEntry(std::string const &content,
- uint16_t group, uint16_t element)
+ uint16_t group, uint16_t elem)
{
- return HeaderInternal->SetEntry(content,group,element);
+ return HeaderInternal->SetEntry(content,group,elem);
}
* @param content new value (void* -> uint8_t*) to substitute with
* @param lgth new value length
* @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
+ * @param elem element number of the Dicom Element to modify
*/
bool File::SetEntry(uint8_t *content, int lgth,
- uint16_t group, uint16_t element)
+ uint16_t group, uint16_t elem)
{
- return HeaderInternal->SetEntry(content,lgth,group,element);
+ return HeaderInternal->SetEntry(content,lgth,group,elem);
}
/**
* when it exists. Create it with the given value when unexistant.
* @param content (string) Value to be set
* @param group Group number of the Entry
- * @param element Element number of the Entry
+ * @param elem Element number of the Entry
* \return pointer to the modified/created Header Entry (NULL when creation
* failed).
*/
bool File::ReplaceOrCreate(std::string const &content,
- uint16_t group, uint16_t element)
+ uint16_t group, uint16_t elem)
{
- return HeaderInternal->ReplaceOrCreate(content,group,element) != NULL;
+ return HeaderInternal->ReplaceOrCreate(content,group,elem) != NULL;
}
/*
* A copy of the binArea is made to be kept in the Document.
* @param binArea (binary) value to be set
* @param group Group number of the Entry
- * @param element Element number of the Entry
+ * @param elem Element number of the Entry
* \return pointer to the modified/created Header Entry (NULL when creation
* failed).
*/
bool File::ReplaceOrCreate(uint8_t *binArea, int lgth,
- uint16_t group, uint16_t element)
+ uint16_t group, uint16_t elem)
{
- return HeaderInternal->ReplaceOrCreate(binArea,lgth,group,element) != NULL;
+ return HeaderInternal->ReplaceOrCreate(binArea,lgth,group,elem) != NULL;
}
/**
Archive->Restore(0x0008,0x0010);
}
-ValEntry *File::CopyValEntry(uint16_t group,uint16_t element)
+ValEntry *File::CopyValEntry(uint16_t group,uint16_t elem)
{
- DocEntry *oldE = HeaderInternal->GetDocEntry(group, element);
+ DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem);
ValEntry *newE;
if(oldE)
}
else
{
- newE = GetHeader()->NewValEntry(group,element);
+ newE = GetHeader()->NewValEntry(group,elem);
}
return newE;
}
-BinEntry *File::CopyBinEntry(uint16_t group,uint16_t element)
+BinEntry *File::CopyBinEntry(uint16_t group,uint16_t elem)
{
- DocEntry *oldE = HeaderInternal->GetDocEntry(group, element);
+ DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem);
BinEntry *newE;
if(oldE)
}
else
{
- newE = GetHeader()->NewBinEntry(group,element);
+ newE = GetHeader()->NewBinEntry(group,elem);
}
return newE;
Program: gdcm
Module: $RCSfile: gdcmGlobal.cxx,v $
Language: C++
- Date: $Date: 2005/01/10 20:52:39 $
- Version: $Revision: 1.13 $
+ Date: $Date: 2005/01/11 11:37:14 $
+ Version: $Revision: 1.14 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
/**
* \ingroup Global
- * \brief returns a pointer to the 'Transfert Syntax Table'
+ * \brief returns a pointer to the 'Transfer Syntax Table'
*/
TS *Global::GetTS()
{
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2005/01/10 17:09:49 $
- Version: $Revision: 1.228 $
+ Date: $Date: 2005/01/11 11:37:14 $
+ Version: $Revision: 1.229 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
/**
- * \brief Accesses the info from 0002,0010 : Transfert Syntax and TS
+ * \brief Accesses the info from 0002,0010 : Transfer Syntax and TS
* else 1.
- * @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID)
+ * @return The full Transfer Syntax Name (as opposed to Transfer Syntax UID)
*/
-std::string Header::GetTransfertSyntaxName()
+std::string Header::GetTransferSyntaxName()
{
- // use the TS (TS : Transfert Syntax)
- std::string transfertSyntax = GetEntry(0x0002,0x0010);
+ // use the TS (TS : Transfer Syntax)
+ std::string transferSyntax = GetEntry(0x0002,0x0010);
- if ( transfertSyntax == GDCM_NOTLOADED )
+ if ( transferSyntax == GDCM_NOTLOADED )
{
- gdcmVerboseMacro( "Transfert Syntax not loaded. " << std::endl
+ gdcmVerboseMacro( "Transfer Syntax not loaded. " << std::endl
<< "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" );
return "Uncompressed ACR-NEMA";
}
- if ( transfertSyntax == GDCM_UNFOUND )
+ if ( transferSyntax == GDCM_UNFOUND )
{
- gdcmVerboseMacro( "Unfound Transfert Syntax (0002,0010)");
+ gdcmVerboseMacro( "Unfound Transfer Syntax (0002,0010)");
return "Uncompressed ACR-NEMA";
}
- while ( ! isdigit((unsigned char)transfertSyntax[transfertSyntax.length()-1]) )
+ while ( ! isdigit((unsigned char)transferSyntax[transferSyntax.length()-1]) )
{
- transfertSyntax.erase(transfertSyntax.length()-1, 1);
+ transferSyntax.erase(transferSyntax.length()-1, 1);
}
// we do it only when we need it
TS* ts = Global::GetTS();
- std::string tsName = ts->GetValue( transfertSyntax );
+ std::string tsName = ts->GetValue( transferSyntax );
//delete ts; /// \todo Seg Fault when deleted ?!
return tsName;
Program: gdcm
Module: $RCSfile: gdcmHeader.h,v $
Language: C++
- Date: $Date: 2005/01/06 20:03:28 $
- Version: $Revision: 1.97 $
+ Date: $Date: 2005/01/11 11:37:14 $
+ Version: $Revision: 1.98 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
int GetLUTNbits();
/// Return the Transfer Syntax as a string
- std::string GetTransfertSyntaxName();
+ std::string GetTransferSyntaxName();
/// Accessor to \ref Header::GrPixel
uint16_t GetGrPixel() { return GrPixel; }
Program: gdcm
Module: $RCSfile: gdcmTS.h,v $
Language: C++
- Date: $Date: 2005/01/11 00:37:42 $
- Version: $Revision: 1.14 $
+ Date: $Date: 2005/01/11 11:37:14 $
+ Version: $Revision: 1.15 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
//-----------------------------------------------------------------------------
typedef std::string TSKey;
typedef std::string TSAtr;
-typedef std::map<TSKey, TSAtr> TSHT; // Transfert Syntax Hash Table
+typedef std::map<TSKey, TSAtr> TSHT; // Transfer Syntax Hash Table
//-----------------------------------------------------------------------------
/*
- * Container for dicom Transfert Syntax Hash Table
+ * Container for dicom Transfer Syntax Hash Table
* \note This is a singleton
*/
class GDCM_EXPORT TS