]> Creatis software - gdcm.git/blob - src/gdcmJPEGFragmentsInfo.cxx
* FIX : remove so many friend between classes
[gdcm.git] / src / gdcmJPEGFragmentsInfo.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/26 16:28:58 $
7   Version:   $Revision: 1.11 $
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 JPEGFragmentsInfo::JPEGFragmentsInfo()
26 {
27    StateSuspension = 0;
28 }
29
30 /**
31  * \brief Default destructor
32  */
33 JPEGFragmentsInfo::~JPEGFragmentsInfo()
34 {
35    for(JPEGFragmentsList::iterator it  = Fragments.begin();
36                                    it != Fragments.end();
37                                  ++it )
38    {
39       delete *it;
40    }
41    Fragments.clear();
42 }
43
44 /**
45  * \brief        Print self.
46  * @param os     Stream to print to.
47  * @param indent Indentation string to be prepended during printing.
48  */
49 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent )
50 {
51    os << std::endl;
52    os << indent
53       << "----------------- JPEG fragments --------------------------------"
54       << std::endl << std::endl;
55    os << indent
56       << "Total number of fragments : " << Fragments.size()
57       << std::endl;
58    int fragmentNumber = 0;
59    for(JPEGFragmentsList::iterator it  = Fragments.begin();
60                                    it != Fragments.end();
61                                  ++it)
62    {
63       os << indent
64          << "   fragment number :" << fragmentNumber++;
65       (*it)->Print( os, indent + "   ");
66    }
67    os << std::endl;
68 }
69
70 /**
71  * \brief  Calculate sum of all fragments length and return total
72  * @return Total size of JPEG fragments length
73  */
74 size_t JPEGFragmentsInfo::GetFragmentsLength()
75 {
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();
81         ++it )
82    {
83       totalLength += (*it)->GetLength();
84    }
85    return totalLength;
86 }
87
88 /**
89  * \brief Read the all the JPEG Fragment into the input buffer
90  */
91 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
92 {
93    JOCTET *p = buffer;
94
95    // Loop on the fragment[s]
96    JPEGFragmentsList::const_iterator it;
97    for( it  = Fragments.begin();
98         it != Fragments.end();
99         ++it )
100    {
101       fp->seekg( (*it)->GetOffset(), std::ios::beg);
102       size_t len = (*it)->GetLength();
103       fp->read((char *)p,len);
104       p += len;
105    }
106
107 }
108
109 void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length)
110 {
111    // Pointer to the Raw image
112    uint8_t *localRaw = buffer;
113
114   // Loop on the fragment[s]
115    JPEGFragmentsList::const_iterator it;
116    for( it  = Fragments.begin();
117         it != Fragments.end();
118         ++it )
119    {
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)
126
127       //localRaw += length * numBytes;
128      //std::cerr << "Used to increment by: " << length * numBytes << std::endl;
129    }
130 }
131
132 void JPEGFragmentsInfo::AddFragment(JPEGFragment *fragment)
133 {
134    Fragments.push_back(fragment);
135 }
136
137 } // end namespace gdcm
138