From: jpr Date: Sat, 30 Jul 2005 18:27:00 +0000 (+0000) Subject: User is now allowed to pass a Pointer to a function of his own X-Git-Tag: Version1.2.bp~245 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=58c14d2a459b733b3bd18442cfbb2c92ea77d1dd;p=gdcm.git User is now allowed to pass a Pointer to a function of his own to allow modification of pixel order (i.e. : Mirror, TopDown, ) to gdcm::FileHeleper, using SetUserFunction(userSuppliedFunction) described as : void userSuppliedFunction(uint8_t *im, gdcm::File *f); NB : the "uint8_t *" type of first param is just for prototyping. User will Cast it according what he founds with f->GetPixelType() See ctkgdcmSerieViewer for an example --- diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 0bf7bf7d..ad3454a0 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/07/23 01:59:21 $ - Version: $Revision: 1.50 $ + Date: $Date: 2005/07/30 18:27:00 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -122,6 +122,7 @@ FileHelper::FileHelper( ) { FileInternal = new File( ); SelfHeader = true; + UserFunction = 0; Initialize(); } @@ -142,6 +143,7 @@ FileHelper::FileHelper(File *header) { FileInternal = header; SelfHeader = false; + UserFunction = 0; Initialize(); } @@ -1507,6 +1509,8 @@ void FileHelper::Initialize() */ uint8_t *FileHelper::GetRaw() { + PixelReadConverter->SetUserFunction( UserFunction ); + uint8_t *raw = PixelReadConverter->GetRaw(); if ( ! raw ) { diff --git a/src/gdcmFileHelper.h b/src/gdcmFileHelper.h index 3661ebfe..39b9de92 100644 --- a/src/gdcmFileHelper.h +++ b/src/gdcmFileHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.h,v $ Language: C++ - Date: $Date: 2005/07/19 15:19:27 $ - Version: $Revision: 1.19 $ + Date: $Date: 2005/07/30 18:27:00 $ + 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 @@ -23,6 +23,8 @@ #include "gdcmBase.h" //#include + + namespace gdcm { class File; @@ -32,6 +34,9 @@ class SeqEntry; class PixelReadConvert; class PixelWriteConvert; class DocEntryArchive; + +typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *); + //----------------------------------------------------------------------------- /** * \brief In addition to Dicom header exploration, this class is designed @@ -63,7 +68,9 @@ public: void SetLoadMode(int loadMode); void SetFileName(std::string const &fileName); bool Load(); - + /// to allow user user to modify pixel order (Mirror, TopDown, 90°Rotate,...) + void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) + { UserFunction = userFunc; } // File methods bool SetValEntry(std::string const &content, uint16_t group, uint16_t elem); @@ -106,7 +113,7 @@ public: /// \brief Tells the writer we want to keep 'Grey pixels + Palettes color' /// when possible (as opposed to convert 'Palettes color' to RGB) - void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }; + void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); }; /// \brief Tells the writer we want to write RGB image when possible /// (as opposed to 'Grey pixels + Palettes color') void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }; @@ -177,7 +184,7 @@ private: /// When false the destructor is in charge of deletion. bool SelfHeader; - /// Wether already parsed or not + /// Whether already parsed or not bool Parsed; // Utility pixel converter @@ -195,6 +202,13 @@ private: FileMode WriteMode; /// \brief (ImplicitVR, ExplicitVR, ACR, ACR_LIBIDO) FileType WriteType; + /// Pointer to a user supplied function to allow modification of pixel order + /// (i.e. : Mirror, TopDown, 90°Rotation, ...) + /// use as : void userSuppliedMirrorFunction(uint8_t *im, gdcm::File *f) + /// NB : the "uint8_t *" type of first param is just for prototyping. + /// User will Cast it according what he founds with f->GetPixelType() + /// See ctkgdcmSerieViewer for an example + VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction; }; } // end namespace gdcm diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 9b97cbb1..cd2bc609 100644 --- a/src/gdcmPixelReadConvert.cxx +++ b/src/gdcmPixelReadConvert.cxx @@ -1,10 +1,10 @@ /*========================================================================= - + Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.cxx,v $ Language: C++ - Date: $Date: 2005/07/01 11:25:51 $ - Version: $Revision: 1.74 $ + Date: $Date: 2005/07/30 18:27:00 $ + Version: $Revision: 1.75 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -52,6 +52,8 @@ PixelReadConvert::PixelReadConvert() LutBlueData = 0; RLEInfo = 0; JPEGInfo = 0; + UserFunction = 0; + FileInternal = 0; } /// Canonical Destructor @@ -109,7 +111,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) YSize = file->GetYSize(); ZSize = file->GetZSize(); SamplesPerPixel = file->GetSamplesPerPixel(); - PixelSize = file->GetPixelSize(); + //PixelSize = file->GetPixelSize(); Useless PixelSign = file->IsSignedPixelData(); SwapCode = file->GetSwapCode(); std::string ts = file->GetTransferSyntax(); @@ -188,6 +190,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) gdcmWarningMacro( "Unable to read Blue Palette Color Lookup Table data" ); } } + FileInternal = file; ComputeRawAndRGBSizes(); } @@ -261,7 +264,8 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) { //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" ); //return false; - //ReadMPEGFile(fp, Raw, PixelDataLength); // fp has already been seek to start of mpeg + // fp has already been seek to start of mpeg + //ReadMPEGFile(fp, Raw, PixelDataLength); return true; } else @@ -279,6 +283,8 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp ) ConvertReorderEndianity(); ConvertReArrangeBits(); ConvertFixGreyLevels(); + if (UserFunction) // user is allowed to Mirror, TopDown, Rotate, .. the image + UserFunction( Raw, FileInternal); ConvertHandleColor(); return true; diff --git a/src/gdcmPixelReadConvert.h b/src/gdcmPixelReadConvert.h index 4c6f96c0..5c34a043 100644 --- a/src/gdcmPixelReadConvert.h +++ b/src/gdcmPixelReadConvert.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.h,v $ Language: C++ - Date: $Date: 2005/06/17 12:35:00 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/07/30 18:27:00 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,9 +30,13 @@ class File; class RLEFramesInfo; class JPEGFragmentsInfo; +typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, File *); + /** * \brief Utility container for gathering the various forms the pixel data * migth take during the user demanded processes. + * WARNING : *none* of these functions may be invoked by gdm user + * (internal use only) */ class GDCM_EXPORT PixelReadConvert : public Base { @@ -60,6 +64,8 @@ public: bool BuildRGBImage(); void BuildLUTRGBA(); + void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) + { UserFunction = userFunc; } private: // Use the fp: void ReadAndDecompress12BitsTo16Bits( std::ifstream *fp ) @@ -111,7 +117,7 @@ private: int BitsStored; int HighBitPosition; int SamplesPerPixel; - int PixelSize; + //int PixelSize; // useless bool PixelSign; int SwapCode; @@ -141,6 +147,9 @@ private: uint8_t *LutRedData; uint8_t *LutGreenData; uint8_t *LutBlueData; + + File *FileInternal; // must be passed to User Function + VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction; }; } // end namespace gdcm