GDCM  2.2.0
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);
73 
74  // For transparency of use
75  operator ScalarType() const { return GetScalarType(); }
76 
79  unsigned short GetSamplesPerPixel() const;
80  void SetSamplesPerPixel(unsigned short spp)
81  {
82  gdcmAssertMacro( spp <= 4 );
83  SamplesPerPixel = spp;
84  assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
85  }
86 
88  unsigned short GetBitsAllocated() const
89  {
90  return BitsAllocated;
91  }
92  void SetBitsAllocated(unsigned short ba)
93  {
94  BitsAllocated = ba;
95  BitsStored = ba;
96  HighBit = ba - 1;
97  }
98 
100  unsigned short GetBitsStored() const
101  {
102  assert( BitsStored <= BitsAllocated );
103  return BitsStored;
104  }
105  void SetBitsStored(unsigned short bs)
106  {
107  if( bs <= BitsAllocated )
108  {
109  BitsStored = bs;
110  SetHighBit( BitsStored - 1 );
111  }
112  }
113 
115  unsigned short GetHighBit() const
116  {
117  assert( HighBit < BitsStored );
118  return HighBit;
119  }
120  void SetHighBit(unsigned short hb)
121  {
122  if( hb < BitsStored )
123  HighBit = hb;
124  }
125 
127  unsigned short GetPixelRepresentation() const
128  {
129  return (unsigned short)(PixelRepresentation ? 1 : 0);
130  }
131  void SetPixelRepresentation(unsigned short pr)
132  {
133  PixelRepresentation = (unsigned short)(pr ? 1 : 0);
134  }
135 
137  ScalarType GetScalarType() const;
138 
141  void SetScalarType(ScalarType st);
142  const char *GetScalarTypeAsString() const;
143 
149  uint8_t GetPixelSize() const;
150 
152  void Print(std::ostream &os) const;
153 
155  int64_t GetMin() const;
156 
158  int64_t GetMax() const;
159 
161  bool IsValid();
162 
163  bool operator==(ScalarType st) const
164  {
165  return GetScalarType() == st;
166  }
167  bool operator!=(ScalarType st) const
168  {
169  return GetScalarType() != st;
170  }
171  bool operator==(const PixelFormat &pf) const
172  {
173  return
174  SamplesPerPixel == pf.SamplesPerPixel &&
175  BitsAllocated == pf.BitsAllocated &&
176  BitsStored == pf.BitsStored &&
177  HighBit == pf.HighBit &&
178  PixelRepresentation == pf.PixelRepresentation;
179  }
180  bool operator!=(const PixelFormat &pf) const
181  {
182  return
183  SamplesPerPixel != pf.SamplesPerPixel ||
184  BitsAllocated != pf.BitsAllocated ||
185  BitsStored != pf.BitsStored ||
186  HighBit != pf.HighBit ||
187  PixelRepresentation != pf.PixelRepresentation;
188  }
189 
190 protected:
192  bool Validate();
193 
194 private:
195  // D 0028|0002 [US] [Samples per Pixel] [1]
196  unsigned short SamplesPerPixel;
197  // D 0028|0100 [US] [Bits Allocated] [8]
198  unsigned short BitsAllocated;
199  // D 0028|0101 [US] [Bits Stored] [8]
200  unsigned short BitsStored;
201  // D 0028|0102 [US] [High Bit] [7]
202  unsigned short HighBit;
203  // D 0028|0103 [US] [Pixel Representation] [0]
204  unsigned short PixelRepresentation;
205 };
206 //-----------------------------------------------------------------------------
207 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
208 {
209  pf.Print( os );
210  return os;
211 }
212 
213 } // end namespace gdcm
214 
215 #endif //GDCMPIXELFORMAT_H

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo