Program: gdcm
Module: $RCSfile: gdcmJPEGFragment.cxx,v $
Language: C++
- Date: $Date: 2005/01/17 01:14:32 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2005/01/17 03:05:55 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
*/
void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits)
{
- if ( nBits == 8)
- {
- // JPEG Lossy : call to IJG 6b
- if ( ! gdcm_read_JPEG_file8( fp, buffer) )
- {
- //return false;
- }
- }
- else if ( nBits <= 12)
+ // 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 ( ! gdcm_read_JPEG_file8( fp, buffer) )
{
- // Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file12 ( fp, buffer) )
- {
- //return false;
- }
+ //return false;
}
- else if ( nBits <= 16)
+ }
+ else if ( nBits <= 12 )
+ {
+ // Reading Fragment pixels
+ if ( ! gdcm_read_JPEG_file12 ( fp, buffer) )
{
- // Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file16 ( fp, buffer) )
- {
- //return false;
- }
- //gdcmAssertMacro( IsJPEGLossless );
+ //return false;
}
- else
+ }
+ else if ( nBits <= 16 )
+ {
+ // Reading Fragment pixels
+ if ( ! gdcm_read_JPEG_file16 ( fp, buffer) )
{
- // other JPEG lossy not supported
- gdcmErrorMacro( "Unknown jpeg lossy compression ");
//return false;
}
+ //gdcmAssertMacro( IsJPEGLossless );
+ }
+ else
+ {
+ // other JPEG lossy not supported
+ gdcmErrorMacro( "Unknown jpeg lossy compression ");
+ //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
- {
- // other JPEG lossy not supported
- gdcmErrorMacro( "Unsupported jpeg lossy compression ");
+ 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
+ {
+ // other JPEG lossy not supported
+ gdcmErrorMacro( "Unsupported jpeg lossy compression ");
+ //delete [] buffer;
+ //return false;
+ }
}
} // end namespace gdcm
Program: gdcm
Module: $RCSfile: gdcmJPEGFragment.h,v $
Language: C++
- Date: $Date: 2005/01/17 01:14:33 $
- Version: $Revision: 1.8 $
+ Date: $Date: 2005/01/17 03:05:55 $
+ Version: $Revision: 1.9 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
friend class Document;
friend class File;
friend class PixelReadConvert;
+friend class JPEGFragmentsInfo;
};
} // end namespace gdcm
Program: gdcm
Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
Language: C++
- Date: $Date: 2005/01/17 01:14:33 $
- Version: $Revision: 1.6 $
+ Date: $Date: 2005/01/17 03:05:55 $
+ Version: $Revision: 1.7 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmJPEGFragmentsInfo.h"
+#include <fstream>
namespace gdcm
{
}
}
+/**
+ * \brief Calculate sum of all fragments lenght and return total
+ * @return Total size of JPEG fragments length
+ */
+size_t JPEGFragmentsInfo::GetFragmentsLength()
+{
+ // Loop on the fragment[s] to get total length
+ size_t totalLength = 0;
+ JPEGFragmentsList::const_iterator it;
+ for( it = Fragments.begin();
+ it != Fragments.end();
+ ++it )
+ {
+ totalLength += (*it)->Length;
+ }
+ return totalLength;
+}
+
+/**
+ * \brief Read the all the JPEG Fragment into the input buffer
+ */
+void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
+{
+ JOCTET *p = buffer;
+
+ // Loop on the fragment[s]
+ JPEGFragmentsList::const_iterator it;
+ for( it = Fragments.begin();
+ it != Fragments.end();
+ ++it )
+ {
+ fp->seekg( (*it)->Offset, std::ios::beg);
+ size_t len = (*it)->Length;
+ fp->read((char *)p,len);
+ p += len;
+ }
+
+}
+
} // end namespace gdcm
Program: gdcm
Module: $RCSfile: gdcmJPEGFragmentsInfo.h,v $
Language: C++
- Date: $Date: 2005/01/17 01:14:33 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2005/01/17 03:05:55 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
public:
~JPEGFragmentsInfo();
void Print( std::ostream &os = std::cout, std::string const & indent = "" );
+ size_t GetFragmentsLength();
+ void ReadAllFragments(std::ifstream *fp, JOCTET *buffer );
+
private:
typedef std::list< JPEGFragment* > JPEGFragmentsList;
JPEGFragmentsList Fragments;
Program: gdcm
Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
Language: C++
- Date: $Date: 2005/01/17 01:14:33 $
- Version: $Revision: 1.29 $
+ Date: $Date: 2005/01/17 03:05:55 $
+ Version: $Revision: 1.30 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
// Special kludge in order to deal with xmedcon broken images:
- if ( ( BitsAllocated == 16 )
- && ( BitsStored < BitsAllocated )
- && ( ! PixelSign ) )
+ if ( BitsAllocated == 16
+ && BitsStored < BitsAllocated
+ && !PixelSign )
{
int l = (int)( RawSize / ( BitsAllocated / 8 ) );
uint16_t *deb = (uint16_t *)Raw;
*/
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 )
{
- fp->seekg( (*it)->Offset, std::ios::beg);
-
(*it)->DecompressJPEGFramesFromFile(fp, localRaw, BitsStored );
// Advance to next free location in Raw
// for next fragment decompression (if any)
- int length = XSize * YSize * SamplesPerPixel;
- int numberBytes = BitsAllocated / 8;
localRaw += length * numberBytes;
}
ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp )
{
// Loop on the fragment[s] to get total length
- size_t totalLength = 0;
- JPEGFragmentsInfo::JPEGFragmentsList::iterator it;
- for( it = JPEGInfo->Fragments.begin();
- it != JPEGInfo->Fragments.end();
- ++it )
- {
- totalLength += (*it)->Length;
- }
+ size_t totalLength = JPEGInfo->GetFragmentsLength();
// Concatenate the jpeg fragments into a local buffer
JOCTET *buffer = new JOCTET [totalLength];
- JOCTET *p = buffer;
-
- // Loop on the fragment[s]
- for( it = JPEGInfo->Fragments.begin();
- it != JPEGInfo->Fragments.end();
- ++it )
- {
- fp->seekg( (*it)->Offset, std::ios::beg);
- size_t len = (*it)->Length;
- fp->read((char *)p,len);
- p += len;
- }
+ // 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
ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp )
{
// Loop on the fragment[s] to get total length
- size_t totalLength = 0;
- JPEGFragmentsInfo::JPEGFragmentsList::iterator it;
- for( it = JPEGInfo->Fragments.begin();
- it != JPEGInfo->Fragments.end();
- ++it )
- {
- totalLength += (*it)->Length;
- }
+ size_t totalLength = JPEGInfo->GetFragmentsLength();
// Concatenate the jpeg fragments into a local buffer
JOCTET *buffer = new JOCTET [totalLength];
- JOCTET *p = buffer;
-
- // Loop on the fragment[s]
- for( it = JPEGInfo->Fragments.begin();
- it != JPEGInfo->Fragments.end();
- ++it )
- {
- fp->seekg( (*it)->Offset, std::ios::beg);
- size_t len = (*it)->Length;
- fp->read((char *)p,len);
- p+=len;
- }
+ // 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 )
{
fp->seekg( (*JPEGInfo->Fragments.begin())->Offset, std::ios::beg);
// if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
-// return false;
+ return false;
}
if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) )