os/mm/imagingandcamerafws/camerafw/testapps/testcameraapp/TestCameraApp.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <eikenv.h>
sl@0
    17
#include <testcameraapp.rsg>
sl@0
    18
#include "TestCameraApp.h"
sl@0
    19
#include "TestCameraApp.hrh"
sl@0
    20
#include "TestCamera.h"
sl@0
    21
sl@0
    22
const TInt KMaxErrLength=50;
sl@0
    23
_LIT(KErrorFormat,"Error - %d (%S)");
sl@0
    24
sl@0
    25
//
sl@0
    26
//  CTCamAppUi
sl@0
    27
//
sl@0
    28
sl@0
    29
void CTCamAppUi::ConstructL()
sl@0
    30
	{
sl@0
    31
	CEikAppUi::ConstructL();
sl@0
    32
	iAppView = new(ELeave) CTCamAppView;
sl@0
    33
	iAppView->ConstructL(ClientRect());
sl@0
    34
	AddToStackL(iAppView);
sl@0
    35
	
sl@0
    36
	// The plugin relies on a specific file existing
sl@0
    37
	// hence this has to be created.
sl@0
    38
	CreateDependencyFileL();
sl@0
    39
sl@0
    40
	iCamera = CCamera::NewL(*this,0,0);
sl@0
    41
	
sl@0
    42
	iCameraAdvSet = CCamera::CCameraAdvancedSettings::NewL(*iCamera);
sl@0
    43
	iCameraPresets = CCamera::CCameraPresets::NewL(*iCamera);
sl@0
    44
	iCameraImgProc = CCamera::CCameraImageProcessing::NewL(*iCamera);
sl@0
    45
	iCameraSnapshot = CCamera::CCameraSnapshot::NewL(*iCamera);
sl@0
    46
	
sl@0
    47
	iCamera->Reserve();
sl@0
    48
	}
sl@0
    49
sl@0
    50
CTCamAppUi::~CTCamAppUi()
sl@0
    51
	{
sl@0
    52
	if (iCamera!=NULL)
sl@0
    53
		iCamera->Release();
sl@0
    54
	
sl@0
    55
	delete iCameraSnapshot;
sl@0
    56
	delete iCameraImgProc;	
sl@0
    57
	delete iCameraPresets;
sl@0
    58
	delete iCameraAdvSet;
sl@0
    59
	delete iCamera;
sl@0
    60
sl@0
    61
	// as the application is being closed, delete the file
sl@0
    62
	// so that the plugin will not be reactivated accidentaly
sl@0
    63
	RemoveDependencyFile();
sl@0
    64
	
sl@0
    65
	if (iAppView)
sl@0
    66
		{
sl@0
    67
		RemoveFromStack(iAppView);
sl@0
    68
		delete iAppView;
sl@0
    69
		}
sl@0
    70
	}
sl@0
    71
sl@0
    72
void CTCamAppUi::HandleCommandL(TInt aCommand)
sl@0
    73
	{
sl@0
    74
	switch (aCommand)
sl@0
    75
		{
sl@0
    76
	case ETCamCmdPowerOn:
sl@0
    77
		iCamera->PowerOn();
sl@0
    78
		break;
sl@0
    79
	case ETCamCmdPowerOff:
sl@0
    80
		iCamera->PowerOff();
sl@0
    81
		break;
sl@0
    82
	case ETCamCmdViewFinder:
sl@0
    83
		ViewFinderL();
sl@0
    84
		break;
sl@0
    85
	case ETCamCmdCaptureImage:
sl@0
    86
		SingleShotL();
sl@0
    87
		break;
sl@0
    88
	case ETCamCmdBurstMode:
sl@0
    89
		BurstModeL();
sl@0
    90
		break;
sl@0
    91
	case ETCamCmdCaptureVideo:
sl@0
    92
		CaptureVideoL();
sl@0
    93
		break;
sl@0
    94
	case ETCamCmdIncBrightness:
sl@0
    95
		iCamera->SetBrightnessL(iCamera->Brightness() + 10);
sl@0
    96
		break;
sl@0
    97
	case ETCamCmdIncContrast:
sl@0
    98
		iCamera->SetContrastL(iCamera->Contrast() + 10);
sl@0
    99
		break;
sl@0
   100
	case ETCamCmdDecBrightness:
sl@0
   101
		iCamera->SetBrightnessL(iCamera->Brightness() - 10);
sl@0
   102
		break;
sl@0
   103
	case ETCamCmdDecContrast:
sl@0
   104
		iCamera->SetContrastL(iCamera->Contrast() - 10);
sl@0
   105
		break;
sl@0
   106
	case ETCamCmdResetBrightness:
sl@0
   107
		iCamera->SetBrightnessL(0);
sl@0
   108
		break;
sl@0
   109
	case ETCamCmdResetContrast:
sl@0
   110
		iCamera->SetContrastL(0);
sl@0
   111
		break;
sl@0
   112
	case ETCamCmdIncNumBurstImages:
sl@0
   113
		iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() + 1);
sl@0
   114
		break;
sl@0
   115
	case ETCamCmdDecNumBurstImages:
sl@0
   116
		iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() - 1);
sl@0
   117
		break;
sl@0
   118
	case ETCamCmdResetNumBurstImages:
sl@0
   119
		iCameraAdvSet->SetBurstImages(4);
sl@0
   120
		break;
sl@0
   121
		
sl@0
   122
	case ETCamCmdFactoryPreset:
sl@0
   123
		iCameraPresets->SetPreset(KUidECamPresetFactoryDefault);
sl@0
   124
		break;
sl@0
   125
	
sl@0
   126
	case ETCamCmdOutdoorPreset:
sl@0
   127
		iCameraPresets->SetPreset(KUidECamPresetOutdoor);
sl@0
   128
		break;	
sl@0
   129
		
sl@0
   130
	case ETCamCmdOutdoorSportPreset:
sl@0
   131
		iCameraPresets->SetPreset(KUidECamPresetOutdoorSport);
sl@0
   132
		break;
sl@0
   133
	
sl@0
   134
	case ETCamCmdFogPreset:
sl@0
   135
		iCameraPresets->SetPreset(KUidECamPresetFog);
sl@0
   136
		break;	
sl@0
   137
sl@0
   138
	case ETCamCmdNightPartyIndoorPreset:
sl@0
   139
		iCameraPresets->SetPreset(KUidECamPresetNightPartyIndoor);
sl@0
   140
		break;
sl@0
   141
	
sl@0
   142
	case ETCamCmdTextDocumentPreset:
sl@0
   143
		iCameraPresets->SetPreset(KUidECamPresetTextDocument);
sl@0
   144
		break;	
sl@0
   145
		
sl@0
   146
	case ETCamCmdImgProcIncBrightness:
sl@0
   147
		IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
sl@0
   148
		break;
sl@0
   149
		
sl@0
   150
	case ETCamCmdImgProcDecBrightness:
sl@0
   151
		DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
sl@0
   152
		break;
sl@0
   153
		
sl@0
   154
	case ETCamCmdImgProcIncContrast:
sl@0
   155
		IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
sl@0
   156
		break;
sl@0
   157
		
sl@0
   158
	case ETCamCmdImgProcDecContrast:
sl@0
   159
		DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
sl@0
   160
		break;
sl@0
   161
		
sl@0
   162
	case ETCamCmdEnableSnapshot:
sl@0
   163
		EnableSnapshotL();
sl@0
   164
		break;
sl@0
   165
		
sl@0
   166
	case ETCamCmdDisableSnapshot:
sl@0
   167
		DisableSnapshot();
sl@0
   168
		break;
sl@0
   169
	
sl@0
   170
	case EEikCmdExit:
sl@0
   171
		Exit();
sl@0
   172
		break;
sl@0
   173
		}
sl@0
   174
	}
sl@0
   175
sl@0
   176
void CTCamAppUi::ViewFinderL()
sl@0
   177
	{
sl@0
   178
	TSize imageSize;
sl@0
   179
	iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
sl@0
   180
	const TPoint pos = iAppView->DrawBorders(imageSize);
sl@0
   181
	TRect screenRect(pos,imageSize);
sl@0
   182
	TRect clipRect;
sl@0
   183
sl@0
   184
	if (!iCamera->ViewFinderActive())
sl@0
   185
		{
sl@0
   186
		iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);		
sl@0
   187
		}
sl@0
   188
	else
sl@0
   189
		{
sl@0
   190
		iCamera->StopViewFinder();
sl@0
   191
		}
sl@0
   192
	}
sl@0
   193
sl@0
   194
void CTCamAppUi::BurstModeL()
sl@0
   195
	{
sl@0
   196
	if (!iCameraAdvSet)
sl@0
   197
		{
sl@0
   198
		User::Leave(KErrNotSupported);
sl@0
   199
		}
sl@0
   200
	
sl@0
   201
	if(CCamera::CCameraAdvancedSettings::EDriveModeBurst & iCameraAdvSet->SupportedDriveModes() )
sl@0
   202
		{
sl@0
   203
		iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeBurst);
sl@0
   204
		}
sl@0
   205
	else
sl@0
   206
		{
sl@0
   207
		User::Leave(KErrNotSupported);	
sl@0
   208
		}
sl@0
   209
	}
sl@0
   210
	
sl@0
   211
void CTCamAppUi::EnableSnapshotL()
sl@0
   212
	{
sl@0
   213
	if(!iCameraSnapshot->IsSnapshotActive())
sl@0
   214
		{
sl@0
   215
		TSize size;
sl@0
   216
		iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
sl@0
   217
		if(iCameraSnapshot->SupportedFormats() & CCamera::EFormatFbsBitmapColor4K)
sl@0
   218
			{
sl@0
   219
			iCameraSnapshot->PrepareSnapshotL(CCamera::EFormatFbsBitmapColor4K, TPoint(0,0), size, KRgbWhite, EFalse);
sl@0
   220
			iCameraSnapshot->StartSnapshot();
sl@0
   221
			}
sl@0
   222
		}
sl@0
   223
	}
sl@0
   224
	
sl@0
   225
void CTCamAppUi::DisableSnapshot()
sl@0
   226
	{
sl@0
   227
	if(iCameraSnapshot->IsSnapshotActive())
sl@0
   228
		{
sl@0
   229
		iCameraSnapshot->StopSnapshot();
sl@0
   230
		}
sl@0
   231
	}
sl@0
   232
	
sl@0
   233
void CTCamAppUi::SingleShotL()
sl@0
   234
	{
sl@0
   235
	if (!iCameraAdvSet)
sl@0
   236
		{
sl@0
   237
		User::Leave(KErrNotSupported);
sl@0
   238
		}
sl@0
   239
	
sl@0
   240
	if(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot & iCameraAdvSet->SupportedDriveModes() )
sl@0
   241
		{
sl@0
   242
		iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot);
sl@0
   243
		}
sl@0
   244
	else
sl@0
   245
		{
sl@0
   246
		User::Leave(KErrNotSupported);	
sl@0
   247
		}
sl@0
   248
	}
sl@0
   249
sl@0
   250
void CTCamAppUi::CaptureImageL()
sl@0
   251
	{
sl@0
   252
	TSize size;
sl@0
   253
	iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
sl@0
   254
	iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
sl@0
   255
	iCamera->CaptureImage();
sl@0
   256
	}
sl@0
   257
sl@0
   258
void CTCamAppUi::CaptureVideoL()
sl@0
   259
	{
sl@0
   260
	if (!iCamera->VideoCaptureActive())
sl@0
   261
		{
sl@0
   262
		iCameraSnapshot->StopSnapshot();
sl@0
   263
		
sl@0
   264
		TSize size;
sl@0
   265
		TReal32 rate = 0;
sl@0
   266
		iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
sl@0
   267
		iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
sl@0
   268
		iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
sl@0
   269
		iCamera->StartVideoCapture();
sl@0
   270
		}
sl@0
   271
	else
sl@0
   272
		{
sl@0
   273
		iCamera->StopVideoCapture();
sl@0
   274
		}	
sl@0
   275
	}
sl@0
   276
	
sl@0
   277
void CTCamAppUi::IncImgProcAdjustmentL(TUid aTransformation)
sl@0
   278
	{
sl@0
   279
	if(!iCameraImgProc)	
sl@0
   280
		{
sl@0
   281
		User::Leave(KErrNotSupported);
sl@0
   282
		}
sl@0
   283
	
sl@0
   284
	RArray<TUid> supportedTransformations;
sl@0
   285
	CleanupClosePushL(supportedTransformations);
sl@0
   286
	iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
sl@0
   287
	
sl@0
   288
	TInt error = supportedTransformations.Find(aTransformation);
sl@0
   289
	CleanupStack::PopAndDestroy(); 
sl@0
   290
sl@0
   291
	if(error == KErrNotFound)
sl@0
   292
		{
sl@0
   293
		User::Leave(error);
sl@0
   294
		}
sl@0
   295
		
sl@0
   296
	TInt valuetx;
sl@0
   297
	User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
sl@0
   298
	
sl@0
   299
	iCameraImgProc->SetTransformationValue(aTransformation, valuetx + 10);
sl@0
   300
	}
sl@0
   301
	
sl@0
   302
void CTCamAppUi::DecImgProcAdjustmentL(TUid aTransformation)
sl@0
   303
	{
sl@0
   304
	if(!iCameraImgProc)	
sl@0
   305
		{
sl@0
   306
		User::Leave(KErrNotSupported);
sl@0
   307
		}
sl@0
   308
	
sl@0
   309
	RArray<TUid> supportedTransformations;
sl@0
   310
	CleanupClosePushL(supportedTransformations);
sl@0
   311
	iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
sl@0
   312
	
sl@0
   313
	TInt error = supportedTransformations.Find(aTransformation);
sl@0
   314
	CleanupStack::PopAndDestroy(); 
sl@0
   315
sl@0
   316
	if(error == KErrNotFound)
sl@0
   317
		{
sl@0
   318
		User::Leave(error);
sl@0
   319
		}
sl@0
   320
		
sl@0
   321
	TInt valuetx;
sl@0
   322
	User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
sl@0
   323
	
sl@0
   324
	iCameraImgProc->SetTransformationValue(aTransformation, valuetx - 10);
sl@0
   325
	}
sl@0
   326
	
sl@0
   327
void CTCamAppUi::ReserveComplete(TInt /*aError*/)
sl@0
   328
	{
sl@0
   329
	}
sl@0
   330
sl@0
   331
void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
sl@0
   332
	{
sl@0
   333
	}
sl@0
   334
sl@0
   335
void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
sl@0
   336
	{
sl@0
   337
	}
sl@0
   338
sl@0
   339
void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
sl@0
   340
	{
sl@0
   341
	TBuf<KMaxErrLength> msgBuffer;
sl@0
   342
	_LIT(KErrMessage,"CTCamAppUi::ImageReady");
sl@0
   343
	if (aBitmap)
sl@0
   344
		{
sl@0
   345
		iAppView->DrawImage(aBitmap);
sl@0
   346
		delete aBitmap;
sl@0
   347
		}
sl@0
   348
	if (aError)
sl@0
   349
		{
sl@0
   350
		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
sl@0
   351
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   352
		}
sl@0
   353
	}
sl@0
   354
sl@0
   355
void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
sl@0
   356
	{
sl@0
   357
	TBuf<KMaxErrLength> msgBuffer;
sl@0
   358
	_LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
sl@0
   359
	if (aError)
sl@0
   360
		{
sl@0
   361
		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
sl@0
   362
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   363
		return;
sl@0
   364
		}
sl@0
   365
	TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
sl@0
   366
	aFrameBuffer->Release();
sl@0
   367
	if (error)
sl@0
   368
		{
sl@0
   369
		msgBuffer.Format(KErrorFormat,error,&KErrMessage);
sl@0
   370
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   371
		}
sl@0
   372
	}
sl@0
   373
	
sl@0
   374
void CTCamAppUi::HandleEvent(const TECAMEvent& aEvent)
sl@0
   375
	{
sl@0
   376
	if(!TECAMEvent2::IsEventEncapsulationValid(aEvent))
sl@0
   377
		{
sl@0
   378
		HandleEvent1(aEvent);
sl@0
   379
		}
sl@0
   380
	else
sl@0
   381
		{
sl@0
   382
		HandleEvent2(static_cast<const TECAMEvent2&>(aEvent));
sl@0
   383
		}
sl@0
   384
	}
sl@0
   385
	
sl@0
   386
void CTCamAppUi::HandleEvent2(const TECAMEvent2& /*aEvent2*/)
sl@0
   387
	{
sl@0
   388
	
sl@0
   389
	}
sl@0
   390
	
sl@0
   391
void CTCamAppUi::HandleEvent1(const TECAMEvent& aEvent)
sl@0
   392
	{
sl@0
   393
	TBuf<KMaxErrLength> msgBuffer;
sl@0
   394
	
sl@0
   395
	switch(aEvent.iEventType.iUid)
sl@0
   396
		{
sl@0
   397
		case KUidECamEventCameraSettingDriveModeUidValue:
sl@0
   398
			{
sl@0
   399
			if(!aEvent.iErrorCode)
sl@0
   400
				{
sl@0
   401
				TRAPD(error,CaptureImageL());	
sl@0
   402
				if(error)
sl@0
   403
					{
sl@0
   404
					_LIT(KErrMessage,"CaptureImage");
sl@0
   405
					msgBuffer.Format(KErrorFormat,error,&KErrMessage);
sl@0
   406
					iEikonEnv->InfoMsg(msgBuffer);
sl@0
   407
					}
sl@0
   408
				}
sl@0
   409
			else
sl@0
   410
				{
sl@0
   411
				_LIT(KErrMessage,"SettingDriveMode");
sl@0
   412
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   413
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   414
				}
sl@0
   415
			break;
sl@0
   416
			}
sl@0
   417
		case KUidECamEventBurstImagesUidValue:
sl@0
   418
			{
sl@0
   419
			if(aEvent.iErrorCode)
sl@0
   420
				{
sl@0
   421
				_LIT(KErrMessage,"SettingNumOfBurstImage");
sl@0
   422
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   423
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   424
				}	
sl@0
   425
			break;	
sl@0
   426
			}
sl@0
   427
		case KUidECamEventSnapshotUidValue:
sl@0
   428
			{
sl@0
   429
			if(aEvent.iErrorCode)
sl@0
   430
				{
sl@0
   431
				_LIT(KErrMessage,"SnapshotDataNotification");
sl@0
   432
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   433
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   434
				}
sl@0
   435
			else
sl@0
   436
				{
sl@0
   437
				if(iCamera->ViewFinderActive())
sl@0
   438
					{	
sl@0
   439
					iCamera->StopViewFinder();
sl@0
   440
					}
sl@0
   441
			
sl@0
   442
				TRAPD(error, SnapshotDataDisplayL());
sl@0
   443
sl@0
   444
				if(error != KErrNone)
sl@0
   445
					{
sl@0
   446
					_LIT(KErrMessage,"SnapshotDataDisplay");
sl@0
   447
					msgBuffer.Format(KErrorFormat,error,&KErrMessage);
sl@0
   448
					iEikonEnv->InfoMsg(msgBuffer);
sl@0
   449
					}
sl@0
   450
				}
sl@0
   451
			break;
sl@0
   452
			}
sl@0
   453
			
sl@0
   454
		case KUidECamPresetFactoryDefaultUidValue:
sl@0
   455
			{
sl@0
   456
			if(aEvent.iErrorCode)
sl@0
   457
				{
sl@0
   458
				_LIT(KErrMessage,"FactoryPreset");
sl@0
   459
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   460
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   461
				}
sl@0
   462
			break;
sl@0
   463
			}
sl@0
   464
			
sl@0
   465
		case KUidECamPresetOutdoorUidValue:
sl@0
   466
			{
sl@0
   467
			if(aEvent.iErrorCode)
sl@0
   468
				{
sl@0
   469
				_LIT(KErrMessage,"OutdoorPreset");
sl@0
   470
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   471
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   472
				}
sl@0
   473
			break;
sl@0
   474
			}
sl@0
   475
			
sl@0
   476
		case KUidECamPresetOutdoorSportUidValue:
sl@0
   477
			{
sl@0
   478
			if(aEvent.iErrorCode)
sl@0
   479
				{
sl@0
   480
				_LIT(KErrMessage,"OutdoorSportPreset");
sl@0
   481
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   482
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   483
				}
sl@0
   484
			break;
sl@0
   485
			}
sl@0
   486
			
sl@0
   487
		case KUidECamPresetFogUidValue:
sl@0
   488
			{
sl@0
   489
			if(aEvent.iErrorCode)
sl@0
   490
				{
sl@0
   491
				_LIT(KErrMessage,"FogPreset");
sl@0
   492
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   493
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   494
				}
sl@0
   495
			break;
sl@0
   496
			}
sl@0
   497
			
sl@0
   498
		case KUidECamPresetNightPartyIndoorUidValue:
sl@0
   499
			{
sl@0
   500
			if(aEvent.iErrorCode)
sl@0
   501
				{
sl@0
   502
				_LIT(KErrMessage,"NightPartyIndoorPreset");
sl@0
   503
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   504
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   505
				}
sl@0
   506
			break;
sl@0
   507
			}
sl@0
   508
			
sl@0
   509
		case KUidECamPresetTextDocumentUidValue:
sl@0
   510
			{
sl@0
   511
			if(aEvent.iErrorCode)
sl@0
   512
				{
sl@0
   513
				_LIT(KErrMessage,"TextDocumentPreset");
sl@0
   514
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   515
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   516
				}
sl@0
   517
			break;
sl@0
   518
			}
sl@0
   519
		
sl@0
   520
		case KUidECamEventImageProcessingAdjustBrightnessUidValue:
sl@0
   521
			{
sl@0
   522
			if(aEvent.iErrorCode)
sl@0
   523
				{
sl@0
   524
				_LIT(KErrMessage,"ImageProcessingAdjustBrightness");
sl@0
   525
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   526
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   527
				}
sl@0
   528
			break;
sl@0
   529
			}
sl@0
   530
			
sl@0
   531
		case KUidECamEventImageProcessingAdjustContrastUidValue:
sl@0
   532
			{
sl@0
   533
			if(aEvent.iErrorCode)
sl@0
   534
				{
sl@0
   535
				_LIT(KErrMessage,"ImageProcessingAdjustContrast");
sl@0
   536
				msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
sl@0
   537
				iEikonEnv->InfoMsg(msgBuffer);
sl@0
   538
				}
sl@0
   539
			break;
sl@0
   540
			}
sl@0
   541
					
sl@0
   542
		default:
sl@0
   543
			break;
sl@0
   544
		}
sl@0
   545
	}
sl@0
   546
	
sl@0
   547
void CTCamAppUi::ViewFinderReady(MCameraBuffer& /*aCameraBuffer*/,TInt /*aError*/)
sl@0
   548
	{
sl@0
   549
	
sl@0
   550
	}
sl@0
   551
	
sl@0
   552
void CTCamAppUi::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
sl@0
   553
	{
sl@0
   554
	TBuf<KMaxErrLength> msgBuffer;
sl@0
   555
	_LIT(KErrMessage,"CTCamAppUi::ImageBufferReady");
sl@0
   556
	if(aError)
sl@0
   557
		{
sl@0
   558
		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
sl@0
   559
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   560
		return;
sl@0
   561
		}
sl@0
   562
	if(!iCameraSnapshot->IsSnapshotActive())
sl@0
   563
		{
sl@0
   564
		if (iCamera->ViewFinderActive())
sl@0
   565
			{	
sl@0
   566
			iCamera->StopViewFinder();
sl@0
   567
			}
sl@0
   568
		TRAP(aError,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));		
sl@0
   569
		}
sl@0
   570
sl@0
   571
	aCameraBuffer.Release();
sl@0
   572
	
sl@0
   573
	if (aError)
sl@0
   574
		{
sl@0
   575
		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
sl@0
   576
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   577
		}
sl@0
   578
		
sl@0
   579
	}
sl@0
   580
	
sl@0
   581
void CTCamAppUi::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
sl@0
   582
	{
sl@0
   583
	TBuf<KMaxErrLength> msgBuffer;
sl@0
   584
	_LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
sl@0
   585
	if (aError)
sl@0
   586
		{
sl@0
   587
		msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
sl@0
   588
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   589
		return;
sl@0
   590
		}
sl@0
   591
	TRAPD(error,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
sl@0
   592
	aCameraBuffer.Release();
sl@0
   593
	if (error)
sl@0
   594
		{
sl@0
   595
		msgBuffer.Format(KErrorFormat,error,&KErrMessage);
sl@0
   596
		iEikonEnv->InfoMsg(msgBuffer);
sl@0
   597
		}		
sl@0
   598
	}
sl@0
   599
	
sl@0
   600
void CTCamAppUi::SnapshotDataDisplayL()
sl@0
   601
	{
sl@0
   602
	RArray<TInt> array;
sl@0
   603
	array.Reset();
sl@0
   604
	RTestCameraFrameBuffer& buffer = static_cast<RTestCameraFrameBuffer&>(iCameraSnapshot->SnapshotDataL(array));
sl@0
   605
	iAppView->DrawImage(&buffer.BitmapL(0));
sl@0
   606
	array.Close();
sl@0
   607
	buffer.Release();
sl@0
   608
	}	
sl@0
   609
sl@0
   610
void CTCamAppUi::CreateDependencyFileL()
sl@0
   611
	{
sl@0
   612
	// enforce dependency
sl@0
   613
	// create the file the plugin depends on.
sl@0
   614
	User::LeaveIfError(ifsSession.Connect());
sl@0
   615
	RFile file;
sl@0
   616
	TInt err = file.Replace(ifsSession, KTestCameraPluginName, EFileShareAny);
sl@0
   617
  	file.Close();
sl@0
   618
  	if(err != KErrNone)
sl@0
   619
  		{
sl@0
   620
	    User::LeaveIfError(KErrNotSupported);
sl@0
   621
  		}
sl@0
   622
	}
sl@0
   623
	
sl@0
   624
void CTCamAppUi::RemoveDependencyFile()
sl@0
   625
	{
sl@0
   626
	ifsSession.Delete(KTestCameraPluginName);
sl@0
   627
	ifsSession.Close();
sl@0
   628
	}
sl@0
   629
sl@0
   630
//
sl@0
   631
// CTCamAppView
sl@0
   632
//
sl@0
   633
sl@0
   634
CTCamAppView::CTCamAppView():
sl@0
   635
	CCoeControl()
sl@0
   636
	{
sl@0
   637
	}
sl@0
   638
sl@0
   639
void CTCamAppView::ConstructL(const TRect& /*aRect*/)
sl@0
   640
	{
sl@0
   641
	CreateWindowL();
sl@0
   642
	EnableDragEvents();
sl@0
   643
	SetExtentToWholeScreen();
sl@0
   644
	ActivateL();
sl@0
   645
	}
sl@0
   646
sl@0
   647
CTCamAppView::~CTCamAppView()
sl@0
   648
	{
sl@0
   649
	}
sl@0
   650
sl@0
   651
void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
sl@0
   652
	{
sl@0
   653
	CWindowGc& gc = SystemGc();
sl@0
   654
	gc.Activate(Window());
sl@0
   655
	TRect drawRect=Rect();
sl@0
   656
	TPoint pos;
sl@0
   657
	pos.iX = (3 * drawRect.iBr.iX / 4) - (aImage->SizeInPixels().iWidth / 2);
sl@0
   658
	pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iWidth) / 2;
sl@0
   659
	gc.BitBlt(pos,aImage);
sl@0
   660
	TRect border(pos,aImage->SizeInPixels());
sl@0
   661
	border.Grow(1,1);
sl@0
   662
	gc.DrawRect(border);
sl@0
   663
	gc.Deactivate();
sl@0
   664
	iCoeEnv->WsSession().Flush();
sl@0
   665
	}
sl@0
   666
sl@0
   667
void CTCamAppView::Draw(const TRect& /*aRect*/) const
sl@0
   668
	{
sl@0
   669
	CWindowGc& gc = SystemGc();
sl@0
   670
	TRect drawRect(Rect());
sl@0
   671
	drawRect.Shrink(1,1);
sl@0
   672
	gc.DrawRect(drawRect);
sl@0
   673
	gc.Clear();
sl@0
   674
	}
sl@0
   675
sl@0
   676
TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
sl@0
   677
	{
sl@0
   678
	CWindowGc& gc = SystemGc();
sl@0
   679
	gc.Activate(Window());
sl@0
   680
	TRect drawRect(Rect());
sl@0
   681
	TPoint pos;
sl@0
   682
	pos.iX = (drawRect.iBr.iX / 4) - (aSize.iWidth / 2);
sl@0
   683
	pos.iY = (drawRect.iBr.iY - aSize.iWidth) / 2;
sl@0
   684
	TRect border(pos,aSize);
sl@0
   685
	border.Grow(1,1);
sl@0
   686
	gc.SetPenColor(KRgbBlack);
sl@0
   687
	gc.DrawRect(border);
sl@0
   688
	gc.Deactivate();
sl@0
   689
	iCoeEnv->WsSession().Flush();
sl@0
   690
	return pos;
sl@0
   691
	}
sl@0
   692
sl@0
   693
//
sl@0
   694
// CTCamDocument
sl@0
   695
//
sl@0
   696
sl@0
   697
CTCamDocument::CTCamDocument(CEikApplication& aApp)
sl@0
   698
		: CEikDocument(aApp)
sl@0
   699
	{
sl@0
   700
	}
sl@0
   701
sl@0
   702
CEikAppUi* CTCamDocument::CreateAppUiL()
sl@0
   703
	{
sl@0
   704
    return new(ELeave) CTCamAppUi;
sl@0
   705
	}
sl@0
   706
sl@0
   707
//
sl@0
   708
// CTCamApp
sl@0
   709
//
sl@0
   710
sl@0
   711
TUid CTCamApp::AppDllUid() const
sl@0
   712
	{
sl@0
   713
	return KUidTestCameraApp;
sl@0
   714
	}
sl@0
   715
sl@0
   716
CApaDocument* CTCamApp::CreateDocumentL()
sl@0
   717
	{
sl@0
   718
	return new(ELeave) CTCamDocument(*this);
sl@0
   719
	}
sl@0
   720
sl@0
   721
sl@0
   722
sl@0
   723
//
sl@0
   724
// Base factory function
sl@0
   725
//
sl@0
   726
sl@0
   727
#include <eikstart.h>
sl@0
   728
LOCAL_C CApaApplication* NewApplication()
sl@0
   729
	{
sl@0
   730
	return new CTCamApp;
sl@0
   731
	}
sl@0
   732
sl@0
   733
//
sl@0
   734
// EXE Entry point
sl@0
   735
//
sl@0
   736
sl@0
   737
GLDEF_C TInt E32Main()
sl@0
   738
	{
sl@0
   739
	return EikStart::RunApplication(NewApplication);
sl@0
   740
	}
sl@0
   741
sl@0
   742
sl@0
   743
sl@0
   744