⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dibipl.h

📁 BCAM 1394 Driver
💻 H
字号:
//-----------------------------------------------------------------------------
//  (c) 2002 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  BCAM
//  $Header: DibIpl.h, 2, 16.09.2002 10:28:24, Nebelung, H.$
//-----------------------------------------------------------------------------
/*!
  \file     DibIpl.h
  \brief    interface for the CDibIpl class.
*/
#if !defined(AFX_DIBIPL_H__A0DB1738_D137_4F4B_82FD_C54039265FA8__INCLUDED_)
#define AFX_DIBIPL_H__A0DB1738_D137_4F4B_82FD_C54039265FA8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <ipl.h>


  class CDibIplPtr;
  
  //! Encapsulates a Windows DIB section and implements some missing features
  /*! The Windows GDI Bitmap object has two drawbacks:
  - It does not handle the image's orientation (bottom up or top down) properly
  - It does not know about monochrome palettes
  
    This class overcomes these drawbacks. It encapsulates a Windows GDI Bitmap handle
    and adds the missing functionality.
    
    The life time of CDibIpl objects is controlled by a reference counter implementing the same semantics 
    as COM objects.
      
    This class is intended to be used only via the corresponding smart pointer #CDibIplPtr.
    To ensure this the constructor, the creator functions and the functions to 
    increase and decrease the reference counter are accessible through CDibIplPtr only.
        
  */
  class CDibIpl 
  {
    friend CDibIplPtr;
    
    // Public enums
  public:
    //! Orientation of the image
    enum Orientation_t
    {
      BottomUp, //!< The bottom line of the image is located at lower adress than the top line
        TopDown   //!< The top line of the image is located at lower adress than the bottom line
    };
    
    //! The way the colors in the palette are choosen
    enum PaletteType_t
    {
      Color,          //!< The resulting image is a color image
        Monochrome      //!< The resulting image is a monochrome image
    };
    
    // Protected creation functions anly to be accessed by CDibIplPtr
  protected:
    //! Default constructor
    CDibIpl();
    //! Destroy all BMP related resources 
    void Destroy(); 
    //! Increments the reference counter of this object
    long AddRef();
    //! Decrements the reference counter of this object. Destroys the object if the reference counter becomes 0.
    void Release();
    //! Create a CDibIpl object
    static CDibIpl* Create( CSize Size, unsigned int BitsPerPixel, Orientation_t Orientation, PaletteType_t PaletteType ) ;
    //!  Loads the bitmap from a BMP file
    static CDibIpl* LoadBMP( CString FileName );
  public:
    //! Virtual destructor
    virtual ~CDibIpl();
    //! checks if twobitmaps share the same properties
    bool IsEqualType(CDibIpl& Dib);
    //!  Stores the bitmap to a BMP file
    void StoreBMP( CString FileName );
    //! Gets a HBITMAP handle (no ownership is granted!)
    HBITMAP GetBitmapHandle();
    //!  Returns a pointer to the pixel data 
    void* GetPixels();
    //!  Returns the bitmap's size 1
    void GetSize(CSize *pSize);
    //!  Returns the bitmap's size 2
    CSize GetSize();
    //!  Returns the total size of a line in bytes
    unsigned long GetWidthBytes();
    //!  Returns the total size of the image in bytes
    unsigned long GetTotalPixelBytes();
    //!  Returns the bitmap's bits per pixel
    unsigned short GetBitsPerPixel();
    //! Returns the bitmaps orientation (BottomUp or TopDown)
    Orientation_t GetOrientation();
    //! Returns the bitmaps palette type (e.g., color or monochrome )
    PaletteType_t GetPaletteType();
    //! Returns the bitmaps BITMAPINFORHEADER 
    void GetBitmapInfoHeader(BITMAPINFOHEADER *pBitmapInfoHeader);
    //! Returns a bitmaps BITMAPINFO which has to be freed by the user
    void GetBitmapInfo(BITMAPINFO **ppBitmapInfo, unsigned long *pBitmapInfoBytes);
    //! Returns the bitmaps BITMAP 
    void GetBitmap(BITMAP *pBitmap);
    //!  Topples the bitmap
    void Topple();
    //! Clones the Bitmap 
    CDibIpl* Clone(
      bool Topple = false  //!< If true the clone will be toppled with resprect to the original bitmap
      );
    //! Copies the image to the clipboard
    void CopyToClipboard();

    //! Copies the image to the clipboard
    IplImage* GetIplImage()
    {
      return m_pIplImage;
    }
    
    
    // Helper functions
  protected:
    //!  Returns a DIB section which is a copy of the referenced bitmap
    HBITMAP GetCopy();
    //!  Returns a DIB section which is a toppled copy of the referenced bitmap
    HBITMAP GetToppledCopy();
    //!  This function is called whenever the bitmap is re-created
    void Refresh();
    // Member Variables
  protected:
    //! Handle of the referenced Bitmap
    HBITMAP m_hBitmap;
    
    //! Indicates the orientation of the image (topdown or bottomup)
    /*! In Windows a Bitmap object can be created topdown by setting Height < 0.
    For some strange reason the BITMAP structure returned from a topdown
    bitmap will have Height > 0 so the information has to be cached here.
    */
    Orientation_t m_Orientation;
    
    //! Indicates if the bitmap is monochrome or color
    /*! In Windows a monochrome Bitmap is a 8 bit palletized image with a special
    palette : RGB(i) = {i,i,i}. This information is cached.
    */
    PaletteType_t m_PaletteType;
    
    //! Reference counter controlling the life of the CDibIpl object 
    //! Same semantic as in COM objects
    long m_RefCount;
    
    //! Pointer to a header describing the bitmap as IPL image
    IplImage* m_pIplImage;
    
};
//! Smart pointer to CDibIpl objects
/*! This class implements the same semantics as a COM smart pointer.
In addition it provides creator functions to create CDibIpl objects.
*/
class CDibIplPtr
{
public:
  //! Default constructor
  CDibIplPtr()
  {
    m_pDib = NULL;
  }
  
  //! Copy constructor 1
  CDibIplPtr(CDibIplPtr* pDibPtr)
  {
    if(pDibPtr != NULL)
    {
      if ((m_pDib = pDibPtr->m_pDib) != NULL)
        m_pDib->AddRef();
    }
    else
      m_pDib = NULL;
  }
  
  //! Copy constructor 2
  CDibIplPtr(CDibIplPtr& DibPtr)
  {
    if ((m_pDib = DibPtr.m_pDib) != NULL)
      m_pDib->AddRef();
  }
  
  //! Creates a bismap object
  void Create( CSize Size, 
    unsigned int BitsPerPixel, 
    CDibIpl::Orientation_t Orientation = CDibIpl::BottomUp, 
    CDibIpl::PaletteType_t PaletteType = CDibIpl::Color) 
  {
    Release();
    
    m_pDib = CDibIpl::Create( Size, BitsPerPixel, Orientation, PaletteType );
  }
  
  //!  Loads a bitmap from a BMP file
  void LoadBMP( CString FileName )
  {
    Release();
    
    m_pDib = CDibIpl::LoadBMP( FileName );
  }
  
  //! virtual Destructor
  virtual ~CDibIplPtr()
  {
    if(m_pDib)
      m_pDib->Release();
  }
  
  //! releases the referenced CDibIpl object
  void Release()
  {
    CDibIpl* pTemp = m_pDib;
    if (pTemp)
    {
      m_pDib = NULL;
      pTemp->Release();
    }
  }
  
  //! Gets access to the referenced CDibIpl object
  CDibIpl& operator*() const
  {
    if(!m_pDib)
      throw  BvcException(E_POINTER, "CDibIplPtr::operator*");
    
    return *m_pDib;
  }
  
  //! Gets access to the referenced CDibIpl object
  CDibIpl* operator->() const
  {
    if(!m_pDib)
      throw  BvcException(E_POINTER, "CDibIplPtr::operator->");
    
    return m_pDib;
  }
  
  //! Assigns a CDibIpl pointer 
  CDibIplPtr& operator=(CDibIpl* pDib)
  {
    Release();
    
    if(pDib)
    {
      m_pDib = pDib;
      if(m_pDib)
        m_pDib->AddRef();
    }
    else
      m_pDib = NULL;
    
    return *this;
  }
  
  //! Assigns a smart pointer 1
  CDibIplPtr& operator=(CDibIplPtr* pDibPtr)
  {
    Release();
    
    if(pDibPtr)
    {
      m_pDib = pDibPtr->m_pDib;
      if(m_pDib)
        m_pDib->AddRef();
    }
    else
      m_pDib = NULL;
    
    return *this;
  }
  
  //! Assigns a smart pointer 2
  CDibIplPtr& operator=(CDibIplPtr& DibPtr)
  {
    Release();
    
    m_pDib = DibPtr.m_pDib;
    if(m_pDib)
      m_pDib->AddRef();
    
    return *this;
  }
  
  //! True, if this smart pointer does not reference a CDibIpl object
  bool IsNull() 
  {
    return (m_pDib == NULL);
  }
  
  //! True, if this smart pointer references a CDibIpl object
  operator bool() 
  {
    return !IsNull();
  }
  
  //! True, if this smart pointer does not reference a CDibIpl object
  bool operator!()
  {
    return IsNull();
  }
  
  //! Compares if two smar pointers are equal
  bool operator==(CDibIplPtr& DibPtr) const
  {
    return m_pDib == DibPtr.m_pDib;
  }
  
  //! Pointer to the referenced CDibIpl object
  CDibIpl* m_pDib;
};

#endif // !defined(AFX_DIBIPL_H__A0DB1738_D137_4F4B_82FD_C54039265FA8__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -