/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*---(GetRow)--------------------------------------------------------------- We have made the assumption that the user has the knowledge of Object Oriented programing of C under Windows. This example will: 1. load an image from a file, whose name is sent through the command line, to a bitmap, 2. display the image, 3. do a 90 degree rotation using LBitmapBase::GetRow() and LBitmapBase::PutRowCol(), 4. re-display the image. Usage: GETROW --------------------------------------------------------------------------*/ // GetRowVw.cpp : implementation of the CGetRowView class // #include "stdafx.h" #include "GetRow.h" #include "GetRwDoc.h" #include "GetRowVw.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CGetRowView IMPLEMENT_DYNCREATE(CGetRowView, CView) BEGIN_MESSAGE_MAP(CGetRowView, CView) //{{AFX_MSG_MAP(CGetRowView) ON_WM_TIMER() ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CGetRowView construction/destruction CGetRowView::CGetRowView() { // TODO: add construction code here m_nCount = 0; } CGetRowView::~CGetRowView() { } ///////////////////////////////////////////////////////////////////////////// // CGetRowView drawing void CGetRowView::OnDraw(CDC* pDC) { CGetRowDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CGetRowView diagnostics #ifdef _DEBUG void CGetRowView::AssertValid() const { CView::AssertValid(); } void CGetRowView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CGetRowDoc* CGetRowView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGetRowDoc))); return (CGetRowDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CGetRowView message handlers void CGetRowView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default m_nCount++; /* Increment the Counter. */ /* Has the image been displayed about 3 seconds? (this is reset in the function Window_OnPaint) */ if (m_nCount == 1) { m_hOrigCursor = SetCursor (LoadCursor (NULL, IDC_SIZENS)); return; } else if (m_nCount == 2) { SetCursor (LoadCursor (NULL, IDC_SIZENESW)); return; } KillTimer (m_nTimer); SetCursor (m_hOrigCursor); PostMessage(WM_COMMAND); CView::OnTimer(nIDEvent); } BOOL CGetRowView::OnCommand(WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class HCURSOR hCursor; L_UCHAR L_FAR * pData; L_INT nOutCol = 0; LBitmapBase tmpBitmap; LBuffer tmpBuffer; hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)); AfxGetMainWnd()->SetWindowText (_T("Rotating Image...")); L_INT nBitmapHeight = m_LBitmapWnd.GetHeight(); L_INT nBitmapWidth = m_LBitmapWnd.GetWidth(); // swap Height and width tmpBitmap.Create(nBitmapHeight, nBitmapWidth, m_LBitmapWnd.GetBitsPerPixel(), m_LBitmapWnd.GetColorOrder(), NULL, m_LBitmapWnd.GetViewPerspective()); L_INT nNewWidth = tmpBitmap.GetWidth(); L_INT nNewHeight = tmpBitmap.GetHeight(); L_INT nRet; L_INT nOutRow = nBitmapWidth - 1; L_INT nBytesBP = m_LBitmapWnd.GetBitsPerPixel() / 8; for (L_INT nInRow = 0; nInRow < nBitmapHeight; nInRow++) { LBuffer LeadBuffer; // Get data from the original bitmap one row at a time. If the view // perspective is TOP_LEFT, the rows should be retrieved "backwards". if (m_LBitmapWnd.GetViewPerspective() == TOP_LEFT) nRet = m_LBitmapWnd.GetRow(&LeadBuffer, (nBitmapHeight - 1) - nInRow); else nRet = m_LBitmapWnd.GetRow(&LeadBuffer,nInRow); if (nRet != m_LBitmapWnd.GetBytesPerLine() ) { AfxGetMainWnd()->MessageBox (_T("Error getting rows of data!"), _T("ERROR"), MB_OK); PostQuitMessage(0); return FALSE; } pData = (L_UCHAR *) LeadBuffer.Lock(); for (L_INT i = 0; i < nNewHeight; i++) { // Put the data in pBuf as a column in tmpBitmap. tmpBuffer.Copy((pData + (i * nBytesBP)), nBytesBP); nRet = tmpBitmap.PutRowCol(tmpBuffer, nOutRow, nOutCol); if (nRet != nBytesBP) { LBase::DisplayError(AfxGetMainWnd()->m_hWnd, nRet); PostQuitMessage(0); return FALSE; } nOutRow--; } LeadBuffer.Unlock(); nOutCol++; nOutRow = nBitmapWidth - 1; } HPALETTE hPalette = m_LBitmapWnd.DupPalette(m_LBitmapWnd.GetPalette()); tmpBitmap.SetPalette(hPalette); m_LBitmapWnd.SetHandle(tmpBitmap.GetHandle()); AfxGetMainWnd()->SetWindowText (_T("Image Is Rotated, Example Is Complete (Class library)")); SetCursor (hCursor); return CView::OnCommand(wParam, lParam); } void CGetRowView::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class if ((m_nTimer = SetTimer (1, 1000, NULL)) == 0) { AfxMessageBox (_T("No Timers Are Available!")); AfxGetMainWnd()->PostMessage(WM_DESTROY); } } int CGetRowView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; CGetRowApp* pCApp = (CGetRowApp*)AfxGetApp(); L_INT nRet = m_LBitmapWnd.Load((L_TCHAR*)(LPCTSTR)pCApp->m_strFileName); if (nRet != SUCCESS) { LBase::DisplayError(m_hWnd, nRet); return -1; } if (m_LBitmapWnd.GetBitsPerPixel() < 8) { AfxGetMainWnd()->MessageBox(_T("Image should be 8-bit or higher!"), _T("ERROR"), MB_OK); PostQuitMessage(0); return 0; } m_LBitmapWnd.SetWndHandle(GetSafeHwnd()); return 0; } void CGetRowView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if(bActivate==TRUE && pActivateView==this) if(m_LBitmapWnd.HandlePalette(WM_QUERYNEWPALETTE, 0, 0)==FALSE) m_LBitmapWnd.Repaint(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); }