]> Creatis software - gdcm.git/commitdiff
ENH: Removed all FILE* ref and replace by ifstream/ofstream. For now I use a temp...
authormalaterre <malaterre>
Fri, 22 Oct 2004 03:05:39 +0000 (03:05 +0000)
committermalaterre <malaterre>
Fri, 22 Oct 2004 03:05:39 +0000 (03:05 +0000)
40 files changed:
ChangeLog
src/gdcmBinEntry.cxx
src/gdcmBinEntry.h
src/gdcmDicomDir.cxx
src/gdcmDicomDirMeta.cxx
src/gdcmDicomDirMeta.h
src/gdcmDicomDirPatient.cxx
src/gdcmDicomDirPatient.h
src/gdcmDicomDirSerie.cxx
src/gdcmDicomDirSerie.h
src/gdcmDicomDirStudy.cxx
src/gdcmDicomDirStudy.h
src/gdcmDocEntry.cxx
src/gdcmDocEntry.h
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmDocument.h
src/gdcmElementSet.cxx
src/gdcmElementSet.h
src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmHeader.cxx
src/gdcmHeader.h
src/gdcmJpeg.cxx
src/gdcmJpeg12.cxx
src/gdcmJpeg16.cxx
src/gdcmJpeg2000.cxx
src/gdcmJpeg8.cxx
src/gdcmPixelConvert.cxx
src/gdcmPixelConvert.h
src/gdcmSQItem.cxx
src/gdcmSQItem.h
src/gdcmSeqEntry.cxx
src/gdcmSeqEntry.h
src/gdcmValEntry.cxx
src/gdcmValEntry.h
src/jdatadst.cxx [new file with mode: 0644]
src/jdatasrc.cxx [new file with mode: 0644]
src/jpeg/CMakeLists.txt
src/jpeg/libijg/jinclude.h

index 4ccb8201a4205f2fd143476af9a9217d7eaf31b6..a02571b43c9622ec6f25989d335ee92d33c856c4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-21 Mathieu Malaterre  <Mathieu.Malaterre@creatis.insa-lyon.fr>
+  * Removed all FILE* ref and replace by ifstream/ofstream. For now I use a temp 
+    solution with the two files jdatadst.cxx and jdatasrc.cxx, this need to be 
+    discussed (plus I didn't like having a 2000 lines patch not commited)
+
 2004-10-21 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
   * src/gdcmDocument.cxx: wrong type on return fixed (thanks dashboard)
   * CLEANUP_ROUND (14) for gdcmPixelConvert
index ce75c594c4d383fe7e3fb79fd83836ae55c0fd7a..b560cc2cd0787d70b2c20f42c6172d6a94f0fd85 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:44 $
-  Version:   $Revision: 1.33 $
+  Date:      $Date: 2004/10/22 03:05:40 $
+  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
@@ -18,6 +18,7 @@
 
 #include "gdcmBinEntry.h"
 #include "gdcmDebug.h"
+#include <fstream>
 
 namespace gdcm 
 {
@@ -101,7 +102,7 @@ void BinEntry::Print(std::ostream &os)
  * @param fp already open file pointer
  * @param filetype type of the file to be written
 */
-void BinEntry::Write(FILE* fp, FileType filetype)
+void BinEntry::Write(std::ofstream* fp, FileType filetype)
 {
    DocEntry::Write(fp, filetype);
    void* binArea = GetBinArea();
@@ -109,12 +110,13 @@ void BinEntry::Write(FILE* fp, FileType filetype)
    if (binArea)
    {
       // there is a 'non string' LUT, overlay, etc
-      fwrite ( binArea,(size_t)lgr ,(size_t)1 ,fp); // Elem value
+      fp->write ( (char*)binArea, lgr ); // Elem value
+
    }
    else
    {
     // nothing was loaded, but we need to skip space on disc
-      fseek(fp,(size_t)lgr,SEEK_CUR); 
+      fp->seekp(lgr, std::ios_base::cur);
    }
 }
 //-----------------------------------------------------------------------------
index 5191670a54b6872916e1d5ebf6f9d70c86edeace..285d94189a929904114c15877593f281239c6a94 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/18 12:49:22 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2004/10/22 03:05:40 $
+  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
@@ -42,7 +42,7 @@ public:
    ~BinEntry();
    
    void Print( std::ostream &os = std::cout );
-   void Write( FILE*, FileType );
+   void Write( std::ofstream*, FileType );
 
    /// \brief Returns the area value of the current Dicom Header Entry
    ///  when it's not string-translatable (e.g : a LUT table)         
index 35726eac96b77eb1e632e162b00347daed4cb68d..03cc6a20c939c2cdc175ae2db38e06dad6fefaed 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:44 $
-  Version:   $Revision: 1.73 $
+  Date:      $Date: 2004/10/22 03:05:40 $
+  Version:   $Revision: 1.74 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -29,6 +29,7 @@
 #include "gdcmSQItem.h"
 #include "gdcmValEntry.h"
 
+#include <fstream>
 #include <string>
 #include <algorithm>
 #include <sys/types.h>
@@ -342,7 +343,8 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
    uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
    uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
 
-   FILE* fp = fopen(fileName.c_str(), "wb");
+   std::ofstream* fp = new std::ofstream(fileName.c_str(),  
+                                         std::ios::out | std::ios::binary);
    if( !fp ) 
    {
       printf("Failed to open(write) File [%s] \n", fileName.c_str());
@@ -351,14 +353,14 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
 
    uint8_t filePreamble[128];
    memset(filePreamble, 0, 128);
-   fwrite(filePreamble,128,1,fp);
-   fwrite("DICM",4,1,fp);
+   fp->write((char*)filePreamble, 128);
+   fp->write("DICM",4);
  
    DicomDirMeta *ptrMeta = GetDicomDirMeta();
    ptrMeta->Write(fp, ExplicitVR);
    
    // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
-   fwrite(&sq[0],8,1,fp);  // 0004 1220 ffff ffff
+   fp->write((char*)&sq[0],8);
         
    for(ListDicomDirPatient::iterator cc  = Patients.begin();
                                      cc != Patients.end();
@@ -368,9 +370,9 @@ bool DicomDir::WriteDicomDir(std::string const& fileName)
    }
    
    // force writing Sequence Delimitation Item
-   fwrite(&sqt[0],8,1,fp);  // fffe e0dd ffff ffff 
+   fp->write((char*)&sqt[0],8);  // fffe e0dd ffff ffff 
 
-   fclose( fp );
+   fp->close();
    return true;
 }
 
index f0657a5c130fe293af929939601a149678aaa04f..8c00a238caf9e8d55cdbead5523381a2231e42d1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:44 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2004/10/22 03:05:40 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -68,7 +68,7 @@ void DicomDirMeta::Print(std::ostream& os)
  * \brief   Writes the Meta Elements
  * @return
  */ 
-void DicomDirMeta::Write(FILE* fp, FileType t)
+void DicomDirMeta::Write(std::ofstream* fp, FileType t)
 {   
    for (ListDocEntry::iterator i = docEntries.begin();  
         i != docEntries.end();
index 0e665a59979a036410bfa5feca1dba4ce5c5cfed..a15732047dcfee641f08a5833dcbc8f558567e6b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirMeta.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:44 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.10 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -32,7 +32,7 @@ public:
    ~DicomDirMeta();
 
    virtual void Print(std::ostream &os = std::cout);
-   virtual void Write(FILE * fp, FileType t);
+   virtual void Write(std::ofstream * fp, FileType t);
 };
 } // end namespace gdcm
 //-----------------------------------------------------------------------------
index d6673ac79bab943812ee5fb7949ee94d08142a86..827604aa9982125ad5991d3c6949e99db5ef46e4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  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
@@ -79,7 +79,7 @@ void DicomDirPatient::Print(std::ostream& os)
  * \brief   Writes the Object
  * @return
  */ 
-void DicomDirPatient::Write(FILE* fp, FileType t)
+void DicomDirPatient::Write(std::ofstream* fp, FileType t)
 {
    DicomDirObject::Write(fp, t);
 
index d203a6294865b8d01203055986777da7e5dcb7c4..4302ca2008cf1af76fc4713c7a3519acafeca84d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirPatient.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  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
@@ -39,7 +39,7 @@ public:
    ~DicomDirPatient();
 
    virtual void Print(std::ostream &os = std::cout);
-   virtual void Write(FILE *fp, FileType t);
+   virtual void Write(std::ofstream *fp, FileType t);
    /// Returns the STUDY chained List for this PATIENT.
    ListDicomDirStudy &GetDicomDirStudies() { return studies; };
 
index 62396da10ed4aec928474c606f088a9306420026..f1c32c6f4ad2854adb467dca5c7117759d5b8795 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.17 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.18 $
                                                                                 
   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 @@ void DicomDirSerie::Print(std::ostream& os)
  * \brief   Writes the Object
  * @return
  */ 
-void DicomDirSerie::Write(FILE* fp, FileType t)
+void DicomDirSerie::Write(std::ofstream* fp, FileType t)
 {
    DicomDirObject::Write(fp, t);
 
index 8e73240d57d54cc019e3cb6dcc98e60d2f09a9c1..26e61c47b5b3121566b4c2a4d79d03eafc6011d0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirSerie.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/13 14:15:29 $
-  Version:   $Revision: 1.11 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.12 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@ public:
    ~DicomDirSerie();
 
    virtual void Print( std::ostream& os = std::cout );
-   virtual void Write( FILE* fp, FileType t );
+   virtual void Write( std::ofstream* fp, FileType t );
 /**
  * \ingroup DicomDirSerie
  * \brief   returns the IMAGE chained List for this SERIE.
index ea46883016c4c945d9cd54c1588ec25468278dcd..24a15bca3b0962eaa9ecaec9beba173c68c98365 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -88,7 +88,7 @@ void DicomDirStudy::Print(std::ostream& os)
  * \brief   Writes the Object
  * @return
  */ 
-void DicomDirStudy::Write(FILE* fp, FileType t)
+void DicomDirStudy::Write(std::ofstream* fp, FileType t)
 {
    DicomDirObject::Write(fp, t);
 
index 91e798c244fae2ad1f887eff4f6bc8da26ece997..965dfbcb5f7f48bed930d773a3137b387fabb5c4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDirStudy.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.10 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  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
@@ -37,7 +37,7 @@ public:
    ~DicomDirStudy();
 
    virtual void Print(std::ostream &os = std::cout);
-   virtual void Write(FILE *fp, FileType t);
+   virtual void Write(std::ofstream *fp, FileType t);
 /**
  * \ingroup DicomDirStudy
  * \brief   returns the SERIE chained List for this STUDY.
index 61cc963477ee0e5d85a5315dd215c659715aaa9a..dce3028c11a37db9e755f09601d39df20b7f836b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.27 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  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
@@ -22,6 +22,8 @@
 #include "gdcmUtil.h"
 
 #include <iomanip> // for std::ios::left, ...
+#include <fstream>
+
 namespace gdcm 
 {
 
@@ -116,7 +118,7 @@ void DocEntry::Print(std::ostream& os)
  * @param fp already open file pointer
  * @param filetype type of the file to be written
  */
-void DocEntry::Write(FILE* fp, FileType filetype)
+void DocEntry::Write(std::ofstream* fp, FileType filetype)
 {
    uint32_t ffff  = 0xffffffff;
    uint16_t group = GetGroup();
@@ -135,8 +137,8 @@ void DocEntry::Write(FILE* fp, FileType filetype)
    //
    // ----------- Writes the common part
    //
-   fwrite ( &group,(size_t)2 ,(size_t)1 ,fp);  //group
-   fwrite ( &el,   (size_t)2 ,(size_t)1 ,fp);  //element
+   fp->write ((char*) &group,(size_t)2 );  //group
+   fp->write ( (char*)&el,   (size_t)2 );  //element
       
    if ( filetype == ExplicitVR )
    {
@@ -154,7 +156,7 @@ void DocEntry::Write(FILE* fp, FileType filetype)
          // TODO : verify if the Sequence Delimitor Item was forced during Parsing 
 
          int ff = 0xffffffff;
-         fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
+         fp->write ((char*)&ff,(size_t)4 );
          return;
       }
 
@@ -165,31 +167,32 @@ void DocEntry::Write(FILE* fp, FileType filetype)
       {
          // Unknown was 'written'
          // deal with Little Endian            
-         fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
-         fwrite ( &z,       (size_t)2 ,(size_t)1 ,fp);
+         fp->write ( (char*)&shortLgr,(size_t)2 );
+         fp->write ( (char*)&z,       (size_t)2 );
       }
       else
       {
-         fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp); 
+         fp->write (vr.c_str(),(size_t)2 ); 
+
                   
          if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
          {
-            fwrite ( &z,  (size_t)2 ,(size_t)1 ,fp);
+            fp->write ( (char*)&z,  (size_t)2 );
             if (vr == "SQ")
             {
                // we set SQ length to ffffffff
                // and  we shall write a Sequence Delimitor Item 
                // at the end of the Sequence! 
-               fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+               fp->write ( (char*)&ffff,(size_t)4 );
             }
             else
             {
-               fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+               fp->write ( (char*)&lgr,(size_t)4 );
             }
          }
          else
          {
-            fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
+            fp->write ( (char*)&shortLgr,(size_t)2 );
          }
       }
    } 
@@ -197,11 +200,11 @@ void DocEntry::Write(FILE* fp, FileType filetype)
    { 
       if (vr == "SQ")
       {
-         fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+         fp->write ( (char*)&ffff,(size_t)4 );
       }
       else
       {
-         fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+         fp->write ( (char*)&lgr,(size_t)4 );
       }
    }
 }
index d48d9bef1cbfeb534e661d926d3695e3ce19868e..8c909273175a050eb93ed036b4a73d383d2c035e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/13 14:15:29 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.27 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -128,7 +128,7 @@ public:
    int GetPrintLevel() { return PrintLevel; };
    
    virtual void Print (std::ostream & os = std::cout); 
-   virtual void Write(FILE *fp, FileType filetype);
+   virtual void Write(std::ofstream *fp, FileType filetype);
    
    uint32_t GetFullLength();
    
index 088aa255f45912e645d5014b6aaedc7762809d67..e40b3f977df819ee5550062b38fe55515d419850 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.20 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.21 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -66,7 +66,7 @@ public:
    virtual void Print (std::ostream & os = std::cout) = 0;// pure virtual
 
    /// \brief write any type of entry to the entry set
-   virtual void Write (FILE *fp, FileType filetype) = 0;// pure virtual
+   virtual void Write (std::ofstream *fp, FileType filetype) = 0;// pure virtual
 
    virtual DocEntry* GetDocEntryByNumber(uint16_t group,
                                              uint16_t element) = 0;
index d8bdf65bed7cac89650b9d4594f5f24781590f57..eff4ffdc89a25269be33c07b408a2dca384fe4ce 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 22:31:52 $
-  Version:   $Revision: 1.107 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.108 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -25,6 +25,7 @@
 #include "gdcmDebug.h"
 
 #include <vector>
+#include <iomanip>
 
 // For nthos:
 #ifdef _MSC_VER
@@ -33,8 +34,6 @@
    #include <netinet/in.h>
 #endif
 
-#include <iomanip>
-
 namespace gdcm 
 {
 
@@ -99,19 +98,19 @@ Document::Document( std::string const & filename )
 
    dbg.Verbose(0, "Document::Document: starting parsing of file: ",
                   Filename.c_str());
-   rewind(Fp);
+   Fp->seekg( 0,  std::ios_base::beg);
    
-   fseek(Fp,0L,SEEK_END);
-   long lgt = ftell(Fp);    
+   Fp->seekg(0,  std::ios_base::end);
+   long lgt = Fp->tellg();
            
-   rewind(Fp);
+   Fp->seekg( 0,  std::ios_base::beg);
    CheckSwap();
-   long beg = ftell(Fp);
+   long beg = Fp->tellg();
    lgt -= beg;
    
    ParseDES( this, beg, lgt, false); // le Load sera fait a la volee
 
-   rewind(Fp);
+   Fp->seekg( 0,  std::ios_base::beg);
    
    // Load 'non string' values
       
@@ -507,9 +506,9 @@ FileType Document::GetFileType()
  *         checks the preamble when existing.
  * @return The FILE pointer on success. 
  */
-FILE* Document::OpenFile()
+std::ifstream* Document::OpenFile()
 {
-   Fp = fopen(Filename.c_str(),"rb");
+   Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary);
 
    if(!Fp)
    {
@@ -520,7 +519,7 @@ FILE* Document::OpenFile()
    }
  
    uint16_t zero;
-   fread(&zero,  (size_t)2, (size_t)1, Fp);
+   Fp->read((char*)&zero,  (size_t)2 );
  
    //ACR -- or DICOM with no Preamble --
    if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200 )
@@ -529,15 +528,15 @@ FILE* Document::OpenFile()
    }
  
    //DICOM
-   fseek(Fp, 126L, SEEK_CUR);
+   Fp->seekg(126L, std::ios_base::cur);
    char dicm[4];
-   fread(dicm,  (size_t)4, (size_t)1, Fp);
+   Fp->read(dicm,  (size_t)4);
    if( memcmp(dicm, "DICM", 4) == 0 )
    {
       return Fp;
    }
  
-   fclose(Fp);
+   Fp->close();
    dbg.Verbose( 0,
                 "Document::OpenFile not DICOM/ACR (missing preamble)",
                 Filename.c_str());
@@ -551,17 +550,11 @@ FILE* Document::OpenFile()
  */
 bool Document::CloseFile()
 {
-  int closed = fclose(Fp);
+  Fp->close();
+  delete Fp;
   Fp = 0;
 
-  if ( ! closed )
-  {
-     return false;
-  }
-  else
-  {
-     return true;
-  }
+  return true; //FIXME how do we detect a non-close ifstream ?
 }
 
 /**
@@ -571,7 +564,7 @@ bool Document::CloseFile()
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  * \return Always true.
  */
-void Document::Write(FILE* fp,FileType filetype)
+void Document::Write(std::ofstream* fp, FileType filetype)
 {
    /// \todo move the following lines (and a lot of others, to be written)
    /// to a future function CheckAndCorrectHeader  
@@ -1027,9 +1020,9 @@ bool Document::SetEntryByNumber(std::string const& content,
  * @param   element element number of the Dicom Element to modify
  */
 bool Document::SetEntryByNumber(uint8_t*content,
-                                    int lgth, 
-                                    uint16_t group,
-                                    uint16_t element) 
+                                int lgth, 
+                                uint16_t group,
+                                uint16_t element) 
 {
    (void)lgth;  //not used
    TagKey key = DictEntry::TranslateToKey(group, element);
@@ -1065,8 +1058,8 @@ bool Document::SetEntryByNumber(uint8_t*content,
  * @return  true on success, false otherwise.
  */
 bool Document::SetEntryLengthByNumber(uint32_t l, 
-                                          uint16_t group, 
-                                          uint16_t element) 
+                                      uint16_t group, 
+                                      uint16_t element) 
 {
    /// \todo use map methods, instead of multimap JPR
    TagKey key = DictEntry::TranslateToKey(group, element);
@@ -1138,7 +1131,7 @@ void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
       return NULL;
    }
    size_t o =(size_t)docElement->GetOffset();
-   fseek(Fp, o, SEEK_SET);
+   Fp->seekg( o, std::ios_base::beg);
    size_t l = docElement->GetLength();
    uint8_t* a = new uint8_t[l];
    if(!a)
@@ -1146,13 +1139,13 @@ void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
       dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
       return NULL;
    }
-   size_t l2 = fread(a, 1, l , Fp);
-   if( l != l2 )
+   Fp->read((char*)a, l);
+   if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1
    {
       delete[] a;
       return NULL;
    }
-   /// \todo Drop any already existing void area! JPR
+  /// \todo Drop any already existing void area! JPR
    if( !SetEntryBinAreaByNumber( a, group, elem ) )
    {
       dbg.Verbose(0, "Document::LoadEntryBinArea setting failed.");
@@ -1167,7 +1160,7 @@ void* Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
 void* Document::LoadEntryBinArea(BinEntry* element) 
 {
    size_t o =(size_t)element->GetOffset();
-   fseek(Fp, o, SEEK_SET);
+   Fp->seekg(o, std::ios_base::beg);
    size_t l = element->GetLength();
    uint8_t* a = new uint8_t[l];
    if( !a )
@@ -1177,8 +1170,8 @@ void* Document::LoadEntryBinArea(BinEntry* element)
    }
    element->SetBinArea((uint8_t*)a);
    /// \todo check the result 
-   size_t l2 = fread(a, 1, l , Fp);
-   if( l != l2 )
+   Fp->read((char*)a, l);
+   if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1
    {
       delete[] a;
       return NULL;
@@ -1330,9 +1323,9 @@ ValEntry* Document::GetValEntryByNumber(uint16_t group,
  */
 void Document::LoadDocEntrySafe(DocEntry * entry)
 {
-   long PositionOnEntry = ftell(Fp);
+   long PositionOnEntry = Fp->tellg();
    LoadDocEntry(entry);
-   fseek(Fp, PositionOnEntry, SEEK_SET);
+   Fp->seekg(PositionOnEntry, std::ios_base::beg);
 }
 
 /**
@@ -1406,15 +1399,15 @@ uint16_t Document::UnswapShort(uint16_t a)
  * @return  length of the parsed set. 
  */ 
 void Document::ParseDES(DocEntrySet *set,
-                            long offset,
-                            long l_max,
-                            bool delim_mode)
+                        long offset,
+                        long l_max,
+                        bool delim_mode)
 {
    DocEntry *newDocEntry = 0;
    
    while (true)
    { 
-      if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+      if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
       {
          break;
       }
@@ -1457,7 +1450,7 @@ void Document::ParseDES(DocEntrySet *set,
             {
                break;
             }
-            if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+            if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
             {
                break;
             }
@@ -1501,18 +1494,18 @@ void Document::ParseDES(DocEntrySet *set,
          {
              if ( IsRLELossLessTransferSyntax() ) 
              {
-                long PositionOnEntry = ftell(Fp);
-                fseek( Fp, newDocEntry->GetOffset(), SEEK_SET );
+                long PositionOnEntry = Fp->tellg();
+                Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
                 ComputeRLEInfo();
-                fseek( Fp, PositionOnEntry, SEEK_SET );
+                Fp->seekg( PositionOnEntry, std::ios_base::beg );
              }
              else 
              if ( IsJPEGTransferSyntax() )
              {
-                long PositionOnEntry = ftell(Fp);
-                fseek( Fp, newDocEntry->GetOffset(), SEEK_SET );
+                long PositionOnEntry = Fp->tellg();
+                Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
                 ComputeJPEGFragmentInfo();
-                fseek( Fp, PositionOnEntry, SEEK_SET );
+                Fp->seekg( PositionOnEntry, std::ios_base::beg );
              }
          }
     
@@ -1567,7 +1560,7 @@ void Document::ParseDES(DocEntrySet *set,
                      l, delim_mode);
          }
          set->AddEntry( newSeqEntry );
-         if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+         if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
          {
             break;
          }
@@ -1602,7 +1595,7 @@ void Document::ParseSQ( SeqEntry* seqEntry,
             break;
          }
       }
-      if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+      if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
       {
           break;
       }
@@ -1629,7 +1622,7 @@ void Document::ParseSQ( SeqEntry* seqEntry,
       
       seqEntry->AddEntry( itemSQ, SQItemNumber ); 
       SQItemNumber++;
-      if ( !delim_mode && ( ftell(Fp) - offset ) >= l_max )
+      if ( !delim_mode && ( Fp->tellg() - offset ) >= l_max )
       {
          break;
       }
@@ -1643,12 +1636,11 @@ void Document::ParseSQ( SeqEntry* seqEntry,
  */
 void Document::LoadDocEntry(DocEntry* entry)
 {
-   size_t item_read;
    uint16_t group  = entry->GetGroup();
    std::string  vr = entry->GetVR();
    uint32_t length = entry->GetLength();
 
-   fseek(Fp, (long)entry->GetOffset(), SEEK_SET);
+   Fp->seekg((long)entry->GetOffset(), std::ios_base::beg);
 
    // A SeQuence "contains" a set of Elements.  
    //          (fffe e000) tells us an Element is beginning
@@ -1701,7 +1693,7 @@ void Document::LoadDocEntry(DocEntry* entry)
       }
 
       // to be sure we are at the end of the value ...
-      fseek(Fp,(long)entry->GetOffset()+(long)entry->GetLength(),SEEK_SET);      
+      Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(),std::ios_base::beg);
       return;
    }
 
@@ -1764,17 +1756,15 @@ void Document::LoadDocEntry(DocEntry* entry)
    }
    
    // We need an additional byte for storing \0 that is not on disk
-   //std::string newValue(length,0);
-   //item_read = fread(&(newValue[0]), (size_t)length, (size_t)1, Fp);  
-   //rah !! I can't believe it could work, normally this is a const char* !!!
    char *str = new char[length+1];
-   item_read = fread(str, (size_t)length, (size_t)1, Fp);
+   Fp->read(str, (size_t)length);
    str[length] = '\0';
    std::string newValue = str;
    delete[] str;
+
    if ( ValEntry* valEntry = dynamic_cast<ValEntry* >(entry) )
    {  
-      if ( item_read != 1 )
+      if ( Fp->fail() || Fp->eof())//Fp->gcount() == 1
       {
          dbg.Verbose(1, "Document::LoadDocEntry",
                         "unread element value");
@@ -1818,7 +1808,7 @@ void Document::FindDocEntryLength( DocEntry *entry )
          // The following reserved two bytes (see PS 3.5-2003, section
          // "7.1.2 Data element structure with explicit vr", p 27) must be
          // skipped before proceeding on reading the length on 4 bytes.
-         fseek(Fp, 2L, SEEK_CUR);
+         Fp->seekg( 2L, std::ios_base::cur);
          uint32_t length32 = ReadInt32();
 
          if ( (vr == "OB" || vr == "OW") && length32 == 0xffffffff ) 
@@ -1837,10 +1827,10 @@ void Document::FindDocEntryLength( DocEntry *entry )
                // chance to get the pixels by deciding the element goes
                // until the end of the file. Hence we artificially fix the
                // the length and proceed.
-               long currentPosition = ftell(Fp);
-               fseek(Fp,0L,SEEK_END);
-               long lengthUntilEOF = ftell(Fp) - currentPosition;
-               fseek(Fp, currentPosition, SEEK_SET);
+               long currentPosition = Fp->tellg();
+               Fp->seekg(0L,std::ios_base::end);
+               long lengthUntilEOF = Fp->tellg() - currentPosition;
+               Fp->seekg(currentPosition, std::ios_base::beg);
                entry->SetLength(lengthUntilEOF);
                return;
             }
@@ -1943,7 +1933,7 @@ void Document::FindDocEntryVR( DocEntry *entry )
 
    char vr[3];
 
-   long positionOnEntry = ftell(Fp);
+   long positionOnEntry = Fp->tellg();
    // Warning: we believe this is explicit VR (Value Representation) because
    // we used a heuristic that found "UL" in the first tag. Alas this
    // doesn't guarantee that all the tags will be in explicit VR. In some
@@ -1952,12 +1942,12 @@ void Document::FindDocEntryVR( DocEntry *entry )
    // is in explicit VR and try to fix things if it happens not to be
    // the case.
    
-   fread (vr, (size_t)2,(size_t)1, Fp);
+   Fp->read (vr, (size_t)2);
    vr[2] = 0;
 
    if( !CheckDocEntryVR(entry, vr) )
    {
-      fseek(Fp, positionOnEntry, SEEK_SET);
+      Fp->seekg(positionOnEntry, std::ios_base::beg);
       // When this element is known in the dictionary we shall use, e.g. for
       // the semantics (see the usage of IsAnInteger), the VR proposed by the
       // dictionary entry. Still we have to flag the element as implicit since
@@ -2202,8 +2192,8 @@ void Document::SkipDocEntry(DocEntry *entry)
  */
 void Document::SkipToNextDocEntry(DocEntry *entry) 
 {
-   fseek(Fp, (long)(entry->GetOffset()),     SEEK_SET);
-   fseek(Fp, (long)(entry->GetReadLength()), SEEK_CUR);
+   Fp->seekg((long)(entry->GetOffset()),     std::ios_base::beg);
+   Fp->seekg( (long)(entry->GetReadLength()), std::ios_base::cur);
 }
 
 /**
@@ -2318,7 +2308,7 @@ bool Document::IsDocEntryAnInteger(DocEntry *entry)
          // encounter such an ill-formed image, we simply display a warning
          // message and proceed on parsing (while crossing fingers).
          std::ostringstream s;
-         long filePosition = ftell(Fp);
+         long filePosition = Fp->tellg();
          s << "Erroneous Group Length element length  on : (" \
            << std::hex << group << " , " << element 
            << ") -before- position x(" << filePosition << ")"
@@ -2345,7 +2335,7 @@ uint32_t Document::FindDocEntryLengthOB()
    throw( FormatUnexpected )
 {
    // See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
-   long positionOnEntry = ftell(Fp);
+   long positionOnEntry = Fp->tellg();
    bool foundSequenceDelimiter = false;
    uint32_t totalLength = 0;
 
@@ -2371,7 +2361,7 @@ uint32_t Document::FindDocEntryLengthOB()
       {
          dbg.Verbose(1, "Document::FindDocEntryLengthOB: neither an Item "
                         "tag nor a Sequence delimiter tag."); 
-         fseek(Fp, positionOnEntry, SEEK_SET);
+         Fp->seekg(positionOnEntry, std::ios_base::beg);
          throw FormatUnexpected("Document::FindDocEntryLengthOB()",
                                 "Neither an Item tag nor a Sequence "
                                 "delimiter tag.");
@@ -2392,7 +2382,7 @@ uint32_t Document::FindDocEntryLengthOB()
          break;
       }
    }
-   fseek(Fp, positionOnEntry, SEEK_SET);
+   Fp->seekg( positionOnEntry, std::ios_base::beg);
    return totalLength;
 }
 
@@ -2405,13 +2395,13 @@ uint16_t Document::ReadInt16()
    throw( FormatError )
 {
    uint16_t g;
-   size_t item_read = fread (&g, (size_t)2,(size_t)1, Fp);
-   if ( item_read != 1 )
+   Fp->read ((char*)&g, (size_t)2);
+   if ( Fp->fail() )
+   {
+          throw FormatError( "Document::ReadInt16()", " file error." );
+   }
+   if( Fp->eof() )
    {
-      if( ferror(Fp) )
-      {
-         throw FormatError( "Document::ReadInt16()", " file error." );
-      }
       throw FormatError( "Document::ReadInt16()", "EOF." );
    }
    g = SwapShort(g); 
@@ -2427,13 +2417,13 @@ uint32_t Document::ReadInt32()
    throw( FormatError )
 {
    uint32_t g;
-   size_t item_read = fread (&g, (size_t)4,(size_t)1, Fp);
-   if ( item_read != 1 )
+   Fp->read ((char*)&g, (size_t)4);
+   if ( Fp->fail() )
+   {
+      throw FormatError( "Document::ReadInt32()", " file error." );
+   }
+   if( Fp->eof() )
    {
-      if( ferror(Fp) )
-      {
-         throw FormatError( "Document::ReadInt16()", " file error." );
-      }
       throw FormatError( "Document::ReadInt32()", "EOF." );
    }
    g = SwapLong(g);
@@ -2448,7 +2438,7 @@ uint32_t Document::ReadInt32()
 void Document::SkipBytes(uint32_t nBytes)
 {
    //FIXME don't dump the returned value
-   (void)fseek(Fp, (long)nBytes, SEEK_CUR);
+   Fp->seekg((long)nBytes, std::ios_base::cur);
 }
 
 /**
@@ -2498,8 +2488,7 @@ bool Document::CheckSwap()
          
    // The easiest case is the one of a DICOM header, since it possesses a
    // file preamble where it suffice to look for the string "DICM".
-   int lgrLue = fread(deb, 1, HEADER_LENGTH_TO_READ, Fp);
-   (void)lgrLue;  //FIXME not used
+   Fp->read(deb, HEADER_LENGTH_TO_READ);
    
    char *entCur = deb + 128;
    if( memcmp(entCur, "DICM", (size_t)4) == 0 )
@@ -2563,8 +2552,8 @@ bool Document::CheckSwap()
       
       // Position the file position indicator at first tag (i.e.
       // after the file preamble and the "DICM" string).
-      rewind(Fp);
-      fseek (Fp, 132L, SEEK_SET);
+      Fp->seekg(0, std::ios_base::beg);
+      Fp->seekg ( 132L, std::ios_base::beg);
       return true;
    } // End of DicomV3
 
@@ -2572,7 +2561,7 @@ bool Document::CheckSwap()
    // preamble. We can reset the file position indicator to where the data
    // is (i.e. the beginning of the file).
    dbg.Verbose(1, "Document::CheckSwap:", "not a DICOM Version3 file");
-   rewind(Fp);
+   Fp->seekg(0, std::ios_base::beg);
 
    // Our next best chance would be to be considering a 'clean' ACR/NEMA file.
    // By clean we mean that the length of the first tag is written down.
@@ -2757,7 +2746,7 @@ DocEntry* Document::ReadNextDocEntry()
       return 0;
    }
 
-   newEntry->SetOffset(ftell(Fp));  
+   newEntry->SetOffset(Fp->tellg());  
 
    return newEntry;
 }
@@ -2797,8 +2786,8 @@ uint32_t Document::GenerateFreeTagKeyInGroup(uint16_t group)
  */
 bool Document::ReadTag(uint16_t testGroup, uint16_t testElement)
 {
-   long positionOnEntry = ftell(Fp);
-   long currentPosition = ftell(Fp);          // On debugging purposes
+   long positionOnEntry = Fp->tellg();
+   long currentPosition = Fp->tellg();          // On debugging purposes
 
    //// Read the Item Tag group and element, and make
    // sure they are what we expected:
@@ -2815,7 +2804,7 @@ bool Document::ReadTag(uint16_t testGroup, uint16_t testElement)
       s << "  at address: " << (unsigned)currentPosition << std::endl;
       dbg.Verbose(0, "Document::ReadItemTagLength: wrong Item Tag found:");
       dbg.Verbose(0, s.str().c_str());
-      fseek(Fp, positionOnEntry, SEEK_SET);
+      Fp->seekg(positionOnEntry, std::ios_base::beg);
 
       return false;
    }
@@ -2838,7 +2827,7 @@ bool Document::ReadTag(uint16_t testGroup, uint16_t testElement)
  */
 uint32_t Document::ReadTagLength(uint16_t testGroup, uint16_t testElement)
 {
-   long positionOnEntry = ftell(Fp);
+   long positionOnEntry = Fp->tellg();
    (void)positionOnEntry;
 
    if ( !ReadTag(testGroup, testElement) )
@@ -2847,7 +2836,7 @@ uint32_t Document::ReadTagLength(uint16_t testGroup, uint16_t testElement)
    }
                                                                                 
    //// Then read the associated Item Length
-   long currentPosition = ftell(Fp);
+   long currentPosition = Fp->tellg();
    uint32_t itemLength  = ReadInt32();
    {
       std::ostringstream s;
@@ -2877,7 +2866,7 @@ void Document::ReadAndSkipEncapsulatedBasicOffsetTable()
    if ( itemLength != 0 )
    {
       char* basicOffsetTableItemValue = new char[itemLength + 1];
-      fread(basicOffsetTableItemValue, itemLength, 1, Fp);
+      Fp->read(basicOffsetTableItemValue, itemLength);
 
 #ifdef GDCM_DEBUG
       for (unsigned int i=0; i < itemLength; i += 4 )
@@ -2939,7 +2928,7 @@ void Document::ComputeRLEInfo()
       // Offset Table information on fragments of this current Frame.
       // Note that the fragment pixels themselves are not loaded
       // (but just skipped).
-      long frameOffset = ftell(Fp);
+      long frameOffset = Fp->tellg();
 
       uint32_t nbRleSegments = ReadInt32();
  
@@ -3009,7 +2998,7 @@ void Document::ComputeJPEGFragmentInfo()
    long fragmentLength;
    while ( (fragmentLength = ReadTagLength(0xfffe, 0xe000)) )
    { 
-      long fragmentOffset = ftell(Fp);
+      long fragmentOffset = Fp->tellg();
 
        // Store the collected info
        JPEGFragment* newFragment = new JPEGFragment;
index 6b730260e576388e2eae7034af73b8f5c9b9a4f4..f7384be5e94e13418d5d79e5e5e2d95447fcdd24 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/18 12:49:22 $
-  Version:   $Revision: 1.52 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.53 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -36,6 +36,8 @@ class SeqEntry;
 
 #include <map>
 #include <list>
+#include <fstream>
+
 namespace gdcm 
 {
 
@@ -75,7 +77,7 @@ protected:
    int SwapCode;
 
    /// File Pointer, opened during Header parsing.
-   FILE* Fp;
+   std::ifstream* Fp;
 
    /// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
    FileType Filetype;  
@@ -135,10 +137,10 @@ public:
 
    FileType GetFileType();
 
-   FILE* OpenFile();
+   std::ifstream * OpenFile();
    bool CloseFile();
 
-   void Write( FILE* fp, FileType type );
+   void Write( std::ofstream* fp, FileType type );
 
    ValEntry* ReplaceOrCreateByNumber(std::string const & value,
                                          uint16_t group, uint16_t elem,
@@ -267,7 +269,7 @@ public:
    int GetSwapCode() { return SwapCode; }
    
    /// File pointer
-   FILE * GetFP() { return Fp; }
+   std::ifstream * GetFP() { return Fp; }
 
    bool operator<(Document &document);
 
index 947170973357e917f07a358547cd990be73de6ae..261c623ce922555926b21d325dd10a40b380e55c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:45 $
-  Version:   $Revision: 1.24 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.25 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -88,7 +88,7 @@ void ElementSet::Print(std::ostream& os)
   *          from the H Table
   * @return
   */ 
-void ElementSet::Write(FILE* fp, FileType filetype)
+void ElementSet::Write(std::ofstream* fp, FileType filetype)
 {
    for (TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
    {
index 4bf25ae86b7d91c97741c16a27b61d0676c1b1b1..c76fefee9fe956a9682321c0bc924c96b1f8affd 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:46 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  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
@@ -45,7 +45,7 @@ public:
    bool RemoveEntryNoDestroy(DocEntry *EntryToRemove);
    
    virtual void Print(std::ostream &os = std::cout); 
-   virtual void Write(FILE *fp, FileType filetype); 
+   virtual void Write(std::ofstream *fp, FileType filetype); 
 
    /// Accessor to \ref TagHT
    // Do not expose this to user (public API) !
index 6909a643aa7d8a859a841f59181b313977b34696..414229ec909b6b3112c254c10a93fc949693e0ab 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 22:31:52 $
-  Version:   $Revision: 1.147 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.148 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -18,6 +18,7 @@
 
 #include "gdcmFile.h"
 #include "gdcmDebug.h"
+#include <fstream>
 
 namespace gdcm 
 {
@@ -362,6 +363,7 @@ size_t File::GetImageDataIntoVector (void* destination, size_t maxSize)
       return ImageDataSize;
    }
                             
+   std::ifstream* fp = HeaderInternal->OpenFile();
    if ( PixelConverter->BuildRGBImage() )
    {
       memmove( destination,
@@ -414,7 +416,7 @@ uint8_t* File::GetImageDataRaw ()
    if ( ! decompressed )
    {
       // The decompressed image migth not be loaded yet:
-      FILE* fp = HeaderInternal->OpenFile();
+     std::ifstream* fp = HeaderInternal->OpenFile();
       PixelConverter->ReadAndDecompressPixelData( fp );
       HeaderInternal->CloseFile();
       if ( ! decompressed )
@@ -508,7 +510,7 @@ void File::GetImageDataIntoVectorRaw (void* destination, size_t maxSize)
       return;
    }
 
-   FILE* fp = HeaderInternal->OpenFile();
+   std::ifstream* fp = HeaderInternal->OpenFile();
    PixelConverter->ReadAndDecompressPixelData( fp );
    HeaderInternal->CloseFile();
    memmove( destination,
@@ -578,14 +580,14 @@ bool File::SetImageData(uint8_t* inData, size_t expectedSize)
 
 bool File::WriteRawData(std::string const & fileName)
 {
-   FILE* fp1 = fopen(fileName.c_str(), "wb");
-   if (fp1 == NULL)
+  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());
       return false;
    }
-   fwrite (Pixel_Data, ImageDataSize, 1, fp1);
-   fclose (fp1);
+   fp1.write((char*)Pixel_Data, ImageDataSize);
+   fp1.close();
 
    return true;
 }
@@ -653,7 +655,8 @@ bool File::WriteBase (std::string const & fileName, FileType type)
       return false;
    }
 
-   FILE* fp1 = fopen(fileName.c_str(), "wb");
+   std::ofstream* fp1 = new std::ofstream(fileName.c_str(), 
+                              std::ios::out | std::ios::binary);
    if (fp1 == NULL)
    {
       printf("Failed to open (write) File [%s] \n", fileName.c_str());
@@ -665,8 +668,8 @@ bool File::WriteBase (std::string const & fileName, FileType type)
       // writing Dicom File Preamble
       uint8_t* filePreamble = new uint8_t[128];
       memset(filePreamble, 0, 128);
-      fwrite(filePreamble, 128, 1, fp1);
-      fwrite("DICM", 4, 1, fp1);
+      fp1->write((char*)filePreamble, 128);
+      fp1->write("DICM", 4);
 
       delete[] filePreamble;
    }
@@ -723,9 +726,8 @@ bool File::WriteBase (std::string const & fileName, FileType type)
       HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
    }
    // ----------------- End of Special Patch ----------------
-   
-   // fwrite(Pixel_Data, ImageDataSize, 1, fp1);  // should be useless, now
-   fclose (fp1);
+   fp1->close ();
 
    return true;
 }
index 7fd947fb16ea947a2aecfd31b778f4a25d43e91a..632d558035e8ce56317ade441d205b4a338f1078 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 14:30:40 $
-  Version:   $Revision: 1.64 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.65 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -87,16 +87,6 @@ protected:
 private:
    void Initialise();
 
-   // For JPEG 8 Bits, body in file gdcmJpeg.cxx
-   bool gdcm_write_JPEG_file    (FILE* fp, void* image_buffer, 
-                                 int image_width, int image_heigh,
-                                 int quality);
-
-   // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
-   bool gdcm_write_JPEG_file12  (FILE* fp, void* image_buffer, 
-                                 int image_width, int image_height,
-                                 int quality);
-
    void SaveInitialValues();    // will belong to the future PixelData class
    void RestoreInitialValues(); // will belong to the future PixelData class
    void DeleteInitialValues();  // will belong to the future PixelData class 
index 12420a38e289e041380df7b4e1a017132ed1fb16..21227e47a86f7d6994475e3892296914c1ffe2eb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/18 12:49:22 $
-  Version:   $Revision: 1.194 $
+  Date:      $Date: 2004/10/22 03:05:41 $
+  Version:   $Revision: 1.195 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -102,7 +102,7 @@ Header::~Header ()
  * @param filetype Type of the File to be written 
  *          (ACR-NEMA, ExplicitVR, ImplicitVR)
  */
-void Header::Write(FILE* fp,FileType filetype)
+void Header::Write(std::ofstream* fp,FileType filetype)
 {
    // Bits Allocated
    if ( GetEntryByNumber(0x0028,0x0100) ==  "12")
index 684b99aac0d2641d1caebf7fc3654684111f981d..85291cac8968e17f56ccbcbe4d382729a2880489 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/18 12:49:22 $
-  Version:   $Revision: 1.90 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.91 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -174,7 +174,7 @@ public:
    /// Read (used in File)
    void SetImageDataSize(size_t expectedSize);
 
-   void Write(FILE* fp, FileType filetype);
+   void Write(std::ofstream* fp, FileType filetype);
  
 protected:
    bool AnonymizeHeader();
index 00cf4b0af90e46e5e30db4be414fb7283e3805cd..86403c62c8fd471a1921b02030c05531ee97746a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/18 02:17:07 $
-  Version:   $Revision: 1.27 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  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
@@ -85,10 +85,12 @@ of the uncompressed pixel data from which the compressed data is derived
  */
 
 #include <setjmp.h>
+#include <fstream>
+#include "jdatasrc.cxx"
+#include "jdatadst.cxx"
 
 namespace gdcm 
 {
-
 /******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
 
 /* This half of the example shows how to feed data into the JPEG compressor.
@@ -136,7 +138,7 @@ namespace gdcm
  * @return 1 on success, 0 on error
  */
  
-bool gdcm_write_JPEG_file (FILE* fp, void*  im_buf, 
+bool gdcm_write_JPEG_file (std::ofstream* fp, void*  im_buf, 
                            int image_width, int image_height, int quality)
 {
 
@@ -362,7 +364,7 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo) {
  * @return 1 on success, 0 on error
  */
  
-bool gdcm_read_JPEG_file ( FILE* fp, void* image_buffer )
+bool gdcm_read_JPEG_file ( std::ifstream* fp, void* image_buffer )
 {
    char* pimage;
 
@@ -503,7 +505,7 @@ bool gdcm_read_JPEG_file ( FILE* fp, void* image_buffer )
     */ 
 
    /* JSAMPLEs per row in output buffer */
-   row_stride = cinfo.output_width * cinfo.output_components;
+   row_stride = cinfo.output_width * cinfo.output_components*2;
   
 #ifdef GDCM_JPG_DEBUG
   printf ("cinfo.output_width %d cinfo.output_components %d  row_stride %d\n",
index 8c3ac350ae42d2043f55b623697893952d3ee5fd..7cb84bf2e0d8de40479900d960acdd51432ba24c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg12.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/14 22:35:01 $
-  Version:   $Revision: 1.22 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.23 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 extern "C" {
 #include "src/jpeg/libijg12/jconfig.h"
 #include "src/jpeg/libijg12/jpeglib.h"
+#include "src/jpeg/libijg12/jinclude.h"
+#include "src/jpeg/libijg12/jerror.h"
 }
 
+
 #define gdcm_write_JPEG_file gdcm_write_JPEG_file12
 #define gdcm_read_JPEG_file  gdcm_read_JPEG_file12
 
index 205b5643c8434566146ae2af033295bc2bd07490..cff5c6d7cab456ccb49608ca926b53d25d97d207 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg16.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/14 22:16:33 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  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
 extern "C" {
 #include "src/jpeg/libijg16/jconfig.h"
 #include "src/jpeg/libijg16/jpeglib.h"
+#include "src/jpeg/libijg16/jinclude.h"
+#include "src/jpeg/libijg16/jerror.h"
 }
 
+
 #define gdcm_write_JPEG_file gdcm_write_JPEG_file16
 #define gdcm_read_JPEG_file  gdcm_read_JPEG_file16
 
index a6f3a42a90d3a3335e2a7b30c27a9f76257042b5..f5ea6569936d3e8c491477669afa781793224bb0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg2000.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:46 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -31,7 +31,7 @@ namespace gdcm
  * @warning : not yet made
  */
 
-bool gdcm_read_JPEG2000_file (FILE* fp,void* image_buffer) {
+bool gdcm_read_JPEG2000_file (std::ifstream* fp,void* image_buffer) {
    (void)fp;                  //FIXME
    (void)image_buffer;        //FIXME
    std::cout << "Sorry JPEG 2000 File not yet taken into account" << std::endl;
index 800975d70a7d3e7736d08cb2062b83ada763a6b5..b747f492c4da4fef46ae364072b3fe5efe31f392 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg8.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/14 22:35:02 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -20,6 +20,8 @@
 extern "C" {
 #include "src/jpeg/libijg8/jconfig.h"
 #include "src/jpeg/libijg8/jpeglib.h"
+#include "src/jpeg/libijg8/jinclude.h"
+#include "src/jpeg/libijg8/jerror.h"
 }
 
 #define gdcm_write_JPEG_file gdcm_write_JPEG_file8
index d89550502970ec5c0faebed340ccac6438943020..e345dceaf92c0c3c539d807a0177ae548b13faf0 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 22:31:52 $
-  Version:   $Revision: 1.17 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.18 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -24,6 +24,7 @@
 
 #include "gdcmDebug.h"
 #include "gdcmPixelConvert.h"
+#include <fstream>
 
 namespace gdcm
 {
@@ -31,18 +32,18 @@ namespace gdcm
 #define str2num(str, typeNum) *((typeNum *)(str))
 
 // For JPEG 2000, body in file gdcmJpeg2000.cxx
-bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* image_buffer);
 
 // For JPEG 8 Bits, body in file gdcmJpeg8.cxx
-bool gdcm_read_JPEG_file8    (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file8    (std::ifstream* fp, void* image_buffer);
 
 // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
-bool gdcm_read_JPEG_file12   (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file12   (std::ifstream* fp, void* image_buffer);
 
 // For JPEG 16 Bits, body in file gdcmJpeg16.cxx
 // Beware this is misleading there is no 16bits DCT algorithm, only
 // jpeg lossless compression exist in 16bits.
-bool gdcm_read_JPEG_file16   (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file16   (std::ifstream* fp, void* image_buffer);
 
 
 //-----------------------------------------------------------------------------
@@ -100,7 +101,7 @@ void PixelConvert::AllocateDecompressed()
  * \brief Read from file a 12 bits per pixel image and decompress it
  *        into a 16 bits per pixel image.
  */
-void PixelConvert::ReadAndDecompress12BitsTo16Bits( FILE* fp )
+void PixelConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream* fp )
                throw ( FormatError )
 {
    int nbPixels = XSize * YSize;
@@ -109,24 +110,23 @@ void PixelConvert::ReadAndDecompress12BitsTo16Bits( FILE* fp )
    for( int p = 0; p < nbPixels; p += 2 )
    {
       uint8_t b0, b1, b2;
-      size_t ItemRead;
-                                                                                
-      ItemRead = fread( &b0, 1, 1, fp );
-      if ( ItemRead != 1 )
+
+      fp->read( (char*)&b0, 1);
+      if ( fp->fail() || fp->eof() )//Fp->gcount() == 1
       {
          throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound first block" );
       }
-                                                                                
-      ItemRead = fread( &b1, 1, 1, fp );
-      if ( ItemRead != 1 )
+
+      fp->read( (char*)&b1, 1 );
+      if ( fp->fail() || fp->eof())//Fp->gcount() == 1
       {
          throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound second block" );
       }
-                                                                                
-      ItemRead = fread( &b2, 1, 1, fp );
-      if ( ItemRead != 1 )
+
+      fp->read( (char*)&b2, 1 );
+      if ( fp->fail() || fp->eof())//Fp->gcount() == 1
       {
          throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
                                 "Unfound second block" );
@@ -199,7 +199,7 @@ bool PixelConvert::DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames )
 bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
                                                  long fragmentSize,
                                                  long decompressedSegmentSize,
-                                                 FILE* fp )
+                                                 std::ifstream* fp )
 {
    int8_t count;
    long numberOfOutputBytes = 0;
@@ -207,7 +207,7 @@ bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
                                                                                 
    while( numberOfOutputBytes < decompressedSegmentSize )
    {
-      fread( &count, 1, 1, fp );
+      fp->read( (char*)&count, 1 );
       numberOfReadBytes += 1;
       if ( count >= 0 )
       // Note: count <= 127 comparison is always true due to limited range
@@ -215,7 +215,7 @@ bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
       //       signed integer of width N is 2^(N-1) - 1, which for int8_t
       //       is 127].
       {
-         fread( subDecompressed, count + 1, 1, fp);
+         fp->read( (char*)subDecompressed, count + 1);
          numberOfReadBytes   += count + 1;
          subDecompressed     += count + 1;
          numberOfOutputBytes += count + 1;
@@ -225,7 +225,7 @@ bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
          if ( ( count <= -1 ) && ( count >= -127 ) )
          {
             int8_t newByte;
-            fread( &newByte, 1, 1, fp);
+            fp->read( (char*)&newByte, 1);
             numberOfReadBytes += 1;
             for( int i = 0; i < -count + 1; i++ )
             {
@@ -254,7 +254,7 @@ bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
  *            at which the pixel data should be copied
  * @return    Boolean
  */
-bool PixelConvert::ReadAndDecompressRLEFile( FILE* fp )
+bool PixelConvert::ReadAndDecompressRLEFile( std::ifstream* fp )
 {
    uint8_t* subDecompressed = Decompressed;
    long decompressedSegmentSize = XSize * YSize;
@@ -268,7 +268,8 @@ bool PixelConvert::ReadAndDecompressRLEFile( FILE* fp )
       // Loop on the fragments
       for( int k = 1; k <= (*it)->NumberFragments; k++ )
       {
-         fseek( fp, (*it)->Offset[k] ,SEEK_SET );
+         //fseek( fp, (*it)->Offset[k] ,SEEK_SET );
+         fp->seekg(  (*it)->Offset[k] , std::ios_base::beg );
          (void)ReadAndDecompressRLEFragment( subDecompressed,
                                              (*it)->Length[k],
                                              decompressedSegmentSize, 
@@ -399,7 +400,7 @@ void PixelConvert::ConvertReorderEndianity()
  * @param     fp File Pointer
  * @return    Boolean
  */
-bool PixelConvert::ReadAndDecompressJPEGFile( FILE* fp )
+bool PixelConvert::ReadAndDecompressJPEGFile( std::ifstream* fp )
 {
    uint8_t* localDecompressed = Decompressed;
    // Loop on the fragment[s]
@@ -408,7 +409,8 @@ bool PixelConvert::ReadAndDecompressJPEGFile( FILE* fp )
         it != JPEGInfo->Fragments.end();
       ++it )
    {
-      fseek( fp, (*it)->Offset, SEEK_SET );
+      //fseek( fp, (*it)->Offset, SEEK_SET );
+      fp->seekg( (*it)->Offset, std::ios_base::beg);
 
       if ( IsJPEG2000 )
       {
@@ -580,7 +582,7 @@ void PixelConvert::ConvertRGBPlanesToRGBPixels()
    delete[] copyDecompressed;
 }
 
-bool PixelConvert::ReadAndDecompressPixelData( FILE* fp )
+bool PixelConvert::ReadAndDecompressPixelData( std::ifstream* fp )
 {
    ComputeDecompressedAndRGBSizes();
    AllocateDecompressed();
@@ -593,7 +595,9 @@ bool PixelConvert::ReadAndDecompressPixelData( FILE* fp )
       return false;
    }
                                                                                 
-   if ( fseek( fp, PixelOffset, SEEK_SET ) == -1 )
+   //if ( fseek( fp, PixelOffset, SEEK_SET ) == -1 )
+   fp->seekg( PixelOffset, std::ios_base::beg );
+   if( fp->fail() || fp->eof()) //Fp->gcount() == 1
    {
      dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
                      "unable to find PixelOffset in file." );
@@ -608,8 +612,8 @@ bool PixelConvert::ReadAndDecompressPixelData( FILE* fp )
    }
    else if ( IsDecompressed )
    {
-      size_t ItemRead = fread( Decompressed, PixelDataLength, 1, fp );
-      if ( ItemRead != 1 )
+      fp->read( (char*)Decompressed, PixelDataLength);
+      if ( fp->fail() | |fp->eof())//Fp->gcount() == 1
       {
          dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
                          "reading of decompressed pixel data failed." );
@@ -748,7 +752,7 @@ void PixelConvert::GrabInformationsFromHeader( Header* header )
 {
    // Just in case some access to a Header element requires disk access.
    // Note: gdcmDocument::Fp is leaved open after OpenFile.
-   FILE* fp = header->OpenFile();
+  std::ifstream* fp = header->OpenFile();
    // Number of Bits Allocated for storing a Pixel is defaulted to 16
    // when absent from the header.
    BitsAllocated = header->GetBitsAllocated();
@@ -829,11 +833,11 @@ void PixelConvert::GrabInformationsFromHeader( Header* header )
          DocEntry* lutRedDataEntry = header->GetDocEntryByNumber( 0x0028,
                                                                   0x1201 );
          LutRedData = new uint8_t[ lutRedDataEntry->GetLength() ];
-         fseek( fp, lutRedDataEntry->GetOffset() ,SEEK_SET );
-         int numberItem = fread( LutRedData,
-                                 (size_t)lutRedDataEntry->GetLength(),
-                                 1, fp );
-         if ( numberItem != 1 )
+         //fseek( fp, lutRedDataEntry->GetOffset() ,SEEK_SET );
+         fp->seekg(  lutRedDataEntry->GetOffset() ,std::ios_base::beg );
+          fp->read( (char*)LutRedData, (size_t)lutRedDataEntry->GetLength());
+        //if ( numberItem != 1 )
+        if ( fp->fail() || fp->eof())//Fp->gcount() == 1
          {
             dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
                             "unable to read red LUT data" );
@@ -849,11 +853,11 @@ void PixelConvert::GrabInformationsFromHeader( Header* header )
          DocEntry* lutGreenDataEntry = header->GetDocEntryByNumber( 0x0028,
                                                                     0x1202 );
          LutGreenData = new uint8_t[ lutGreenDataEntry->GetLength() ];
-         fseek( fp, lutGreenDataEntry->GetOffset() ,SEEK_SET );
-         int numberItem = fread( LutGreenData,
-                                 (size_t)lutGreenDataEntry->GetLength(),
-                                 1, fp );
-         if ( numberItem != 1 )
+         //fseek( fp, lutGreenDataEntry->GetOffset() ,SEEK_SET );
+         fp->seekg( lutGreenDataEntry->GetOffset() , std::ios_base::beg );
+          fp->read( (char*)LutGreenData, (size_t)lutGreenDataEntry->GetLength() );
+        //if ( numberItem != 1 )
+        if ( fp->fail() || fp->eof())//Fp->gcount() == 1
          {
             dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
                            "unable to read green LUT data" );
@@ -869,11 +873,11 @@ void PixelConvert::GrabInformationsFromHeader( Header* header )
          DocEntry* lutBlueDataEntry  = header->GetDocEntryByNumber( 0x0028,
                                                                     0x1203 );
          LutBlueData = new uint8_t[ lutBlueDataEntry->GetLength() ];
-         fseek( fp, lutBlueDataEntry->GetOffset() ,SEEK_SET );
-         int numberItem = fread( LutBlueData,
-                                 (size_t)lutBlueDataEntry->GetLength(),
-                                 1, fp );
-         if ( numberItem != 1 )
+         //fseek( fp, lutBlueDataEntry->GetOffset() ,SEEK_SET );
+         fp->seekg(  lutBlueDataEntry->GetOffset() , std::ios_base::beg );
+         fp->read( (char*)LutBlueData, (size_t)lutBlueDataEntry->GetLength() );
+        //if ( numberItem != 1 )
+        if ( fp->fail() || fp->eof())//Fp->gcount() == 1
          {
             dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
                            "unable to read blue LUT data" );
index 4de455554c33c9fe98cbb020ced6ddd77817050c..13c20822786a9b60437855b6e0b1f9413d6cde6a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelConvert.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 22:31:52 $
-  Version:   $Revision: 1.12 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.13 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -52,7 +52,7 @@ public:
 
 // In progress
    void GrabInformationsFromHeader( Header* header );
-   bool ReadAndDecompressPixelData( FILE* fp );
+   bool ReadAndDecompressPixelData( std::ifstream* fp );
    void Squeeze();
    bool BuildRGBImage();
 
@@ -62,10 +62,11 @@ private:
                   uint8_t* subDecompressed,
                   long fragmentSize,
                   long decompressedSegmentSize,
-                  FILE* fp );
-   void ReadAndDecompress12BitsTo16Bits( FILE* fp ) throw ( FormatError );
-   bool ReadAndDecompressRLEFile( FILE* fp );
-   bool ReadAndDecompressJPEGFile( FILE* fp );
+                  std::ifstream* fp );
+   void ReadAndDecompress12BitsTo16Bits( std::ifstream* fp ) throw ( FormatError );
+   bool ReadAndDecompressRLEFile( std::ifstream* fp );
+   bool ReadAndDecompressJPEGFile( std::ifstream* fp );
+   void BuildLUTRGBA( std::ifstream* fp );
 
    // In place (within Decompressed and with no fp access) decompression
    // or convertion:
index ac3442dde84108873911b72407a18fac2171a06b..2c7bcd796c8ab763f1b23fa3285e356017bbf77a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:47 $
-  Version:   $Revision: 1.29 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.30 $
   
   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,7 @@
 #include "gdcmGlobal.h"
 #include "gdcmUtil.h"
 #include "gdcmDebug.h"
+#include <fstream>
 
 namespace gdcm 
 {
@@ -96,14 +97,14 @@ SQItem::~SQItem()
  * \ingroup SQItem
  * \brief   canonical Writer
  */
-void SQItem::Write(FILE* fp,FileType filetype)
+void SQItem::Write(std::ofstream* fp,FileType filetype)
 {
    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
-   fwrite(&item[0],8,1,fp);  // fffe e000 ffff ffff 
+   fp->write((char*)&item[0],8);  // fffe e000 ffff ffff 
      
    for (ListDocEntry::iterator i = docEntries.begin();  
         i != docEntries.end();
@@ -129,7 +130,7 @@ void SQItem::Write(FILE* fp,FileType filetype)
       
     //we force the writting of an 'Item Delimitation' item
     // because we wrote the Item as a 'no Length' item
-   fwrite(&itemt[0],8,1,fp);  // fffe e000 ffff ffff 
+   fp->write((char*)&itemt[0],8);  // fffe e000 ffff ffff 
 
 }
 
index 8d2b585b353c8a292de99be75385f4a82c834704..0f42e54b1d717ad097285e3ac99d335d2013be49 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:47 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  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
@@ -43,7 +43,7 @@ public:
    ~SQItem();
 
    virtual void Print(std::ostream &os = std::cout); 
-   virtual void Write(FILE *fp, FileType filetype);
+   virtual void Write(std::ofstream *fp, FileType filetype);
 
    /// \brief   returns the DocEntry chained List for this SQ Item.
    ListDocEntry &GetDocEntries() { return docEntries; };
index 41b2b30afe7926141938e472f319ea0ffe047479..bb5135594c4b8713fe6ba08cc7d086bfaadb274f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:48 $
-  Version:   $Revision: 1.31 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  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
@@ -24,6 +24,7 @@
 
 #include <iostream>
 #include <iomanip>
+#include <fstream>
 
 namespace gdcm 
 {
@@ -114,7 +115,7 @@ void SeqEntry::Print( std::ostream &os )
 /*
  * \brief   canonical Writer
  */
-void SeqEntry::Write(FILE* fp, FileType filetype)
+void SeqEntry::Write(std::ofstream* fp, FileType filetype)
 {
    uint16_t seq_term_gr = 0xfffe;
    uint16_t seq_term_el = 0xe0dd;
@@ -133,9 +134,9 @@ void SeqEntry::Write(FILE* fp, FileType filetype)
    
    // we force the writting of a Sequence Delimitation item
    // because we wrote the Sequence as a 'no Length' sequence
-   fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
-   fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
-   fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp); 
+   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 );
 }
 
 //-----------------------------------------------------------------------------
index 0358bf0db9b9e7b3cc4df62e6e007694ab2fec4f..fd016fe0509b284cc039c695545613deb5ef653f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:48 $
-  Version:   $Revision: 1.20 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.21 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@ public:
    virtual ~SeqEntry();
    
    virtual void Print(std::ostream &os = std::cout); 
-   virtual void Write(FILE *fp, FileType);
+   virtual void Write(std::ofstream *fp, FileType);
 
    /// returns the SQITEM chained List for this SeQuence.
    ListSQItem &GetSQItems() { return items; }
index aaf16de4d076b6fd718fe6352df86048d173a7f6..9f337bdea15fef6f9fd84aaef8bdbbfaeb3872ce 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:48 $
-  Version:   $Revision: 1.30 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.31 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -21,6 +21,8 @@
 #include "gdcmGlobal.h"
 #include "gdcmUtil.h"
 
+#include <fstream>
+
 namespace gdcm 
 {
 
@@ -174,7 +176,7 @@ void ValEntry::Print(std::ostream & os)
 /*
  * \brief   canonical Writer
  */
-void ValEntry::Write(FILE* fp, FileType filetype)
+void ValEntry::Write(std::ofstream* fp, FileType filetype)
 {
    DocEntry::Write(fp, filetype);
 
@@ -199,7 +201,7 @@ void ValEntry::Write(FILE* fp, FileType filetype)
       {
          uint16_t val_uint16 = atoi(tokens[i].c_str());
          void* ptr = &val_uint16;
-         fwrite ( ptr,(size_t)2 ,(size_t)1 ,fp);
+         fp->write ( (char*)ptr,(size_t)2);
       }
       tokens.clear();
       return;
@@ -217,13 +219,13 @@ void ValEntry::Write(FILE* fp, FileType filetype)
       {
          uint32_t val_uint32 = atoi(tokens[i].c_str());
          void* ptr = &val_uint32;
-         fwrite ( ptr,(size_t)4 ,(size_t)1 ,fp);
+         fp->write ( (char*)ptr,(size_t)4 );
       }
       tokens.clear();
       return;
    } 
           
-   fwrite (GetValue().c_str(), (size_t)lgr ,(size_t)1, fp); // Elem value
+   fp->write (GetValue().c_str(), (size_t)lgr ); // Elem value
 } 
 
 //-----------------------------------------------------------------------------
index 76f122b7b72f9ae2394cfc2ae8bb8b43c6b76115..653abadf6e43661df830d6d8f2d7a73120cc273f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/10/12 04:35:48 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2004/10/22 03:05:42 $
+  Version:   $Revision: 1.27 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -46,7 +46,7 @@ public:
    void SetValue(std::string const & val) { Value = val; };
 
    virtual void Print(std::ostream &os = std::cout); 
-   virtual void Write(FILE *fp, FileType filetype);
+   virtual void Write(std::ofstream *fp, FileType filetype);
 
 protected:
    
diff --git a/src/jdatadst.cxx b/src/jdatadst.cxx
new file mode 100644 (file)
index 0000000..3b85057
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * jdatadst.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains compression data destination routines for the case of
+ * emitting JPEG data to a file (or any stdio stream).  While these routines
+ * are sufficient for most applications, some will want to use a different
+ * destination manager.
+ * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
+ * JOCTETs into 8-bit-wide elements on external storage.  If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+
+
+/* Expanded data destination object for stdio output */
+
+typedef struct {
+  struct jpeg_destination_mgr pub; /* public fields */
+
+  std::ofstream * outfile; /* target stream */ 
+  JOCTET * buffer;         /* start of buffer */
+} my_destination_mgr;
+
+typedef my_destination_mgr * my_dest_ptr;
+
+#define OUTPUT_BUF_SIZE  4096  /* choose an efficiently fwrite'able size */
+
+
+/*
+ * Initialize destination --- called by jpeg_start_compress
+ * before any data is actually written.
+ */
+
+METHODDEF(void)
+init_destination (j_compress_ptr cinfo)
+{
+  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+  /* Allocate the output buffer --- it will be released when done with image */
+  dest->buffer = (JOCTET *)
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+          OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
+
+  dest->pub.next_output_byte = dest->buffer;
+  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+}
+
+
+/*
+ * Empty the output buffer --- called whenever buffer fills up.
+ *
+ * In typical applications, this should write the entire output buffer
+ * (ignoring the current state of next_output_byte & free_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been dumped.
+ *
+ * In applications that need to be able to suspend compression due to output
+ * overrun, a FALSE return indicates that the buffer cannot be emptied now.
+ * In this situation, the compressor will return to its caller (possibly with
+ * an indication that it has not accepted all the supplied scanlines).  The
+ * application should resume compression after it has made more room in the
+ * output buffer.  Note that there are substantial restrictions on the use of
+ * suspension --- see the documentation.
+ *
+ * When suspending, the compressor will back up to a convenient restart point
+ * (typically the start of the current MCU). next_output_byte & free_in_buffer
+ * indicate where the restart point will be if the current call returns FALSE.
+ * Data beyond this point will be regenerated after resumption, so do not
+ * write it out when emptying the buffer externally.
+ */
+
+METHODDEF(boolean)
+empty_output_buffer (j_compress_ptr cinfo)
+{
+  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+#if 0
+  if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
+      (size_t) OUTPUT_BUF_SIZE)
+    ERREXIT(cinfo, JERR_FILE_WRITE);
+#else
+  dest->outfile->write((char*)dest->buffer, OUTPUT_BUF_SIZE);
+  if( dest->outfile->fail() )
+    ERREXIT(cinfo, JERR_FILE_WRITE);
+#endif
+
+  dest->pub.next_output_byte = dest->buffer;
+  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+
+  return TRUE;
+}
+
+
+/*
+ * Terminate destination --- called by jpeg_finish_compress
+ * after all data has been written.  Usually needs to flush buffer.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_destination (j_compress_ptr cinfo)
+{
+  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
+
+  /* Write any data remaining in the buffer */
+#if 0
+  if (datacount > 0) {
+    if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
+      ERREXIT(cinfo, JERR_FILE_WRITE);
+  }
+  fflush(dest->outfile);
+  /* Make sure we wrote the output file OK */
+  if (ferror(dest->outfile))
+    ERREXIT(cinfo, JERR_FILE_WRITE);
+#else
+  if (datacount > 0) {
+    dest->outfile->write((char*)dest->buffer, datacount);
+    if (dest->outfile->fail())
+      ERREXIT(cinfo, JERR_FILE_WRITE);
+    dest->outfile->flush();
+    /* Make sure we wrote the output file OK */
+    if (dest->outfile->fail())
+      ERREXIT(cinfo, JERR_FILE_WRITE);
+  }
+#endif
+}
+
+
+/*
+ * Prepare for output to a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing compression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_dest (j_compress_ptr cinfo, std::ofstream * outfile)
+{
+  my_dest_ptr dest;
+
+  /* The destination object is made permanent so that multiple JPEG images
+   * can be written to the same file without re-executing jpeg_stdio_dest.
+   * This makes it dangerous to use this manager and a different destination
+   * manager serially with the same JPEG object, because their private object
+   * sizes may be different.  Caveat programmer.
+   */
+  if (cinfo->dest == NULL) {  /* first time for this JPEG object? */
+    cinfo->dest = (struct jpeg_destination_mgr *)
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+          SIZEOF(my_destination_mgr));
+  }
+
+  dest = (my_dest_ptr) cinfo->dest;
+  dest->pub.init_destination = init_destination;
+  dest->pub.empty_output_buffer = empty_output_buffer;
+  dest->pub.term_destination = term_destination;
+  dest->outfile = outfile;
+}
diff --git a/src/jdatasrc.cxx b/src/jdatasrc.cxx
new file mode 100644 (file)
index 0000000..e6c6443
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * jdatasrc.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains decompression data source routines for the case of
+ * reading JPEG data from a file (or any stdio stream).  While these routines
+ * are sufficient for most applications, some will want to use a different
+ * source manager.
+ * IMPORTANT: we assume that fread() will correctly transcribe an array of
+ * JOCTETs from 8-bit-wide elements on external storage.  If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+
+/* Expanded data source object for stdio input */
+
+typedef struct {
+  struct jpeg_source_mgr pub;  /* public fields */
+
+  std::ifstream *infile;  /* source stream */ 
+  JOCTET * buffer;        /* start of buffer */
+  boolean start_of_file;  /* have we gotten any data yet? */
+} my_source_mgr;
+
+typedef my_source_mgr * my_src_ptr;
+
+#define INPUT_BUF_SIZE  4096  /* choose an efficiently fread'able size */
+
+
+/*
+ * Initialize source --- called by jpeg_read_header
+ * before any data is actually read.
+ */
+
+METHODDEF(void)
+init_source (j_decompress_ptr cinfo)
+{
+  my_src_ptr src = (my_src_ptr) cinfo->src;
+
+  /* We reset the empty-input-file flag for each image,
+   * but we don't clear the input buffer.
+   * This is correct behavior for reading a series of images from one source.
+   */
+  src->start_of_file = TRUE;
+}
+
+
+/*
+ * Fill the input buffer --- called whenever buffer is emptied.
+ *
+ * In typical applications, this should read fresh data into the buffer
+ * (ignoring the current state of next_input_byte & bytes_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been reloaded.  It is not necessary to
+ * fill the buffer entirely, only to obtain at least one more byte.
+ *
+ * There is no such thing as an EOF return.  If the end of the file has been
+ * reached, the routine has a choice of ERREXIT() or inserting fake data into
+ * the buffer.  In most cases, generating a warning message and inserting a
+ * fake EOI marker is the best course of action --- this will allow the
+ * decompressor to output however much of the image is there.  However,
+ * the resulting error message is misleading if the real problem is an empty
+ * input file, so we handle that case specially.
+ *
+ * In applications that need to be able to suspend compression due to input
+ * not being available yet, a FALSE return indicates that no more data can be
+ * obtained right now, but more may be forthcoming later.  In this situation,
+ * the decompressor will return to its caller (with an indication of the
+ * number of scanlines it has read, if any).  The application should resume
+ * decompression after it has loaded more data into the input buffer.  Note
+ * that there are substantial restrictions on the use of suspension --- see
+ * the documentation.
+ *
+ * When suspending, the decompressor will back up to a convenient restart point
+ * (typically the start of the current MCU). next_input_byte & bytes_in_buffer
+ * indicate where the restart point will be if the current call returns FALSE.
+ * Data beyond this point must be rescanned after resumption, so move it to
+ * the front of the buffer rather than discarding it.
+ */
+
+METHODDEF(boolean)
+fill_input_buffer (j_decompress_ptr cinfo)
+{
+  my_src_ptr src = (my_src_ptr) cinfo->src;
+
+  src->infile->read( (char*)src->buffer, INPUT_BUF_SIZE);
+  size_t nbytes = src->infile->gcount();
+
+  if (nbytes <= 0) {
+    if (src->start_of_file)  /* Treat empty input file as fatal error */
+      ERREXIT(cinfo, JERR_INPUT_EMPTY);
+    WARNMS(cinfo, JWRN_JPEG_EOF);
+    /* Insert a fake EOI marker */
+    src->buffer[0] = (JOCTET) 0xFF;
+    src->buffer[1] = (JOCTET) JPEG_EOI;
+    nbytes = 2;
+  }
+
+  src->pub.next_input_byte = src->buffer;
+  src->pub.bytes_in_buffer = nbytes;
+  src->start_of_file = FALSE;
+
+  return TRUE;
+}
+
+
+/*
+ * Skip data --- used to skip over a potentially large amount of
+ * uninteresting data (such as an APPn marker).
+ *
+ * Writers of suspendable-input applications must note that skip_input_data
+ * is not granted the right to give a suspension return.  If the skip extends
+ * beyond the data currently in the buffer, the buffer can be marked empty so
+ * that the next read will cause a fill_input_buffer call that can suspend.
+ * Arranging for additional bytes to be discarded before reloading the input
+ * buffer is the application writer's problem.
+ */
+
+METHODDEF(void)
+skip_input_data (j_decompress_ptr cinfo, long num_bytes)
+{
+  my_src_ptr src = (my_src_ptr) cinfo->src;
+
+  /* Just a dumb implementation for now.  Could use fseek() except
+   * it doesn't work on pipes.  Not clear that being smart is worth
+   * any trouble anyway --- large skips are infrequent.
+   */
+  if (num_bytes > 0) {
+    while (num_bytes > (long) src->pub.bytes_in_buffer) {
+      num_bytes -= (long) src->pub.bytes_in_buffer;
+      (void) fill_input_buffer(cinfo);
+      /* note we assume that fill_input_buffer will never return FALSE,
+       * so suspension need not be handled.
+       */
+    }
+    src->pub.next_input_byte += (size_t) num_bytes;
+    src->pub.bytes_in_buffer -= (size_t) num_bytes;
+  }
+}
+
+
+/*
+ * An additional method that can be provided by data source modules is the
+ * resync_to_restart method for error recovery in the presence of RST markers.
+ * For the moment, this source module just uses the default resync method
+ * provided by the JPEG library.  That method assumes that no backtracking
+ * is possible.
+ */
+
+
+/*
+ * Terminate source --- called by jpeg_finish_decompress
+ * after all data has been read.  Often a no-op.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_source (j_decompress_ptr cinfo)
+{
+  cinfo=cinfo;
+  /* no work necessary here */
+}
+
+
+/*
+ * Prepare for input from a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing decompression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_src (j_decompress_ptr cinfo, std::ifstream * infile)
+{
+  my_src_ptr src;
+
+  /* The source object and input buffer are made permanent so that a series
+   * of JPEG images can be read from the same file by calling jpeg_stdio_src
+   * only before the first one.  (If we discarded the buffer at the end of
+   * one image, we'd likely lose the start of the next one.)
+   * This makes it unsafe to use this manager and a different source
+   * manager serially with the same JPEG object.  Caveat programmer.
+   */
+  if (cinfo->src == NULL) {  /* first time for this JPEG object? */
+    cinfo->src = (struct jpeg_source_mgr *)
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+          SIZEOF(my_source_mgr));
+    src = (my_src_ptr) cinfo->src;
+    src->buffer = (JOCTET *)
+      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+          INPUT_BUF_SIZE * SIZEOF(JOCTET));
+  }
+
+  src = (my_src_ptr) cinfo->src;
+  src->pub.init_source = init_source;
+  src->pub.fill_input_buffer = fill_input_buffer;
+  src->pub.skip_input_data = skip_input_data;
+  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
+  src->pub.term_source = term_source;
+  src->infile = infile;
+  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+  src->pub.next_input_byte = NULL; /* until buffer loaded */
+}
index 605b7b713beeab9c82418c7d3fdda75092cac52a..678534d2d584cab132f357e5f5a2cdd305d8d9b5 100644 (file)
@@ -16,11 +16,11 @@ jcomapi.c jutils.c jerror.c jmemmgr.c
 
 # compression library object files
 SET(compression_SRCS
-jcapimin.c jcapistd.c jctrans.c jcparam.c jdatadst.c jcinit.c
+jcapimin.c jcapistd.c jctrans.c jcparam.c  jcinit.c
 jcmaster.c jcmarker.c jcmainct.c jcprepct.c jccoefct.c jccolor.c
 jcsample.c jchuff.c jcphuff.c jcdctmgr.c jfdctfst.c jfdctflt.c
 )
-
+#jdatadst.c
 # Lossy (DCT) codec:
 SET(comp_lossy_SRCS
 jfdctint.c
@@ -40,10 +40,11 @@ jcdiffct.c
 
 # decompression library object files
 SET(decompression_SRCS
-jdapimin.c jdapistd.c jdtrans.c jdatasrc.c jdmaster.c
+jdapimin.c jdapistd.c jdtrans.c  jdmaster.c
 jdinput.c jdmarker.c jdhuff.c jdphuff.c jdmainct.c jdcoefct.c
 jdpostct.c jddctmgr.c jidctfst.c jidctflt.c jidctint.c jidctred.c
-jdsample.c jdcolor.c jquant1.c jquant2.c jdmerge.c)
+jdsample.c jdcolor.c jquant1.c jquant2.c jdmerge.c
+) #jdatasrc.c
 
 SET(decomp_lossy_SRCS
  jdlossls.c jdlossy.c
index 5d554f373c6782b53840aa572b27221ef008fb80..38683c398e596570c14a1ac0b82d319ab8a0d3c7 100644 (file)
@@ -85,7 +85,7 @@
  * CAUTION: argument order is different from underlying functions!
  */
 
-#define JFREAD(file,buf,sizeofbuf)  \
+/*#define JFREAD(file,buf,sizeofbuf)  \
   ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
 #define JFWRITE(file,buf,sizeofbuf)  \
-  ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
+  ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))*/