]> Creatis software - gdcm.git/blob - src/gdcmFile.h
* Rename src/gdcmPixelConvert.[h|cxx] to src/gdcmPixelReadConvert.[h|cxx]
[gdcm.git] / src / gdcmFile.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmFile.h,v $
5   Language:  C++
6   Date:      $Date: 2004/12/03 10:21:54 $
7   Version:   $Revision: 1.80 $
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 #include "gdcmPixelReadConvert.h"
25 #include "gdcmDocEntryArchive.h"
26
27 namespace gdcm 
28 {
29 //-----------------------------------------------------------------------------
30 /*
31  * In addition to Dicom header exploration, this class is designed
32  * for accessing the image/volume content. One can also use it to
33  * write Dicom/ACR-NEMA/RAW files.
34  */
35 class GDCM_EXPORT File
36 {
37 public:
38    enum TWriteMode
39    {
40       WMODE_DECOMPRESSED,
41       WMODE_RGB
42    };
43      
44    enum TWriteType
45    {
46       WTYPE_IMPL_VR,
47       WTYPE_EXPL_VR,
48       WTYPE_ACR
49    };
50      
51 public:
52    File( Header* header );
53    File( std::string const& filename );
54  
55    virtual ~File();
56
57    /// Accessor to \ref Header
58    Header* GetHeader() { return HeaderInternal; }
59
60    size_t GetImageDataSize();
61    size_t GetImageDataRawSize();
62
63    /// Accessor to \ref PixelReadConverter
64    PixelReadConvert* GetPixelReadConverter() { return PixelReadConverter; };
65
66    uint8_t* GetImageData();
67    uint8_t* GetImageDataRaw();
68    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
69
70    bool SetImageData (uint8_t* data, size_t expectedSize);
71
72    // Write pixels of ONE image on hard drive
73    // No test is made on processor "endianity"
74    // The user must call his reader correctly
75    bool WriteRawData  (std::string const& fileName);
76    bool WriteDcmImplVR(std::string const& fileName);
77    bool WriteDcmExplVR(std::string const& fileName);
78    bool WriteAcr      (std::string const& fileName);
79    bool Write(std::string const& fileName);
80
81    virtual bool SetEntryByNumber(std::string const& content,
82                                  uint16_t group, uint16_t element)
83    { 
84       HeaderInternal->SetEntryByNumber(content,group,element);
85       return true;
86    }
87    uint8_t* GetLutRGBA();
88
89    // Write mode
90    void SetWriteModeToDecompressed()    { SetWriteMode(WMODE_DECOMPRESSED); };
91    void SetWriteModeToRGB()             { SetWriteMode(WMODE_RGB); };
92    void SetWriteMode(unsigned int mode) { WriteMode = mode; };
93    unsigned int GetWriteMode()          { return WriteMode; };
94
95    // Write format
96    void SetWriteTypeToDcmImplVR()         { SetWriteType(WTYPE_EXPL_VR); };
97    void SetWriteTypeToDcmExplVR()         { SetWriteType(WTYPE_EXPL_VR); };
98    void SetWriteTypeToAcr()               { SetWriteType(WTYPE_ACR); };
99    void SetWriteType(unsigned int format) { WriteType = format; };
100    unsigned int GetWriteType()            { return WriteType; };
101
102 protected:
103    bool WriteBase(std::string const& fileName, FileType type);
104    bool CheckWriteIntegrity();
105
106    void SetWriteToDecompressed();
107    void SetWriteToRGB();
108    void RestoreWrite();
109
110    void SetWriteFileTypeToACR();
111    void SetWriteFileTypeToExplicitVR();
112    void SetWriteFileTypeToImplicitVR();
113    void RestoreWriteFileType();
114
115    void SetWriteToLibido();
116    void SetWriteToNoLibido();
117    void RestoreWriteOfLibido();
118
119    ValEntry* CopyValEntry(uint16_t group,uint16_t element);
120    BinEntry* CopyBinEntry(uint16_t group,uint16_t element);
121
122 private:
123    void Initialise();
124
125    uint8_t* GetDecompressed();
126    int ComputeDecompressedPixelDataSizeFromHeader();
127
128 private:
129 // members variables:
130
131    /// Header to use to load the file
132    Header *HeaderInternal;
133
134    /// \brief Whether the underlying \ref Header was loaded by
135    ///  the constructor or passed to the constructor. When false
136    ///  the destructor is in charge of deletion.
137    bool SelfHeader;
138    
139    /// Wether already parsed or not
140    bool Parsed;
141
142    /// Utility pixel converter
143    PixelReadConvert* PixelReadConverter;
144
145    // Utility header archive
146    DocEntryArchive *Archive;
147
148    // Write variables
149    unsigned int WriteMode;
150    unsigned int WriteType;
151
152 /// FIXME
153 // --------------- Will be moved to a PixelData class
154 //
155
156    /// \brief to hold the Pixels (when read)
157    uint8_t* Pixel_Data;  // (was PixelData)
158    
159    /// \brief Size (in bytes) of requited memory to hold the the pixels
160    ///        of this image in it's RGB convertion either from:
161    ///        - Plane R, Plane G, Plane B 
162    ///        - Grey Plane + Palette Color
163    ///        - YBR Pixels (or from RGB Pixels, as well) 
164    size_t ImageDataSize;
165        
166 //
167 // --------------- end of future PixelData class
168 // 
169
170 };
171 } // end namespace gdcm
172
173 //-----------------------------------------------------------------------------
174 #endif