]> Creatis software - gdcm.git/blobdiff - src/gdcmPixelReadConvert.cxx
BUG: Remove mem leak.
[gdcm.git] / src / gdcmPixelReadConvert.cxx
index 300bedb3f4a5397ec19d2d2545f91c1cce108281..8c8bd2db17eb8562e3f25e371f6932419538095d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/26 16:28:58 $
-  Version:   $Revision: 1.36 $
+  Date:      $Date: 2005/01/31 03:22:26 $
+  Version:   $Revision: 1.38 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -243,21 +243,20 @@ bool PixelReadConvert::ReadAndDecompressRLEFile( std::ifstream *fp )
    long RawSegmentSize = XSize * YSize;
 
    // Loop on the frame[s]
-   for( RLEFramesInfo::RLEFrameList::iterator
-        it  = RLEInfo->Frames.begin();
-        it != RLEInfo->Frames.end();
-      ++it )
+   RLEFrame *frame = RLEInfo->GetFirstFrame();
+   while( frame )
    {
       // Loop on the fragments
-      for( unsigned int k = 1; k <= (*it)->GetNumberOfFragments(); k++ )
+      for( unsigned int k = 1; k <= frame->GetNumberOfFragments(); k++ )
       {
-         fp->seekg(  (*it)->GetOffset(k) , std::ios::beg );
-         (void)ReadAndDecompressRLEFragment( subRaw,
-                                             (*it)->GetLength(k),
-                                             RawSegmentSize, 
-                                             fp );
+         fp->seekg(frame->GetOffset(k),std::ios::beg);
+         ReadAndDecompressRLEFragment(subRaw,
+                                      frame->GetLength(k),
+                                      RawSegmentSize, 
+                                      fp);
          subRaw += RawSegmentSize;
       }
+      frame = RLEInfo->GetNexttFrame();
    }
 
    if ( BitsAllocated == 16 )
@@ -370,115 +369,6 @@ void PixelReadConvert::ConvertReorderEndianity()
    }
 }
 
-
-/**
- * \brief     Reads from disk the Pixel Data of JPEG Dicom encapsulated
- *            file and decompress it. This function assumes that each
- *            jpeg fragment contains a whole frame (jpeg file).
- * @param     fp File Pointer
- * @return    Boolean
- */
-bool PixelReadConvert::ReadAndDecompressJPEGFramesFromFile( std::ifstream *fp )
-{
-   // Pointer to the Raw image
-   //uint8_t *localRaw = Raw;
-
-   // Precompute the offset localRaw will be shifted with
-   int length = XSize * YSize * SamplesPerPixel;
-   int numberBytes = BitsAllocated / 8;
-
-//   // Loop on the fragment[s]
-//   for( JPEGFragmentsInfo::JPEGFragmentsList::iterator
-//        it  = JPEGInfo->Fragments.begin();
-//        it != JPEGInfo->Fragments.end();
-//      ++it )
-//   {
-//      (*it)->DecompressJPEGFramesFromFile(fp, localRaw, BitsStored );
-//
-//      // Advance to next free location in Raw 
-//      // for next fragment decompression (if any)
-//
-//      localRaw += length * numberBytes;
-//   }
-   JPEGInfo->DecompressJPEGFramesFromFile(fp, Raw, BitsStored, numberBytes, length );
-   return true;
-}
-
-/**
- * \brief     Reads from disk the Pixel Data of JPEG Dicom encapsulated
- *            file and decompress it. This function assumes that the dicom
- *            image is a single frame split into several JPEG fragments.
- *            Those fragments will be glued together into a memory buffer
- *            before being read.
- * @param     fp File Pointer
- * @return    Boolean
- */
-bool PixelReadConvert::
-ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp )
-{
-   // Loop on the fragment[s] to get total length
-   size_t totalLength = JPEGInfo->GetFragmentsLength();
-
-   // Concatenate the jpeg fragments into a local buffer
-   JOCTET *buffer = new JOCTET [totalLength];
-   // Fill in the buffer:
-   JPEGInfo->ReadAllFragments(fp, buffer);
-
-   // kludge: // FIXME
-   JPEGFragmentsInfo::JPEGFragmentsList::const_iterator it = JPEGInfo->Fragments.begin();
-   (*it)->DecompressJPEGSingleFrameFragmentsFromFile(buffer, totalLength, Raw, BitsStored);
-
-   // free local buffer
-   delete [] buffer;
-   
-   return true;      
-}
-
-/**
- * \brief     Reads from disk the Pixel Data of JPEG Dicom encapsulated
- *            file and decompress it. This function handles the generic 
- *            and complex case where the DICOM contains several frames,
- *            and some of the frames are possibly split into several JPEG
- *            fragments. 
- * @param     fp File Pointer
- * @return    Boolean
- */
-bool PixelReadConvert::
-ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp )
-{
-   // Loop on the fragment[s] to get total length
-   size_t totalLength = JPEGInfo->GetFragmentsLength();
-
-   // Concatenate the jpeg fragments into a local buffer
-   JOCTET *buffer = new JOCTET [totalLength];
-   // Fill in the buffer:
-   JPEGInfo->ReadAllFragments(fp, buffer);
-
-   size_t howManyRead = 0;
-   size_t howManyWritten = 0;
-   size_t fragmentLength = 0;
-   
-   JPEGFragmentsInfo::JPEGFragmentsList::const_iterator it;
-   for( it  = JPEGInfo->Fragments.begin() ;
-        (it != JPEGInfo->Fragments.end()) && (howManyRead < totalLength);
-        ++it )
-   {
-      fragmentLength += (*it)->GetLength();
-      
-      if (howManyRead > fragmentLength) continue;
-      
-      (*it)->DecompressJPEGFragmentedFramesFromFile(buffer, Raw, BitsStored, howManyRead, howManyWritten, totalLength);
-      
-      if (howManyRead < fragmentLength)
-         howManyRead = fragmentLength;
-   }
-
-   // free local buffer
-   delete [] buffer;
-   
-   return true;
-}
-
 /**
  * \brief     Reads from disk the Pixel Data of JPEG Dicom encapsulated
  *            file and decompress it.
@@ -490,48 +380,26 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
    if ( IsJPEG2000 )
    {
       gdcmVerboseMacro( "Sorry, JPEG2000 not yet taken into account" );
-      fp->seekg( (*JPEGInfo->Fragments.begin())->GetOffset(), std::ios::beg);
+      fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
 //    if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
-          gdcmVerboseMacro( "Wrong Blue LUT descriptor" );
           return false;
    }
 
    if ( IsJPEGLS )
    {
       gdcmVerboseMacro( "Sorry, JPEG-LS not yet taken into account" );
-      fp->seekg( (*JPEGInfo->Fragments.begin())->GetOffset(), std::ios::beg);
+      fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
 //    if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
          return false;
    }
 
-   if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) )
-   {
-      // we have one frame split into several fragments
-      // we will pack those fragments into a single buffer and 
-      // read from it
-      return ReadAndDecompressJPEGSingleFrameFragmentsFromFile( fp );
-   }
-   else if (JPEGInfo->Fragments.size() == (size_t)ZSize)
-   {
-   }
-//   if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) )
-//   {
-//      // we have one frame split into several fragments
-//      // we will pack those fragments into a single buffer and 
-//      // read from it
-//      return ReadAndDecompressJPEGSingleFrameFragmentsFromFile( fp );
-//   }
-//   else if (JPEGInfo->Fragments.size() == (size_t)ZSize)
-//   {
-      // suppose each fragment is a frame
-      return ReadAndDecompressJPEGFramesFromFile( fp );
-//   }
-//   else 
-//   {
-//      // The dicom image contains frames containing fragments of images
-//      // a more complex algorithm :-)
-//      return ReadAndDecompressJPEGFragmentedFramesFromFile( fp );
-//   }   
+   // else ??
+   // Precompute the offset localRaw will be shifted with
+   int length = XSize * YSize * SamplesPerPixel;
+   int numberBytes = BitsAllocated / 8;
+
+   JPEGInfo->DecompressJPEGFramesFromFile(fp, Raw, BitsStored, numberBytes, length );
+   return true;
 }
 
 /**