Program: gdcm
Module: $RCSfile: gdcmBinEntry.cxx,v $
Language: C++
- Date: $Date: 2004/09/15 03:50:48 $
- Version: $Revision: 1.27 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ Version: $Revision: 1.28 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
if (VoidArea)
{
- //free (VoidArea);
+ free (VoidArea);
VoidArea = 0; // let's be carefull !
}
}
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/09/17 13:11:16 $
- Version: $Revision: 1.81 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ Version: $Revision: 1.82 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
void gdcmDocument::Write(FILE* fp,FileType filetype)
{
/// \todo move the following lines (and a lot of others, to be written)
- /// to a future function CheckAndCorrectHeader
-
- /// WARNING : Si on veut ecrire du DICOM V3 a partir d'un DcmHeader ACR-NEMA
- /// no way (check : FileType est un champ de gdcmDocument ...)
- /// a moins de se livrer a un tres complique ajout des champs manquants.
- /// faire un CheckAndCorrectHeader (?)
-
+ /// to a future function CheckAndCorrectHeader
+ /// (necessary if user wants to write a DICOM V3 file
+ /// starting from an ACR-NEMA (V2) gdcmHeader
+
if (filetype == gdcmImplicitVR)
{
std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2;
}
-/**
- * \brief Modifies the value of a given Header Entry (Dicom Element)
- * when it exists. Create it with the given value when unexistant.
- * @param value (string) Value to be set
- * @param group Group number of the Entry
- * @param elem Element number of the Entry
- * \return pointer to the modified/created Header Entry (NULL when creation
- * failed).
- */
-
-/*
-gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
- std::string const & value,
- uint16_t group,
- uint16_t elem )
-{
- gdcmValEntry* valEntry = 0;
- gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem);
-
- if (!currentEntry)
- {
- // The entry wasn't present and we simply create the required ValEntry:
- currentEntry = NewDocEntryByNumber(group, elem);
- if (!currentEntry)
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to"
- " NewDocEntryByNumber failed.");
- return NULL;
- }
- valEntry = new gdcmValEntry(currentEntry);
- if ( !AddEntry(valEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry"
- " failed allthough this is a creation.");
- }
- }
- else
- {
- valEntry = dynamic_cast< gdcmValEntry* >(currentEntry);
- if ( !valEntry ) // Euuuuh? It wasn't a ValEntry
- // then we change it to a ValEntry ?
- // Shouldn't it be considered as an error ?
- {
- // We need to promote the gdcmDocEntry to a gdcmValEntry:
- valEntry = new gdcmValEntry(currentEntry);
- if (!RemoveEntry(currentEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal"
- " of previous DocEntry failed.");
- return NULL;
- }
- if ( !AddEntry(valEntry))
- {
- dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding"
- " promoted ValEntry failed.");
- return NULL;
- }
- }
- }
-
- SetEntryByNumber(value, group, elem);
-
- return valEntry;
-}
-*/
-
/**
* \brief Modifies the value of a given Header Entry (Dicom Element)
* when it exists. Create it with the given value when unexistant.
* @param VR V(alue) R(epresentation) of the Entry -if private Entry-
* \return pointer to the modified/created Header Entry (NULL when creation
* failed).
- */
-
- // TODO : write something clever, using default value for VR
- // to avoid code duplication
- // (I don't know how to tell NewDocEntryByNumber
- // that ReplaceOrCreateByNumber was called with a default value)
-
+ */
gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber(
std::string const & value,
uint16_t group,
return elem->GetVR();
}
-
/**
* \brief Searches within Header Entries (Dicom Elements) parsed with
* the public and private dictionaries
{
dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea setting failed.");
}
-
return a;
}
/**
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/09/17 13:11:16 $
- Version: $Revision: 1.38 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ 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
virtual bool SetEntryLengthByNumber(uint32_t length,
uint16_t group, uint16_t element);
- virtual size_t GetEntryOffsetByNumber(uint16_t group, uint16_t elem);
+ virtual size_t GetEntryOffsetByNumber (uint16_t group, uint16_t elem);
virtual void* GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem);
virtual bool SetEntryVoidAreaByNumber(void* a, uint16_t group,
uint16_t elem);
-/*=========================================================================
+ /*=========================================================================
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/09/13 07:49:36 $
- Version: $Revision: 1.125 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ Version: $Revision: 1.126 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
Header = header;
SelfHeader = false;
- SetInitialValues();
+ SaveInitialValues();
}
/**
{
Header = new gdcmHeader( filename );
SelfHeader = true;
- SetInitialValues();
+ SaveInitialValues();
}
/**
* \ingroup gdcmFile
- * \brief Sets some initial for the Constructor
+ * \brief canonical destructor
+ * \note If the gdcmHeader was created by the gdcmFile constructor,
+ * it is destroyed by the gdcmFile
*/
-void gdcmFile::SetInitialValues()
-{
+gdcmFile::~gdcmFile()
+{
+ if( SelfHeader )
+ {
+ delete Header;
+ }
+ Header = 0;
+
+ DeleteInitialValues();
+}
+
+/**
+ * \ingroup gdcmFile
+ * \brief Sets some initial values for the Constructor
+ * \warning not end user intended
+ */
+void gdcmFile::SaveInitialValues()
+{
+
PixelRead = -1; // no ImageData read yet.
LastAllocatedPixelDataLength = 0;
Pixel_Data = 0;
InitialPhotInt = "";
InitialPlanConfig = "";
InitialBitsAllocated = "";
+ InitialHighBit = "";
InitialRedLUTDescr = 0;
InitialGreenLUTDescr = 0;
InitialSpp = Header->GetEntryByNumber(0x0028,0x0002);
InitialPhotInt = Header->GetEntryByNumber(0x0028,0x0004);
InitialPlanConfig = Header->GetEntryByNumber(0x0028,0x0006);
+
InitialBitsAllocated = Header->GetEntryByNumber(0x0028,0x0100);
-
+ InitialHighBit = Header->GetEntryByNumber(0x0028,0x0102);
+
// the following entries *may* be removed from the H table
// (NOT deleted ...) by gdcmFile::GetImageDataIntoVectorRaw
// we keep a pointer on them.
InitialRedLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1101);
InitialGreenLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1102);
InitialBlueLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1103);
+
InitialRedLUTData = Header->GetDocEntryByNumber(0x0028,0x1201);
InitialGreenLUTData = Header->GetDocEntryByNumber(0x0028,0x1202);
InitialBlueLUTData = Header->GetDocEntryByNumber(0x0028,0x1203);
/**
* \ingroup gdcmFile
- * \brief canonical destructor
- * \note If the gdcmHeader was created by the gdcmFile constructor,
- * it is destroyed by the gdcmFile
+ * \brief restores some initial values
+ * \warning not end user intended
*/
-gdcmFile::~gdcmFile()
-{
- if( SelfHeader )
- {
- delete Header;
+void gdcmFile::RestoreInitialValues()
+{
+ if ( Header->IsReadable() )
+ {
+ // the following values *may* have been modified
+ // by gdcmFile::GetImageDataIntoVectorRaw
+ // we restore their initial value.
+ if ( InitialSpp != "")
+ Header->SetEntryByNumber(InitialSpp,0x0028,0x0002);
+ if ( InitialPhotInt != "")
+ Header->SetEntryByNumber(InitialPhotInt,0x0028,0x0004);
+ if ( InitialPlanConfig != "")
+
+ Header->SetEntryByNumber(InitialPlanConfig,0x0028,0x0006);
+ if ( InitialBitsAllocated != "")
+ Header->SetEntryByNumber(InitialBitsAllocated,0x0028,0x0100);
+ if ( InitialHighBit != "")
+ Header->SetEntryByNumber(InitialHighBit,0x0028,0x0102);
+
+ // the following entries *may* be have been removed from the H table
+ // (NOT deleted ...) by gdcmFile::GetImageDataIntoVectorRaw
+ // we restore them.
+
+ if (InitialRedLUTDescr)
+ Header->AddEntry(InitialRedLUTDescr);
+ if (InitialGreenLUTDescr)
+ Header->AddEntry(InitialGreenLUTDescr);
+ if (InitialBlueLUTDescr)
+ Header->AddEntry(InitialBlueLUTDescr);
+
+ if (InitialRedLUTData)
+ Header->AddEntry(InitialBlueLUTDescr);
+ if (InitialGreenLUTData)
+ Header->AddEntry(InitialGreenLUTData);
+ if (InitialBlueLUTData)
+ Header->AddEntry(InitialBlueLUTData);
}
- Header = 0;
+}
+
+/**
+ * \ingroup gdcmFile
+ * \brief delete initial values (il they were saved)
+ * of InitialLutDescriptors and InitialLutData
+ */
+void gdcmFile::DeleteInitialValues()
+{
// InitialLutDescriptors and InitialLutData
// will have to be deleted if the don't belong any longer
-// to the Header H table ...
+// to the Header H table when the header is deleted...
+
+ if ( InitialRedLUTDescr )
+ delete InitialRedLUTDescr;
+
+ if ( InitialGreenLUTDescr )
+ delete InitialGreenLUTDescr;
+
+ if ( InitialBlueLUTDescr )
+ delete InitialBlueLUTDescr;
+
+ if ( InitialRedLUTData )
+ delete InitialRedLUTData;
+
+ if ( InitialGreenLUTData != NULL)
+ delete InitialGreenLUTData;
+
+ if ( InitialBlueLUTData != NULL)
+ delete InitialBlueLUTData;
}
+/**
+ * \ingroup gdcmFile
+ * \brief drop palette related initial values -if any-
+ * (InitialLutDescriptors and InitialLutData)
+ * out of header, to make it consistent with the Pixel_Data
+ * as it's loaded in memory
+ */
+
+//FIXME : Should be nice, if we could let it here.
+// will be moved to PixelData class
+// Now, the job is done in gdcmHeader.cxx
+
+ /*
+void gdcmFile::DropInitialValues()
+{
+ gdcmHeader* h=GetHeader();
+ if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' )
+ {
+ // if SamplesPerPixel = 3, sure we don't need any LUT !
+ // Drop 0028|1101, 0028|1102, 0028|1103
+ // Drop 0028|1201, 0028|1202, 0028|1203
+
+ gdcmDocEntry* e = h->GetDocEntryByNumber(0x0028,0x01101);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ e = h->GetDocEntryByNumber(0x0028,0x1102);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ e = h->GetDocEntryByNumber(0x0028,0x1103);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ e = h->GetDocEntryByNumber(0x0028,0x01201);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ e = h->GetDocEntryByNumber(0x0028,0x1202);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ e = h->GetDocEntryByNumber(0x0028,0x1203);
+ if (e)
+ {
+ h->RemoveEntryNoDestroy(e);
+ }
+ }
+}
+*/
+
//-----------------------------------------------------------------------------
// Print
// in order to be able to restore the header in a disk-consistent state
// (if user asks twice to get the pixels from disk)
- if ( PixelRead == -1 ) // File was never "read" before
+ if ( PixelRead != -1 ) // File was "read" before
{
- InitialSpp = Header->GetEntryByNumber(0x0028,0x0002);
- InitialPhotInt = Header->GetEntryByNumber(0x0028,0x0004);
- InitialPlanConfig = Header->GetEntryByNumber(0x0028,0x0006);
- InitialBitsAllocated = Header->GetEntryByNumber(0x0028,0x0100);
- }
- else // File was already "read", the following *may* have been modified
- // we restore them to be in a disk-consistent state
- {
- // FIXME : What happened with the LUTs ?
- Header->SetEntryByNumber(InitialSpp,0x0028,0x0002);
- Header->SetEntryByNumber(InitialPhotInt,0x0028,0x0004);
- Header->SetEntryByNumber(InitialPlanConfig,0x0028,0x0006);
- Header->SetEntryByNumber(InitialBitsAllocated,0x0028,0x0100);
+ RestoreInitialValues();
}
PixelRead = 1 ; // PixelRaw
}
// now, it's an RGB image
// Lets's write it in the Header
+
+ // Droping Palette Color out of the Header
+ // has been moved to the Write process.
- // CreateOrReplaceIfExist ?
+ // TODO : move 'values' modification to the write process
+ // : save also (in order to be able to restore)
+ // : 'high bit' -when not equal to 'bits stored' + 1
+ // : 'bits allocated', when it's equal to 12 ?!
std::string spp = "3"; // Samples Per Pixel
std::string photInt = "RGB "; // Photometric Interpretation
std::string planConfig = "0"; // Planar Configuration
-
-
Header->SetEntryByNumber(spp,0x0028,0x0002);
Header->SetEntryByNumber(photInt,0x0028,0x0004);
Header->SetEntryByNumber(planConfig,0x0028,0x0006);
- /// \todo Drop Palette Color out of the Header?
return ImageDataSize;
}
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/09/17 08:54:26 $
- Version: $Revision: 1.48 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ Version: $Revision: 1.49 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
private:
void SwapZone(void* im, int swap, int lgr, int nb);
- void SetInitialValues();
+
bool ReadPixelData(void * destination);
// For JPEG 8 Bits, body in file gdcmJpeg.cxx
// How do we write that in C++ ?)
static int gdcm_read_RLE_fragment(char **areaToRead, long lengthToDecode,
long uncompressedSegmentSize, FILE *fp);
+
+ void SaveInitialValues(); // will belong to the future gdcmPixelData class
+ void RestoreInitialValues(); // will belong to the future gdcmPixelData class
+ void DeleteInitialValues(); // will belong to the future gdcmPixelData class
+
// members variables:
/// \brief Header to use to load the file
/// the constructor or passed to the constructor. When false
/// the destructor is in charge of deletion.
bool SelfHeader;
+
+ /// wether already parsed
+ bool Parsed;
+
+ //
+ // --------------- Will be moved to a gdcmPixelData class
+ //
/// \brief to hold the Pixels (when read)
- void* Pixel_Data; // (was PixelData; should be removed)
+ void* Pixel_Data; // (was PixelData)
- /// \brief Area length to receive the pixels
+ /// \brief Area length to receive the Gray Level pixels
size_t ImageDataSizeRaw;
- /// \brief Area length to receive the RGB pixels
- /// from Grey Plane + Palette Color
+ /// \brief Area length to receive the pixels making RGB
+ /// from Plane R, Plane G, Plane B
+ /// or from Grey Plane + Palette Color
+ /// or from YBR Pixels (or from RGB Pixels, as well)
size_t ImageDataSize;
/// \brief ==1 if GetImageDataRaw was used
/// ==0 if GetImageData was used
/// ==-1 if ImageData never read
int PixelRead;
-
- /// wether already parsed
- bool Parsed;
-
+
/// \brief length of the last allocated area devoided to receive Pixels
/// ( to allow us not to (free + new) if un necessary )
size_t LastAllocatedPixelDataLength;
// Initial values of some fields that can be modified during reading process
+ // (in a future stage, they will be modified just before the writting process
+ // and restored just after)
// if user asked to transform gray level + LUT image into RGB image
/// \brief Samples Per Pixel (0x0028,0x0002), as found on disk
/// \brief Photometric Interpretation (0x0028,0x0004), as found on disk
std::string InitialPhotInt;
/// \brief Planar Configuration (0x0028,0x0006), as found on disk
- std::string InitialPlanConfig;
+ std::string InitialPlanConfig;
+
+ // Initial values of some fields that can be modified during reading process
+ // (in a future stage, they will be modified just before the writting process
+ // and restored just after)
+ // if the image was a 'strange' ACR-NEMA
+ // (Bits Allocated=12, High Bit not equal to Bits stored +1)
/// \brief Bits Allocated (0x0028,0x0100), as found on disk
std::string InitialBitsAllocated;
-
+ /// \brief High Bit (0x0028,0x0102), as found on disk
+ std::string InitialHighBit;
+
// some DocEntry that can be moved out of the H table during reading process
+ // (in a future stage, they will be modified just before the writting process
+ // and restored just after)
// if user asked to transform gray level + LUT image into RGB image
// We keep a pointer on them for a future use.
gdcmDocEntry* InitialGreenLUTData;
/// \brief Blue Palette Color Lookup Table Data 0028 1203 as read
gdcmDocEntry* InitialBlueLUTData;
+
+ //
+ // --------------- end of future gdcmPixelData class
+ //
};
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/09/14 16:47:08 $
- Version: $Revision: 1.186 $
+ Date: $Date: 2004/09/20 18:14:23 $
+ Version: $Revision: 1.187 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
delete[] dumm;
ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000);
}
-
+
+ // FIXME : should be nice if we could move it to gdcmFile
+ // (or in future gdcmPixelData class)
+
// Drop Palette Color, if necessary
if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' )
gdcmDocEntry* e = GetDocEntryByNumber(0x0028,0x01101);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
e = GetDocEntryByNumber(0x0028,0x1102);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
e = GetDocEntryByNumber(0x0028,0x1103);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
e = GetDocEntryByNumber(0x0028,0x01201);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
e = GetDocEntryByNumber(0x0028,0x1202);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
e = GetDocEntryByNumber(0x0028,0x1203);
if (e)
{
- RemoveEntry(e);
+ RemoveEntryNoDestroy(e);
}
}
gdcmDocument::Write(fp,filetype);