]> Creatis software - gdcm.git/commitdiff
User is now allowed to pass a Pointer to a function of his own
authorjpr <jpr>
Sat, 30 Jul 2005 18:27:00 +0000 (18:27 +0000)
committerjpr <jpr>
Sat, 30 Jul 2005 18:27:00 +0000 (18:27 +0000)
      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

src/gdcmFileHelper.cxx
src/gdcmFileHelper.h
src/gdcmPixelReadConvert.cxx
src/gdcmPixelReadConvert.h

index 0bf7bf7d11f499ad4859da40f8853edfe54b1e18..ad3454a079c9bef1e67695393e6221bf83c46a6f 100644 (file)
@@ -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 )
    {
index 3661ebfe3a955b6a4efd1cf6cae218c16f6b9dbc..39b9de92f8bcaa9d771eca119e1d07ca6543dbbc 100644 (file)
@@ -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 <iostream>
 
+
+
 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
 
index 9b97cbb171e525e98fc0ea176a36a55d2e208ddc..cd2bc609e059d65003f68f42afc9f3fe9dfc38db 100644 (file)
@@ -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;
index 4c6f96c0d824ed766e6b4dc9f3cfe09d96f68aa3..5c34a043d2e86bbc12816ec99d53f2d7964b5bb0 100644 (file)
@@ -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