]> Creatis software - gdcm.git/blob - src/gdcmJPEGFragmentsInfo.cxx
ddfaaabd5d55cfed55a3f36191e5f04be58ee2a8
[gdcm.git] / src / gdcmJPEGFragmentsInfo.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/23 10:12:34 $
7   Version:   $Revision: 1.8 $
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 os     Stream to print to.
42  * @param indent Indentation string to be prepended during printing.
43  */
44 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent )
45 {
46    os << std::endl;
47    os << indent
48       << "----------------- JPEG fragments --------------------------------"
49       << std::endl << std::endl;
50    os << indent
51       << "Total number of fragments : " << Fragments.size()
52       << std::endl;
53    int fragmentNumber = 0;
54    for(JPEGFragmentsList::iterator it  = Fragments.begin();
55                                    it != Fragments.end();
56                                  ++it)
57    {
58       os << indent
59          << "   fragment number :" << fragmentNumber++;
60       (*it)->Print( os, indent + "   ");
61    }
62    os << std::endl;
63 }
64
65 /**
66  * \brief  Calculate sum of all fragments length and return total
67  * @return Total size of JPEG fragments length
68  */
69 size_t JPEGFragmentsInfo::GetFragmentsLength()
70 {
71    // Loop on the fragment[s] to get total length
72    size_t totalLength = 0;
73    JPEGFragmentsList::const_iterator it;
74    for( it  = Fragments.begin();
75         it != Fragments.end();
76         ++it )
77    {
78       totalLength += (*it)->Length;
79    }
80    return totalLength;
81 }
82
83 /**
84  * \brief Read the all the JPEG Fragment into the input buffer
85  */
86 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
87 {
88    JOCTET *p = buffer;
89
90    // Loop on the fragment[s]
91    JPEGFragmentsList::const_iterator it;
92    for( it  = Fragments.begin();
93         it != Fragments.end();
94         ++it )
95    {
96       fp->seekg( (*it)->Offset, std::ios::beg);
97       size_t len = (*it)->Length;
98       fp->read((char *)p,len);
99       p += len;
100    }
101
102 }
103
104 } // end namespace gdcm
105