📄 image.h
字号:
//-----------------------------------------------------------------------------
// Company: Basler Vision Technologies
// Section: Vision Components
// Project: 1394 Driver
// Subproject: BcamViewer
// <b> Visual SourceSafe Information:</b>
// $Archive: /Software/src/BCAMViewer/Image.h $
// $Author: Nebelung, H.$
// $Revision: 5$
// $Date: 02.10.2003 19:21:26$
//-----------------------------------------------------------------------------
/**
\file Image.h
*
* *
\brief Interfaces for the CBcamBitmap classe
*/
//-----------------------------------------------------------------------------
#if !defined(AFX_IMAGEBUFFER_H__F4349286_8B01_11D5_921E_0090278E5E96__INCLUDED_)
#define AFX_IMAGEBUFFER_H__F4349286_8B01_11D5_921E_0090278E5E96__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Bcam.h"
#include "BcamError.h"
#include "BcamViewer_e.h"
#include "utility.h"
//------------------------------------------------------------------------------
// class CBcamBitmap
// Author:
// Date: 20.09.2002
//------------------------------------------------------------------------------
/**
* \brief Wrapper class for DIBSections
*
* This wrapper for DIBSections is used by the BcamViewer as image buffers and to
* display grabbed images. A CBcamBitmap holds additional information, e.g. the size
* of the sensor, the AOI size and position
*
*
*/
//------------------------------------------------------------------------------
class CBcamBitmap
{
public:
CBcamBitmap(CSize& ImageSize, CSize& SensorSize, CPoint& Origin, DCSColorCode ColorCode)
:
m_Size(ImageSize),
m_SensorSize(SensorSize),
m_Origin(Origin),
m_ColorCode(ColorCode),
m_bHasUserData(false),
m_UserData(0)
{
m_BufferSize = ImageSize.cx * ImageSize.cy * BcamUtility::BitsPerPixel(ColorCode) / 8;
if (ColorCode >= DCSColor_VendorSpecific0)
throw BcamException( E_UNSUPPORTED_COLOR_CODE, _T( "CBcamBitmap()" ), _T( "Vendor Specific Color Code" ) );
BITMAPINFO* pBmi;
if ( ColorCode != DCSColor_Mono8 && ColorCode != DCSColor_Raw8 )
{
pBmi = (BITMAPINFO*) new char[sizeof(BITMAPINFO)];
if ( pBmi == NULL )
{
throw BcamException(E_OUTOFMEMORY, "CBcamBitmap()");
}
ZeroMemory(pBmi, sizeof(BITMAPINFO) );
pBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBmi->bmiHeader.biWidth = m_Size.cx;
pBmi->bmiHeader.biHeight = m_Size.cy;
pBmi->bmiHeader.biPlanes = 1;
pBmi->bmiHeader.biCompression = BI_RGB;
pBmi->bmiHeader.biSizeImage = 0;
pBmi->bmiHeader.biXPelsPerMeter = 0;
pBmi->bmiHeader.biYPelsPerMeter = 0;
pBmi->bmiHeader.biClrImportant = 0;
pBmi->bmiHeader.biBitCount = BcamUtility::BitsPerPixel(ColorCode);
pBmi->bmiHeader.biClrUsed = 0;
m_bIsTopDown = false;
}
else
{
pBmi = (BITMAPINFO*) new char[sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD)];
if ( pBmi == NULL )
{
throw BcamException(E_OUTOFMEMORY, "CBcamBitmap()");
}
ZeroMemory(pBmi, sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD));
pBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pBmi->bmiHeader.biWidth = m_Size.cx;
pBmi->bmiHeader.biHeight = - m_Size.cy;
pBmi->bmiHeader.biPlanes = 1;
pBmi->bmiHeader.biCompression = BI_RGB;
pBmi->bmiHeader.biSizeImage = 0;
pBmi->bmiHeader.biXPelsPerMeter = 0;
pBmi->bmiHeader.biYPelsPerMeter = 0;
pBmi->bmiHeader.biClrImportant = 0;
pBmi->bmiHeader.biBitCount = 8;
pBmi->bmiHeader.biClrUsed = 0;
for ( int i = 0; i < 256; i++ )
{
pBmi->bmiColors[i].rgbBlue = i;
pBmi->bmiColors[i].rgbGreen = i;
pBmi->bmiColors[i].rgbRed = i;
}
m_bIsTopDown = true;
}
if ( m_Bitmap.CreateDIBSection(NULL, pBmi, DIB_RGB_COLORS, &m_pPixelData, NULL, NULL ) == NULL )
{
delete [] pBmi;
throw BcamException(::GetLastError(), "CBcamBitmap::CBcamBitmap()");
}
delete [] pBmi;
}
CBcamBitmap(CString FileName)
: m_Origin(0,0),
m_bHasUserData(false),
m_UserData(0)
{
HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if ( hBitmap == NULL )
throw BcamException(::GetLastError(), "LoadImage()");
m_Bitmap.Attach(hBitmap);
// retrieve information about loaded image
DIBSECTION DibSection;
::GetObject(hBitmap, sizeof(DibSection), &DibSection);
if ( DibSection.dsBmih.biBitCount == 8 )
m_ColorCode = DCSColor_Mono8;
else if ( DibSection.dsBmih.biBitCount == 16 )
m_ColorCode = DCSColor_Mono16;
else if ( DibSection.dsBmih.biBitCount == 24 )
m_ColorCode = DCSColor_RGB8;
else{
m_Bitmap.DeleteObject();
throw BcamException(E_IMAGE_FORMAT_NOT_SUPPORTED, "LoadImage()");
}
m_Size.cx = m_SensorSize.cx = DibSection.dsBmih.biWidth;
m_Size.cy = m_SensorSize.cy = DibSection.dsBmih.biHeight;
// retrieve pointer to pixel
m_pPixelData = DibSection.dsBm.bmBits;
// images load from file are bottom-up images
m_bIsTopDown = false;
}
virtual ~CBcamBitmap()
{
}
bool Save(CString FileName);
bool CopyToClipboard(HWND hWnd);
CSize GetSize()
{
return m_Size;
}
CSize GetSensorSize()
{
return m_SensorSize;
}
CPoint GetOrigin()
{
return m_Origin;
}
CRect GetRect()
{
return CRect(m_Origin, m_Size);
}
DCSColorCode GetColorCode()
{
return m_ColorCode;
}
RGBTRIPLE operator()(unsigned int x, unsigned int y);
operator CBitmap&() { return m_Bitmap; }
operator const CBitmap&() const { return m_Bitmap; }
operator HBITMAP() { return (HBITMAP) m_Bitmap; }
operator void*() { return m_pPixelData; }
operator PBYTE() { return (PBYTE) m_pPixelData; }
unsigned long GetBufferSize()
{
return m_BufferSize;
}
void SetUserData(long data) { m_UserData = data; m_bHasUserData = true; }
long GetUserData() { return m_UserData; }
bool HasUserData() { return m_bHasUserData; }
bool IsTopDown() { return m_bIsTopDown; }
private:
// hide copy constructor and assignment operator
CBcamBitmap( const CBcamBitmap& );
CBcamBitmap& operator=( const CBcamBitmap& );
bool m_bIsTopDown;
public:
void* m_pPixelData;
CBitmap m_Bitmap;
CSize m_Size;
CSize m_SensorSize;
CPoint m_Origin;
DCSColorCode m_ColorCode;
unsigned long m_BufferSize;
bool m_bHasUserData;
long m_UserData;
};
#endif // !defined(AFX_IMAGEBUFFER_H__F4349286_8B01_11D5_921E_0090278E5E96__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -