+ localRaw += length * numberBytes;
+ }
+ 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)->Length;
+
+ if (howManyRead > fragmentLength) continue;
+
+ (*it)->DecompressJPEGFragmentedFramesFromFile(buffer, Raw, BitsStored, howManyRead, howManyWritten, totalLength);
+
+ if (howManyRead < fragmentLength)
+ howManyRead = fragmentLength;