]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* CLEANUP_ROUND (9) for gdcmPixelConvert
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/10/08 17:02:53 $
7   Version:   $Revision: 1.58 $
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 #ifndef GDCMFILE_H
20 #define GDCMFILE_H
21
22 #include "gdcmCommon.h"
23 #include "gdcmHeader.h"
24
25 //-----------------------------------------------------------------------------
26 /*
27  * In addition to Dicom header exploration, this class is designed
28  * for accessing the image/volume content. One can also use it to
29  * write Dicom/ACR-NEMA/RAW files.
30  */
31 class GDCM_EXPORT gdcmFile
32 {
33 public:
34    gdcmFile( gdcmHeader *header );
35    gdcmFile( std::string const& filename );
36  
37    virtual ~gdcmFile();
38
39    /// Accessor to \ref Header
40    gdcmHeader* GetHeader() { return Header; }
41
42    int ComputeDecompressedPixelDataSizeFromHeader();
43
44    void ConvertRGBPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
45    void ConvertYcBcRPlanesToRGBPixels( uint8_t* source, uint8_t* destination );
46    void ConvertReArrangeBits(
47            uint8_t* pixelZone,
48            size_t imageDataSize,
49            int numberBitsStored,
50            int numberBitsAllocated,
51            int highBitPosition ) throw ( gdcmFormatError );
52    
53    /// Accessor to \ref ImageDataSize
54    size_t GetImageDataSize(){ return ImageDataSize; };
55
56    /// Accessor to \ref ImageDataSizeRaw
57    size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; };
58
59    uint8_t* GetImageData();
60    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
61    uint8_t* GetImageDataRaw();
62    size_t GetImageDataIntoVectorRaw(void* destination, size_t maxSize);
63
64    // see also gdcmHeader::SetImageDataSize ?!?         
65    bool SetImageData (uint8_t* data, size_t expectedSize);
66
67    /// \todo When the caller is aware we simply point to the data:
68    /// int SetImageDataNoCopy (void* Data, size_t ExpectedSize);
69
70    // Write pixels of ONE image on hard drive
71    // No test is made on processor "endianity"
72    // The user must call his reader correctly
73    bool WriteRawData  (std::string const& fileName);
74    bool WriteDcmImplVR(std::string const& fileName);
75    bool WriteDcmExplVR(std::string const& fileName);
76    bool WriteAcr      (std::string const& fileName);
77
78    // Don't look any longer for the code : 
79    // It's in file gdcmParsePixels.cxx
80    bool ParsePixelData();
81
82    virtual bool SetEntryByNumber(std::string const& content,
83                                  uint16_t group, uint16_t element)
84    { 
85       Header->SetEntryByNumber(content,group,element);
86       return true;
87    }
88      
89 protected:
90    bool WriteBase(std::string const& fileName, FileType type);
91
92 private:
93    void Initialise();
94
95    bool ReadPixelData(void* destination);
96    
97    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
98    bool gdcm_read_JPEG_file     (FILE* fp, void* image_buffer); 
99    bool gdcm_write_JPEG_file    (FILE* fp, void* image_buffer, 
100                                  int image_width, int image_heigh,
101                                  int quality);
102
103    // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
104    bool gdcm_read_JPEG_file12   (FILE* fp, void* image_buffer);
105    bool gdcm_write_JPEG_file12  (FILE* fp, void* image_buffer, 
106                                  int image_width, int image_height,
107                                  int quality);
108
109    // For JPEG 2000, body in file gdcmJpeg2000.cxx
110    bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
111
112    void SaveInitialValues();    // will belong to the future gdcmPixelData class
113    void RestoreInitialValues(); // will belong to the future gdcmPixelData class
114    void DeleteInitialValues();  // will belong to the future gdcmPixelData class 
115
116 // members variables:
117
118    /// \brief Header to use to load the file
119    gdcmHeader *Header;
120
121    /// \brief Whether the underlying \ref gdcmHeader was loaded by
122    ///  the constructor or passed to the constructor. When false
123    ///  the destructor is in charge of deletion.
124    bool SelfHeader;
125    
126    /// wether already parsed 
127    bool Parsed;
128       
129 //
130 // --------------- Will be moved to a gdcmPixelData class
131 //
132
133    /// \brief to hold the Pixels (when read)
134    uint8_t* Pixel_Data;  // (was PixelData)
135    
136    /// \brief Size (in bytes) of required memory to hold the Gray Level pixels
137    ///        represented in this file. This is used when the user DOESN'T want
138    ///        the RGB pixels image when it's stored as a PALETTE COLOR image
139    size_t ImageDataSizeRaw;
140    
141    /// \brief Size (in bytes) of requited memory to hold the the pixels
142    ///        of this image in it's RGB convertion either from:
143    ///        - Plane R, Plane G, Plane B 
144    ///        - Grey Plane + Palette Color
145    ///        - YBR Pixels (or from RGB Pixels, as well) 
146    size_t ImageDataSize;
147        
148   /// \brief ==1  if GetImageDataRaw was used
149   ///        ==0  if GetImageData    was used
150   ///        ==-1 if ImageData never read                       
151    int PixelRead;
152
153   /// \brief length of the last allocated area devoided to receive Pixels
154   ///        ( to allow us not to (free + new) if un necessary )     
155    size_t LastAllocatedPixelDataLength; 
156
157   // Initial values of some fields that can be modified during reading process
158   // if user asked to transform gray level + LUT image into RGB image
159      
160   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
161    std::string InitialSpp;
162   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
163    std::string InitialPhotInt;
164   /// \brief Planar Configuration        (0x0028,0x0006), as found on disk   
165    std::string InitialPlanConfig;
166     
167   // Initial values of some fields that can be modified during reading process
168   // if the image was a 'strange' ACR-NEMA 
169   // (Bits Allocated=12, High Bit not equal to Bits stored +1) 
170   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
171    std::string InitialBitsAllocated;
172   /// \brief High Bit                    (0x0028,0x0102), as found on disk
173    std::string InitialHighBit;
174   
175   // some DocEntry that can be moved out of the H table during reading process
176   // if user asked to transform gray level + LUT image into RGB image
177   // We keep a pointer on them for a future use.
178      
179   /// \brief Red Palette Color Lookup Table Descriptor   0028 1101 as read
180   gdcmDocEntry* InitialRedLUTDescr;  
181   /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
182   gdcmDocEntry* InitialGreenLUTDescr;
183   /// \brief Blue Palette Color Lookup Table Descriptor  0028 1103 as read
184   gdcmDocEntry* InitialBlueLUTDescr;
185   
186   /// \brief Red Palette Color Lookup Table Data         0028 1201 as read
187   gdcmDocEntry* InitialRedLUTData;  
188   /// \brief Green Palette Color Lookup Table Data       0028 1202 as read
189   gdcmDocEntry* InitialGreenLUTData;
190   /// \brief Blue Palette Color Lookup Table Data        0028 1203 as read
191   gdcmDocEntry* InitialBlueLUTData;
192   
193 //
194 // --------------- end of future gdcmPixelData class
195 //  
196
197 };
198
199 //-----------------------------------------------------------------------------
200 #endif