📄 cameracaptureengine.cpp
字号:
//To be saved
User::LeaveIfError( iBitmapSave->Resize( iPortraitSize ));
CleanupStack::PopAndDestroy(bmpDeviceSave);//bmpDeviceSave
}
else
{
fbsBitGc->DrawBitmap( TRect(iLandscapeSize), iBitmapSave );
delete bmpDevice;
}
CleanupStack::PopAndDestroy(fbsBitGc);//fbsBitGc;
// Start to save the image.
AsyncStateChange(EStartToSaveImage);
}
/*
-------------------------------------------------------------------------------
Sets the zoom factor
-------------------------------------------------------------------------------
*/
TInt CCameraCaptureEngine::SetZoomFactorL(TBool aEnable) // CSI: 40 # (Zoom factor is not an error code)
{
TInt bitmapCount = ECameraZoomLimit - ECameraZoom2Uid;
//both 0 and 1 indicate that zoom functionality is not supported
if ( iInfo.iMaxZoomFactor != 0 && iInfo.iMaxZoomFactor != 1 )
{
if ( aEnable && iZoomFactor < iInfo.iMaxZoom )
{
iZoomFactor++;
}
if ( !aEnable && iZoomFactor > iInfo.iMinZoom )
{
iZoomFactor--;
}
iCamera->SetZoomFactorL( iZoomFactor );
//Zoom ind. bitmap offset
return ( iInfo.iMaxZoom > bitmapCount )?KErrNotFound:iZoomFactor-1;
}
if ( iInfo.iMaxDigitalZoomFactor != 0 && iInfo.iMaxDigitalZoomFactor != 1 )
{
if ( aEnable && iZoomFactor < iInfo.iMaxDigitalZoom )
{
iZoomFactor++;
}
if ( !aEnable && iZoomFactor > 0 )
{
iZoomFactor--;
}
iCamera->SetDigitalZoomFactorL(iZoomFactor);
//Zoom ind. bitmap offset
return (iInfo.iMaxDigitalZoom>bitmapCount)?KErrNotFound:iZoomFactor-1;
}
return KErrNotFound;
}
/*
-------------------------------------------------------------------------------
Sets the autofocus range.
Does nothing if AF is not supported.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SetFocusRangeL( CCamAutoFocus::TAutoFocusRange aRange )
{
// do nothing if AF not supported or focusing already in progress
if( !iAutoFocus || iState == EFocusing )
return;
iAutoFocus->SetFocusRangeL( aRange );
iRange = aRange;
// reset capture mode so the new range will be shown in UI
iController->SetCaptureModeL( iCaptureSize,
(TInt)iFormat,
ETrue );
}
/*
-------------------------------------------------------------------------------
Gets the current autofocus range
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::FocusRange( CCamAutoFocus::TAutoFocusRange& aRange )
{
if( !iAutoFocus )
return;
iAutoFocus->FocusRange( aRange );
}
/*
-------------------------------------------------------------------------------
Starts the optimised autofocus operation.
Does nothing if AF is not supported.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::StartFocusL()
{
// do nothing if AF not supported or focusing already in progress
if( !iAutoFocus || iState == EFocusing)
return;
// if AF range is not defined, set to normal before first focus attempt
if( !iRange )
{
iRange = CCamAutoFocus::ERangeNormal;
iAutoFocus->SetFocusRangeL( iRange );
}
iState = EFocusing;
iAutoFocus->AttemptOptimisedFocusL();
}
/*
-------------------------------------------------------------------------------
Cancels an ongoing autofocus operation
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::FocusCancel()
{
if(iAutoFocus && iState == EFocusing)
{
iState = EEngineIdle;
iAutoFocus->Cancel();
}
}
/*
-------------------------------------------------------------------------------
Handles error situations
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::HandleError(TInt aError )
{
TInt reason(KErrNone);
switch( aError )
{
case KErrNone:
reason = KErrNone;
break;
case KErrNoMemory:
iEikEnv->HandleError( aError );
reason = ECameraOverflow;
break;
case KErrInUse:
reason = ECameraInUse;
iController->HandleError( aError );
break;
case KErrHardwareNotAvailable:
iState = EEngineNoHardware;
reason = ECameraHwFailure;
break;
case KErrExtensionNotSupported: // AF not supported
reason = KErrNone;
iController->HandleError( aError );
break;
case KErrTimedOut:
reason = ECameraOverflow;
break;
default:
iEikEnv->HandleError( aError );
reason = ECameraOverflow;
}
if ( reason )
{
if(iBitmapSave)
iBitmapSave->Reset();
delete iImageExif;
iImageExif = 0;
}
}
/*
-------------------------------------------------------------------------------
Cancels the Active Object
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DoCancel()
{
if ( iState == EConvertingImage )
{
iEncoder->Cancel();
DeleteEncoder();
iFile.Close(); // Close file if open
}
}
/*
-------------------------------------------------------------------------------
Called when an asynchronous request is completed
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::RunL()
{
if ( iStatus == KErrNone )
{
switch ( iState )
{
case EStartingViewFinder:
{
TRAPD( err, DoViewFinderL() );
HandleError( err );
if( err == KErrNone )
{
iState = EEngineIdle;
}
break;
}
case EStartToSaveImage:
{
iController->SaveImageL();
break;
}
// Conversion process ends
case EConvertingImage:
{
iFile.Close(); // Close file if open
if( iFormat == CCamera::EFormatExif ) // EXIF file has been saved
{ // - ok to discard image data
delete iImageExif;
iImageExif = 0;
}
else
DeleteEncoder(); // release captured image file
AsyncStateChange( EConverted );
break;
}
case EConverted:
{
HBufC* resImageSaved = StringLoader::LoadLC(R_IMAGE_SAVED);
iController->ShowConversionStatusL( *resImageSaved, ETrue );
CleanupStack::PopAndDestroy(resImageSaved);
break;
}
default:
break;
}
}
else if (iStatus == KErrDiskFull)
{
// TODO: Disk full. Reset the engine (cf. selecting New Image).
}
else
{
// RunL called with status iStatus.Int()
}
}
/*
-------------------------------------------------------------------------------
Changes the engine state and completes an asynchronous request immediately
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::AsyncStateChange( const TEngineState& aNextState )
{
TRequestStatus* status=(&iStatus);
iState = aNextState;
User::RequestComplete(status, KErrNone);
SetActive();
}
/*
-------------------------------------------------------------------------------
Returns whether the image conversion is in progress or not
-------------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsImageConversionInProgress()
{
return ( iState == EConvertingImage || iState == EStartToSaveImage );
}
/*
-------------------------------------------------------------------------------
Returns the engine state
-------------------------------------------------------------------------------
*/
TEngineState CCameraCaptureEngine::GetEngineState()
{
return iState;
}
/*
-------------------------------------------------------------------------------
Sets the engine state
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SetEngineState( TEngineState aState )
{
iState = aState;
}
/*
-------------------------------------------------------------------------------
Returns whether the camera is being used by another application
-------------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsCameraUsedByAnotherApp()
{
return (!iCameraReserved);
}
/*
-------------------------------------------------------------------------------
Returns whether viewfinder is currently active
-------------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsViewFinderActive()
{
return iCamera->ViewFinderActive();
}
/*
-------------------------------------------------------------------------------
Returns whether AF is supported
-------------------------------------------------------------------------------
*/
TBool CCameraCaptureEngine::IsAutoFocusSupported()
{
return ( iAutoFocus != 0 );
}
/*
-------------------------------------------------------------------------------
Notifies the engine if the client rect size changes
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ClientRectChangedL(const TRect& aRect)
{
if( iLandscapeSize == aRect.Size() )
{
return;
}
// The given client rect size is the same as the landscape picture size
iLandscapeSize = aRect.Size();
// In portrait mode the height is the same, but the width needs to be
// calculated according to the aspect ratio
iPortraitSize = TSize(
(aRect.Size().iHeight * aRect.Size().iHeight / aRect.Size().iWidth),
aRect.Size().iHeight);
delete iBitmapPortraitVF;
iBitmapPortraitVF = 0;
iBitmapPortraitVF = new (ELeave) CWsBitmap( iEikEnv->WsSession() );
User::LeaveIfError( iBitmapPortraitVF->Create( iPortraitSize,
iDisplayMode ) );
}
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -