X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmJPEGFragmentsInfo.cxx;h=6adb33f0220e95237489ac9e53b0b9bfbd01cb2c;hb=c67ffef593e7635d8dfa7d3fe63d702e5afafc3e;hp=06f331b3e6a3f27f8edd60fa9b60151dd929cdb8;hpb=5bf7c51796867388334836847a6874640bc83f89;p=gdcm.git diff --git a/src/gdcmJPEGFragmentsInfo.cxx b/src/gdcmJPEGFragmentsInfo.cxx index 06f331b3..6adb33f0 100644 --- a/src/gdcmJPEGFragmentsInfo.cxx +++ b/src/gdcmJPEGFragmentsInfo.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $ Language: C++ - Date: $Date: 2004/10/20 14:30:40 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/01/26 16:28:58 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,10 +17,16 @@ =========================================================================*/ #include "gdcmJPEGFragmentsInfo.h" +#include namespace gdcm { +JPEGFragmentsInfo::JPEGFragmentsInfo() +{ + StateSuspension = 0; +} + /** * \brief Default destructor */ @@ -30,21 +36,22 @@ JPEGFragmentsInfo::~JPEGFragmentsInfo() it != Fragments.end(); ++it ) { - delete (*it); + delete *it; } Fragments.clear(); } /** * \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 JPEGFragmentsInfo::Print( std::string indent, std::ostream &os ) +void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent ) { + os << std::endl; os << indent << "----------------- JPEG fragments --------------------------------" - << std::endl; + << std::endl << std::endl; os << indent << "Total number of fragments : " << Fragments.size() << std::endl; @@ -55,10 +62,77 @@ void JPEGFragmentsInfo::Print( std::string indent, std::ostream &os ) { os << indent << " fragment number :" << fragmentNumber++; - (*it)->Print( indent + " ", os ); - os << std::endl; + (*it)->Print( os, indent + " "); + } + os << std::endl; +} + +/** + * \brief Calculate sum of all fragments length 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)->GetLength(); + } + 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)->GetOffset(), std::ios::beg); + size_t len = (*it)->GetLength(); + fp->read((char *)p,len); + p += len; + } + +} + +void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length) +{ + // Pointer to the Raw image + uint8_t *localRaw = buffer; + + // Loop on the fragment[s] + JPEGFragmentsList::const_iterator it; + for( it = Fragments.begin(); + it != Fragments.end(); + ++it ) + { + //(*it)->pimage = localRaw; + (*it)->DecompressJPEGFramesFromFile(fp, localRaw, nBits, StateSuspension); + // update pointer to image after some scanlines read: + localRaw = (*it)->GetImage(); + // Advance to next free location in Raw + // for next fragment decompression (if any) + + //localRaw += length * numBytes; + //std::cerr << "Used to increment by: " << length * numBytes << std::endl; } } +void JPEGFragmentsInfo::AddFragment(JPEGFragment *fragment) +{ + Fragments.push_back(fragment); +} } // end namespace gdcm +