Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
const unsigned int gdcmDocument::HEADER_LENGTH_TO_READ = 256;
// Refer to gdcmDocument::SetMaxSizeLoadEntry()
const unsigned int gdcmDocument::HEADER_LENGTH_TO_READ = 256;
// Refer to gdcmDocument::SetMaxSizeLoadEntry()
-const unsigned int gdcmDocument::MAX_SIZE_LOAD_ELEMENT_VALUE = 0x7fffffff;// 4096;//
-const unsigned int gdcmDocument::MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff;//64;
+const unsigned int gdcmDocument::MAX_SIZE_LOAD_ELEMENT_VALUE = 0xfff; // 4096
+const unsigned int gdcmDocument::MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff;
//-----------------------------------------------------------------------------
// Constructor / Destructor
//-----------------------------------------------------------------------------
// Constructor / Destructor
// Load 'non string' values
std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
// Load 'non string' values
std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004);
LoadEntryVoidArea(0x0028,0x1200); // gray LUT
LoadEntryVoidArea(0x0028,0x1201); // R LUT
LoadEntryVoidArea(0x0028,0x1202); // G LUT
LoadEntryVoidArea(0x0028,0x1200); // gray LUT
LoadEntryVoidArea(0x0028,0x1201); // R LUT
LoadEntryVoidArea(0x0028,0x1202); // G LUT
-bool gdcmDocument::SetShaDict(DictKey dictName){
- RefShaDict=gdcmGlobal::GetDicts()->GetDict(dictName);
+bool gdcmDocument::SetShaDict(DictKey dictName)
+{
+ RefShaDict = gdcmGlobal::GetDicts()->GetDict(dictName);
std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype
<< " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR
dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype");
return false;
}
std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype
<< " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR
dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype");
return false;
}
* the current document. False either when the document contains
* no Transfer Syntax, or when the Tranfer Syntaxes don't match.
*/
* the current document. False either when the document contains
* no Transfer Syntax, or when the Tranfer Syntaxes don't match.
*/
// The entry might be present but not loaded (parsing and loading
// happen at differente stages): try loading and proceed with check...
// The entry might be present but not loaded (parsing and loading
// happen at differente stages): try loading and proceed with check...
// The actual transfer (as read from disk) might be padded. We
// first need to remove the potential padding. We can make the
// weak assumption that padding was not executed with digits...
// The actual transfer (as read from disk) might be padded. We
// first need to remove the potential padding. We can make the
// weak assumption that padding was not executed with digits...
* \sa \ref gdcmDocument::IsGivenTransferSyntax.
* @return True when ImplicitVRLittleEndian found. False in all other cases.
*/
* \sa \ref gdcmDocument::IsGivenTransferSyntax.
* @return True when ImplicitVRLittleEndian found. False in all other cases.
*/
* and if it corresponds to a ExplicitVRLittleEndian one.
* @return True when ExplicitVRLittleEndian found. False in all other cases.
*/
* and if it corresponds to a ExplicitVRLittleEndian one.
* @return True when ExplicitVRLittleEndian found. False in all other cases.
*/
* and if it corresponds to a DeflatedExplicitVRLittleEndian one.
* @return True when DeflatedExplicitVRLittleEndian found. False in all other cases.
*/
* and if it corresponds to a DeflatedExplicitVRLittleEndian one.
* @return True when DeflatedExplicitVRLittleEndian found. False in all other cases.
*/
* and if it corresponds to a Explicit VR Big Endian one.
* @return True when big endian found. False in all other cases.
*/
* and if it corresponds to a Explicit VR Big Endian one.
* @return True when big endian found. False in all other cases.
*/
* and if it corresponds to a JPEGBaseLineProcess1 one.
* @return True when JPEGBaseLineProcess1found. False in all other cases.
*/
* and if it corresponds to a JPEGBaseLineProcess1 one.
* @return True when JPEGBaseLineProcess1found. False in all other cases.
*/
* and if it corresponds to a JPEGExtendedProcess2-4 one.
* @return True when JPEGExtendedProcess2-4 found. False in all other cases.
*/
* and if it corresponds to a JPEGExtendedProcess2-4 one.
* @return True when JPEGExtendedProcess2-4 found. False in all other cases.
*/
* and if it corresponds to a JPEGExtendeProcess3-5 one.
* @return True when JPEGExtendedProcess3-5 found. False in all other cases.
*/
* and if it corresponds to a JPEGExtendeProcess3-5 one.
* @return True when JPEGExtendedProcess3-5 found. False in all other cases.
*/
{
return ( IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_55)
|| IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_57)
{
return ( IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_55)
|| IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_57)
{
return ( IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_90)
|| IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_91) );
{
return ( IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_90)
|| IsGivenTransferSyntax(UI1_2_840_10008_1_2_4_91) );
// Checking if Transfert 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 !)
// Checking if Transfert 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 !)
* (ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown)
* @return the FileType code
*/
* (ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown)
* @return the FileType code
*/
fread(&zero, (size_t)2, (size_t)1, fp);
//ACR -- or DICOM with no Preamble --
if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
fread(&zero, (size_t)2, (size_t)1, fp);
//ACR -- or DICOM with no Preamble --
if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200)
//DICOM
fseek(fp, 126L, SEEK_CUR);
char dicm[4];
fread(dicm, (size_t)4, (size_t)1, fp);
if( memcmp(dicm, "DICM", 4) == 0 )
//DICOM
fseek(fp, 126L, SEEK_CUR);
char dicm[4];
fread(dicm, (size_t)4, (size_t)1, fp);
if( memcmp(dicm, "DICM", 4) == 0 )
/// \todo move the following lines (and a lot of others, to be written)
/// to a future function CheckAndCorrectHeader
/// \todo move the following lines (and a lot of others, to be written)
/// to a future function CheckAndCorrectHeader
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
" NewDocEntryByNumber failed.");
return NULL;
}
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
" NewDocEntryByNumber failed.");
return NULL;
}
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
" failed allthough this is a creation.");
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
" failed allthough this is a creation.");
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
" of previous DocEntry failed.");
return NULL;
}
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
" of previous DocEntry failed.");
return NULL;
}
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
" promoted ValEntry failed.");
{
dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
" promoted ValEntry failed.");
- a = GetDocEntryByNumber( Group, Elem);
- if (a == NULL) {
- a =NewBinEntryByNumber(Group, Elem);
- if (a == NULL)
- return NULL;
+ gdcmDocEntry* a = GetDocEntryByNumber( group, elem);
+ if (!a)
+ {
+ a = NewBinEntryByNumber(group, elem);
+ if (!a)
+ {
+ return 0;
+ }
- SetEntryByNumber(voidArea, lgth, Group, Elem);
- b->SetVoidArea(voidArea);
+ SetEntryByNumber(voidArea, lgth, group, elem);
+ //b->SetVoidArea(voidArea); //what if b == 0 !!
* @return Corresponding element value when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
-std::string gdcmDocument::GetEntryByNumber(guint16 group, guint16 element){
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+std::string gdcmDocument::GetEntryByNumber(uint16_t group, uint16_t element)
+{
+ gdcmTagKey key = gdcmDictEntry::TranslateToKey(group, element);
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @return Corresponding element value representation when it exists,
* and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
*/
* @param element Element number of the searched tag.
* @return Corresponding element length; -2 if not found
*/
* @param element Element number of the searched tag.
* @return Corresponding element length; -2 if not found
*/
* @param element element number of the Dicom Element to modify
*/
bool gdcmDocument::SetEntryByNumber(std::string content,
* @param element element number of the Dicom Element to modify
*/
bool gdcmDocument::SetEntryByNumber(std::string content,
* @param element element number of the Dicom Element to modify
*/
bool gdcmDocument::SetEntryByNumber(void *content,
* @param element element number of the Dicom Element to modify
*/
bool gdcmDocument::SetEntryByNumber(void *content,
* @param element element number of the Entry to modify
* @return true on success, false otherwise.
*/
* @param element element number of the Entry to modify
* @return true on success, false otherwise.
*/
long PositionOnEntry = ftell(fp);
LoadDocEntry(entry);
fseek(fp, PositionOnEntry, SEEK_SET);
long PositionOnEntry = ftell(fp);
LoadDocEntry(entry);
fseek(fp, PositionOnEntry, SEEK_SET);
* \brief Swaps the bytes so they agree with the processor order
* @return The properly swaped 16 bits integer.
*/
* \brief Swaps the bytes so they agree with the processor order
* @return The properly swaped 16 bits integer.
*/
* \brief Unswaps the bytes so they agree with the processor order
* @return The properly unswaped 16 bits integer.
*/
* \brief Unswaps the bytes so they agree with the processor order
* @return The properly unswaped 16 bits integer.
*/
* the value specified with gdcmDocument::SetMaxSizeLoadEntry()
* @param Entry Header Entry (Dicom Element) to be dealt with
*/
* the value specified with gdcmDocument::SetMaxSizeLoadEntry()
* @param Entry Header Entry (Dicom Element) to be dealt with
*/
- guint16 group = Entry->GetGroup();
- std::string vr= Entry->GetVR();
- guint32 length = Entry->GetLength();
+ uint16_t group = Entry->GetGroup();
+ std::string vr = Entry->GetVR();
+ uint32_t length = Entry->GetLength();
// (fffe e000) tells us an Element is beginning
// (fffe e00d) tells us an Element just ended
// (fffe e0dd) tells us the current SeQuence just ended
// (fffe e000) tells us an Element is beginning
// (fffe e00d) tells us an Element just ended
// (fffe e0dd) tells us the current SeQuence just ended
if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) )
{
s << "gdcm::NotLoaded (BinEntry)";
if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) )
{
s << "gdcm::NotLoaded (BinEntry)";
return;
// Be carefull : a BinEntry IS_A ValEntry ...
if (gdcmValEntry* ValEntryPtr = dynamic_cast< gdcmValEntry* >(Entry) )
return;
// Be carefull : a BinEntry IS_A ValEntry ...
if (gdcmValEntry* ValEntryPtr = dynamic_cast< gdcmValEntry* >(Entry) )
LoadEntryVoidArea(BinEntryPtr);
s << "gdcm::Loaded (BinEntry)";
BinEntryPtr->SetValue(s.str());
return;
}
LoadEntryVoidArea(BinEntryPtr);
s << "gdcm::Loaded (BinEntry)";
BinEntryPtr->SetValue(s.str());
return;
}
- // When short integer(s) are expected, read and convert the following
- // n *two characters properly i.e. as short integers as opposed to strings.
- // Elements with Value Multiplicity > 1
- // contain a set of integers (not a single one)
- if (vr == "US" || vr == "SS") {
+ // When short integer(s) are expected, read and convert the following
+ // n *two characters properly i.e. consider them as short integers as
+ // opposed to strings.
+ // Elements with Value Multiplicity > 1
+ // contain a set of integers (not a single one)
+ if (vr == "US" || vr == "SS")
+ {
- // When integer(s) are expected, read and convert the following
- // n * four characters properly i.e. as integers as opposed to strings.
- // Elements with Value Multiplicity > 1
- // contain a set of integers (not a single one)
- else if (vr == "UL" || vr == "SL") {
+ // See above comment on multiple integers (mutatis mutandis).
+ else if (vr == "UL" || vr == "SL")
+ {
// We need an additional byte for storing \0 that is not on disk
std::string NewValue(length,0);
item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp);
// We need an additional byte for storing \0 that is not on disk
std::string NewValue(length,0);
item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp);
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(Entry) ) {
- if ( item_read != 1 ) {
- dbg.Verbose(1, "gdcmDocument::LoadElementValue","unread element value");
+ if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(Entry) )
+ {
+ if ( item_read != 1 )
+ {
+ dbg.Verbose(1, "gdcmDocument::LoadDocEntry",
+ "unread element value");
* \brief Find the value Length of the passed Header Entry
* @param Entry Header Entry whose length of the value shall be loaded.
*/
* \brief Find the value Length of the passed Header Entry
* @param Entry Header Entry whose length of the value shall be loaded.
*/
* @return false if the VR is incorrect of if the VR isn't referenced
* otherwise, it returns true
*/
* @return false if the VR is incorrect of if the VR isn't referenced
* otherwise, it returns true
*/
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
Tokenize (((gdcmValEntry *)Entry)->GetValue(), tokens, "\\");
* applying some heuristics.
*/
void gdcmDocument::FixDocEntryFoundLength(gdcmDocEntry *Entry,
* applying some heuristics.
*/
void gdcmDocument::FixDocEntryFoundLength(gdcmDocEntry *Entry,
{
Entry->SetReadLength(FoundLength); // will be updated only if a bug is found
if ( FoundLength == 0xffffffff) {
FoundLength = 0;
}
{
Entry->SetReadLength(FoundLength); // will be updated only if a bug is found
if ( FoundLength == 0xffffffff) {
FoundLength = 0;
}
* @return The result of the heuristical predicate.
*/
bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *Entry) {
* @return The result of the heuristical predicate.
*/
bool gdcmDocument::IsDocEntryAnInteger(gdcmDocEntry *Entry) {
- guint16 element = Entry->GetElement();
- guint16 group = Entry->GetGroup();
- std::string vr = Entry->GetVR();
- guint32 length = Entry->GetLength();
+ uint16_t element = Entry->GetElement();
+ uint16_t group = Entry->GetGroup();
+ std::string vr = Entry->GetVR();
+ uint32_t length = Entry->GetLength();
// When we have some semantics on the element we just read, and if we
// a priori know we are dealing with an integer, then we shall be
// When we have some semantics on the element we just read, and if we
// a priori know we are dealing with an integer, then we shall be
size_t item_read;
item_read = fread (&g, (size_t)2,(size_t)1, fp);
if ( item_read != 1 ) {
size_t item_read;
item_read = fread (&g, (size_t)2,(size_t)1, fp);
if ( item_read != 1 ) {
size_t item_read;
item_read = fread (&g, (size_t)4,(size_t)1, fp);
if ( item_read != 1 ) {
size_t item_read;
item_read = fread (&g, (size_t)4,(size_t)1, fp);
if ( item_read != 1 ) {
//FIXME don't dump the returned value
(void)fseek(fp, (long)NBytes, SEEK_CUR);
}
//FIXME don't dump the returned value
(void)fseek(fp, (long)NBytes, SEEK_CUR);
}
// 0x00000004. Finding the swap code in then straigthforward. Trouble
// occurs when we can't find such group...
// 0x00000004. Finding the swap code in then straigthforward. Trouble
// occurs when we can't find such group...
// We assume the array of char we are considering contains the binary
// representation of a 32 bits integer. Hence the following dirty
// trick :
// We assume the array of char we are considering contains the binary
// representation of a 32 bits integer. Hence the following dirty
// trick :
* \brief Restore the unproperly loaded values i.e. the group, the element
* and the dictionary entry depending on them.
*/
* \brief Restore the unproperly loaded values i.e. the group, the element
* and the dictionary entry depending on them.
*/
{
dbg.Verbose(1, "gdcmDocument::SwitchSwapToBigEndian",
"Switching to BigEndian mode.");
{
dbg.Verbose(1, "gdcmDocument::SwitchSwapToBigEndian",
"Switching to BigEndian mode.");
* gets the VR, gets the length, gets the offset value)
* @return On succes the newly created DocEntry, NULL on failure.
*/
* gets the VR, gets the length, gets the offset value)
* @return On succes the newly created DocEntry, NULL on failure.
*/
* in the TagHt dictionary.
* @param group The generated tag must belong to this group.
* @return The element of tag with given group which is fee.
*/
* in the TagHt dictionary.
* @param group The generated tag must belong to this group.
* @return The element of tag with given group which is fee.
*/
uint32_t gdcmDocument::ReadTagLength(uint16_t TestGroup, uint16_t TestElement)
{
long PositionOnEntry = ftell(fp);
uint32_t gdcmDocument::ReadTagLength(uint16_t TestGroup, uint16_t TestElement)
{
long PositionOnEntry = ftell(fp);
// ---------------- for Parsing : Position on begining of Jpeg/RLE Pixels
//// Read the Basic Offset Table Item Tag length...
// ---------------- for Parsing : Position on begining of Jpeg/RLE Pixels
//// Read the Basic Offset Table Item Tag length...
//// ... and then read length[s] itself[themselves]. We don't use
// the values read (BTW what is the purpous of those lengths ?)
//// ... and then read length[s] itself[themselves]. We don't use
// the values read (BTW what is the purpous of those lengths ?)
char * BasicOffsetTableItemValue = new char[ItemLength + 1];
fread(BasicOffsetTableItemValue, ItemLength, 1, fp);
for (unsigned int i=0; i < ItemLength; i += 4){
char * BasicOffsetTableItemValue = new char[ItemLength + 1];
fread(BasicOffsetTableItemValue, ItemLength, 1, fp);
for (unsigned int i=0; i < ItemLength; i += 4){
- guint32 IndividualLength;
- IndividualLength = str2num(&BasicOffsetTableItemValue[i],guint32);
+ uint32_t IndividualLength;
+ IndividualLength = str2num(&BasicOffsetTableItemValue[i],uint32_t);
{
// Parse fragments of the current Fragment (Frame)
//------------------ scanning (not reading) fragment pixels
{
// Parse fragments of the current Fragment (Frame)
//------------------ scanning (not reading) fragment pixels
- printf(" at : %x Offset Segment %d : %d (%x)\n",
- (unsigned)ftellRes,k,RleSegmentOffsetTable[k],
- RleSegmentOffsetTable[k]);
- printf (" Segment %d : Length = %d x(%x) Start at %x\n",
- k,(unsigned)RleSegmentLength[k],
- (unsigned)RleSegmentLength[k], (unsigned)ftellRes);
- printf (" Segment %d : Length = %d x(%x) Start at %x\n",
- nbRleSegments,(unsigned)RleSegmentLength[nbRleSegments],
- (unsigned)RleSegmentLength[nbRleSegments],(unsigned)ftellRes);