]> Creatis software - gdcm.git/blobdiff - src/gdcmJPEGFragment.cxx
ENH: Huge commit to remove the previous implementation for jpeg/fragments/multiframes...
[gdcm.git] / src / gdcmJPEGFragment.cxx
index 621134002588133871f51e8039581f1426c29c12..65b9e3934194c56ba32ba301bef8559ba4f53116 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJPEGFragment.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/10/20 14:31:44 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2005/01/31 03:22:25 $
+  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
 =========================================================================*/
                                                                                 
 #include "gdcmJPEGFragment.h"
-                                                                                
+#include "gdcmDebug.h"
+
 namespace gdcm
 {
 
+// For JPEG 2000, body in file gdcmJpeg2000.cxx
+// Not yet made
+bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* image_buffer);
+
+// For JPEG-LS, body in file gdcmJpegLS.cxx
+// Not yet made
+bool gdcm_read_JPEGLS_file (std::ifstream* fp, void* image_buffer);
+
 /**
  * \brief Default constructor.
  */
@@ -28,14 +37,19 @@ JPEGFragment::JPEGFragment()
 {
    Offset = 0;
    Length = 0;
+
+//   StateSuspension = 0;
+//   void *SampBuffer;
+   pImage = 0;
+
 }
 
 /**
  * \brief        Print self.
- * @param indent Indentation string to be prepended during printing.
  * @param os     Stream to print to.
+ * @param indent Indentation string to be prepended during printing.
  */
-void JPEGFragment::Print( std::string indent, std::ostream &os )
+void JPEGFragment::Print( std::ostream &os, std::string indent )
 {
    os << indent
       << "JPEG fragment: offset : " <<  Offset
@@ -43,5 +57,56 @@ void JPEGFragment::Print( std::string indent, std::ostream &os )
       << std::endl;
 }
 
+/**
+ * \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, 
+                                                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 ( ! this->gdcm_read_JPEG_file8( fp, buffer, statesuspension) )
+      {
+         //return false;
+      }
+   }
+   else if ( nBits <= 12 )
+   {
+      // Reading Fragment pixels
+      if ( ! this->gdcm_read_JPEG_file12 ( fp, buffer, statesuspension) )
+      {
+         //return false;
+      }
+   }
+   else if ( nBits <= 16 )
+   {
+      // Reading Fragment pixels
+      if ( ! this->gdcm_read_JPEG_file16 ( fp, buffer, statesuspension) )
+      {
+         //return false;
+      }
+      //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;
+   }
+
+}
+
 } // end namespace gdcm