📄 cameracaptureengine.cpp
字号:
User::Leave( KErrArgument );
}
}
// If it is not busy, start to do the conversion.
if ( !IsActive() )
{
iEncoder->Convert( &iStatus, *iBitmapSave );
iState = EConvertingImage;
// Update the status pane to "Saving image..."
HBufC* resSavingImage = StringLoader::LoadLC(R_SAVING_IMAGE);
iController->ShowConversionStatusL( *resSavingImage );
CleanupStack::PopAndDestroy(resSavingImage);
SetActive();
}
}
/*
-------------------------------------------------------------------------------
Reserves the camera.
"ReserveComplete" will be called after completion.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReserveCameraL()
{
iStart = ETrue;
// Async. Will set iCameraReserved to ETrue on success.
if (!iCameraReserved && iCamera)
{
iCamera->Reserve();
}
else if (iCameraReserved && iCamera)
{
if( iCapturePrepared && !iCamera->ViewFinderActive() )
{
iCamera->StartViewFinderBitmapsL( iLandscapeSize );
iState = EEngineIdle;
}
}
}
/*
-------------------------------------------------------------------------------
Releases the camera
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReleaseCamera()
{
iStart = EFalse;
if ( iCameraReserved )
{
if(iAutoFocus)
{
// bring AF subsystem to idle
TRAP_IGNORE(iAutoFocus->ResetToIdleL());
iAutoFocus->Close();
}
iCamera->Release();
iCameraReserved = EFalse;
}
iCapturePrepared = EFalse;
iState = EEngineNotReady;
}
/*
-------------------------------------------------------------------------------
Switches off camera power
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::PowerOff()
{
if ( !iPowering && iCameraReserved )
{
iCamera->PowerOff();
ReleaseCamera();
}
}
/*
-------------------------------------------------------------------------------
Symbian Onboard Camera API observer. Gets called after CCamera::Reserve() is
called.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ReserveComplete(TInt aError)
{
if ( aError )
{
iCameraReserved = EFalse;
HandleError( aError );
}
else
{
iCameraReserved = ETrue;
}
if ( iStart )
{
iPowering = ETrue;
iCamera->PowerOn();
}
else
{
ReleaseCamera();
}
}
/*
-------------------------------------------------------------------------------
Powering operation completes.
Symbian Onboard Camera API observer. Gets called after CCamera::PowerOn() is
called.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::PowerOnComplete(TInt aError)
{
HandleError( aError );
iPowering = EFalse;
if ( iStart ) //The Operation is not cancelled
{
// try to init the AF control - not fatal if fails
if( iAutoFocus )
{
TRAPD( afErr, iAutoFocus->InitL( *this ) );
if(afErr)
{
HandleError( KErrExtensionNotSupported );
delete iAutoFocus;
iAutoFocus = 0;
}
}
// start viewfinder
AsyncStateChange(EStartingViewFinder);
}
else
{
ReleaseCamera();
}
}
/*
-------------------------------------------------------------------------------
Switches off camera power.
Symbian Onboard Camera API observer. Gets called after StartViewFinderBitmapsL
is called.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ViewFinderFrameReady(CFbsBitmap& aFrame)
{
if (!iController)
{
return;
}
if (iController->CameraOrientation() == ECameraPortrait)
{
TRAP_IGNORE(ClipL(aFrame));
iController->ViewFinding( *iBitmapPortraitVF );
}
else
{
// Pass the Bitmap frame to the controller
iController->ViewFinding( aFrame );
}
}
/*
-------------------------------------------------------------------------------
called when an image is ready
Symbian Onboard Camera API observer. Gets called after CCamera::CaptureImage()
is called.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ImageReady(CFbsBitmap* aBitmap, HBufC8* aData,
TInt aError)
{
__LOGSTR_TOFILE1("ImageReady: %d", aError);
TInt err(KErrNone);
if ( aError == KErrNone )
{
if( iFormat == CCamera::EFormatExif )
{
if ( iImageExif )
{
delete iImageExif;
iImageExif = 0;
}
iImageExif = aData;
// TODO: Post-exposure drawing for images
// captured directly in EXIF JPEG format
AsyncStateChange(EStartToSaveImage);
}
else
{
iBitmapSave->Reset();
if( aBitmap )
{
err = iBitmapSave->Duplicate( aBitmap->Handle() );
if( err == KErrNone )
{
TRAP(err, DrawL()); // draw post-exposure image
}
HandleError( err );
}
}
}
else
{
HandleError( aError );
}
}
/*
-------------------------------------------------------------------------------
Called when initalising autofocus is ready
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::InitComplete( TInt aError )
{
__LOGSTR_TOFILE1("InitComplete: %d", aError);
// TODO: Error handling
}
/*
-------------------------------------------------------------------------------
Called when camera has optimised the focus
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::OptimisedFocusComplete( TInt aError )
{
__LOGSTR_TOFILE1("OptimisedFocusComplete: %d", aError);
iState = EEngineIdle;
if(!aError)
{
// In 3rd Ed. devices, play sound only if not in Meeting or Silent
// profile
CRepository* cRepository = NULL;
TRAP_IGNORE(cRepository = CRepository::NewL(KCRUidProfileEngine));
TInt currentProfileId;
cRepository->Get(KProEngActiveProfile, currentProfileId);
delete cRepository;
if (currentProfileId != 1 && currentProfileId != 2) // CSI: 47 # (1 = Meeting, 2 = Silent)
{
iController->PlaySound(ESoundIdFocused);
}
}
}
/*
-------------------------------------------------------------------------------
Called when a framebuffer is ready.
Symbian Onboard Camera API observer. Gets called once
CCamera::StartVideoCapture() is called.
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/,
TInt /*aError*/)
{
// We are not using video capture
}
/*
-------------------------------------------------------------------------------
Clips the viewfinding images according to portrait mode size
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ClipL(const CFbsBitmap& aFrame)
{
TSize size = aFrame.SizeInPixels();
TInt x1 = (size.iWidth-iPortraitSize.iWidth)/2;
TInt x2 = x1+iPortraitSize.iWidth;
TInt y1 = (size.iHeight-iPortraitSize.iHeight)/2;
TInt y2 = y1+iPortraitSize.iHeight;
CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); //graphic context
CleanupStack::PushL( fbsBitGc );
CFbsBitmapDevice* portraitImageDevice =
CFbsBitmapDevice::NewL( iBitmapPortraitVF );
fbsBitGc->Activate( portraitImageDevice );
fbsBitGc->SetBrushColor( KRgbBlack );
fbsBitGc->Clear();
fbsBitGc->BitBlt( TPoint(0,0), &aFrame, TRect(x1,y1,x2,y2) );
delete portraitImageDevice;
CleanupStack::PopAndDestroy(fbsBitGc);
}
/*
-------------------------------------------------------------------------------
Calculates a portrait image size from a bigger snapped image while preserving
the aspect ratio
-------------------------------------------------------------------------------
*/
TRect CCameraCaptureEngine::Portrait( const CFbsBitmap* aBitmap)
{
TRect portrait = TRect();
if ( aBitmap )
{
TSize size = aBitmap->SizeInPixels();
TInt portx =
iPortraitSize.iWidth * size.iWidth / iLandscapeSize.iWidth;
TInt porty =
iPortraitSize.iHeight * size.iHeight / iLandscapeSize.iHeight;
TInt x1 = (size.iWidth-portx)/2;
TInt x2 = x1+portx;
TInt y1 = (size.iHeight-porty)/2;
TInt y2 = y1+porty;
portrait.SetRect(x1,y1,x2,y2);
}
return portrait;
}
/*
-------------------------------------------------------------------------------
Draws the captured image on the screen, modifying it if needed
-------------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DrawL()
{
CFbsBitGc* fbsBitGc = CFbsBitGc::NewL(); //graphic context
CleanupStack::PushL( fbsBitGc );
if (iController->CameraOrientation() == ECameraPortrait)
{
User::LeaveIfError( iController->GetSnappedImage().
Resize( iPortraitSize ));
}
else
{
User::LeaveIfError( iController->GetSnappedImage().
Resize( iLandscapeSize ));
}
CFbsBitmapDevice* bmpDevice =
CFbsBitmapDevice::NewL( &iController->GetSnappedImage() );
fbsBitGc->Activate( bmpDevice );
if (iController->CameraOrientation() == ECameraPortrait)
{
TRect portraitRect = Portrait( iBitmapSave );
//Shrink to snap image size
fbsBitGc->DrawBitmap( TRect(iPortraitSize), iBitmapSave,
portraitRect );
delete bmpDevice;
//Full color image
CFbsBitmapDevice* bmpDeviceSave =
CFbsBitmapDevice::NewL( iBitmapSave );
CleanupStack::PushL( bmpDeviceSave );
fbsBitGc->Activate( bmpDeviceSave );
fbsBitGc->DrawBitmap( TRect(iPortraitSize), iBitmapSave,
portraitRect );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -