GDCM 3.0.24
gdcmPixelFormat.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
14
15#ifndef GDCMPIXELFORMAT_H
16#define GDCMPIXELFORMAT_H
17
18#include "gdcmTypes.h"
19#include <iostream>
20#include <assert.h>
21
22namespace gdcm
23{
24
25class TransferSyntax;
26
46{
47 friend class Bitmap;
48 friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
49public:
50 // When adding a type please add its dual type (its unsigned counterpart)
51 typedef enum {
58 UINT32, // For some DICOM files (RT or SC)
59 INT32, // " "
60 UINT64, // Needed when input is 32bits + intercept/slope (incomplete support)
61 INT64, // " "
62 FLOAT16, // sure why not...
63 FLOAT32, // good ol' 'float'
64 FLOAT64, // aka 'double'
65 SINGLEBIT, // bool / monochrome
66 UNKNOWN // aka BitsAllocated == 0 && PixelRepresentation == 0
67 } ScalarType;
68
69 // default cstor:
70 PixelFormat () : PixelFormat(1, 8, 8, 7, 0) {}
71
72 explicit PixelFormat (
73 unsigned short samplesperpixel,
74 unsigned short bitsallocated = 8,
75 unsigned short bitsstored = 8,
76 unsigned short highbit = 7,
77 unsigned short pixelrepresentation = 0 ) :
78 SamplesPerPixel(samplesperpixel),
79 BitsAllocated(bitsallocated),
80 BitsStored(bitsstored),
81 HighBit(highbit),
82 PixelRepresentation(pixelrepresentation) {}
83 // helper, for the common case
85
86 // For transparency of use
87 operator ScalarType() const { return GetScalarType(); }
88
91 unsigned short GetSamplesPerPixel() const;
92 void SetSamplesPerPixel(unsigned short spp)
93 {
94 gdcmAssertMacro( spp <= 4 );
95 SamplesPerPixel = spp;
96 assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
97 }
98
100 unsigned short GetBitsAllocated() const
101 {
102 return BitsAllocated;
103 }
104 void SetBitsAllocated(unsigned short ba)
105 {
106 if( ba )
107 {
108 switch( ba )
109 {
110 /* some devices (FUJIFILM CR + MONO1) incorrectly set BitsAllocated/BitsStored
111 * as bitmask instead of value. Do what they mean instead of what they say.
112 */
113 case 0xffff: ba = 16; break;
114 case 0x0fff: ba = 12; break;
115 case 0x00ff: ba = 8; break;
116 }
117 BitsAllocated = ba;
118 BitsStored = ba;
119 HighBit = (unsigned short)(ba - 1);
120 }
121 else // Make the PixelFormat as UNKNOWN
122 {
123 BitsAllocated = 0;
124 PixelRepresentation = 0;
125 }
126 }
127
129 unsigned short GetBitsStored() const
130 {
131 assert( BitsStored <= BitsAllocated );
132 return BitsStored;
133 }
134 void SetBitsStored(unsigned short bs)
135 {
136 switch( bs )
137 {
138 /* see SetBitsAllocated for explanation
139 */
140 case 0xffff: bs = 16; break;
141 case 0x0fff: bs = 12; break;
142 case 0x00ff: bs = 8; break;
143 }
144 if( bs <= BitsAllocated && bs )
145 {
146 BitsStored = bs;
147 SetHighBit( (unsigned short) (bs - 1) );
148 }
149 }
150
152 unsigned short GetHighBit() const
153 {
154 assert( HighBit < BitsStored );
155 return HighBit;
156 }
157 void SetHighBit(unsigned short hb)
158 {
159 switch( hb )
160 {
161 /* broken implementations that use bitmask for BitsAllocated/Stored
162 * nonetheless use (BitsStored-1) for HighBit. correct for this here.
163 */
164 case 0xfffe: hb = 15; break;
165 case 0x0ffe: hb = 11; break;
166 case 0x00fe: hb = 7; break;
167 }
168 if( hb < BitsStored )
169 HighBit = hb;
170 }
171
173 unsigned short GetPixelRepresentation() const
174 {
175 return (unsigned short)(PixelRepresentation ? 1 : 0);
176 }
177 void SetPixelRepresentation(unsigned short pr)
178 {
179 PixelRepresentation = (unsigned short)(pr ? 1 : 0);
180 }
181
184
188 const char *GetScalarTypeAsString() const;
189
195 uint8_t GetPixelSize() const;
196
198 void Print(std::ostream &os) const;
199
201 int64_t GetMin() const;
202
204 int64_t GetMax() const;
205
207 bool IsValid() const;
208
209 bool operator==(ScalarType st) const
210 {
211 return GetScalarType() == st;
212 }
213 bool operator!=(ScalarType st) const
214 {
215 return GetScalarType() != st;
216 }
217 bool operator==(const PixelFormat &pf) const
218 {
219 return
220 SamplesPerPixel == pf.SamplesPerPixel &&
221 BitsAllocated == pf.BitsAllocated &&
222 BitsStored == pf.BitsStored &&
223 HighBit == pf.HighBit &&
224 PixelRepresentation == pf.PixelRepresentation;
225 }
226 bool operator!=(const PixelFormat &pf) const
227 {
228 return
229 SamplesPerPixel != pf.SamplesPerPixel ||
230 BitsAllocated != pf.BitsAllocated ||
231 BitsStored != pf.BitsStored ||
232 HighBit != pf.HighBit ||
233 PixelRepresentation != pf.PixelRepresentation;
234 }
235
236 bool IsCompatible(const TransferSyntax & ts ) const;
237protected:
239 bool Validate();
240
241private:
242 // D 0028|0002 [US] [Samples per Pixel] [1]
243 unsigned short SamplesPerPixel;
244 // D 0028|0100 [US] [Bits Allocated] [8]
245 unsigned short BitsAllocated;
246 // D 0028|0101 [US] [Bits Stored] [8]
247 unsigned short BitsStored;
248 // D 0028|0102 [US] [High Bit] [7]
249 unsigned short HighBit;
250 // D 0028|0103 [US] [Pixel Representation] [0]
251 unsigned short PixelRepresentation;
252};
253//-----------------------------------------------------------------------------
254inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
255{
256 pf.Print( os );
257 return os;
258}
259
260} // end namespace gdcm
261
262#endif //GDCMPIXELFORMAT_H
Bitmap class.
Definition gdcmBitmap.h:39
PixelFormat.
Definition gdcmPixelFormat.h:46
bool IsCompatible(const TransferSyntax &ts) const
PixelFormat(unsigned short samplesperpixel, unsigned short bitsallocated=8, unsigned short bitsstored=8, unsigned short highbit=7, unsigned short pixelrepresentation=0)
Definition gdcmPixelFormat.h:72
void SetScalarType(ScalarType st)
bool operator!=(ScalarType st) const
Definition gdcmPixelFormat.h:213
void SetBitsStored(unsigned short bs)
Definition gdcmPixelFormat.h:134
unsigned short GetSamplesPerPixel() const
unsigned short GetPixelRepresentation() const
PixelRepresentation: 0 or 1, see Tag (0028,0103) US Pixel Representation.
Definition gdcmPixelFormat.h:173
void SetSamplesPerPixel(unsigned short spp)
Definition gdcmPixelFormat.h:92
uint8_t GetPixelSize() const
PixelFormat(ScalarType st)
const char * GetScalarTypeAsString() const
void SetHighBit(unsigned short hb)
Definition gdcmPixelFormat.h:157
void SetBitsAllocated(unsigned short ba)
Definition gdcmPixelFormat.h:104
bool operator!=(const PixelFormat &pf) const
Definition gdcmPixelFormat.h:226
void Print(std::ostream &os) const
Print.
bool Validate()
When image with 24/24/23 was read, need to validate.
int64_t GetMax() const
return the max possible of the pixel
PixelFormat()
Definition gdcmPixelFormat.h:70
unsigned short GetHighBit() const
HighBit see Tag (0028,0102) US High Bit.
Definition gdcmPixelFormat.h:152
unsigned short GetBitsAllocated() const
BitsAllocated see Tag (0028,0100) US Bits Allocated.
Definition gdcmPixelFormat.h:100
bool operator==(const PixelFormat &pf) const
Definition gdcmPixelFormat.h:217
bool operator==(ScalarType st) const
Definition gdcmPixelFormat.h:209
unsigned short GetBitsStored() const
BitsStored see Tag (0028,0101) US Bits Stored.
Definition gdcmPixelFormat.h:129
ScalarType
Definition gdcmPixelFormat.h:51
@ UINT32
Definition gdcmPixelFormat.h:58
@ INT32
Definition gdcmPixelFormat.h:59
@ INT8
Definition gdcmPixelFormat.h:53
@ FLOAT32
Definition gdcmPixelFormat.h:63
@ SINGLEBIT
Definition gdcmPixelFormat.h:65
@ INT12
Definition gdcmPixelFormat.h:55
@ FLOAT64
Definition gdcmPixelFormat.h:64
@ FLOAT16
Definition gdcmPixelFormat.h:62
@ UINT8
Definition gdcmPixelFormat.h:52
@ UINT12
Definition gdcmPixelFormat.h:54
@ UINT64
Definition gdcmPixelFormat.h:60
@ UINT16
Definition gdcmPixelFormat.h:56
@ INT16
Definition gdcmPixelFormat.h:57
@ INT64
Definition gdcmPixelFormat.h:61
ScalarType GetScalarType() const
ScalarType does not take into account the sample per pixel.
bool IsValid() const
return IsValid
void SetPixelRepresentation(unsigned short pr)
Definition gdcmPixelFormat.h:177
int64_t GetMin() const
return the min possible of the pixel
Class to manipulate Transfer Syntax.
Definition gdcmTransferSyntax.h:40
#define gdcmAssertMacro(arg)
Assert.
Definition gdcmTrace.h:189
#define GDCM_EXPORT
Definition gdcmWin32.h:34
Definition gdcmASN1.h:21
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition gdcmDirectory.h:88