]> Creatis software - gdcm.git/blob - src/gdcmJPEGFragment.cxx
ENH: Huge commit to remove the previous implementation for jpeg/fragments/multiframes...
[gdcm.git] / src / gdcmJPEGFragment.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmJPEGFragment.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/31 03:22:25 $
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 "gdcmJPEGFragment.h"
20 #include "gdcmDebug.h"
21
22 namespace gdcm
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  * \brief Default constructor.
35  */
36 JPEGFragment::JPEGFragment()
37 {
38    Offset = 0;
39    Length = 0;
40
41 //   StateSuspension = 0;
42 //   void *SampBuffer;
43    pImage = 0;
44
45 }
46
47 /**
48  * \brief        Print self.
49  * @param os     Stream to print to.
50  * @param indent Indentation string to be prepended during printing.
51  */
52 void JPEGFragment::Print( std::ostream &os, std::string indent )
53 {
54    os << indent
55       << "JPEG fragment: offset : " <<  Offset
56       << "   length : " <<  Length
57       << std::endl;
58 }
59
60 /**
61  * \brief Decompress 8bits JPEG Fragment
62  * @param fp ifstream to write to
63  * @param buffer     output (data decompress)
64  * @param nBits      8/12 or 16 bits jpeg
65  * @param statesuspension state suspension
66  */
67 void JPEGFragment::DecompressJPEGFramesFromFile(std::ifstream *fp,
68                                                 uint8_t *buffer, int nBits, 
69                                                 int & statesuspension)
70 {
71    // First thing need to reset file to proper position:
72    fp->seekg( Offset, std::ios::beg);
73
74    if ( nBits == 8 )
75    {
76       // JPEG Lossy : call to IJG 6b
77       if ( ! this->gdcm_read_JPEG_file8( fp, buffer, statesuspension) )
78       {
79          //return false;
80       }
81    }
82    else if ( nBits <= 12 )
83    {
84       // Reading Fragment pixels
85       if ( ! this->gdcm_read_JPEG_file12 ( fp, buffer, statesuspension) )
86       {
87          //return false;
88       }
89    }
90    else if ( nBits <= 16 )
91    {
92       // Reading Fragment pixels
93       if ( ! this->gdcm_read_JPEG_file16 ( fp, buffer, statesuspension) )
94       {
95          //return false;
96       }
97       //gdcmAssertMacro( IsJPEGLossless );
98    }
99    else
100    {
101       // FIXME : only the bits number is checked,
102       //         NOT the compression method
103
104       // other JPEG lossy not supported
105       gdcmErrorMacro( "Unknown jpeg lossy compression ");
106       //return false;
107    }
108
109 }
110
111 } // end namespace gdcm
112