Program: gdcm
Module: $RCSfile: gdcmJPEGFragment.cxx,v $
Language: C++
- Date: $Date: 2005/01/16 04:50:42 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2005/01/17 01:14:32 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
=========================================================================*/
#include "gdcmJPEGFragment.h"
-
+#include "gdcmDebug.h"
+
namespace gdcm
{
+// For JPEG 2000, body in file gdcmJpeg2000.cxx
+bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* image_buffer);
+
+// For JPEG 8 Bits, body in file gdcmJpeg8.cxx
+bool gdcm_read_JPEG_file8 (std::ifstream *fp, void *image_buffer);
+bool gdcm_read_JPEG_memory8 (const JOCTET *buffer, const size_t buflen,
+ void *image_buffer,
+ size_t *howManyRead, size_t *howManyWritten);
+//
+// For JPEG 12 Bits, body in file gdcmJpeg12.cxx
+bool gdcm_read_JPEG_file12 (std::ifstream *fp, void *image_buffer);
+bool gdcm_read_JPEG_memory12 (const JOCTET *buffer, const size_t buflen,
+ void *image_buffer,
+ size_t *howManyRead, size_t *howManyWritten);
+
+// For JPEG 16 Bits, body in file gdcmJpeg16.cxx
+// Beware this is misleading there is no 16bits DCT algorithm, only
+// jpeg lossless compression exist in 16bits.
+bool gdcm_read_JPEG_file16 (std::ifstream *fp, void *image_buffer);
+bool gdcm_read_JPEG_memory16 (const JOCTET *buffer, const size_t buflen,
+ void* image_buffer,
+ size_t *howManyRead, size_t *howManyWritten);
+
/**
* \brief Default constructor.
*/
/**
* \brief Print self.
- * @param indent Indentation string to be prepended during printing.
* @param os Stream to print to.
+ * @param indent Indentation string to be prepended during printing.
*/
void JPEGFragment::Print( std::ostream &os, std::string indent )
{
<< std::endl;
}
+/**
+ * \brief Decompress 8bits JPEG Fragment
+ * @param buffer output (data decompress)
+ * @param nBits 8/12 or 16 bits jpeg
+ */
+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)
+ {
+ // Reading Fragment pixels
+ if ( ! gdcm_read_JPEG_file12 ( fp, buffer) )
+ {
+ //return false;
+ }
+ }
+ else if ( nBits <= 16)
+ {
+ // Reading Fragment pixels
+ if ( ! gdcm_read_JPEG_file16 ( fp, buffer) )
+ {
+ //return false;
+ }
+ //gdcmAssertMacro( IsJPEGLossless );
+ }
+ else
+ {
+ // 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
+ {
+ // 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
+ {
+ // 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/16 04:50:42 $
- Version: $Revision: 1.7 $
+ Date: $Date: 2005/01/17 01:14:33 $
+ Version: $Revision: 1.8 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
namespace gdcm
{
+#define JOCTET uint8_t
/**
* \brief Utility class for summerizing the informations of a JPEG
public:
JPEGFragment();
void Print( std::ostream &os = std::cout, std::string indent = "" );
+ void DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits);
+ void DecompressJPEGSingleFrameFragmentsFromFile(JOCTET *buffer, size_t totalLength, uint8_t* raw, int nBits);
+ void DecompressJPEGFragmentedFramesFromFile(JOCTET *buffer, uint8_t* raw, int nBits, size_t &howManyRead, size_t &howManyWritten, size_t totalLength);
private:
long Offset;
Program: gdcm
Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
Language: C++
- Date: $Date: 2005/01/16 04:50:42 $
- Version: $Revision: 1.5 $
+ Date: $Date: 2005/01/17 01:14:33 $
+ Version: $Revision: 1.6 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
}
-
} // end namespace gdcm
+
Program: gdcm
Module: $RCSfile: gdcmJPEGFragmentsInfo.h,v $
Language: C++
- Date: $Date: 2005/01/16 04:50:42 $
- Version: $Revision: 1.8 $
+ Date: $Date: 2005/01/17 01:14:33 $
+ 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
*/
class GDCM_EXPORT JPEGFragmentsInfo
{
-friend class Document;
-friend class File;
-friend class PixelReadConvert;
-private:
- typedef std::list< JPEGFragment* > JPEGFragmentsList;
- JPEGFragmentsList Fragments;
public:
~JPEGFragmentsInfo();
void Print( std::ostream &os = std::cout, std::string const & indent = "" );
+private:
+ typedef std::list< JPEGFragment* > JPEGFragmentsList;
+ JPEGFragmentsList Fragments;
+
+friend class Document;
+friend class File;
+friend class PixelReadConvert;
};
} // end namespace gdcm
//-----------------------------------------------------------------------------
#endif
+
Program: gdcm
Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
Language: C++
- Date: $Date: 2005/01/16 04:50:42 $
- Version: $Revision: 1.28 $
+ Date: $Date: 2005/01/17 01:14:33 $
+ Version: $Revision: 1.29 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
#define str2num(str, typeNum) *((typeNum *)(str))
-// For JPEG 2000, body in file gdcmJpeg2000.cxx
-bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* image_buffer);
-
-#define JOCTET uint8_t
-// For JPEG 8 Bits, body in file gdcmJpeg8.cxx
-bool gdcm_read_JPEG_file8 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory8 (const JOCTET *buffer, const size_t buflen,
- void *image_buffer,
- size_t *howManyRead, size_t *howManyWritten);
-//
-// For JPEG 12 Bits, body in file gdcmJpeg12.cxx
-bool gdcm_read_JPEG_file12 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory12 (const JOCTET *buffer, const size_t buflen,
- void *image_buffer,
- size_t *howManyRead, size_t *howManyWritten);
-
-// For JPEG 16 Bits, body in file gdcmJpeg16.cxx
-// Beware this is misleading there is no 16bits DCT algorithm, only
-// jpeg lossless compression exist in 16bits.
-bool gdcm_read_JPEG_file16 (std::ifstream *fp, void *image_buffer);
-bool gdcm_read_JPEG_memory16 (const JOCTET *buffer, const size_t buflen,
- void* image_buffer,
- size_t *howManyRead, size_t *howManyWritten);
-
//-----------------------------------------------------------------------------
// Constructor / Destructor
{
fp->seekg( (*it)->Offset, std::ios::beg);
- if ( BitsStored == 8)
- {
- // JPEG Lossy : call to IJG 6b
- if ( ! gdcm_read_JPEG_file8( fp, localRaw ) )
- {
- return false;
- }
- }
- else if ( BitsStored <= 12)
- {
- // Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file12 ( fp, localRaw ) )
- {
- return false;
- }
- }
- else if ( BitsStored <= 16)
- {
- // Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file16 ( fp, localRaw ) )
- {
- return false;
- }
- //gdcmAssertMacro( IsJPEGLossless );
- }
- else
- {
- // other JPEG lossy not supported
- gdcmErrorMacro( "Unknown jpeg lossy compression ");
- return false;
- }
+ (*it)->DecompressJPEGFramesFromFile(fp, localRaw, BitsStored );
// Advance to next free location in Raw
// for next fragment decompression (if any)
p += len;
}
- size_t howManyRead = 0;
- size_t howManyWritten = 0;
-
- if ( BitsStored == 8)
- {
- if ( ! gdcm_read_JPEG_memory8( buffer, totalLength, Raw,
- &howManyRead, &howManyWritten ) )
- {
- gdcmErrorMacro( "Failed to read jpeg8 ");
- delete [] buffer;
- return false;
- }
- }
- else if ( BitsStored <= 12)
- {
- if ( ! gdcm_read_JPEG_memory12( buffer, totalLength, Raw,
- &howManyRead, &howManyWritten ) )
- {
- gdcmErrorMacro( "Failed to read jpeg12 ");
- delete [] buffer;
- return false;
- }
- }
- else if ( BitsStored <= 16)
- {
-
- if ( ! gdcm_read_JPEG_memory16( buffer, totalLength, Raw,
- &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;
- }
+ (*it)->DecompressJPEGSingleFrameFragmentsFromFile(buffer, totalLength, Raw, BitsStored);
// free local buffer
delete [] buffer;
fragmentLength += (*it)->Length;
if (howManyRead > fragmentLength) continue;
-
- if ( BitsStored == 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 ( BitsStored <= 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 ( BitsStored <= 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;
- }
+ (*it)->DecompressJPEGFragmentedFramesFromFile(buffer, Raw, BitsStored, howManyRead, howManyWritten, totalLength);
if (howManyRead < fragmentLength)
howManyRead = fragmentLength;
if ( IsJPEG2000 )
{
fp->seekg( (*JPEGInfo->Fragments.begin())->Offset, std::ios::beg);
- if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
- return false;
+// if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
+// return false;
}
if ( ( ZSize == 1 ) && ( JPEGInfo->Fragments.size() > 1 ) )
Program: gdcm
Module: $RCSfile: gdcmValEntry.cxx,v $
Language: C++
- Date: $Date: 2005/01/16 04:50:42 $
- Version: $Revision: 1.46 $
+ Date: $Date: 2005/01/17 01:14:33 $
+ Version: $Revision: 1.47 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
uint16_t g = GetGroup();
uint16_t e = GetElement();
- std::string vr = GetVR();
+ VRKey vr = GetVR();
std::ostringstream s;
std::string st;
- TSKey v;
std::string d2;
os << "V ";
TS * ts = Global::GetTS();
- v = GetValue(); // not applicable for SQ ...
+ TSAtr v = GetValue(); // not applicable for SQ ...
d2 = Util::CreateCleanString(v); // replace non printable characters by '.'
- if( (GetLength()<=MAX_SIZE_PRINT_ELEMENT_VALUE) ||
- (PrintLevel>=3) || (d2.find(GDCM_NOTLOADED) < d2.length()) )
+ if( GetLength() <= MAX_SIZE_PRINT_ELEMENT_VALUE
+ || PrintLevel >= 3
+ || d2.find(GDCM_NOTLOADED) < d2.length() )
{
s << " [" << d2 << "]";
}
if (g == 0x0002)
{
// Any more to be displayed ?
- if ( (e == 0x0010) || (e == 0x0002) )
+ if ( e == 0x0010 || e == 0x0002 )
{
if ( v.length() != 0 ) // for brain damaged headers
{
{
if (g == 0x0004)
{
- if ( (e == 0x1510) || (e == 0x1512) )
+ if ( e == 0x1510 || e == 0x1512 )
{
if ( v.length() != 0 ) // for brain damaged headers
{
}
}
//if (e == 0x0000) { // elem 0x0000 --> group length
- if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") )
+ if ( vr == "UL" || vr == "US" || vr == "SL" || vr == "SS" )
{
if (v == "4294967295") // to avoid troubles in convertion
{
}
else
{
- if ( GetLength() !=0 )
+ if ( GetLength() != 0 )
{
st = Util::Format(" x(%x)", atoi(v.c_str()));//FIXME
}
int l = val.length();
if ( l != 0) // To avoid to be cheated by 'zero length' integers
{
- VRKey vr = GetVR();
+ const VRKey &vr = GetVR();
if( vr == "US" || vr == "SS" )
{
// for multivaluated items
return; //delimitors have NO value
}
- std::string vr = GetVR();
+ const VRKey &vr = GetVR();
unsigned int lgr = GetLength();
//std::cout<<std::hex<<GetGroup()<<"|"<<GetElement()<<std::dec<<" : "<<GetReadLength()<<" / "<<GetLength()<<"\n";
if (vr == "US" || vr == "SS")