GDCM  2.4.5
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 
22 namespace gdcm
23 {
24 
25 class TransferSyntax;
26 
46 {
47  friend class Bitmap;
48  friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
49 public:
50  // When adding a type please add its dual type (its unsigned conterpart)
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  explicit PixelFormat (
71  unsigned short samplesperpixel = 1,
72  unsigned short bitsallocated = 8,
73  unsigned short bitsstored = 8,
74  unsigned short highbit = 7,
75  unsigned short pixelrepresentation = 0 ) :
76  SamplesPerPixel(samplesperpixel),
77  BitsAllocated(bitsallocated),
78  BitsStored(bitsstored),
79  HighBit(highbit),
80  PixelRepresentation(pixelrepresentation) {}
81  // helper, for the common case
82  PixelFormat(ScalarType st);
83 
84  // For transparency of use
85  operator ScalarType() const { return GetScalarType(); }
86 
89  unsigned short GetSamplesPerPixel() const;
90  void SetSamplesPerPixel(unsigned short spp)
91  {
92  gdcmAssertMacro( spp <= 4 );
93  SamplesPerPixel = spp;
94  assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
95  }
96 
98  unsigned short GetBitsAllocated() const
99  {
100  return BitsAllocated;
101  }
102  void SetBitsAllocated(unsigned short ba)
103  {
104  if( ba )
105  {
106  BitsAllocated = ba;
107  BitsStored = ba;
108  HighBit = (unsigned short)(ba - 1);
109  }
110  else // Make the PixelFormat as UNKNOWN
111  {
112  BitsAllocated = 0;
113  PixelRepresentation = 0;
114  }
115  }
116 
118  unsigned short GetBitsStored() const
119  {
120  assert( BitsStored <= BitsAllocated );
121  return BitsStored;
122  }
123  void SetBitsStored(unsigned short bs)
124  {
125  if( bs <= BitsAllocated && bs )
126  {
127  BitsStored = bs;
128  SetHighBit( (unsigned short) (bs - 1) );
129  }
130  }
131 
133  unsigned short GetHighBit() const
134  {
135  assert( HighBit < BitsStored );
136  return HighBit;
137  }
138  void SetHighBit(unsigned short hb)
139  {
140  if( hb < BitsStored )
141  HighBit = hb;
142  }
143 
145  unsigned short GetPixelRepresentation() const
146  {
147  return (unsigned short)(PixelRepresentation ? 1 : 0);
148  }
149  void SetPixelRepresentation(unsigned short pr)
150  {
151  PixelRepresentation = (unsigned short)(pr ? 1 : 0);
152  }
153 
155  ScalarType GetScalarType() const;
156 
159  void SetScalarType(ScalarType st);
160  const char *GetScalarTypeAsString() const;
161 
167  uint8_t GetPixelSize() const;
168 
170  void Print(std::ostream &os) const;
171 
173  int64_t GetMin() const;
174 
176  int64_t GetMax() const;
177 
179  bool IsValid() const;
180 
181  bool operator==(ScalarType st) const
182  {
183  return GetScalarType() == st;
184  }
185  bool operator!=(ScalarType st) const
186  {
187  return GetScalarType() != st;
188  }
189  bool operator==(const PixelFormat &pf) const
190  {
191  return
192  SamplesPerPixel == pf.SamplesPerPixel &&
193  BitsAllocated == pf.BitsAllocated &&
194  BitsStored == pf.BitsStored &&
195  HighBit == pf.HighBit &&
196  PixelRepresentation == pf.PixelRepresentation;
197  }
198  bool operator!=(const PixelFormat &pf) const
199  {
200  return
201  SamplesPerPixel != pf.SamplesPerPixel ||
202  BitsAllocated != pf.BitsAllocated ||
203  BitsStored != pf.BitsStored ||
204  HighBit != pf.HighBit ||
205  PixelRepresentation != pf.PixelRepresentation;
206  }
207 
208  bool IsCompatible(const TransferSyntax & ts ) const;
209 protected:
211  bool Validate();
212 
213 private:
214  // D 0028|0002 [US] [Samples per Pixel] [1]
215  unsigned short SamplesPerPixel;
216  // D 0028|0100 [US] [Bits Allocated] [8]
217  unsigned short BitsAllocated;
218  // D 0028|0101 [US] [Bits Stored] [8]
219  unsigned short BitsStored;
220  // D 0028|0102 [US] [High Bit] [7]
221  unsigned short HighBit;
222  // D 0028|0103 [US] [Pixel Representation] [0]
223  unsigned short PixelRepresentation;
224 };
225 //-----------------------------------------------------------------------------
226 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
227 {
228  pf.Print( os );
229  return os;
230 }
231 
232 } // end namespace gdcm
233 
234 #endif //GDCMPIXELFORMAT_H
Definition: gdcmPixelFormat.h:63
bool operator==(ScalarType st) const
Definition: gdcmPixelFormat.h:181
Definition: gdcmPixelFormat.h:61
void SetBitsAllocated(unsigned short ba)
Definition: gdcmPixelFormat.h:102
ScalarType
Definition: gdcmPixelFormat.h:51
Definition: gdcmPixelFormat.h:59
bool operator!=(ScalarType st) const
Definition: gdcmPixelFormat.h:185
Definition: gdcmPixelFormat.h:54
bool operator==(const PixelFormat &pf) const
Definition: gdcmPixelFormat.h:189
void SetSamplesPerPixel(unsigned short spp)
Definition: gdcmPixelFormat.h:90
unsigned short GetHighBit() const
HighBit see Tag (0028,0102) US High Bit.
Definition: gdcmPixelFormat.h:133
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
void SetHighBit(unsigned short hb)
Definition: gdcmPixelFormat.h:138
Definition: gdcmPixelFormat.h:58
Definition: gdcmPixelFormat.h:64
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition: gdcmDirectory.h:88
Bitmap class A bitmap based image. Used as parent for both IconImage and the main Pixel Data Image It...
Definition: gdcmBitmap.h:38
#define gdcmAssertMacro(arg)
Assert.
Definition: gdcmTrace.h:186
Definition: gdcmPixelFormat.h:53
unsigned short GetPixelRepresentation() const
PixelRepresentation: 0 or 1, see Tag (0028,0103) US Pixel Representation.
Definition: gdcmPixelFormat.h:145
Class to manipulate Transfer Syntax.
Definition: gdcmTransferSyntax.h:39
Definition: gdcmPixelFormat.h:56
Definition: gdcmPixelFormat.h:60
bool operator!=(const PixelFormat &pf) const
Definition: gdcmPixelFormat.h:198
Definition: gdcmPixelFormat.h:52
Validate class.
Definition: gdcmValidate.h:25
PixelFormat(unsigned short samplesperpixel=1, unsigned short bitsallocated=8, unsigned short bitsstored=8, unsigned short highbit=7, unsigned short pixelrepresentation=0)
Definition: gdcmPixelFormat.h:70
void SetBitsStored(unsigned short bs)
Definition: gdcmPixelFormat.h:123
void Print(std::ostream &os) const
Print.
unsigned short GetBitsStored() const
BitsStored see Tag (0028,0101) US Bits Stored.
Definition: gdcmPixelFormat.h:118
Definition: gdcmPixelFormat.h:55
Definition: gdcmPixelFormat.h:57
Definition: gdcmPixelFormat.h:62
Definition: gdcmASN1.h:20
PixelFormat.
Definition: gdcmPixelFormat.h:45
unsigned short GetBitsAllocated() const
BitsAllocated see Tag (0028,0100) US Bits Allocated.
Definition: gdcmPixelFormat.h:98
void SetPixelRepresentation(unsigned short pr)
Definition: gdcmPixelFormat.h:149
Definition: gdcmPixelFormat.h:65

Generated on Fri Sep 25 2015 17:58:23 for GDCM by doxygen 1.8.9.1
SourceForge.net Logo