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

📄 camengine.cpp

📁 PartiTekSDK.chm is for windows, Unix/Linux and WinCE/WinMobile platform. SDK_Manul_Symbian.pdf i
💻 CPP
字号:
/*
============================================================================
 Name        : CamEngine.cpp
 Author      : Augusta
 Version     :
 Copyright   : All rights reserved
 Description : CCamEngine implementation
============================================================================
*/

#include "CamEngine.h"
#include <ECam.h>
#include <fbs.h>
#include "PtAPISymbian.h"
#include "CamDecode_3rdAppView.h"
#include <AknGlobalNote.h>
#include <libc\string.h>
#include "CamDecodeDlg.h"

CCamEngine::CCamEngine(CCamDecode_3rdAppView& aView)
{
	// No implementation required
	iView=&aView;
}


CCamEngine::~CCamEngine()
{
	delete iCamera;
}

CCamEngine* CCamEngine::NewLC(CCamDecode_3rdAppView& aView)
{
	CCamEngine* self = new (ELeave)CCamEngine(aView);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CCamEngine* CCamEngine::NewL(CCamDecode_3rdAppView& aView)
{
	CCamEngine* self=CCamEngine::NewLC(aView);
	CleanupStack::Pop(); // self;
	return self;
}

void CCamEngine::ConstructL()
{
	if(!CCamera::CamerasAvailable())
	{
		HandleError(KErrHardwareNotAvailable);
		return;
	}
	iCamera=CCamera::NewL(*this,0);
	iCamera->CameraInfo(iInfo);
	iSize=TSize(200,176);                         
	iDecodingNow=EFalse;
	iZoomFactor=NULL;
}

void CCamEngine::Reserve()
{
	iCamera->Reserve();
}

void CCamEngine::ReserveComplete(TInt aError)
{
	if (aError)
	{
		HandleError(aError);
	}
	else
	{
//	message("Reserved complete");
	iCamera->PowerOn();
	}
}

void CCamEngine::PowerOnComplete(TInt aError)
{
	if(aError)
	{
		HandleError(aError);
	}
	else
	{ 
	TInt Count;

	for(Count=iInfo.iNumImageSizesSupported-1;Count>=0;Count--)
	{
	iCamera->EnumerateCaptureSizes(iSize,Count,CCamera::EFormatFbsBitmapColor16M);
		if(iSize.iHeight*iSize.iWidth>=76800)
		{
			break;
		}
	}
	iCamera->StartViewFinderBitmapsL(iSize); 
	iCamera->SetExposureL();
	iView->iCamStart=ETrue;
	}
}
void CCamEngine::HandleError(TInt aError)
{

}
void CCamEngine::Exit()
{
	iCamera->StopViewFinder();
	iCamera->PowerOff();
	iCamera->Release();
}
void CCamEngine::ViewFinderFrameReady(CFbsBitmap& aFrame)
{
	iView->DrawImageNow(&aFrame);

		if(!iDecodingNow)
		{
			//TInt Count;

			if(EFalse == iView->iDecodeType)//decode datamartrix
			{
				iDecodingNow=ETrue;
				PTTOTALBARCODEINFO CodeInfo;
				PTDECODEPARA       para;
				para.dwStartX = 0;
				para.dwStartY = 0;
				para.dwEndX   = 0;
				para.dwEndY   = 0;
				para.dwMaxCount=0;
				CPtDMDecode  PtDMDecode;
				PtDMDecode.PtDMDecodeRegister ("12345678901234567890");//license key for demo
				PtDMDecode.PtDMDecodeInit(&CodeInfo);
				int ret= PtDMDecode.PtDMDecodeFromBitmap ( &aFrame, &para, &CodeInfo );

				if( ret!= PT_DMDECODE_SUCCESS )
				{
				  message("alloc mem error!");
				}
				else
				{
					if ( CodeInfo.dwTotalCount > 0 )
					{
						iView->ClearScr();
						dlg = CCamDecodeDlg::NewL();
						dlg->RunDlgLD((char*)CodeInfo.pInfoList[0].pData);
					}
					else
					{
				//		message("no barcode data");
					}
				}
				PtDMDecode.PtDMDecodeFree( &CodeInfo );
			}
			else//decode QR Code
			{
				iDecodingNow=ETrue;
				PTTOTALBARCODEINFO CodeInfo;
				PTDECODEPARA       para;
				para.dwStartX = 0;
				para.dwStartY = 0;
				para.dwEndX   = 0;
				para.dwEndY   = 0;
				para.dwMaxCount=0;
				CPtQRDecode  PtQRDecode;
				PtQRDecode.PtQRDecodeRegister ("12345678901234567890");//license key for demo 
				PtQRDecode.PtQRDecodeInit(&CodeInfo);
				int ret= PtQRDecode.PtQRDecodeFromBitmap ( &aFrame, &para, &CodeInfo );
				if( ret!= PT_QRDECODE_SUCCESS )
				{
					message("alloc mem error!");
				}
				else
				{
					if ( CodeInfo.dwTotalCount > 0 )
					{
						iView->ClearScr();
						dlg = CCamDecodeDlg::NewL();
						dlg->RunDlgLD((char*)CodeInfo.pInfoList[0].pData);
					}
					else
					{
					//	message("Cannot find barcode.");
					}
				}
				PtQRDecode.PtQRDecodeFree( &CodeInfo );//free the memory

			}
			iDecodingNow=EFalse;
		}
}
void CCamEngine::ImageReady(CFbsBitmap* aBitmap,HBufC8* aData,TInt aError)
{

}

void CCamEngine::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
{

}

void CCamEngine::SetZoomFactorL(TBool aEnable) 
    {   
//	   TInt bitmapCount = ECameraZoomLimit - ECameraZoom2Uid;  
    if ( iInfo.iMaxZoomFactor != 0 && iInfo.iMaxZoomFactor != 1 )//both 0 and 1 indicate that 
                                                                 //zoom functionality is not supported      
        {
        if ( aEnable && iZoomFactor < iInfo.iMaxZoom )
            {
            iZoomFactor++;
            }
        if ( !aEnable && iZoomFactor > iInfo.iMinZoom )
            {
            iZoomFactor--;
            }
        iCamera->SetZoomFactorL( iZoomFactor );
 //       return ( iInfo.iMaxZoom > bitmapCount )?KErrNotFound:iZoomFactor-1;//Zoom ind. bitmap offset 
        }
    if ( iInfo.iMaxDigitalZoomFactor != 0 && iInfo.iMaxDigitalZoomFactor != 1 )
        {
        if ( aEnable && iZoomFactor < iInfo.iMaxDigitalZoom )
            {
            iZoomFactor++;
            }
        if ( !aEnable && iZoomFactor > 0 )
            {
            iZoomFactor--;
            }
        iCamera->SetDigitalZoomFactorL(iZoomFactor);
//        iCapturePrepared = EFalse;
//        return ( iInfo.iMaxDigitalZoom > bitmapCount )?KErrNotFound:iZoomFactor-1;//Zoom ind. bitmap offset 
        }
//    return KErrNotFound; 
    }

TInt CCamEngine::message( char* str)
{
	TBuf8<200>  buf8;
	TBuf16<200> buf16;
	buf8.Copy( (const unsigned char*)str, strlen(str) );
	buf16.Copy(buf8);//CnvUtfConverter::ConvertToUnicodeFromUtf8(buf16, buf8);
	CAknGlobalNote* note = CAknGlobalNote::NewLC();
	note->ShowNoteL(EAknGlobalWaitNote, buf16);//EAknGlobalConfirmationNote
	CleanupStack::PopAndDestroy(note);
	return KErrNone;
}

⌨️ 快捷键说明

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