Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef GDCMPIXELFORMAT_H
00017 #define GDCMPIXELFORMAT_H
00018
00019 #include "gdcmTypes.h"
00020 #include <iostream>
00021 #include <assert.h>
00022
00023 namespace gdcm
00024 {
00025
00037 class GDCM_EXPORT PixelFormat
00038 {
00039 friend class Bitmap;
00040 friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
00041 public:
00042
00043 typedef enum {
00044 UINT8,
00045 INT8,
00046 UINT12,
00047 INT12,
00048 UINT16,
00049 INT16,
00050 UINT32,
00051 INT32,
00052 FLOAT16,
00053 FLOAT32,
00054 FLOAT64,
00055 SINGLEBIT,
00056 UNKNOWN
00057 } ScalarType;
00058
00059
00060 explicit PixelFormat (
00061 unsigned short samplesperpixel = 1,
00062 unsigned short bitsallocated = 8,
00063 unsigned short bitsstored = 8,
00064 unsigned short highbit = 7,
00065 unsigned short pixelrepresentation = 0 ) :
00066 SamplesPerPixel(samplesperpixel),
00067 BitsAllocated(bitsallocated),
00068 BitsStored(bitsstored),
00069 HighBit(highbit),
00070 PixelRepresentation(pixelrepresentation) {}
00071
00072 PixelFormat(ScalarType st);
00073 ~PixelFormat() {}
00074
00075
00076 operator ScalarType() const { return GetScalarType(); }
00077
00080 unsigned short GetSamplesPerPixel() const;
00081 void SetSamplesPerPixel(unsigned short spp)
00082 {
00083 gdcmAssertMacro( spp <= 4 );
00084 SamplesPerPixel = spp;
00085 assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
00086 }
00087
00089 unsigned short GetBitsAllocated() const
00090 {
00091 return BitsAllocated;
00092 }
00093 void SetBitsAllocated(unsigned short ba)
00094 {
00095 BitsAllocated = ba;
00096 }
00097
00099 unsigned short GetBitsStored() const
00100 {
00101 return BitsStored;
00102 }
00103 void SetBitsStored(unsigned short bs)
00104 {
00105 BitsStored = bs;
00106 }
00107
00109 unsigned short GetHighBit() const
00110 {
00111 return HighBit;
00112 }
00113 void SetHighBit(unsigned short hb)
00114 {
00115 HighBit = hb;
00116 }
00117
00119 unsigned short GetPixelRepresentation() const
00120 {
00121 return PixelRepresentation ? 1 : 0;
00122 }
00123 void SetPixelRepresentation(unsigned short pr)
00124 {
00125 PixelRepresentation = (pr ? 1 : 0);
00126 }
00127
00129 ScalarType GetScalarType() const;
00130
00133 void SetScalarType(ScalarType st);
00134 const char *GetScalarTypeAsString() const;
00135
00141 uint8_t GetPixelSize() const;
00142
00144 void Print(std::ostream &os) const;
00145
00147 int64_t GetMin() const;
00148
00150 int64_t GetMax() const;
00151
00153 bool IsValid();
00154
00155 bool operator==(ScalarType st) const
00156 {
00157 return GetScalarType() == st;
00158 }
00159 bool operator!=(ScalarType st) const
00160 {
00161 return GetScalarType() != st;
00162 }
00163 bool operator==(const PixelFormat &pf) const
00164 {
00165 return
00166 SamplesPerPixel == pf.SamplesPerPixel &&
00167 BitsAllocated == pf.BitsAllocated &&
00168 BitsStored == pf.BitsStored &&
00169 HighBit == pf.HighBit &&
00170 PixelRepresentation == pf.PixelRepresentation;
00171 }
00172 bool operator!=(const PixelFormat &pf) const
00173 {
00174 return
00175 SamplesPerPixel != pf.SamplesPerPixel ||
00176 BitsAllocated != pf.BitsAllocated ||
00177 BitsStored != pf.BitsStored ||
00178 HighBit != pf.HighBit ||
00179 PixelRepresentation != pf.PixelRepresentation;
00180 }
00181
00182 protected:
00184 bool Validate();
00185
00186 private:
00187
00188 unsigned short SamplesPerPixel;
00189
00190 unsigned short BitsAllocated;
00191
00192 unsigned short BitsStored;
00193
00194 unsigned short HighBit;
00195
00196 unsigned short PixelRepresentation;
00197 };
00198
00199 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
00200 {
00201 pf.Print( os );
00202 return os;
00203 }
00204
00205 }
00206
00207 #endif //GDCMPIXELFORMAT_H
00208