]> Creatis software - gdcm.git/commitdiff
ENH: Adding support for multiple fragments of jpeg2000... this is SO ugly...
authormalaterre <malaterre>
Mon, 30 May 2005 01:30:39 +0000 (01:30 +0000)
committermalaterre <malaterre>
Mon, 30 May 2005 01:30:39 +0000 (01:30 +0000)
src/gdcmJpeg2000.cxx
src/gdcmPixelReadConvert.cxx
src/gdcmPixelReadConvert.h

index aa73b48a93344f32642e75e6ac345877e1f2b0a4..74f83d205500692bf8d32ca825067acfd1b438ae 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmJpeg2000.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/05/22 18:38:52 $
-  Version:   $Revision: 1.20 $
+  Date:      $Date: 2005/05/30 01:30:39 $
+  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
@@ -34,15 +34,11 @@ namespace gdcm
  * @warning : not yet made
  */
 
-bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* raw, size_t inputlength)
+bool gdcm_read_JPEG2000_file (void* raw, char *inputdata, size_t inputlength)
 {
   jas_init(); //important...
-  // FIXME this is really ugly but it seems I have to load the complete
-  // jpeg2000 stream to use jasper:
-  uint8_t *inputdata = new uint8_t[inputlength];
-  //fp is already 'seek' to proper pos
-  fp->read((char*)inputdata, inputlength);
-  jas_stream_t *jasStream = jas_stream_memopen((char *)inputdata, inputlength);
+  jas_stream_t *jasStream = 
+    jas_stream_memopen((char *)inputdata, inputlength);
     
   int fmtid;
   if ((fmtid = jas_image_getfmt(jasStream)) < 0) 
index 66d41820237be7a95129a27023d397562e14ffb4..d30ba99576c2a1bfd0cd38c19768f91af0835858 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/05/30 00:24:10 $
-  Version:   $Revision: 1.62 $
+  Date:      $Date: 2005/05/30 01:30:39 $
+  Version:   $Revision: 1.63 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
                                                                                 
 =========================================================================*/
 
+#include "gdcmPixelReadConvert.h"
 #include "gdcmDebug.h"
 #include "gdcmFile.h"
 #include "gdcmGlobal.h"
 #include "gdcmTS.h"
-#include "gdcmPixelReadConvert.h"
 #include "gdcmDocEntry.h"
 #include "gdcmRLEFramesInfo.h"
 #include "gdcmJPEGFragmentsInfo.h"
@@ -32,7 +32,8 @@ namespace gdcm
 {
 
 //bool ReadMPEGFile (std::ifstream *fp, void *image_buffer, size_t lenght);
-bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* raw, size_t inputlength);
+bool gdcm_read_JPEG2000_file (void* raw, 
+                              char *inputdata, size_t inputlength);
 //-----------------------------------------------------------------------------
 #define str2num(str, typeNum) *((typeNum *)(str))
 
@@ -397,11 +398,31 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
 {
    if ( IsJPEG2000 )
    {
-      // I don't think we'll ever be able to deal with multiple fragments
-      assert( JPEGInfo->GetFragmentCount() == 1 );
-      fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
-      if ( ! gdcm_read_JPEG2000_file( fp,Raw, 
-          JPEGInfo->GetFirstFragment()->GetLength() ) )
+     // FIXME this is really ugly but it seems I have to load the complete
+     // jpeg2000 stream to use jasper:
+      // I don't think we'll ever be able to deal with multiple fragments properly
+
+      unsigned long inputlength = 0;
+      JPEGFragment *jpegfrag = JPEGInfo->GetFirstFragment();
+      while( jpegfrag )
+      {
+         inputlength += jpegfrag->GetLength();
+         jpegfrag = JPEGInfo->GetNextFragment();
+      }
+      gdcmAssertMacro( inputlength != 0);
+      uint8_t *inputdata = new uint8_t[inputlength];
+      char *pinputdata = (char*)inputdata;
+      jpegfrag = JPEGInfo->GetFirstFragment();
+      while( jpegfrag )
+      {
+         fp->seekg( jpegfrag->GetOffset(), std::ios::beg);
+         fp->read(pinputdata, jpegfrag->GetLength());
+         pinputdata += jpegfrag->GetLength();
+         jpegfrag = JPEGInfo->GetNextFragment();
+      }
+      // Warning the inputdata buffer is delete in the function
+      if ( ! gdcm_read_JPEG2000_file( Raw, 
+          (char*)inputdata, inputlength ) )
       {
          return true;
       }
index 79226b208add22ca06da821f5853af9d55df3dcf..07cc6e0ba4be92b24c4a0a307a9922e97c97c84b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.h,v $
   Language:  C++
-  Date:      $Date: 2005/04/22 13:37:57 $
-  Version:   $Revision: 1.20 $
+  Date:      $Date: 2005/05/30 01:30:39 $
+  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
@@ -20,9 +20,9 @@
 #ifndef GDCMPIXELREADCONVERT_H
 #define GDCMPIXELREADCONVERT_H
 
-#include "gdcmCommon.h"
 #include "gdcmBase.h"
 #include "gdcmException.h"
+#include <fstream>
 
 namespace gdcm
 {