/*[]=====================================================================[]*/ /*[] LEADTOOLS for Windows(Class Library) - Version 11 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2000 LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ /*------(ClrSpace)--------------------------------------------------------------- We have made the assumption that the user has the knowledge of Object Oriented programing of C under Windows. This example will: 1. load the image from a file, whose name is sent through the command line, to a bitmap as 24 bits and allocate a 24 bit bitmap, 2. display the image, 3. call LBuffer::ConvertColorSpace() on each image line to convert from RGB to YUV to CMYK etc., 4. re-display the image. Usage: CLRSPACE ----------------------------------------------------------------------------------*/ // ClspView.cpp : implementation of the ClsView class // #include "stdafx.h" #include "Clrspc.h" #include "ClrspcVw.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // ClsView IMPLEMENT_DYNCREATE(ClsView, CView) BEGIN_MESSAGE_MAP(ClsView, CView) //{{AFX_MSG_MAP(ClsView) ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ClsView construction/destruction ClsView::ClsView() { // TODO: add construction code here } ClsView::~ClsView() { } BOOL ClsView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // ClsView drawing void ClsView::OnDraw(CDC* pDC) { CClr1spcDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); } ///////////////////////////////////////////////////////////////////////////// // ClsView diagnostics #ifdef _DEBUG void ClsView::AssertValid() const { CView::AssertValid(); } void ClsView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CClr1spcDoc* ClsView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClr1spcDoc))); return (CClr1spcDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // ClsView message handler int ClsView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; m_LBitmapWnd.SetWndHandle (GetSafeHwnd()); m_uTimer = SetTimer(1,100,NULL); return 0; } void ClsView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default KillTimer(m_uTimer); CClr1spcApp* theApp = (CClr1spcApp*) AfxGetApp(); L_TCHAR * zsFileName = (L_TCHAR *) theApp->m_lpCmdLine; L_INT nRet = m_LBitmapWnd.Load(zsFileName); if(nRet!=SUCCESS) { m_LBitmapWnd.DisplayErrorFromList(NULL); AfxGetMainWnd()->DestroyWindow(); return ; } if (m_LBitmapWnd.GetBitsPerPixel() != 24) { MessageBox(_T("Image should be a 24-bit one!"), _T("Error"), MB_OK | MB_ICONERROR); AfxGetMainWnd()->DestroyWindow(); return; } AfxGetMainWnd()->SetWindowText(_T("Rotating RGB -> HLS -> CMYK -> HSV -> YUV -> RGB Color Spaces...")); LBuffer LeadBuffer1(m_LBitmapWnd.GetBytesPerLine()*2); LBuffer LeadBuffer2(m_LBitmapWnd.GetBytesPerLine()*2); LBuffer LeadBufferRow(m_LBitmapWnd.GetBytesPerLine()); m_LBitmapWnd.Access(); BeginWaitCursor(); for (L_INT i = 0; i < m_LBitmapWnd.GetHeight()-1; i++) { m_LBitmapWnd.GetRow(&LeadBufferRow,i); LeadBuffer1.ConvertColorSpace(LeadBufferRow,m_LBitmapWnd.GetWidth(), CCS_RGB, CCS_HLS); LeadBuffer2.ConvertColorSpace(LeadBuffer1,m_LBitmapWnd.GetWidth(), CCS_HLS, CCS_CMYK); LeadBuffer1.ConvertColorSpace(LeadBuffer2,m_LBitmapWnd.GetWidth(), CCS_CMYK, CCS_HSV); LeadBuffer2.ConvertColorSpace(LeadBuffer1,m_LBitmapWnd.GetWidth(), CCS_HSV, CCS_YUV); LeadBufferRow.ConvertColorSpace(LeadBuffer2,m_LBitmapWnd.GetWidth(), CCS_YUV, CCS_RGB); m_LBitmapWnd.PutRow(LeadBufferRow,i); } EndWaitCursor(); m_LBitmapWnd.Release(); m_LBitmapWnd.Repaint(); AfxGetMainWnd()->SetWindowText(_T("Rotated Color space is completed ( Class library Demo)")); CView::OnTimer(nIDEvent); } void ClsView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { // TODO: Add your specialized code here and/or call the base class if(bActivate==TRUE && pActivateView==this) if(m_LBitmapWnd.HandlePalette(WM_QUERYNEWPALETTE, 0, 0)==FALSE) m_LBitmapWnd.Repaint(); CView::OnActivateView(bActivate, pActivateView, pDeactiveView); }