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

📄 uploaddlg.h

📁 BCAM 1394 Driver
💻 H
字号:
//-----------------------------------------------------------------------------
//  (c) 2002 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  BCAM
//  $Header: UploadDlg.h, 4, 02.10.2002 14:31:30, Nebelung, H.$
//-----------------------------------------------------------------------------
/**
  \file     UploadDlg.h
 *
 * \brief Shading correction table upload dialog class 
 *
 */
//-----------------------------------------------------------------------------

#pragma once

//------------------------------------------------------------------------------
// class CUploadDlg
// Author: 
// Date: 20.09.2002
//------------------------------------------------------------------------------
/**
 * \brief   Dialog to show the visualize the shading correction table upload 
 * procedure's progress
 *
 */
//------------------------------------------------------------------------------
class CUploadDlg : public CDialogImpl<CUploadDlg>
{
public:
  enum { IDD = IDD_UPLOAD_SHADING };

  BEGIN_MSG_MAP(CAboutDlg)
    MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    MESSAGE_HANDLER(WM_CLOSE, OnClose)
    COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
   
  END_MSG_MAP()

//------------------------------------------------------------------------------
// CUploadDlg(CCamera& camera, CBcamBitmap& bitmap) 
// Author: 
//------------------------------------------------------------------------------
/**
 * Constructor
 *
 * \param     camera reference to the camera object
 * \param     bitmap reference to the bitmap to be uploaded
 */
//------------------------------------------------------------------------------
  CUploadDlg(CCamera& camera, CBcamBitmap& bitmap) : m_Camera(camera), m_Bitmap(bitmap), m_bCancelled(false) {
    m_BufferSize = m_Bitmap.GetSize().cx * m_Bitmap.GetSize().cy * BcamUtility::BitsPerPixel(m_Bitmap.GetColorCode()) /8;
  };

//------------------------------------------------------------------------------
// LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// Author: 
//------------------------------------------------------------------------------
/**
 *
 * Message handler for WM_INITDIALOG
 * 
 * \return    0
 */
//------------------------------------------------------------------------------
  LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  {
    m_ProgressBar.Attach(GetDlgItem(IDC_PROGRESS));
    m_ProgressBar.SetRange32(0, m_Bitmap.GetSize().cx * m_Bitmap.GetSize().cy * BcamUtility::BitsPerPixel(m_Bitmap.GetColorCode()) / 8);
    CenterWindow(GetDesktopWindow());
    // Create the thread which will upload the shading correction data
    if ( ! m_UploadThread.Create(&ThreadProc, this) )
    {
      throw  BcamException(::GetLastError(), "CUploadDlg: Create Thread");
    }
    return TRUE;
  }

//------------------------------------------------------------------------------
// LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// Author: 
//------------------------------------------------------------------------------
/**
 * Handler for the cancel button
 *
 * \return    0
 *
 */
//------------------------------------------------------------------------------
  LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  {
    m_bCancelled = true;
    return 0;
  }

//------------------------------------------------------------------------------
// LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// Author: 
//------------------------------------------------------------------------------
/**
 * WM_CLOSE message handler
 *
 * \return    
 *
 */
//------------------------------------------------------------------------------
  LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  {
    WaitForSingleObject(m_UploadThread, INFINITE);
    return 0;
  }


private:
  bool              m_bCancelled;
  CCamera&          m_Camera;
  CBcamBitmap&      m_Bitmap;
  unsigned long     m_BufferSize;
  CProgressBarCtrl  m_ProgressBar;
  CThread           m_UploadThread; 

//------------------------------------------------------------------------------
// static bool CallbackProc(int written, void* pContext)
// Author: 
//------------------------------------------------------------------------------
/**
 * \brief callback to update the progress bar
 *
 * The Bcam Api calls this callback function to allow the update of the progress bar 
 * to cancel the upload procedure.
 *
 * \param     written number of bytes written to the camera
 * \param     pContext context information, in our case it is the this pointer
 * \return    false, if the upload is to be cancelled
 *
 */
//------------------------------------------------------------------------------
  static bool CallbackProc(int written, void* pContext)
  {
    CUploadDlg* const pThis = (CUploadDlg*) pContext;
    pThis->m_ProgressBar.SetPos(written);
  
    return ! pThis->m_bCancelled;
  }

//------------------------------------------------------------------------------
// static void ReportError(BcamException& e)
// Author: 
// Date: 20.09.2002
//------------------------------------------------------------------------------
/**
 * Display an error message
 *
 * \param     e BcamExeption
 */
//------------------------------------------------------------------------------
  static void ReportError(BcamException& e)
  {
    CString description;
    if ( e.Context() != "" )
      description += e.Context() + CString(" : ") + e.Description();
    else
      description += e.Description();
    CString errorCode;
    errorCode.Format("Error code: 0x%08x \n", e.Error() );
    ::MessageBox( NULL, errorCode + description, "Error", MB_OK | MB_ICONINFORMATION );
  }

//------------------------------------------------------------------------------
// static DWORD WINAPI ThreadProc(void* pContext)
// Author: 
// Date: 20.09.2002
//------------------------------------------------------------------------------
/**
 * \brief The thread procedure of the thread performing the upload
 *
 * \param     pContext This pointer of the upload dialog
 * \return    0
 *
 */
//------------------------------------------------------------------------------
  static DWORD WINAPI ThreadProc(void* pContext)
  {
    CUploadDlg* const pThis = (CUploadDlg*) pContext;
    const unsigned long blocksize = 2048;

    PBYTE pTable;
    try
    {
      // bottom up images have to be converted to top down images ( files loaded from disk are bottom up images )
      pThis->m_Bitmap.IsTopDown() ? pTable = pThis->m_Bitmap : pTable = new BYTE[pThis->m_BufferSize];
      if ( pTable == NULL )
        throw BcamException(E_OUTOFMEMORY);
      if ( ! pThis->m_Bitmap.IsTopDown() )
      {
        CSize size = pThis->m_Bitmap.GetSize();
        for ( int y = size.cy - 1; y >= 0; --y )
        {
          memcpy(pTable + y * size.cx, (PBYTE) pThis->m_Bitmap + ( size.cy - y - 1) * size.cx , size.cx);
        }
      }

      // Perform the upload
      pThis->m_Camera.ShadingCorrection.SetImage(pTable, pThis->m_BufferSize, 10000, &CallbackProc, blocksize, pThis);
    }
    CATCH_REPORT();
    if ( ! pThis->m_Bitmap.IsTopDown() )
      delete [] pTable;

    pThis->EndDialog(0);

    return 0;

  }



};

⌨️ 快捷键说明

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