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

📄 mymotiondetectcamview.cpp

📁 How to control the camera of cellphone.
💻 CPP
字号:
/*
 ============================================================================
 Name		: CMyMotionDetectCamView from MyMotionDetectCamView.h
 Author	  : 
 Version	 :
 Copyright   : 
 
 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2008.

 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
 The use of the software is subject to the terms of the end-user license 
 agreement which accompanies or is included with the software. The software is 
 provided "as is" and Sony Ericsson specifically disclaim any warranty or 
 condition whatsoever regarding merchantability or fitness for a specific 
 purpose, title or non-infringement. No warranty of any kind is made in 
 relation to the condition, suitability, availability, accuracy, reliability, 
 merchantability and/or non-infringement of the software provided herein.

Description : CMyMotionDetectCamView implementation
============================================================================
*/

#include <MyMotionDetectCam.rsg>
#include "MyMotionDetectCamAppUi.h"
#include "MyMotionDetectCamView.h"
#include "MyMotionDetectCam.hrh"
#include "MyMotionDetectCamGlobals.h"

_LIT(KInactiveText, "Inactive");

/**
 Creates and constructs the view.

 @param aAppUi Reference to the AppUi
 @return Pointer to a CMyMotionDetectCamView object
 */
CMyMotionDetectCamView* CMyMotionDetectCamView::NewLC(CQikAppUi& aAppUi)
	{
	CMyMotionDetectCamView* self = new(ELeave) CMyMotionDetectCamView(aAppUi);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

/**
 Constructor for the view.
 Passes the application UI reference to the construction of the super class.

 KNullViewId should normally be passed as parent view for the applications
 default view. The parent view is the logical view that is normally activated
 when a go back command is issued. KNullViewId will activate the system
 default view.

 @param aAppUi Reference to the application UI
 */
CMyMotionDetectCamView::CMyMotionDetectCamView(CQikAppUi& aAppUi) :
	CQikViewBase(aAppUi, KNullViewId)
	{
	}

/**
 Destructor for the view
 */
CMyMotionDetectCamView::~CMyMotionDetectCamView()
	{
    DestroyBitmaps();
	}

/**
 2nd stage construction of the App UI.
 */
void CMyMotionDetectCamView::ConstructL()
	{
	// Calls ConstructL that initialises the standard values.
	// This should always be called in the concrete view implementations.
	CQikViewBase::ConstructL();
	}

/**
 Inherited from CQikViewBase and called upon by the UI Framework.
 It creates the view from resource.
 */
void CMyMotionDetectCamView::ViewConstructL()
	{
	// Loads information about the UI configurations this view supports
	// together with definition of each view.
	 ViewConstructFromResourceL(R_UI_CONFIGURATIONS);
	
	// Switch to landscape mode
	CQUiConfigClient::Static().SetCurrentConfigL(KQikPenStyleTouchLandscape);	
	
	// Switch to fullscreen mode
	TQikViewMode mode;
	mode.SetFullscreen();
	SetViewModeL(mode);

	}

/**
 Returns the view Id

 @return Returns the Uid of the view
 */
TVwsViewId CMyMotionDetectCamView::ViewId() const
	{
	return TVwsViewId(KUidMyMotionDetectCamApp, KUidMyMotionDetectCamView);
	}


/**
Draw the view
 */
void CMyMotionDetectCamView::Draw(const TRect &aRect) const
{
    CWindowGc& gc=SystemGc();
	if(iBmCreated)
		{
		// Bitmaps are available. Use BitBlt to performs bitmap block transfers. The four bitmaps are shown in the view.
		gc.BitBlt(TPoint(0,0),iBmTopLeft);
		gc.BitBlt(TPoint(iBmSize.iWidth,0),iBmTopRight);
		gc.BitBlt(TPoint(0, iBmSize.iHeight),iBmBottomLeft);
		gc.BitBlt(TPoint(iBmSize.iWidth,iBmSize.iHeight),iBmBottomRight);
		}
	else
		{
		// Draw string on white background indicating that app is inactive
		gc.SetBrushColor(KRgbWhite);
		gc.SetPenColor(KRgbBlack);
		gc.Clear(aRect);
		gc.UseFont(iEikonEnv->TitleFont());
		gc.DrawText(KInactiveText, Rect(), Size().iHeight/2, CGraphicsContext::ECenter);
		gc.DiscardFont();
		}
}

/**
Create four greyscale bitmaps filling the entire view area

 @return Returns the size of the view's bitmaps
 */
 
TSize CMyMotionDetectCamView::CreateBitmapsL()
{
  // iBmSize to a fourth of the size of the view 
  iBmSize = Size();
  iBmSize.iHeight = iBmSize.iHeight/2;
  iBmSize.iWidth = iBmSize.iWidth/2;

  // Make sure the bitmaps are destroyed
  DestroyBitmaps();
  // Create new bitmaps
  iBmTopLeft = new(ELeave)CFbsBitmap();
  User::LeaveIfError(iBmTopLeft->Create(iBmSize, EGray256));
  iBmTopRight = new(ELeave)CFbsBitmap();
  User::LeaveIfError(iBmTopRight->Create(iBmSize, EGray256));
  iBmBottomLeft = new(ELeave)CFbsBitmap();
  User::LeaveIfError(iBmBottomLeft->Create(iBmSize, EGray256));
  iBmBottomRight = new(ELeave)CFbsBitmap();
  User::LeaveIfError(iBmBottomRight->Create(iBmSize, EGray256));
  iBmCreated=ETrue;
  return iBmSize;
}

/**
Destroy all bitmaps
 */
 
void CMyMotionDetectCamView::DestroyBitmaps()
	{
	delete iBmTopLeft;
	iBmTopLeft  = NULL;
	delete iBmTopRight;
	iBmTopRight  = NULL;
	delete iBmBottomLeft;
	iBmBottomLeft  = NULL;
    delete iBmBottomRight;
    iBmBottomRight  = NULL;
    iBmCreated=EFalse;
	}



/**
Update the view bitmaps and perform motion detection
iBmCreated must be ETrue

 @param aPic Descriptor holding semi-planar 4:2:0 subsampled YUV data for a video frame with size iBmSize
 @return Returns the amount of movement compared to the last frame
 */
TInt CMyMotionDetectCamView::UpdateBitmaps(const TDesC8& aPic)
{
	ASSERT(iBmCreated);

	// motionUtil will be used to write a motion tracking image
	TBitmapUtil motionUtil(iBmTopLeft);
	// imageUtil will be used to write a normal greyscale image
	TBitmapUtil imageUtil(iBmTopRight);
	// edgeUtil will be used to write an image with highlighted edges
	TBitmapUtil edgeUtil(iBmBottomLeft);
	// negUtil will be used to write a negative image rotated 180 degrees
	TBitmapUtil negUtil(iBmBottomRight);
	
	// The total motion compared to the last frame
	TInt totDiff=0;

	// Call begin to lock set the starting position and lock the heap. The two argument overload assumes that the heap has already been locked
	imageUtil.Begin(TPoint(0,0));
	motionUtil.Begin(TPoint(0,0), imageUtil);
	edgeUtil.Begin(TPoint(0,0), imageUtil);
	negUtil.Begin(TPoint(iBmSize.iWidth-1, iBmSize.iHeight-1), imageUtil);

	// Loop through all pixels in the video frame accessing only it's Y component. This loop takes a long time which should be avoided, but is provided for demo purposes.
	for(TInt row=0;row<iBmSize.iHeight;++row)
	{
		// The Y value of the pixel to the left of the current pixel. Pixels in col 0 gets it self as reference as there is no pixel to the left.
		TInt lastPixVal=aPic[row*iBmSize.iWidth];
		for(TInt col=0;col<iBmSize.iWidth;++col)
		{
			// Get the Y component of the current pixel
			TInt newVal=aPic[row*iBmSize.iWidth + col];
			// Get the value of the current pixel from the old image
			TInt oldVal=imageUtil.GetPixel();
			// Calculate the difference between the same pixel in two consecutive frames
			TInt motionDiff=Abs(newVal-oldVal) & 0xF8;
			// Calculate the difference between two consecutive  pixels in the same frame
			TInt edgeDiff=~Min((Abs(newVal-lastPixVal) & 0xF8) << 2, 0xFF); 
			// Set the pixel values in the images
			imageUtil.SetPixel(newVal);
			motionUtil.SetPixel(motionDiff);
			edgeUtil.SetPixel(edgeDiff);
			negUtil.SetPixel(~newVal);
			// Update variables
			lastPixVal=newVal;			
			totDiff+=motionDiff;
			//Move the current position in the images
			imageUtil.IncXPos();
			motionUtil.IncXPos();
			edgeUtil.IncXPos();
			negUtil.DecXPos();
		}
	}
	
	// Draw the motion meter in the motion image
	totDiff=totDiff/1000;
	for (int j = 0; j < 4; ++j)
		{
		motionUtil.SetPos(TPoint(0, j));
		for (int i = 0; i < totDiff && i <iBmSize.iWidth; ++i)
			{
			motionUtil.SetPixel(0xFF);
			motionUtil.IncXPos();
			}
		}
		
	// End image update. Unlocks the heap.
	imageUtil.End();
	motionUtil.End();
	edgeUtil.End();
	negUtil.End();

	DrawNow();
	return totDiff;
}

⌨️ 快捷键说明

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