From 5d1776a78fb7d94a8325a00e438f7be82c16053c Mon Sep 17 00:00:00 2001 From: regrain Date: Fri, 3 Dec 2004 11:55:37 +0000 Subject: [PATCH] * src/gdcmPixelWriteConvert.[h|cxx] : new class to write datas (and in the future, with convertion) * src/gdcmFile.[h|cxx] : the PixelWriteConverter instance replace Pixel_Data and ImageDataSize values. Remove the method to get the PixelReadConverter from the output of the class -- BeNours --- ChangeLog | 9 ++++- Example/PrintFile.cxx | 8 ++-- Example/TestWrite.cxx | 8 ++-- Example/Write.cxx | 8 ++-- src/CMakeLists.txt | 1 + src/gdcmFile.cxx | 62 +++++++++++++----------------- src/gdcmFile.h | 28 ++------------ src/gdcmPixelReadConvert.h | 6 +-- src/gdcmPixelWriteConvert.cxx | 71 +++++++++++++++++++++++++++++++++++ src/gdcmPixelWriteConvert.h | 61 ++++++++++++++++++++++++++++++ 10 files changed, 187 insertions(+), 75 deletions(-) create mode 100644 src/gdcmPixelWriteConvert.cxx create mode 100644 src/gdcmPixelWriteConvert.h diff --git a/ChangeLog b/ChangeLog index 5bb70d02..a8ec06e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ +2004-12-03 Benoit Regrain + * src/gdcmPixelWriteConvert.[h|cxx] : new class to write datas (and in the + future, with convertion) + * src/gdcmFile.[h|cxx] : the PixelWriteConverter instance replace Pixel_Data + and ImageDataSize values. Remove the method to get the PixelReadConverter + from the output of the class + 2004-12-03 Benoit Regrain * Rename src/gdcmPixelConvert.[h|cxx] to src/gdcmPixelReadConvert.[h|cxx] - + 2004-12-02 Benoit Regrain * vtk/vtkGdcmReader.cxx : correct error in vtkDebugMacro, vtkWarningMacro and vtkErrorMacro use. diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index aae83a4c..2d2f671f 100644 --- a/Example/PrintFile.cxx +++ b/Example/PrintFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintFile.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 10:21:53 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/12/03 11:55:37 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) std::string transferSyntaxName = e1->GetTransfertSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; - if ( transferSyntaxName != "Implicit VR - Little Endian" +/* if ( transferSyntaxName != "Implicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Little Endian" && transferSyntaxName != "Deflated Explicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Big Endian" @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) f1->GetPixelReadConverter()->Print(); std::cout << std::endl << "===========================================" << std::endl; - } + }*/ if(e1->IsReadable()) std::cout <GetTransfertSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; - if ( transferSyntaxName != "Implicit VR - Little Endian" +/* if ( transferSyntaxName != "Implicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Little Endian" && transferSyntaxName != "Deflated Explicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Big Endian" @@ -112,7 +112,7 @@ int main(int argc, char* argv[]) f1->GetPixelReadConverter()->Print(); std::cout << std::endl << "===========================================" << std::endl; - } + }*/ imageData= f1->GetImageData(); switch (argv[2][0]) { diff --git a/Example/Write.cxx b/Example/Write.cxx index 6e2f1e3e..7c1d0e2e 100644 --- a/Example/Write.cxx +++ b/Example/Write.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: Write.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 10:21:53 $ - Version: $Revision: 1.10 $ + Date: $Date: 2004/12/03 11:55:37 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) transferSyntaxName = e1->GetTransfertSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; - if ( transferSyntaxName != "Implicit VR - Little Endian" +/* if ( transferSyntaxName != "Implicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Little Endian" && transferSyntaxName != "Deflated Explicit VR - Little Endian" && transferSyntaxName != "Explicit VR - Big Endian" @@ -107,7 +107,7 @@ int main(int argc, char* argv[]) f1->GetPixelReadConverter()->Print(); std::cout << std::endl << "===========================================" << std::endl; - } + }*/ imageData= f1->GetImageData(); (void)imageData; // to avoid warnings diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 541ba160..9544053e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ SET(libgdcm_la_SOURCES gdcmJpeg16.cxx gdcmJpeg2000.cxx gdcmPixelReadConvert.cxx + gdcmPixelWriteConvert.cxx gdcmRLEFrame.cxx gdcmRLEFramesInfo.cxx gdcmSeqEntry.cxx diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 6d596da7..f582c483 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 10:21:54 $ - Version: $Revision: 1.168 $ + Date: $Date: 2004/12/03 11:55:38 $ + Version: $Revision: 1.169 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -80,15 +80,13 @@ void File::Initialise() WriteType = WTYPE_IMPL_VR; PixelReadConverter = new PixelReadConvert; + PixelWriteConverter = new PixelWriteConvert; Archive = new DocEntryArchive( HeaderInternal ); if ( HeaderInternal->IsReadable() ) { PixelReadConverter->GrabInformationsFromHeader( HeaderInternal ); } - - Pixel_Data = 0; - ImageDataSize = 0; } /** @@ -102,6 +100,10 @@ File::~File() { delete PixelReadConverter; } + if( PixelWriteConverter ) + { + delete PixelWriteConverter; + } if( Archive ) { delete Archive; @@ -270,7 +272,7 @@ uint8_t* File::GetDecompressed() } /** - * \brief Points the internal Pixel_Data pointer to the callers inData + * \brief Points the internal pointer to the callers inData * image representation, BUT WITHOUT COPYING THE DATA. * 'image' Pixels are presented as C-like 2D arrays : line per line. * 'volume'Pixels are presented as C-like 3D arrays : plane per plane @@ -284,10 +286,8 @@ uint8_t* File::GetDecompressed() */ bool File::SetImageData(uint8_t* inData, size_t expectedSize) { -// FIXME : if already allocated, memory leak ! - Pixel_Data = inData; - ImageDataSize = expectedSize; -// FIXME : 7fe0, 0010 IS NOT set ... + PixelWriteConverter->SetUserData(inData,expectedSize); + return true; } @@ -308,7 +308,14 @@ bool File::WriteRawData(std::string const & fileName) dbg.Verbose(2, "Fail to open (write) file:", fileName.c_str()); return false; } - fp1.write((char*)Pixel_Data, ImageDataSize); + + if(PixelWriteConverter->GetUserData()) + fp1.write((char*)PixelWriteConverter->GetUserData(), PixelWriteConverter->GetUserDataSize()); + else if(PixelReadConverter->GetRGB()) + fp1.write((char*)PixelReadConverter->GetRGB(), PixelReadConverter->GetRGBSize()); + else if(PixelReadConverter->GetDecompressed()) + fp1.write((char*)PixelReadConverter->GetDecompressed(), PixelReadConverter->GetDecompressedSize()); + fp1.close(); return true; @@ -471,7 +478,7 @@ bool File::WriteBase (std::string const & fileName, FileType type) */ bool File::CheckWriteIntegrity() { - if(Pixel_Data) + if(PixelWriteConverter->GetUserData()) { int numberBitsAllocated = HeaderInternal->GetBitsAllocated(); if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 ) @@ -491,18 +498,16 @@ bool File::CheckWriteIntegrity() switch(WriteMode) { case WMODE_DECOMPRESSED : - if( decSize!=ImageDataSize ) + if( decSize!=PixelWriteConverter->GetUserDataSize() ) { dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect"); - //std::cerr<<"Dec : "<GetUserDataSize() ) { dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect"); - //std::cerr<<"RGB : "<GetGrPixel(),GetHeader()->GetNumPixel()); - pixel->SetValue(GDCM_BINLOADED); - pixel->SetBinArea(Pixel_Data,false); - pixel->SetLength(ImageDataSize); - - Archive->Push(pixel); - } -}*/ - void File::SetWriteToDecompressed() { if(HeaderInternal->GetNumberOfScalarComponents()==3 && !HeaderInternal->HasLUT()) @@ -547,10 +539,10 @@ void File::SetWriteToDecompressed() BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); pixel->SetValue(GDCM_BINLOADED); - if(Pixel_Data) + if(PixelWriteConverter->GetUserData()) { - pixel->SetBinArea(Pixel_Data,false); - pixel->SetLength(ImageDataSize); + pixel->SetBinArea(PixelWriteConverter->GetUserData(),false); + pixel->SetLength(PixelWriteConverter->GetUserDataSize()); } else { @@ -583,10 +575,10 @@ void File::SetWriteToRGB() BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); pixel->SetValue(GDCM_BINLOADED); - if(Pixel_Data) + if(PixelWriteConverter->GetUserData()) { - pixel->SetBinArea(Pixel_Data,false); - pixel->SetLength(ImageDataSize); + pixel->SetBinArea(PixelWriteConverter->GetUserData(),false); + pixel->SetLength(PixelWriteConverter->GetUserDataSize()); } else if(PixelReadConverter->GetRGB()) { diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 01b638c4..c9bb596e 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.h,v $ Language: C++ - Date: $Date: 2004/12/03 10:21:54 $ - Version: $Revision: 1.80 $ + Date: $Date: 2004/12/03 11:55:38 $ + Version: $Revision: 1.81 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,6 +22,7 @@ #include "gdcmCommon.h" #include "gdcmHeader.h" #include "gdcmPixelReadConvert.h" +#include "gdcmPixelWriteConvert.h" #include "gdcmDocEntryArchive.h" namespace gdcm @@ -60,9 +61,6 @@ public: size_t GetImageDataSize(); size_t GetImageDataRawSize(); - /// Accessor to \ref PixelReadConverter - PixelReadConvert* GetPixelReadConverter() { return PixelReadConverter; }; - uint8_t* GetImageData(); uint8_t* GetImageDataRaw(); size_t GetImageDataIntoVector(void* destination, size_t maxSize); @@ -141,6 +139,7 @@ private: /// Utility pixel converter PixelReadConvert* PixelReadConverter; + PixelWriteConvert* PixelWriteConverter; // Utility header archive DocEntryArchive *Archive; @@ -148,25 +147,6 @@ private: // Write variables unsigned int WriteMode; unsigned int WriteType; - -/// FIXME -// --------------- Will be moved to a PixelData class -// - - /// \brief to hold the Pixels (when read) - uint8_t* Pixel_Data; // (was PixelData) - - /// \brief Size (in bytes) of requited memory to hold the the pixels - /// of this image in it's RGB convertion either from: - /// - Plane R, Plane G, Plane B - /// - Grey Plane + Palette Color - /// - YBR Pixels (or from RGB Pixels, as well) - size_t ImageDataSize; - -// -// --------------- end of future PixelData class -// - }; } // end namespace gdcm diff --git a/src/gdcmPixelReadConvert.h b/src/gdcmPixelReadConvert.h index 72bdf526..2be2bc8e 100644 --- a/src/gdcmPixelReadConvert.h +++ b/src/gdcmPixelReadConvert.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.h,v $ Language: C++ - Date: $Date: 2004/12/03 10:21:55 $ - Version: $Revision: 1.1 $ + Date: $Date: 2004/12/03 11:55:38 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,7 +36,7 @@ class GDCM_EXPORT PixelReadConvert { public: PixelReadConvert(); - ~PixelReadConvert(); + virtual ~PixelReadConvert(); //// Getter accessors: uint8_t* GetRGB() { return RGB; } diff --git a/src/gdcmPixelWriteConvert.cxx b/src/gdcmPixelWriteConvert.cxx new file mode 100644 index 00000000..a4f8cec9 --- /dev/null +++ b/src/gdcmPixelWriteConvert.cxx @@ -0,0 +1,71 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmPixelWriteConvert.cxx,v $ + Language: C++ + Date: $Date: 2004/12/03 11:55:38 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +////////////////// TEMPORARY NOTE +// look for "fixMem" and convert that to a member of this class +// Removing the prefix fixMem and dealing with allocations should do the trick +// +// grep PixelWriteConvert everywhere and clean up ! + +#include "gdcmDebug.h" +#include "gdcmPixelWriteConvert.h" +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +// Constructor / Destructor +PixelWriteConvert::PixelWriteConvert() +{ + ReadData = 0; + ReadDataSize = 0; + + UserData = 0; + UserDataSize = 0; +} + +PixelWriteConvert::~PixelWriteConvert() +{ +} + +//----------------------------------------------------------------------------- +// Public +void PixelWriteConvert::SetReadData(uint8_t* data,size_t size) +{ + ReadData = data; + ReadDataSize = size; +} + +void PixelWriteConvert::SetUserData(uint8_t* data,size_t size) +{ + UserData = data; + UserDataSize = size; +} + +//----------------------------------------------------------------------------- +} // end namespace gdcm + +// NOTES on File internal calls +// User +// ---> GetImageData +// ---> GetImageDataIntoVector +// |---> GetImageDataIntoVectorRaw +// | lut intervention +// User +// ---> GetImageDataRaw +// ---> GetImageDataIntoVectorRaw diff --git a/src/gdcmPixelWriteConvert.h b/src/gdcmPixelWriteConvert.h new file mode 100644 index 00000000..3568b251 --- /dev/null +++ b/src/gdcmPixelWriteConvert.h @@ -0,0 +1,61 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmPixelWriteConvert.h,v $ + Language: C++ + Date: $Date: 2004/12/03 11:55:38 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + + +#ifndef GDCMPIXELWRITECONVERT_H +#define GDCMPIXELWRITECONVERT_H + +#include "gdcmCommon.h" + +namespace gdcm +{ +/* + * \brief Utility container for gathering the various forms the pixel data + * migth take during the user demanded processes. + */ +class GDCM_EXPORT PixelWriteConvert +{ +public: + PixelWriteConvert(); + virtual ~PixelWriteConvert(); + + // Set/Get of images and their size + void SetReadData(uint8_t* data,size_t size); + uint8_t* GetReadData() { return ReadData; } + size_t GetReadDataSize() { return ReadDataSize; } + + void SetUserData(uint8_t* data,size_t size); + uint8_t* GetUserData() { return UserData; } + size_t GetUserDataSize() { return UserDataSize; } + +private: +// Variables + /// Pixel data represented as RGB after LUT color interpretation. + uint8_t* ReadData; + /// Size of \ref RGB image. + size_t ReadDataSize; + + /// User pixel data + uint8_t* UserData; + /// Size of \ref User image. + size_t UserDataSize; +}; +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif -- 2.48.1