1 /*=========================================================================
4 Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
6 Date: $Date: 2005/01/26 16:28:58 $
7 Version: $Revision: 1.11 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmJPEGFragmentsInfo.h"
25 JPEGFragmentsInfo::JPEGFragmentsInfo()
31 * \brief Default destructor
33 JPEGFragmentsInfo::~JPEGFragmentsInfo()
35 for(JPEGFragmentsList::iterator it = Fragments.begin();
36 it != Fragments.end();
46 * @param os Stream to print to.
47 * @param indent Indentation string to be prepended during printing.
49 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent )
53 << "----------------- JPEG fragments --------------------------------"
54 << std::endl << std::endl;
56 << "Total number of fragments : " << Fragments.size()
58 int fragmentNumber = 0;
59 for(JPEGFragmentsList::iterator it = Fragments.begin();
60 it != Fragments.end();
64 << " fragment number :" << fragmentNumber++;
65 (*it)->Print( os, indent + " ");
71 * \brief Calculate sum of all fragments length and return total
72 * @return Total size of JPEG fragments length
74 size_t JPEGFragmentsInfo::GetFragmentsLength()
76 // Loop on the fragment[s] to get total length
77 size_t totalLength = 0;
78 JPEGFragmentsList::const_iterator it;
79 for( it = Fragments.begin();
80 it != Fragments.end();
83 totalLength += (*it)->GetLength();
89 * \brief Read the all the JPEG Fragment into the input buffer
91 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
95 // Loop on the fragment[s]
96 JPEGFragmentsList::const_iterator it;
97 for( it = Fragments.begin();
98 it != Fragments.end();
101 fp->seekg( (*it)->GetOffset(), std::ios::beg);
102 size_t len = (*it)->GetLength();
103 fp->read((char *)p,len);
109 void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length)
111 // Pointer to the Raw image
112 uint8_t *localRaw = buffer;
114 // Loop on the fragment[s]
115 JPEGFragmentsList::const_iterator it;
116 for( it = Fragments.begin();
117 it != Fragments.end();
120 //(*it)->pimage = localRaw;
121 (*it)->DecompressJPEGFramesFromFile(fp, localRaw, nBits, StateSuspension);
122 // update pointer to image after some scanlines read:
123 localRaw = (*it)->GetImage();
124 // Advance to next free location in Raw
125 // for next fragment decompression (if any)
127 //localRaw += length * numBytes;
128 //std::cerr << "Used to increment by: " << length * numBytes << std::endl;
132 void JPEGFragmentsInfo::AddFragment(JPEGFragment *fragment)
134 Fragments.push_back(fragment);
137 } // end namespace gdcm