# gdcmBitmap.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef GDCMBITMAP_H
    00016 #define GDCMBITMAP_H
    00017
    00018 #include "gdcmObject.h"
    00019 #include "gdcmCurve.h"
    00020 #include "gdcmDataElement.h"
    00021 //#include "gdcmIconImage.h"
    00022 #include "gdcmLookupTable.h"
    00023 #include "gdcmOverlay.h"
    00024 #include "gdcmPhotometricInterpretation.h"
    00025 #include "gdcmPixelFormat.h"
    00026 #include "gdcmSmartPointer.h"
    00027 #include "gdcmTransferSyntax.h"
    00028
    00029 #include <vector>
    00030
    00031 namespace gdcm
    00032 {
    00033
    00039 class GDCM_EXPORT Bitmap : public Object
    00040 {
    00041 public:
    00042   Bitmap();
    00043   ~Bitmap();
    00044   void Print(std::ostream &) const;
    00045
    00046   virtual bool AreOverlaysInPixelData() const { return false; }
    00047
    00049   unsigned int GetNumberOfDimensions() const;
    00050   void SetNumberOfDimensions(unsigned int dim);
    00051
    00053   unsigned int GetPlanarConfiguration() const;
    00055   void SetPlanarConfiguration(unsigned int pc);
    00056
    00057   bool GetNeedByteSwap() const
    00058     {
    00059     return NeedByteSwap;
    00060     }
    00061   void SetNeedByteSwap(bool b)
    00062     {
    00063     NeedByteSwap = b;
    00064     }
    00065
    00066
    00068   void SetTransferSyntax(TransferSyntax const &ts) {
    00069     TS = ts;
    00070   }
    00071   const TransferSyntax &GetTransferSyntax() const {
    00072     return TS;
    00073   }
    00074   bool IsTransferSyntaxCompatible( TransferSyntax const & ts ) const;
    00075   void SetDataElement(DataElement const &de) {
    00076     PixelData = de;
    00077   }
    00078   const DataElement& GetDataElement() const { return PixelData; }
    00079   DataElement& GetDataElement() { return PixelData; }
    00080
    00082   void SetLUT(LookupTable const &lut)
    00083     {
    00084     LUT = SmartPointer<LookupTable>( const_cast<LookupTable*>(&lut) );
    00085     }
    00086   const LookupTable &GetLUT() const
    00087     {
    00088     return *LUT;
    00089     }
    00090   LookupTable &GetLUT()
    00091     {
    00092     return *LUT;
    00093     }
    00094
    00095
    00097   const unsigned int *GetDimensions() const;
    00098   unsigned int GetDimension(unsigned int idx) const;
    00099
    00100   void SetColumns(unsigned int col) { SetDimension(0,col); }
    00101   unsigned int GetColumns() const { return GetDimension(0); }
    00102   void SetRows(unsigned int rows) { SetDimension(1,rows); }
    00103   unsigned int GetRows() const { return GetDimension(1); }
    00104   void SetDimensions(const unsigned int dims[3]);
    00105   void SetDimension(unsigned int idx, unsigned int dim);
    00107   const PixelFormat &GetPixelFormat() const
    00108     {
    00109     return PF;
    00110     }
    00111   PixelFormat &GetPixelFormat()
    00112     {
    00113     return PF;
    00114     }
    00115   void SetPixelFormat(PixelFormat const &pf)
    00116     {
    00117     PF = pf;
    00118     PF.Validate();
    00119     }
    00120
    00122   const PhotometricInterpretation &GetPhotometricInterpretation() const;
    00123   void SetPhotometricInterpretation(PhotometricInterpretation const &pi);
    00124
    00125   bool IsEmpty() const { return Dimensions.size() == 0; }
    00126   void Clear();
    00127
    00131   unsigned long GetBufferLength() const;
    00132
    00134   bool GetBuffer(char *buffer) const;
    00135
    00137   bool IsLossy() const;
    00138
    00140   void SetLossyFlag(bool f) { LossyFlag = f; }
    00141
    00142 protected:
    00143   bool TryRAWCodec(char *buffer, bool &lossyflag) const;
    00144   bool TryJPEGCodec(char *buffer, bool &lossyflag) const;
    00145   bool TryPVRGCodec(char *buffer, bool &lossyflag) const;
    00146   bool TryKAKADUCodec(char *buffer, bool &lossyflag) const;
    00147   bool TryJPEGLSCodec(char *buffer, bool &lossyflag) const;
    00148   bool TryJPEG2000Codec(char *buffer, bool &lossyflag) const;
    00149   bool TryRLECodec(char *buffer, bool &lossyflag) const;
    00150
    00151   bool TryJPEGCodec2(std::ostream &os) const;
    00152   bool TryJPEG2000Codec2(std::ostream &os) const;
    00153
    00154   bool GetBuffer2(std::ostream &os) const;
    00155
    00156   friend class PixmapReader;
    00157   friend class ImageChangeTransferSyntax;
    00158   bool ComputeLossyFlag();
    00159
    00160 //private:
    00161 protected:
    00162   unsigned int PlanarConfiguration;
    00163   unsigned int NumberOfDimensions;
    00164   TransferSyntax TS;
    00165   PixelFormat PF; // SamplesPerPixel, BitsAllocated, BitsStored, HighBit, PixelRepresentation
    00166   PhotometricInterpretation PI;
    00167   // Mind dump: unsigned int is required here, since we are reading (0028,0008) Number Of Frames
    00168   // which is VR::IS, so I cannot simply assumed that unsigned short is enough... :(
    00169   std::vector<unsigned int> Dimensions; // Col/Row
    00170   DataElement PixelData; // copied from 7fe0,0010
    00171
    00172   typedef SmartPointer<LookupTable> LUTPtr;
    00173   LUTPtr LUT;
    00174   // I believe the following 3 ivars can be derived from TS ...
    00175   bool NeedByteSwap;
    00176   bool LossyFlag;
    00177
    00178 private:
    00179   bool GetBufferInternal(char *buffer, bool &lossyflag) const;
    00180 };
    00181
    00182 } // end namespace gdcm
    00183
    00184 #endif //GDCMBITMAP_H