]> 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 11:42:02 $
7   Version:   $Revision: 1.10 $
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  * \brief Default destructor
31  */
32 JPEGFragmentsInfo::~JPEGFragmentsInfo()
33 {
34    for(JPEGFragmentsList::iterator it  = Fragments.begin();
35                                    it != Fragments.end();
36                                  ++it )
37    {
38       delete *it;
39    }
40    Fragments.clear();
41 }
42
43 /**
44  * \brief        Print self.
45  * @param os     Stream to print to.
46  * @param indent Indentation string to be prepended during printing.
47  */
48 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent )
49 {
50    os << std::endl;
51    os << indent
52       << "----------------- JPEG fragments --------------------------------"
53       << std::endl << std::endl;
54    os << indent
55       << "Total number of fragments : " << Fragments.size()
56       << std::endl;
57    int fragmentNumber = 0;
58    for(JPEGFragmentsList::iterator it  = Fragments.begin();
59                                    it != Fragments.end();
60                                  ++it)
61    {
62       os << indent
63          << "   fragment number :" << fragmentNumber++;
64       (*it)->Print( os, indent + "   ");
65    }
66    os << std::endl;
67 }
68
69 /**
70  * \brief  Calculate sum of all fragments length and return total
71  * @return Total size of JPEG fragments length
72  */
73 size_t JPEGFragmentsInfo::GetFragmentsLength()
74 {
75    // Loop on the fragment[s] to get total length
76    size_t totalLength = 0;
77    JPEGFragmentsList::const_iterator it;
78    for( it  = Fragments.begin();
79         it != Fragments.end();
80         ++it )
81    {
82       totalLength += (*it)->GetLength();
83    }
84    return totalLength;
85 }
86
87 /**
88  * \brief Read the all the JPEG Fragment into the input buffer
89  */
90 void JPEGFragmentsInfo::ReadAllFragments(std::ifstream *fp, JOCTET *buffer )
91 {
92    JOCTET *p = buffer;
93
94    // Loop on the fragment[s]
95    JPEGFragmentsList::const_iterator it;
96    for( it  = Fragments.begin();
97         it != Fragments.end();
98         ++it )
99    {
100       fp->seekg( (*it)->GetOffset(), std::ios::beg);
101       size_t len = (*it)->GetLength();
102       fp->read((char *)p,len);
103       p += len;
104    }
105
106 }
107
108 void JPEGFragmentsInfo::DecompressJPEGFramesFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int numBytes, int length)
109 {
110    // Pointer to the Raw image
111    uint8_t *localRaw = buffer;
112
113   // Loop on the fragment[s]
114    JPEGFragmentsList::const_iterator it;
115    for( it  = Fragments.begin();
116         it != Fragments.end();
117         ++it )
118    {
119      //(*it)->pimage = localRaw;
120      (*it)->DecompressJPEGFramesFromFile(fp, localRaw, nBits, StateSuspension);
121      // update pointer to image after some scanlines read:
122      localRaw = (*it)->GetImage();
123       // Advance to next free location in Raw 
124       // for next fragment decompression (if any)
125
126       //localRaw += length * numBytes;
127      //std::cerr << "Used to increment by: " << length * numBytes << std::endl;
128    }
129 }
130
131 } // end namespace gdcm
132