GDCM  2.2.6
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 
37 {
38  friend class Bitmap;
39  friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
40 public:
41  // When adding a type please add its dual type (its unsigned conterpart)
42  typedef enum {
49  UINT32, // For some DICOM files (RT or SC)
50  INT32, // " "
51  FLOAT16, // sure why not...
52  FLOAT32, // good ol' 'float'
53  FLOAT64, // aka 'double'
54  SINGLEBIT, // bool / monochrome
55  UNKNOWN // aka BitsAllocated == 0 && PixelRepresentation == 0
56  } ScalarType;
57 
58  // default cstor:
59  explicit PixelFormat (
60  unsigned short samplesperpixel = 1,
61  unsigned short bitsallocated = 8,
62  unsigned short bitsstored = 8,
63  unsigned short highbit = 7,
64  unsigned short pixelrepresentation = 0 ) :
65  SamplesPerPixel(samplesperpixel),
66  BitsAllocated(bitsallocated),
67  BitsStored(bitsstored),
68  HighBit(highbit),
69  PixelRepresentation(pixelrepresentation) {}
70  // helper, for the common case
71  PixelFormat(ScalarType st);
72 
73  // For transparency of use
74  operator ScalarType() const { return GetScalarType(); }
75 
78  unsigned short GetSamplesPerPixel() const;
79  void SetSamplesPerPixel(unsigned short spp)
80  {
81  gdcmAssertMacro( spp <= 4 );
82  SamplesPerPixel = spp;
83  assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
84  }
85 
87  unsigned short GetBitsAllocated() const
88  {
89  return BitsAllocated;
90  }
91  void SetBitsAllocated(unsigned short ba)
92  {
93  if( ba )
94  {
95  BitsAllocated = ba;
96  BitsStored = ba;
97  HighBit = (unsigned short)(ba - 1);
98  }
99  else // Make the PixelFormat as UNKNOWN
100  {
101  BitsAllocated = 0;
102  PixelRepresentation = 0;
103  }
104  }
105 
107  unsigned short GetBitsStored() const
108  {
109  assert( BitsStored <= BitsAllocated );
110  return BitsStored;
111  }
112  void SetBitsStored(unsigned short bs)
113  {
114  if( bs <= BitsAllocated && bs )
115  {
116  BitsStored = bs;
117  SetHighBit( (unsigned short) (bs - 1) );
118  }
119  }
120 
122  unsigned short GetHighBit() const
123  {
124  assert( HighBit < BitsStored );
125  return HighBit;
126  }
127  void SetHighBit(unsigned short hb)
128  {
129  if( hb < BitsStored )
130  HighBit = hb;
131  }
132 
134  unsigned short GetPixelRepresentation() const
135  {
136  return (unsigned short)(PixelRepresentation ? 1 : 0);
137  }
138  void SetPixelRepresentation(unsigned short pr)
139  {
140  PixelRepresentation = (unsigned short)(pr ? 1 : 0);
141  }
142 
144  ScalarType GetScalarType() const;
145 
148  void SetScalarType(ScalarType st);
149  const char *GetScalarTypeAsString() const;
150 
156  uint8_t GetPixelSize() const;
157 
159  void Print(std::ostream &os) const;
160 
162  int64_t GetMin() const;
163 
165  int64_t GetMax() const;
166 
168  bool IsValid() const;
169 
170  bool operator==(ScalarType st) const
171  {
172  return GetScalarType() == st;
173  }
174  bool operator!=(ScalarType st) const
175  {
176  return GetScalarType() != st;
177  }
178  bool operator==(const PixelFormat &pf) const
179  {
180  return
181  SamplesPerPixel == pf.SamplesPerPixel &&
182  BitsAllocated == pf.BitsAllocated &&
183  BitsStored == pf.BitsStored &&
184  HighBit == pf.HighBit &&
185  PixelRepresentation == pf.PixelRepresentation;
186  }
187  bool operator!=(const PixelFormat &pf) const
188  {
189  return
190  SamplesPerPixel != pf.SamplesPerPixel ||
191  BitsAllocated != pf.BitsAllocated ||
192  BitsStored != pf.BitsStored ||
193  HighBit != pf.HighBit ||
194  PixelRepresentation != pf.PixelRepresentation;
195  }
196 
197 protected:
199  bool Validate();
200 
201 private:
202  // D 0028|0002 [US] [Samples per Pixel] [1]
203  unsigned short SamplesPerPixel;
204  // D 0028|0100 [US] [Bits Allocated] [8]
205  unsigned short BitsAllocated;
206  // D 0028|0101 [US] [Bits Stored] [8]
207  unsigned short BitsStored;
208  // D 0028|0102 [US] [High Bit] [7]
209  unsigned short HighBit;
210  // D 0028|0103 [US] [Pixel Representation] [0]
211  unsigned short PixelRepresentation;
212 };
213 //-----------------------------------------------------------------------------
214 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
215 {
216  pf.Print( os );
217  return os;
218 }
219 
220 } // end namespace gdcm
221 
222 #endif //GDCMPIXELFORMAT_H
Definition: gdcmPixelFormat.h:52
bool operator==(ScalarType st) const
Definition: gdcmPixelFormat.h:170
void SetBitsAllocated(unsigned short ba)
Definition: gdcmPixelFormat.h:91
ScalarType
Definition: gdcmPixelFormat.h:42
Definition: gdcmPixelFormat.h:50
bool operator!=(ScalarType st) const
Definition: gdcmPixelFormat.h:174
Definition: gdcmPixelFormat.h:45
bool operator==(const PixelFormat &pf) const
Definition: gdcmPixelFormat.h:178
void SetSamplesPerPixel(unsigned short spp)
Definition: gdcmPixelFormat.h:79
unsigned short GetHighBit() const
HighBit see Tag (0028,0102) US High Bit.
Definition: gdcmPixelFormat.h:122
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
void SetHighBit(unsigned short hb)
Definition: gdcmPixelFormat.h:127
Definition: gdcmPixelFormat.h:49
Definition: gdcmPixelFormat.h:53
std::ostream & operator<<(std::ostream &os, const Directory &d)
Definition: gdcmDirectory.h:92
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:44
unsigned short GetPixelRepresentation() const
PixelRepresentation: 0 or 1, see Tag (0028,0103) US Pixel Representation.
Definition: gdcmPixelFormat.h:134
Definition: gdcmPixelFormat.h:47
bool operator!=(const PixelFormat &pf) const
Definition: gdcmPixelFormat.h:187
Definition: gdcmPixelFormat.h:43
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:59
void SetBitsStored(unsigned short bs)
Definition: gdcmPixelFormat.h:112
void Print(std::ostream &os) const
Print.
unsigned short GetBitsStored() const
BitsStored see Tag (0028,0101) US Bits Stored.
Definition: gdcmPixelFormat.h:107
Definition: gdcmPixelFormat.h:46
Definition: gdcmPixelFormat.h:48
Definition: gdcmPixelFormat.h:51
PixelFormat.
Definition: gdcmPixelFormat.h:36
unsigned short GetBitsAllocated() const
BitsAllocated see Tag (0028,0100) US Bits Allocated.
Definition: gdcmPixelFormat.h:87
void SetPixelRepresentation(unsigned short pr)
Definition: gdcmPixelFormat.h:138
Definition: gdcmPixelFormat.h:54

Generated on Sat Dec 21 2013 05:56:17 for GDCM by doxygen 1.8.5
SourceForge.net Logo