]> Creatis software - gdcm.git/blob - src/gdcmJPEGFragmentsInfo.cxx
ENH: Minor patch that rework code to avoid duplicate code.
[gdcm.git] / src / gdcmJPEGFragmentsInfo.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/17 03:05:55 $
7   Version:   $Revision: 1.7 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmJPEGFragmentsInfo.h"
20 #include <fstream>
21
22 namespace gdcm 
23 {
24
25 /**
26  * \brief Default destructor
27  */
28 JPEGFragmentsInfo::~JPEGFragmentsInfo()
29 {
30    for(JPEGFragmentsList::iterator it  = Fragments.begin();
31                                    it != Fragments.end();
32                                  ++it )
33    {
34       delete *it;
35    }
36    Fragments.clear();
37 }
38
39 /**
40  * \brief        Print self.
41  * @param indent Indentation string to be prepended during printing.
42  * @param os     Stream to print to.
43  */
44 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const & indent )
45 {
46    os << indent
47       << "----------------- JPEG fragments --------------------------------"
48       << std::endl;
49    os << indent
50       << "Total number of fragments : " << Fragments.size()
51       << std::endl;
52    int fragmentNumber = 0;
53    for(JPEGFragmentsList::iterator it  = Fragments.begin();
54                                    it != Fragments.end();
55                                  ++it)
56    {
57       os << indent
58          << "   fragment number :" << fragmentNumber++;
59       (*it)->Print( os, indent + "   ");
60       os << std::endl;
61    }
62 }
63
64 /**
65  * \brief  Calculate sum of all fragments lenght and return total
66  * @return Total size of JPEG fragments length
67  */
68 size_t JPEGFragmentsInfo::GetFragmentsLength()
69 {
70    // Loop on the fragment[s] to get total length
71    size_t totalLength = 0;
72    JPEGFragmentsList::const_iterator it;
73    for( it  = Fragments.begin();
74         it != Fragments.end();
75         ++it )
76    {
77       totalLength += (*it)->Length;
78    }
79    return totalLength;
80 }
81
82 /**
83  * \brief Read the all the JPEG Fragment into the input buffer
84  */
85 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
86 {
87    JOCTET *p = buffer;
88
89    // Loop on the fragment[s]
90    JPEGFragmentsList::const_iterator it;
91    for( it  = Fragments.begin();
92         it != Fragments.end();
93         ++it )
94    {
95       fp->seekg( (*it)->Offset, std::ios::beg);
96       size_t len = (*it)->Length;
97       fp->read((char *)p,len);
98       p += len;
99    }
100
101 }
102
103 } // end namespace gdcm
104