GDCM  2.2.4
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  if( ba )
95  {
96  BitsAllocated = ba;
97  BitsStored = ba;
98  HighBit = (unsigned short)(ba - 1);
99  }
100  else // Make the PixelFormat as UNKNOWN
101  {
102  BitsAllocated = 0;
103  PixelRepresentation = 0;
104  }
105  }
106 
108  unsigned short GetBitsStored() const
109  {
110  assert( BitsStored <= BitsAllocated );
111  return BitsStored;
112  }
113  void SetBitsStored(unsigned short bs)
114  {
115  if( bs <= BitsAllocated && bs )
116  {
117  BitsStored = bs;
118  SetHighBit( (unsigned short) (bs - 1) );
119  }
120  }
121 
123  unsigned short GetHighBit() const
124  {
125  assert( HighBit < BitsStored );
126  return HighBit;
127  }
128  void SetHighBit(unsigned short hb)
129  {
130  if( hb < BitsStored )
131  HighBit = hb;
132  }
133 
135  unsigned short GetPixelRepresentation() const
136  {
137  return (unsigned short)(PixelRepresentation ? 1 : 0);
138  }
139  void SetPixelRepresentation(unsigned short pr)
140  {
141  PixelRepresentation = (unsigned short)(pr ? 1 : 0);
142  }
143 
145  ScalarType GetScalarType() const;
146 
149  void SetScalarType(ScalarType st);
150  const char *GetScalarTypeAsString() const;
151 
157  uint8_t GetPixelSize() const;
158 
160  void Print(std::ostream &os) const;
161 
163  int64_t GetMin() const;
164 
166  int64_t GetMax() const;
167 
169  bool IsValid() const;
170 
171  bool operator==(ScalarType st) const
172  {
173  return GetScalarType() == st;
174  }
175  bool operator!=(ScalarType st) const
176  {
177  return GetScalarType() != st;
178  }
179  bool operator==(const PixelFormat &pf) const
180  {
181  return
182  SamplesPerPixel == pf.SamplesPerPixel &&
183  BitsAllocated == pf.BitsAllocated &&
184  BitsStored == pf.BitsStored &&
185  HighBit == pf.HighBit &&
186  PixelRepresentation == pf.PixelRepresentation;
187  }
188  bool operator!=(const PixelFormat &pf) const
189  {
190  return
191  SamplesPerPixel != pf.SamplesPerPixel ||
192  BitsAllocated != pf.BitsAllocated ||
193  BitsStored != pf.BitsStored ||
194  HighBit != pf.HighBit ||
195  PixelRepresentation != pf.PixelRepresentation;
196  }
197 
198 protected:
200  bool Validate();
201 
202 private:
203  // D 0028|0002 [US] [Samples per Pixel] [1]
204  unsigned short SamplesPerPixel;
205  // D 0028|0100 [US] [Bits Allocated] [8]
206  unsigned short BitsAllocated;
207  // D 0028|0101 [US] [Bits Stored] [8]
208  unsigned short BitsStored;
209  // D 0028|0102 [US] [High Bit] [7]
210  unsigned short HighBit;
211  // D 0028|0103 [US] [Pixel Representation] [0]
212  unsigned short PixelRepresentation;
213 };
214 //-----------------------------------------------------------------------------
215 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
216 {
217  pf.Print( os );
218  return os;
219 }
220 
221 } // end namespace gdcm
222 
223 #endif //GDCMPIXELFORMAT_H

Generated on Tue Aug 13 2013 15:29:57 for GDCM by doxygen 1.8.4
SourceForge.net Logo