1 /*=========================================================================
4 Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
6 Date: $Date: 2005/01/28 17:01:30 $
7 Version: $Revision: 1.13 $
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"
20 #include "gdcmDebug.h"
27 JPEGFragmentsInfo::JPEGFragmentsInfo()
33 * \brief Default destructor
35 JPEGFragmentsInfo::~JPEGFragmentsInfo()
37 for(JPEGFragmentsList::iterator it = Fragments.begin();
38 it != Fragments.end();
48 * @param os Stream to print to.
49 * @param indent Indentation string to be prepended during printing.
51 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent )
55 << "----------------- JPEG fragments --------------------------------"
56 << std::endl << std::endl;
58 << "Total number of fragments : " << Fragments.size()
60 int fragmentNumber = 0;
61 for(JPEGFragmentsList::iterator it = Fragments.begin();
62 it != Fragments.end();
66 << " fragment number :" << fragmentNumber++;
67 (*it)->Print( os, indent + " ");
73 * \brief Calculate sum of all fragments length and return total
74 * @return Total size of JPEG fragments length
76 size_t JPEGFragmentsInfo::GetFragmentsLength()
78 // Loop on the fragment[s] to get total length
79 size_t totalLength = 0;
80 JPEGFragmentsList::const_iterator it;
81 for( it = Fragments.begin();
82 it != Fragments.end();
85 totalLength += (*it)->GetLength();
91 * \brief Read the all the JPEG Fragment into the input buffer
93 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
97 // Loop on the fragment[s]
98 JPEGFragmentsList::const_iterator it;
99 for( it = Fragments.begin();
100 it != Fragments.end();
103 fp->seekg( (*it)->GetOffset(), std::ios::beg);
104 size_t len = (*it)->GetLength();
105 fp->read((char *)p,len);
111 // Keep a track of the old code (maybe Jpeg2000 lib will be less clever than IJG
112 //void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length)
115 void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int , int )
117 // Pointer to the Raw image
118 uint8_t *localRaw = buffer;
120 // Loop on the fragment[s]
121 JPEGFragmentsList::const_iterator it;
122 for( it = Fragments.begin();
123 it != Fragments.end();
126 //(*it)->pimage = localRaw;
127 (*it)->DecompressJPEGFramesFromFile(fp, localRaw, nBits, StateSuspension);
128 // update pointer to image after some scanlines read:
129 localRaw = (*it)->GetImage();
130 // Advance to next free location in Raw
131 // for next fragment decompression (if any)
133 //localRaw += length * numBytes;
134 //std::cerr << "Used to increment by: " << length * numBytes << std::endl;
138 void JPEGFragmentsInfo::AddFragment(JPEGFragment *fragment)
140 Fragments.push_back(fragment);
143 JPEGFragment *JPEGFragmentsInfo::GetFirstFragment()
145 ItFragments = Fragments.begin();
146 if (ItFragments != Fragments.end())
151 JPEGFragment *JPEGFragmentsInfo::GetNextFragment()
153 gdcmAssertMacro (ItFragments != Fragments.end());
156 if (ItFragments != Fragments.end())
161 unsigned int JPEGFragmentsInfo::GetFragmentCount()
163 return Fragments.size();
166 } // end namespace gdcm