]> Creatis software - gdcm.git/blobdiff - src/gdcmJPEGFragment.cxx
Fix mistypings
[gdcm.git] / src / gdcmJPEGFragment.cxx
index 9b5733b5fc65b3b3f0affddaf5ea3459fe67c205..3a50c996bbceac1474a271afba6cc4c04b95a17d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragment.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/18 14:28:32 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2008/01/02 10:48:52 $
+  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
 #include "gdcmJPEGFragment.h"
 #include "gdcmDebug.h"
 
-namespace gdcm
+namespace GDCM_NAME_SPACE
 {
-
+//-------------------------------------------------------------------------
 // For JPEG 2000, body in file gdcmJpeg2000.cxx
-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 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory8    (const JOCTET *buffer, const size_t buflen, 
-                                void *image_buffer,
-                                size_t *howManyRead, size_t *howManyWritten);
-//
-// For JPEG 12 Bits, body in file gdcmJpeg12.cxx
-bool gdcm_read_JPEG_file12 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory12   (const JOCTET *buffer, const size_t buflen, 
-                                void *image_buffer,
-                                size_t *howManyRead, size_t *howManyWritten);
+// Not yet made
+bool gdcm_read_JPEG2000_file (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 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory16   (const JOCTET *buffer, const size_t buflen, 
-                                void* image_buffer,
-                                size_t *howManyRead, size_t *howManyWritten);
+// For JPEG-LS, body in file gdcmJpegLS.cxx
+// Not yet made
+bool gdcm_read_JPEGLS_file (std::ifstream *fp, void *image_buffer);
 
+//-------------------------------------------------------------------------
+// Constructor / Destructor
 /**
  * \brief Default constructor.
  */
@@ -52,157 +39,78 @@ JPEGFragment::JPEGFragment()
 {
    Offset = 0;
    Length = 0;
-}
 
-/**
- * \brief        Print self.
- * @param os     Stream to print to.
- * @param indent Indentation string to be prepended during printing.
- */
-void JPEGFragment::Print( std::ostream &os, std::string indent )
-{
-   os << indent
-      << "JPEG fragment: offset : " <<  Offset
-      << "   length : " <<  Length
-      << std::endl;
+   pImage = 0;
+
 }
 
+//-----------------------------------------------------------------------------
+// Public
 /**
  * \brief Decompress 8bits JPEG Fragment
  * @param fp ifstream to write to
  * @param buffer     output (data decompress)
  * @param nBits      8/12 or 16 bits jpeg
+ * @param statesuspension state suspension
  */
-void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits)
+void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp,
+                                                uint8_t *buffer, int nBits, 
+                                                int &statesuspension)
 {
    // First thing need to reset file to proper position:
    fp->seekg( Offset, std::ios::beg);
 
    if ( nBits == 8 )
    {
-      // JPEG Lossy : call to IJG 6b
-      if ( ! gdcm_read_JPEG_file8( fp, buffer) )
-      {
-         //return false;
-      }
+      // JPEG Lossy : call to IJG 6b - 8 bits
+      ReadJPEGFile8( fp, buffer, statesuspension);
    }
    else if ( nBits <= 12 )
    {
-      // Reading Fragment pixels
-      if ( ! gdcm_read_JPEG_file12 ( fp, buffer) )
-      {
-         //return false;
-      }
+       assert( nBits >= 8 );
+      // JPEG Lossy : call to IJG 6b - 12 bits
+      ReadJPEGFile12 ( fp, buffer, statesuspension);
    }
    else if ( nBits <= 16 )
    {
-      // Reading Fragment pixels
-      if ( ! gdcm_read_JPEG_file16 ( fp, buffer) )
-      {
-         //return false;
-      }
+       assert( nBits >= 12 );
+      // JPEG Lossy : call to IJG 6b - 16 bits
+      ReadJPEGFile16 ( fp, buffer, statesuspension);
       //gdcmAssertMacro( IsJPEGLossless );
    }
    else
    {
+      // FIXME : only the bits number is checked,
+      //         NOT the compression method
+
       // other JPEG lossy not supported
       gdcmErrorMacro( "Unknown jpeg lossy compression ");
-      //return false;
    }
-
 }
 
-void JPEGFragment::DecompressJPEGSingleFrameFragmentsFromFile(JOCTET *buffer, size_t totalLength, uint8_t* raw, int nBits)
-{
-   size_t howManyRead = 0;
-   size_t howManyWritten = 0;
-   
-   if ( nBits == 8)
-   {
-      if ( ! gdcm_read_JPEG_memory8( buffer, totalLength, raw,
-                                     &howManyRead, &howManyWritten ) ) 
-      {
-         gdcmErrorMacro( "Failed to read jpeg8 ");
-         delete [] buffer;
-         //return false;
-      }
-   }
-   else if ( nBits <= 12)
-   {
-      if ( ! gdcm_read_JPEG_memory12( buffer, totalLength, raw,
-                                      &howManyRead, &howManyWritten ) ) 
-      {
-         gdcmErrorMacro( "Failed to read jpeg12 ");
-            delete [] buffer;
-            //return false;
-      }
-   }
-   else if ( nBits <= 16)
-   {
-      
-      if ( ! gdcm_read_JPEG_memory16( buffer, totalLength, raw,
-                                      &howManyRead, &howManyWritten ) ) 
-      {
-         gdcmErrorMacro( "Failed to read jpeg16 ");
-         delete [] buffer;
-         //return false;
-      }
-   }
-   else
-   {
-      // other JPEG lossy not supported
-      gdcmErrorMacro( "Unsupported jpeg lossy compression ");
-      delete [] buffer;
-      //return false;
-   }      
+//-----------------------------------------------------------------------------
+// Protected
 
-}
+//-----------------------------------------------------------------------------
+// Private
 
-void JPEGFragment::DecompressJPEGFragmentedFramesFromFile(JOCTET *buffer, uint8_t* raw, int nBits, size_t &howManyRead, size_t &howManyWritten, size_t totalLength)
+//-----------------------------------------------------------------------------
+// Print
+/**
+ * \brief        Print self.
+ * @param os     Stream to print to.
+ * @param indent Indentation string to be prepended during printing.
+ */
+void JPEGFragment::Print( std::ostream &os, std::string const &indent )
 {
-   if ( nBits == 8 )
-   {
-     if ( ! gdcm_read_JPEG_memory8( buffer+howManyRead, totalLength-howManyRead,
-                                  raw+howManyWritten,
-                                  &howManyRead, &howManyWritten ) ) 
-       {
-         gdcmErrorMacro( "Failed to read jpeg8");
-         //delete [] buffer;
-         //return false;
-       }
-   }
-   else if ( nBits <= 12 )
-   {
-   
-     if ( ! gdcm_read_JPEG_memory12( buffer+howManyRead, totalLength-howManyRead,
-                                   raw+howManyWritten,
-                                   &howManyRead, &howManyWritten ) ) 
-       {
-         gdcmErrorMacro( "Failed to read jpeg12");
-         //delete [] buffer;
-         //return false;
-      }
-   }
-   else if ( nBits <= 16 )
-   {
-   
-     if ( ! gdcm_read_JPEG_memory16( buffer+howManyRead, totalLength-howManyRead,
-                                   raw+howManyWritten,
-                                   &howManyRead, &howManyWritten ) ) 
-       {
-         gdcmErrorMacro( "Failed to read jpeg16 ");
-         //delete [] buffer;
-         //return false;
-       }
-   }
-   else
-   {
-      // other JPEG lossy not supported
-      gdcmErrorMacro( "Unsupported jpeg lossy compression ");
-      //delete [] buffer;
-      //return false;
-   }
+   os << indent
+      << "JPEG fragment: offset : " <<  std::dec << Offset 
+      << " 0x(" << std::hex << Offset << ") "
+      << std::dec << "   length : " <<  Length
+      << " 0x(" << std::hex << Length << ") "      
+      << std::endl;
 }
 
+//-----------------------------------------------------------------------------
 } // end namespace gdcm