+/**
+ * \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;
+ }
+
+}
+
+void JPEGFragment::DecompressJPEGSingleFrameFragmentsFromFile(JOCTET *buffer,
+ size_t totalLength, uint8_t *raw, int nBits)
+{
+ size_t howManyRead = 0;
+ size_t howManyWritten = 0;
+
+ if ( nBits == 8)
+ {
+ if ( ! gdcm_read_JPEG_memory8( buffer, totalLength, raw,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg8 ");
+ delete [] buffer;
+ //return false;
+ }
+ }
+ else if ( nBits <= 12)
+ {
+ if ( ! gdcm_read_JPEG_memory12( buffer, totalLength, raw,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg12 ");
+ delete [] buffer;
+ //return false;
+ }
+ }
+ else if ( nBits <= 16)
+ {
+
+ if ( ! gdcm_read_JPEG_memory16( buffer, totalLength, raw,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg16 ");
+ delete [] buffer;
+ //return false;
+ }
+ }
+ else
+ {
+ // FIXME : only the bits number is checked,
+ // NOT the compression method
+
+ // other JPEG lossy not supported
+ gdcmErrorMacro( "Unsupported jpeg lossy compression ");
+ delete [] buffer;
+ //return false;
+ }
+
+}
+
+void JPEGFragment::DecompressJPEGFragmentedFramesFromFile(JOCTET *buffer,
+ uint8_t* raw, int nBits, size_t &howManyRead,
+ size_t &howManyWritten, size_t totalLength)
+{
+ if ( nBits == 8 )
+ {
+ if ( ! gdcm_read_JPEG_memory8( buffer+howManyRead, totalLength-howManyRead,
+ raw+howManyWritten,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg8");
+ //delete [] buffer;
+ //return false;
+ }
+ }
+ else if ( nBits <= 12 )
+ {
+
+ if ( ! gdcm_read_JPEG_memory12( buffer+howManyRead, totalLength-howManyRead,
+ raw+howManyWritten,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg12");
+ //delete [] buffer;
+ //return false;
+ }
+ }
+ else if ( nBits <= 16 )
+ {
+
+ if ( ! gdcm_read_JPEG_memory16( buffer+howManyRead, totalLength-howManyRead,
+ raw+howManyWritten,
+ &howManyRead, &howManyWritten ) )
+ {
+ gdcmErrorMacro( "Failed to read jpeg16 ");
+ //delete [] buffer;
+ //return false;
+ }
+ }
+ else
+ {
+ // FIXME : only the bits number is checked,
+ // NOT the compression method
+
+ // other JPEG lossy not supported
+ gdcmErrorMacro( "Unsupported jpeg lossy compression ");
+ //delete [] buffer;
+ //return false;
+ }
+}
+