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

Generated on Wed Apr 10 2013 04:43:09 for GDCM by doxygen 1.8.2
SourceForge.net Logo