]> Creatis software - gdcm.git/blobdiff - src/gdcmPixelReadConvert.cxx
* remove ContentEntry::Write() code, yet the method is 'pure virtual'
[gdcm.git] / src / gdcmPixelReadConvert.cxx
index 281eb6967d3886712cbce3cdca6d7ff6e05fabfd..b94a76a82cb57149e26450a1673bafd2d0dd37bb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmPixelReadConvert.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 11:40:55 $
-  Version:   $Revision: 1.31 $
+  Date:      $Date: 2005/01/26 11:42:02 $
+  Version:   $Revision: 1.35 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -180,8 +180,8 @@ bool PixelReadConvert::DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames )
 /**
  * \brief Implementation of the RLE decoding algorithm for decompressing
  *        a RLE fragment. [refer to PS 3.5-2003, section G.3.2 p 86]
- * @param subRaw Sub region of \ref Raw where the de
- *        decoded fragment should be placed.
+ * @param subRaw Sub region of \ref Raw where the decoded fragment
+ *        should be placed.
  * @param fragmentSize The length of the binary fragment as found on the disk.
  * @param RawSegmentSize The expected length of the fragment ONCE
  *        Raw.
@@ -257,11 +257,11 @@ bool PixelReadConvert::ReadAndDecompressRLEFile( std::ifstream *fp )
       ++it )
    {
       // Loop on the fragments
-      for( unsigned int k = 1; k <= (*it)->NumberFragments; k++ )
+      for( unsigned int k = 1; k <= (*it)->GetNumberOfFragments(); k++ )
       {
-         fp->seekg(  (*it)->Offset[k] , std::ios::beg );
+         fp->seekg(  (*it)->GetOffset(k) , std::ios::beg );
          (void)ReadAndDecompressRLEFragment( subRaw,
-                                             (*it)->Length[k],
+                                             (*it)->GetLength(k),
                                              RawSegmentSize, 
                                              fp );
          subRaw += RawSegmentSize;
@@ -351,7 +351,7 @@ void PixelReadConvert::ConvertSwapZone()
 }
 
 /**
- * \brief Deal with endianity i.e. re-arange bytes inside the integer
+ * \brief Deal with endianness i.e. re-arange bytes inside the integer
  */
 void PixelReadConvert::ConvertReorderEndianity()
 {
@@ -389,25 +389,26 @@ void PixelReadConvert::ConvertReorderEndianity()
 bool PixelReadConvert::ReadAndDecompressJPEGFramesFromFile( std::ifstream *fp )
 {
    // Pointer to the Raw image
-   uint8_t *localRaw = Raw;
+   //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;
-   }
+//   // 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;
 }
 
@@ -470,7 +471,7 @@ ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp )
         (it != JPEGInfo->Fragments.end()) && (howManyRead < totalLength);
         ++it )
    {
-      fragmentLength += (*it)->Length;
+      fragmentLength += (*it)->GetLength();
       
       if (howManyRead > fragmentLength) continue;
       
@@ -496,8 +497,18 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
 {
    if ( IsJPEG2000 )
    {
-      fp->seekg( (*JPEGInfo->Fragments.begin())->Offset, std::ios::beg);
-//      if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
+      gdcmVerboseMacro( "Sorry, JPEG2000 not yet taken into account" );
+      fp->seekg( (*JPEGInfo->Fragments.begin())->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);
+//    if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
          return false;
    }
 
@@ -510,15 +521,25 @@ bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *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 
+//   {
+//      // The dicom image contains frames containing fragments of images
+//      // a more complex algorithm :-)
+//      return ReadAndDecompressJPEGFragmentedFramesFromFile( fp );
+//   }   
 }
 
 /**
@@ -562,7 +583,7 @@ bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
 }
 
 /**
- * \brief   Convert (Y plane, cB plane, cR plane) to RGB pixels
+ * \brief   Convert (cY plane, cB plane, cR plane) to RGB pixels
  * \warning Works on all the frames at a time
  */
 void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
@@ -673,8 +694,8 @@ bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp )
    else if ( IsRaw )
    {
       // This problem can be found when some obvious informations are found
-      // after the field containing the image datas. In this case, these
-      // bad datas are added to the size of the image (in the PixelDataLength
+      // after the field containing the image data. In this case, these
+      // bad data are added to the size of the image (in the PixelDataLength
       // variable). But RawSize is the right size of the image !
       if( PixelDataLength != RawSize)
       {
@@ -841,7 +862,7 @@ void PixelReadConvert::GrabInformationsFromHeader( File *header )
       BitsAllocated = 16;
    }
 
-   // Number of "Bits Stored" defaulted to number of "Bits Allocated"
+   // Number of "Bits Stored", defaulted to number of "Bits Allocated"
    // when absent from the header.
    BitsStored = header->GetBitsStored();
    if ( BitsStored == 0 )
@@ -849,7 +870,7 @@ void PixelReadConvert::GrabInformationsFromHeader( File *header )
       BitsStored = BitsAllocated;
    }
 
-   // High Bit Position
+   // High Bit Position, defaulted to "Bits Allocated" - 1
    HighBitPosition = header->GetHighBitPosition();
    if ( HighBitPosition == 0 )
    {
@@ -871,9 +892,13 @@ void PixelReadConvert::GrabInformationsFromHeader( File *header )
      || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian
      || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian
      || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian;
-   IsJPEG2000     = Global::GetTS()->IsJPEG2000(ts);
-   IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts);
-   IsRLELossless  =  Global::GetTS()->IsRLELossless(ts);
+
+   IsJPEG2000      = Global::GetTS()->IsJPEG2000(ts);
+   IsJPEGLS        = Global::GetTS()->IsJPEGLS(ts);
+   IsJPEGLossy     = Global::GetTS()->IsJPEGLossy(ts);
+   IsJPEGLossless  = Global::GetTS()->IsJPEGLossless(ts);
+   IsRLELossless   = Global::GetTS()->IsRLELossless(ts);
+
    PixelOffset     = header->GetPixelOffset();
    PixelDataLength = header->GetPixelAreaLength();
    RLEInfo  = header->GetRLEInfo();
@@ -890,9 +915,9 @@ void PixelReadConvert::GrabInformationsFromHeader( File *header )
    if ( HasLUT )
    {
       // Just in case some access to a File element requires disk access.
-      LutRedDescriptor   = header->GetEntry( 0x0028, 0x1101 );
-      LutGreenDescriptor = header->GetEntry( 0x0028, 0x1102 );
-      LutBlueDescriptor  = header->GetEntry( 0x0028, 0x1103 );
+      LutRedDescriptor   = header->GetEntryValue( 0x0028, 0x1101 );
+      LutGreenDescriptor = header->GetEntryValue( 0x0028, 0x1102 );
+      LutBlueDescriptor  = header->GetEntryValue( 0x0028, 0x1103 );
    
       // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE
       // [ refer to invocation of Document::SetMaxSizeLoadEntry() in
@@ -1137,7 +1162,7 @@ void PixelReadConvert::Print( std::ostream &os, std::string const & indent )
       }
    }
 
-   if ( IsJPEG2000 || IsJPEGLossless )
+   if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS )
    {
       if ( JPEGInfo )
       {