这段程序没有main函数,是属于什么程序,运行流程是什么样的

loupeiwei6431 2017-04-07 09:22:40
#include "stdafx.h"
#include "ImageRenderer.h"

/// <summary>
/// Constructor
/// </summary>
ImageRenderer::ImageRenderer() :
m_hWnd(0),
m_sourceWidth(0),
m_sourceHeight(0),
m_sourceStride(0),
m_pD2DFactory(NULL),
m_pRenderTarget(NULL),
m_pBitmap(0)
{
}

/// <summary>
/// Destructor
/// </summary>
ImageRenderer::~ImageRenderer()
{
DiscardResources();
SafeRelease(m_pD2DFactory);
}

/// <summary>
/// Ensure necessary Direct2d resources are created
/// </summary>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::EnsureResources()
{
HRESULT hr = S_OK;

if (NULL == m_pRenderTarget)
{
D2D1_SIZE_U size = D2D1::SizeU(m_sourceWidth, m_sourceHeight);

D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties();
rtProps.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE);
rtProps.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;

// Create a hWnd render target, in order to render to the window set in initialize
hr = m_pD2DFactory->CreateHwndRenderTarget(
rtProps,
D2D1::HwndRenderTargetProperties(m_hWnd, size),
&m_pRenderTarget
);

if (FAILED(hr))
{
return hr;
}

// Create a bitmap that we can copy image data into and then render to the target
hr = m_pRenderTarget->CreateBitmap(
size,
D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE)),
&m_pBitmap
);

if (FAILED(hr))
{
SafeRelease(m_pRenderTarget);
return hr;
}
}

return hr;
}

/// <summary>
/// Dispose of Direct2d resources
/// </summary>
void ImageRenderer::DiscardResources()
{
SafeRelease(m_pRenderTarget);
SafeRelease(m_pBitmap);
}

/// <summary>
/// Set the window to draw to as well as the video format
/// Implied bits per pixel is 32
/// </summary>
/// <param name="hWnd">window to draw to</param>
/// <param name="pD2DFactory">already created D2D factory object</param>
/// <param name="sourceWidth">width (in pixels) of image data to be drawn</param>
/// <param name="sourceHeight">height (in pixels) of image data to be drawn</param>
/// <param name="sourceStride">length (in bytes) of a single scanline</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Initialize(HWND hWnd, ID2D1Factory* pD2DFactory, int sourceWidth, int sourceHeight, int sourceStride)
{
if (NULL == pD2DFactory)
{
return E_INVALIDARG;
}

m_hWnd = hWnd;

// One factory for the entire application so save a pointer here
m_pD2DFactory = pD2DFactory;

m_pD2DFactory->AddRef();

// Get the frame size
m_sourceWidth = sourceWidth;
m_sourceHeight = sourceHeight;
m_sourceStride = sourceStride;

return S_OK;
}

/// <summary>
/// Draws a 32 bit per pixel image of previously specified width, height, and stride to the associated hwnd
/// </summary>
/// <param name="pImage">image data in RGBX format</param>
/// <param name="cbImage">size of image data in bytes</param>
/// <returns>indicates success or failure</returns>
HRESULT ImageRenderer::Draw(BYTE* pImage, unsigned long cbImage)
{
// incorrectly sized image data passed in
if (cbImage < ((m_sourceHeight - 1) * m_sourceStride) + (m_sourceWidth * 4))
{
return E_INVALIDARG;
}

// create the resources for this draw device
// they will be recreated if previously lost
HRESULT hr = EnsureResources();

if (FAILED(hr))
{
return hr;
}

// Copy the image that was passed in into the direct2d bitmap
hr = m_pBitmap->CopyFromMemory(NULL, pImage, m_sourceStride);

if (FAILED(hr))
{
return hr;
}

m_pRenderTarget->BeginDraw();

// Draw the bitmap stretched to the size of the window
m_pRenderTarget->DrawBitmap(m_pBitmap);

hr = m_pRenderTarget->EndDraw();

// Device lost, need to recreate the render target
// We'll dispose it now and retry drawing
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardResources();
}

return hr;
}
...全文
225 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
FD_2013 2017-04-07
  • 打赏
  • 举报
回复
就是两个类,也许是 两个导出类,意思就是这两个类是封装成库供别人调用的
loupeiwei6431 2017-04-07
  • 打赏
  • 举报
回复
这是kinect相机读取深度图的程序,项目里只有2个cpp文件,4个头文件,ImageRenderer.cpp就是上面那段代码,DepthBasics.cpp如下,这两个cpp文件我只看到了类函数的定义,看不懂程序的运行流程是怎么样的,请问这是属于什么程序,该怎么学。
幻夢之葉 2017-04-07
  • 打赏
  • 举报
回复
win32应用程序,如果是控制台程序那么入口函数是main,如果是windows程序那么入口函数是winmain 你这只是部分代码,而且是否是MFC也不从判断
loupeiwei6431 2017-04-07
  • 打赏
  • 举报
回复
这段程序没有main函数,是属于什么程序,运行流程是什么样的。是mfc程序吗

64,684

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧