+2004-11-03 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
+ * /binary_write/ gdcm source. Now even on big endian we are writting
+ little endian. This should -heopfully- fix some tests
+
2004-11-03 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
* Now the dictionary is compiled into gdcm lib. This is a default
behavior, thus any dic file specified is picked before failback to
Program: gdcm
Module: $RCSfile: gdcmBinEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/22 03:05:40 $
- Version: $Revision: 1.34 $
+ Date: $Date: 2004/11/03 20:52:12 $
+ Version: $Revision: 1.35 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
// there is a 'non string' LUT, overlay, etc
fp->write ( (char*)binArea, lgr ); // Elem value
+ //assert( strlen((char*)binArea) == lgr );
}
else
Program: gdcm
Module: $RCSfile: gdcmCommon.h,v $
Language: C++
- Date: $Date: 2004/11/02 03:10:32 $
- Version: $Revision: 1.37 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.38 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#endif
#include <string>
+#include <cassert>
namespace gdcm
{
Program: gdcm
Module: $RCSfile: gdcmDefaultDicts.cxx.in,v $
Language: C++
- Date: $Date: 2004/11/03 19:35:49 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
Program: gdcm
Module: $RCSfile: gdcmDicomDir.cxx,v $
Language: C++
- Date: $Date: 2004/10/25 04:47:43 $
- Version: $Revision: 1.76 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.77 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
bool DicomDir::WriteDicomDir(std::string const& fileName)
{
+ int i;
uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
std::ios::out | std::ios::binary);
if( !fp )
{
- printf("Failed to open(write) File [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Failed to open(write) File: ", fileName.c_str());
return false;
}
- uint8_t filePreamble[128];
+ char filePreamble[128];
memset(filePreamble, 0, 128);
- fp->write((char*)filePreamble, 128);
- fp->write("DICM",4);
+ fp->write(filePreamble, 128); //FIXME
+ binary_write( *fp, "DICM");
DicomDirMeta *ptrMeta = GetDicomDirMeta();
ptrMeta->Write(fp, ExplicitVR);
// force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
- fp->write((char*)&sq[0],8);
+ for(i=0;i<4;++i)
+ {
+ binary_write(*fp, sq[i]);
+ }
for(ListDicomDirPatient::iterator cc = Patients.begin();
cc != Patients.end();
}
// force writing Sequence Delimitation Item
- fp->write((char*)&sqt[0],8); // fffe e0dd ffff ffff
+ for(i=0;i<4;++i)
+ {
+ binary_write(*fp, sqt[i]); // fffe e0dd ffff ffff
+ }
fp->close();
return true;
Program: gdcm
Module: $RCSfile: gdcmDocEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/22 03:05:41 $
- Version: $Revision: 1.28 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.29 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
//
// ----------- Writes the common part
//
- fp->write ((char*) &group,(size_t)2 ); //group
- fp->write ( (char*)&el, (size_t)2 ); //element
-
+ binary_write( *fp, group); //group
+ binary_write( *fp, el); //element
+
if ( filetype == ExplicitVR )
{
// Special case of delimiters:
// TODO : verify if the Sequence Delimitor Item was forced during Parsing
- int ff = 0xffffffff;
- fp->write ((char*)&ff,(size_t)4 );
+ uint32_t ff = 0xffffffff;
+ binary_write(*fp, ff);
return;
}
{
// Unknown was 'written'
// deal with Little Endian
- fp->write ( (char*)&shortLgr,(size_t)2 );
- fp->write ( (char*)&z, (size_t)2 );
+ binary_write(*fp, shortLgr);
+ binary_write(*fp, z);
}
else
{
- fp->write (vr.c_str(),(size_t)2 );
-
+ binary_write(*fp, vr);
+ assert( vr.size() == 2 );
if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
{
- fp->write ( (char*)&z, (size_t)2 );
+ binary_write(*fp, z);
if (vr == "SQ")
{
// we set SQ length to ffffffff
// and we shall write a Sequence Delimitor Item
// at the end of the Sequence!
- fp->write ( (char*)&ffff,(size_t)4 );
+ binary_write(*fp, ffff);
}
else
{
- fp->write ( (char*)&lgr,(size_t)4 );
+ binary_write(*fp, lgr);
}
}
else
{
- fp->write ( (char*)&shortLgr,(size_t)2 );
+ binary_write(*fp, shortLgr);
}
}
}
{
if (vr == "SQ")
{
- fp->write ( (char*)&ffff,(size_t)4 );
+ binary_write(*fp, ffff);
}
else
{
- fp->write ( (char*)&lgr,(size_t)4 );
+ binary_write(*fp, lgr);
}
}
}
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 03:10:58 $
- Version: $Revision: 1.150 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.151 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
if (!fp1)
{
- printf("Fail to open (write) file [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str());
return false;
}
fp1.write((char*)Pixel_Data, ImageDataSize);
std::ios::out | std::ios::binary);
if (fp1 == NULL)
{
- printf("Failed to open (write) File [%s] \n", fileName.c_str());
+ dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
return false;
}
if ( type == ImplicitVR || type == ExplicitVR )
{
// writing Dicom File Preamble
- uint8_t filePreamble[128];
+ char filePreamble[128];
memset(filePreamble, 0, 128);
- fp1->write((char*)filePreamble, 128);
+ fp1->write(filePreamble, 128);
fp1->write("DICM", 4);
}
Program: gdcm
Module: $RCSfile: gdcmSQItem.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 03:10:58 $
- Version: $Revision: 1.33 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.34 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
*/
void SQItem::Write(std::ofstream* fp, FileType filetype)
{
+ int i;
uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff };
uint16_t itemt[4]= { 0xfffe, 0xe00d, 0xffff, 0xffff };
//we force the writting of an 'Item' Start Element
// because we want to write the Item as a 'no Length' item
- fp->write((char*)&item[0],8); // fffe e000 ffff ffff
+ for(i=0;i<4;++i)
+ {
+ binary_write( *fp, item[i]); // fffe e000 ffff ffff
+ }
for (ListDocEntry::iterator i = DocEntries.begin();
i != DocEntries.end();
//we force the writting of an 'Item Delimitation' item
// because we wrote the Item as a 'no Length' item
- fp->write((char*)&itemt[0],8); // fffe e000 ffff ffff
-
+ for(i=0;i<4;++i)
+ {
+ binary_write( *fp, itemt[i]); // fffe e000 ffff ffff
+ }
+
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmSeqEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/25 03:03:45 $
- Version: $Revision: 1.33 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.34 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// we force the writting of a Sequence Delimitation item
// because we wrote the Sequence as a 'no Length' sequence
- fp->write ( (char*)&seq_term_gr,(size_t)2 );
- fp->write ( (char*)&seq_term_el,(size_t)2 );
- fp->write ( (char*)&seq_term_lg,(size_t)4 );
+ binary_write(*fp, seq_term_gr);
+ binary_write(*fp, seq_term_el);
+ binary_write(*fp, seq_term_lg);
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmUtil.cxx,v $
Language: C++
- Date: $Date: 2004/10/28 23:10:25 $
- Version: $Revision: 1.58 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.59 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
return os.write(val, strlen(val));
}
+std::ostream& binary_write(std::ostream& os, std::string const & val)
+{
+ return os.write(val.c_str(), val.size());
+}
+
} // end namespace gdcm
Program: gdcm
Module: $RCSfile: gdcmUtil.h,v $
Language: C++
- Date: $Date: 2004/10/27 22:58:06 $
- Version: $Revision: 1.38 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.39 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
static std::string NormalizePath(std::string const & name);
static std::string GetPath(std::string const &fullName);
static std::string GetName(std::string const &fullName);
+
};
+ template <class T>
+ std::ostream& binary_write(std::ostream& os, const T& val);
+ std::ostream& binary_write(std::ostream& os, const uint16_t& val);
+ std::ostream& binary_write(std::ostream& os, const uint32_t& val);
+ std::ostream& binary_write(std::ostream& os, const char* val);
+ std::ostream& binary_write(std::ostream& os, std::string const & val);
} // end namespace gdcm
//-----------------------------------------------------------------------------
#endif
Program: gdcm
Module: $RCSfile: gdcmValEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/22 03:05:42 $
- Version: $Revision: 1.31 $
+ Date: $Date: 2004/11/03 20:52:13 $
+ Version: $Revision: 1.32 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
for (unsigned int i=0; i<tokens.size();i++)
{
uint16_t val_uint16 = atoi(tokens[i].c_str());
- void* ptr = &val_uint16;
- fp->write ( (char*)ptr,(size_t)2);
+ binary_write( *fp, val_uint16);
}
tokens.clear();
return;
for (unsigned int i=0; i<tokens.size();i++)
{
uint32_t val_uint32 = atoi(tokens[i].c_str());
- void* ptr = &val_uint32;
- fp->write ( (char*)ptr,(size_t)4 );
+ binary_write( *fp, val_uint32);
}
tokens.clear();
return;
}
fp->write (GetValue().c_str(), (size_t)lgr ); // Elem value
+// assert( lgr == GetValue().size() ); // FIXME ?????
+// dbg.Assert(2, lgr == strlen(GetValue().c_str()), "Should be equal" );
}
//-----------------------------------------------------------------------------