GDCM  2.2.0
gdcmPixelFormat.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004 
00005   Copyright (c) 2006-2011 Mathieu Malaterre
00006   All rights reserved.
00007   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00008 
00009      This software is distributed WITHOUT ANY WARRANTY; without even
00010      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00011      PURPOSE.  See the above copyright notice for more information.
00012 
00013 =========================================================================*/
00014 
00015 #ifndef GDCMPIXELFORMAT_H
00016 #define GDCMPIXELFORMAT_H
00017 
00018 #include "gdcmTypes.h"
00019 #include <iostream>
00020 #include <assert.h>
00021 
00022 namespace gdcm
00023 {
00024 
00036 class GDCM_EXPORT PixelFormat
00037 {
00038   friend class Bitmap;
00039   friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
00040 public:
00041   // When adding a type please add its dual type (its unsigned conterpart)
00042   typedef enum {
00043     UINT8,
00044     INT8,
00045     UINT12,
00046     INT12,
00047     UINT16,
00048     INT16,
00049     UINT32,  // For some DICOM files (RT or SC)
00050     INT32,   //                        "   "
00051     FLOAT16, // sure why not...
00052     FLOAT32, // good ol' 'float'
00053     FLOAT64, // aka 'double'
00054     SINGLEBIT, // bool / monochrome
00055     UNKNOWN // aka BitsAllocated == 0 && PixelRepresentation == 0
00056   } ScalarType;
00057 
00058   // default cstor:
00059   explicit PixelFormat (
00060     unsigned short samplesperpixel = 1,
00061     unsigned short bitsallocated = 8,
00062     unsigned short bitsstored = 8,
00063     unsigned short highbit = 7,
00064     unsigned short pixelrepresentation = 0 ) :
00065   SamplesPerPixel(samplesperpixel),
00066   BitsAllocated(bitsallocated),
00067   BitsStored(bitsstored),
00068   HighBit(highbit),
00069   PixelRepresentation(pixelrepresentation) {}
00070   // helper, for the common case
00071   PixelFormat(ScalarType st);
00072   ~PixelFormat() {}
00073 
00074   // For transparency of use
00075   operator ScalarType() const { return GetScalarType(); }
00076 
00079   unsigned short GetSamplesPerPixel() const;
00080   void SetSamplesPerPixel(unsigned short spp)
00081     {
00082     gdcmAssertMacro( spp <= 4 );
00083     SamplesPerPixel = spp;
00084     assert( SamplesPerPixel == 1 || SamplesPerPixel == 3 || SamplesPerPixel == 4 );
00085     }
00086 
00088   unsigned short GetBitsAllocated() const
00089     {
00090     return BitsAllocated;
00091     }
00092   void SetBitsAllocated(unsigned short ba)
00093     {
00094     BitsAllocated = ba;
00095     BitsStored = ba;
00096     HighBit = ba - 1;
00097     }
00098 
00100   unsigned short GetBitsStored() const
00101     {
00102     assert( BitsStored <= BitsAllocated );
00103     return BitsStored;
00104     }
00105   void SetBitsStored(unsigned short bs)
00106     {
00107     if( bs <= BitsAllocated )
00108       {
00109       BitsStored = bs;
00110       SetHighBit( BitsStored - 1 );
00111       }
00112     }
00113 
00115   unsigned short GetHighBit() const
00116     {
00117     assert( HighBit < BitsStored );
00118     return HighBit;
00119     }
00120   void SetHighBit(unsigned short hb)
00121     {
00122     if( hb < BitsStored )
00123       HighBit = hb;
00124     }
00125 
00127   unsigned short GetPixelRepresentation() const
00128     {
00129     return (unsigned short)(PixelRepresentation ? 1 : 0);
00130     }
00131   void SetPixelRepresentation(unsigned short pr)
00132     {
00133     PixelRepresentation = (unsigned short)(pr ? 1 : 0);
00134     }
00135 
00137   ScalarType GetScalarType() const;
00138 
00141   void SetScalarType(ScalarType st);
00142   const char *GetScalarTypeAsString() const;
00143 
00149   uint8_t GetPixelSize() const;
00150 
00152   void Print(std::ostream &os) const;
00153 
00155   int64_t GetMin() const;
00156 
00158   int64_t GetMax() const;
00159 
00161   bool IsValid();
00162 
00163   bool operator==(ScalarType st) const
00164     {
00165     return GetScalarType() == st;
00166     }
00167   bool operator!=(ScalarType st) const
00168     {
00169     return GetScalarType() != st;
00170     }
00171   bool operator==(const PixelFormat &pf) const
00172     {
00173     return
00174       SamplesPerPixel     == pf.SamplesPerPixel &&
00175       BitsAllocated       == pf.BitsAllocated &&
00176       BitsStored          == pf.BitsStored &&
00177       HighBit             == pf.HighBit &&
00178       PixelRepresentation == pf.PixelRepresentation;
00179     }
00180   bool operator!=(const PixelFormat &pf) const
00181     {
00182     return
00183       SamplesPerPixel     != pf.SamplesPerPixel ||
00184       BitsAllocated       != pf.BitsAllocated ||
00185       BitsStored          != pf.BitsStored ||
00186       HighBit             != pf.HighBit ||
00187       PixelRepresentation != pf.PixelRepresentation;
00188     }
00189 
00190 protected:
00192   bool Validate();
00193 
00194 private:
00195   // D 0028|0002 [US] [Samples per Pixel] [1]
00196   unsigned short SamplesPerPixel;
00197   // D 0028|0100 [US] [Bits Allocated] [8]
00198   unsigned short BitsAllocated;
00199   // D 0028|0101 [US] [Bits Stored] [8]
00200   unsigned short BitsStored;
00201   // D 0028|0102 [US] [High Bit] [7]
00202   unsigned short HighBit;
00203   // D 0028|0103 [US] [Pixel Representation] [0]
00204   unsigned short PixelRepresentation;
00205 };
00206 //-----------------------------------------------------------------------------
00207 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
00208 {
00209   pf.Print( os );
00210   return os;
00211 }
00212 
00213 } // end namespace gdcm
00214 
00215 #endif //GDCMPIXELFORMAT_H

Generated on Tue Mar 27 2012 18:19:33 for GDCM by doxygen 1.8.0
SourceForge.net Logo