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

📄 cameracaptureengine.cpp

📁 SYMBIAN camera 样例程序如果需要了解更多或缺少什么文件可以邮件联系我
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
* ============================================================================
*  Name     : CCameraCapureEngine from CameraCaptureEngine.cpp
*  Part of  : CameraApp
*  Description : Provides all still image releated methods. 
*                Interface to Symbian Onboard Camera API.
*  Created  : 05/06/2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Nokia Corporation, 2006
* ============================================================================
*/

#include "CameraCaptureEngine.h"
#include "Cameraapp.hrh"

#include <AknViewAppUi.h>
#include <eikenv.h>
#include <barsread.h>
#include "filelogger.h"


_LIT( KSavingImage, "Saving image..." );
_LIT( KImageSaved, "Saved" );

// GetImageSizeIndexL() could be used for selecting a specific image
// size. Here, we simply select 2nd largest size (index 1)
const TUint KImageSizeIndex = 1;

/*
-----------------------------------------------------------------------------

	CCameraCaptureEngine::CCameraCaptureEngine( 
            CCameraAppController& aController,
            const TRect& aRect )

	Description: C++ default constructor can NOT contain any code that might 
                 leave.
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CCameraCaptureEngine::CCameraCaptureEngine( CCameraAppController& aController)
: CActive( EPriorityStandard ),
  iController( aController ), 
  iZoomFactor( 0 ),
  iCapturePrepared( EFalse ), 
  iBitmapSave( 0 ),
  iImageExif( 0 ),
  iEncoder( 0 ), 
  iCameraReserved( EFalse ),
  iAutoFocus( 0 )
    {
    CActiveScheduler::Add( this );
	  iState = EEngineNotReady;
    }

/*
-----------------------------------------------------------------------------

	CCameraCaptureEngine* CCameraCaptureEngine::NewL( CCameraAppController& 
												aController )

	Description: Two-phased constructor.

	Comments   :

    Return values: CCameraCaptureEngine object pointer

-----------------------------------------------------------------------------
*/
CCameraCaptureEngine* CCameraCaptureEngine::NewL( 
    CCameraAppController& aController, const TRect& aRect )
    {
    CCameraCaptureEngine* self = 
        new (ELeave) CCameraCaptureEngine( aController );

    CleanupStack::PushL( self );
    self->ConstructL(aRect);
    CleanupStack::Pop(self);

    return self;
    }


/*
-----------------------------------------------------------------------------

	CCameraCaptureEngine::~CCameraCaptureEngine()

	Description: Destructor, free allocated resources
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
CCameraCaptureEngine::~CCameraCaptureEngine()
    {
    delete iAutoFocus;
    delete iEncoder;      
    delete iCamera;
    delete iBitmapPortraitVF;
    delete iBitmapSave;
    delete iImageExif;

	// Cancel any outstanding request
	Cancel();
    }

/*
-----------------------------------------------------------------------------

    void CCameraCaptureEngine::ConstructL(const TRect& aRect)

    Description: Symbian 2nd phase constructor can leave.
    Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::ConstructL(const TRect& aRect)
    {
    iEikEnv = CEikonEnv::Static();
    if ( !CCamera::CamerasAvailable() )
        {
        HandleError( KErrHardwareNotAvailable );
        return;
        }
    
    // camera index 0 (the main camera)
    iCamera = CCamera::NewL( *this, 0 );
    
    // try to construct autofocus object
    TRAPD(afErr, iAutoFocus = CCamAutoFocus::NewL( iCamera ));
    if(afErr)
        {
        iAutoFocus = 0;
        HandleError( KErrExtensionNotSupported );
        }
    
    iCameraReserveComplete = ETrue; //No requests issued yet
    
    iBitmapSave = new (ELeave) CFbsBitmap;
    
    // Gets information about the camera device. refer to SDK for more info.
    iCamera->CameraInfo(iInfo); 
    iDisplayMode = DisplayMode();
    iColorDepth = ImageFormat();
    iColorDepthHW = ImageFormatMax();
    ClientRectChangedL(aRect); 
    }

/*
-----------------------------------------------------------------------------

	TDisplayMode CCameraCaptureEngine::DisplayMode() const

	Description: Returns default display mode
	Comments   :

    Return values: Returns default display mode

-----------------------------------------------------------------------------
*/
TDisplayMode CCameraCaptureEngine::DisplayMode() const
    {
    TInt color;
    TInt gray;
	TDisplayMode displayMode = 
		iEikEnv->WsSession().GetDefModeMaxNumColors( color, gray );
    return displayMode;
    }

/*
-----------------------------------------------------------------------------

	CCamera::TFormat CCameraCaptureEngine::ImageFormat() const

	Description: Returns camera image format to be used with current display 
				 mode
	Comments   :

    Return values: Returns camera image format to be used with current display 
				   mode

-----------------------------------------------------------------------------
*/
CCamera::TFormat CCameraCaptureEngine::ImageFormat() const
    {
    switch ( iDisplayMode )
        {
        case EColor16M:
            return CCamera::EFormatFbsBitmapColor16M;
        case EColor64K:
            return CCamera::EFormatFbsBitmapColor64K;
        case EColor4K:
            return CCamera::EFormatFbsBitmapColor4K;
        default:
            return CCamera::EFormatFbsBitmapColor4K;
        }
    }

/*
-----------------------------------------------------------------------------

	CCamera::TFormat CCameraCaptureEngine::ImageFormatMax() const

	Description: Returns highest color mode supported by HW
	Comments   :

    Return values: Returns highest color mode supported by HW

-----------------------------------------------------------------------------
*/
CCamera::TFormat CCameraCaptureEngine::ImageFormatMax() const
    {
    if ( iInfo.iImageFormatsSupported & CCamera::EFormatFbsBitmapColor16M )
        {
        return CCamera::EFormatFbsBitmapColor16M;
        }
    else if ( iInfo.iImageFormatsSupported & CCamera::EFormatFbsBitmapColor64K)
        {
        return CCamera::EFormatFbsBitmapColor64K;
        }
    else 
        {
        return CCamera::EFormatFbsBitmapColor4K;
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::StopViewFinder() 

	Description: Stops view finding
	Comments   :

    Return values: Stops view finding

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::StopViewFinder() 
    {
    if ( iCameraReserved && iCameraReserveComplete )
        {
        __LOGSTR_TOFILE("stop vf");
        iCamera->StopViewFinder();        
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::DoViewFinderL() 

	Description: Starts view finding and prepares image capturing
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DoViewFinderL() 
    {
	  //Default, always supported by API
    iCamera->SetExposureL();
    
    TRAPD(ignore, iCamera->SetDigitalZoomFactorL( iZoomFactor ));


    if ( iInfo.iOptionsSupported & TCameraInfo::EViewFinderBitmapsSupported ) 
        {
        if ( iInfo.iOptionsSupported & TCameraInfo::EImageCaptureSupported 
            && !iCapturePrepared ) // first try capturing in EXIF JPEG format
            {
            iFormat = CCamera::EFormatExif;            
            TRAPD(exifErr, iCamera->PrepareImageCaptureL(iFormat, KImageSizeIndex));
            if(exifErr) // capturing in EXIF format not supported, 
                        // fall back to bitmap format
                {
                iFormat = iColorDepthHW;
                iCamera->PrepareImageCaptureL(iFormat, 1);
                }
            else    // notify controller that we're using EXIF capture mode
                {
                iCamera->EnumerateCaptureSizes( iCaptureSize, KImageSizeIndex, 
                                               iFormat );
                                               
                iController.SetCaptureModeL( iCaptureSize, 
                                             (TInt)iFormat, 
                                             (TBool)iAutoFocus );
                }

            iCapturePrepared = ETrue;
            }

        // Start the view finding, and transfer the view finder data.
        // Bitmaps are returned by MCameraObserver::ViewFinderFrameReady().
        iCamera->StartViewFinderBitmapsL( iLandscapeSize );
        }
    else if (iInfo.iOptionsSupported & TCameraInfo::EViewFinderDirectSupported)
        {
        User::Leave(KErrNotSupported);
        }
    else
        {
        //Images could be taken even without viewfinder, if following is true:
        //( iInfo.iOptionsSupported & TCameraInfo::EImageCaptureSupported )                          
        User::Leave(KErrNotSupported);
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::StartViewFinderL() 

	Description: Reserves camera, switches power on, and starts finally view 
				 finding
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::StartViewFinderL() 
    {
    __LOGSTR_TOFILE("start vf");
    ReserveCameraL();
    }


/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::GetImageSizeIndexL() 

	Description: Returns the index for the requested image size, if supported
	             by camera
	Comments   : May leave with KErrNotSupported

    Return values: N/A

-----------------------------------------------------------------------------
*/
TInt CCameraCaptureEngine::GetImageSizeIndexL(const TSize& aRequestedSize, 
                                              const CCamera::TFormat& aFormat)
    {
    TCameraInfo camInfo;
    iCamera->CameraInfo(camInfo);

    for (TInt i=0; i< camInfo.iNumImageSizesSupported; i++)
        {
        TSize supportedSize;
        iCamera->EnumerateCaptureSizes(supportedSize, i, aFormat);
        if (supportedSize == aRequestedSize)
            {
            // Found the index
            return(i);
            }
        }
    // Index not found
    User::Leave(KErrNotSupported);
    return(0);
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::SnapL()

	Description: take a picture
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SnapL()
    {
    if ( iCameraReserved && iCameraReserveComplete && !iPowering )
        {
        iState = ESnappingPicture;
        iCamera->StopViewFinder();
        iCamera->CaptureImage();
        iController.ShowConversionStatusL( KSavingImage );
        
        // On completion, MCameraObserver::ImageReady() will be called
        }
    else
        {
        User::Leave( KErrNotReady );
        }
    }


/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::SetMode( TCameraState aMode )

	Description: Sets engine's camera mode
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SetMode( TCameraState aMode )
    {   
    iMode = aMode;
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::DeleteEncoder()

	Description: Destructs JPEG encoder
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::DeleteEncoder()
    {
    if (iEncoder)
        {
        delete iEncoder;
        iEncoder = NULL;
        }

    if (iBitmapSave)
        {
        iBitmapSave->Reset();
        }
    }

/*
-----------------------------------------------------------------------------

	void CCameraCaptureEngine::SaveImageL(TJpegQualityFactor aQuality, 
							const TFileName* aNewFilePathAndName, RFs* aFs)

	Description: Converts and saves bitmap to JPEG image
	Comments   :

    Return values: N/A

-----------------------------------------------------------------------------
*/
void CCameraCaptureEngine::SaveImageL(TJpegQualityFactor /*aQuality*/,
    const TFileName* aNewFilePathAndName, RFs* aFs)
    {

⌨️ 快捷键说明

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