]> Creatis software - gdcm.git/blob - src/gdcmJPEGFragment.cxx
Fix mistypings
[gdcm.git] / src / gdcmJPEGFragment.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJPEGFragment.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/01/02 10:48:52 $
7   Version:   $Revision: 1.20 $
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 "gdcmJPEGFragment.h"
20 #include "gdcmDebug.h"
21
22 namespace GDCM_NAME_SPACE
23 {
24 //-------------------------------------------------------------------------
25 // For JPEG 2000, body in file gdcmJpeg2000.cxx
26 // Not yet made
27 bool gdcm_read_JPEG2000_file (std::ifstream *fp, void *image_buffer);
28
29 // For JPEG-LS, body in file gdcmJpegLS.cxx
30 // Not yet made
31 bool gdcm_read_JPEGLS_file (std::ifstream *fp, void *image_buffer);
32
33 //-------------------------------------------------------------------------
34 // Constructor / Destructor
35 /**
36  * \brief Default constructor.
37  */
38 JPEGFragment::JPEGFragment()
39 {
40    Offset = 0;
41    Length = 0;
42
43    pImage = 0;
44
45 }
46
47 //-----------------------------------------------------------------------------
48 // Public
49 /**
50  * \brief Decompress 8bits JPEG Fragment
51  * @param fp ifstream to write to
52  * @param buffer     output (data decompress)
53  * @param nBits      8/12 or 16 bits jpeg
54  * @param statesuspension state suspension
55  */
56 void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp,
57                                                 uint8_t *buffer, int nBits, 
58                                                 int &statesuspension)
59 {
60    // First thing need to reset file to proper position:
61    fp->seekg( Offset, std::ios::beg);
62
63    if ( nBits == 8 )
64    {
65       // JPEG Lossy : call to IJG 6b - 8 bits
66       ReadJPEGFile8( fp, buffer, statesuspension);
67    }
68    else if ( nBits <= 12 )
69    {
70        assert( nBits >= 8 );
71       // JPEG Lossy : call to IJG 6b - 12 bits
72       ReadJPEGFile12 ( fp, buffer, statesuspension);
73    }
74    else if ( nBits <= 16 )
75    {
76        assert( nBits >= 12 );
77       // JPEG Lossy : call to IJG 6b - 16 bits
78       ReadJPEGFile16 ( fp, buffer, statesuspension);
79       //gdcmAssertMacro( IsJPEGLossless );
80    }
81    else
82    {
83       // FIXME : only the bits number is checked,
84       //         NOT the compression method
85
86       // other JPEG lossy not supported
87       gdcmErrorMacro( "Unknown jpeg lossy compression ");
88    }
89 }
90
91 //-----------------------------------------------------------------------------
92 // Protected
93
94 //-----------------------------------------------------------------------------
95 // Private
96
97 //-----------------------------------------------------------------------------
98 // Print
99 /**
100  * \brief        Print self.
101  * @param os     Stream to print to.
102  * @param indent Indentation string to be prepended during printing.
103  */
104 void JPEGFragment::Print( std::ostream &os, std::string const &indent )
105 {
106    os << indent
107       << "JPEG fragment: offset : " <<  std::dec << Offset 
108       << " 0x(" << std::hex << Offset << ") "
109       << std::dec << "   length : " <<  Length
110       << " 0x(" << std::hex << Length << ") "      
111       << std::endl;
112 }
113
114 //-----------------------------------------------------------------------------
115 } // end namespace gdcm
116