PrjName = 'swCameraSnapshot' UID = '0x02222225' resource.caption = ['swCamera Snapshot', 'CamSnap'] #resource.model = '7610' prep_menu = [] for colordepth in ['4K', '64K', '16M']: for res in [(1152,864), (640,480), (320,240), (160,120)]: text = '%s_%dx%d' % (colordepth, res[0], res[1]) args = 'CCamera::EFormatFbsBitmapColor%s, %d, %d, NULL, ETrue' % (colordepth, res[0], res[1]) prep_menu.append( [text, """\ SearchImageFormatIndex( %s ); PrepareCaptureImage();""" % args ] ) cmd_capture = """\ iAppView->SetBitmap( NULL ); TRAPD( err, iCamera->CaptureImage() ); ErrorNotifyL( _L("Image Capture err: "), err, EFalse);""" resource.menu = [ ['Control', [['Reserve', ' iCamera->Reserve();' ], ['Release', ' iCamera->Release();\niReserved = FALSE;' ], ['Power On', ' iCamera->PowerOn();' ], ['Power Off', ' iCamera->PowerOff();\niPowerOn = FALSE;' ], ]], ['View Finder', [['Start', ' StartViewFinder();' ], ['Stop', ' StopViewFinder();' ], ]], ['Still Image', [['Prepare Capture', prep_menu ], ['Capture', cmd_capture ], ['Save', ' SaveCapturedImageL();' ], ]], ['Media Gallery', ' LaunchMediaGallery();' ], ] resource.libraries += [ 'fbscli', 'efsrv', 'platformenv', 'ws32' ] appui.intro_src = """\ // Default still image capture format and size, color 16M type and 1152x864 pixels. const CCamera::TFormat KCameraSnapShotDefaultImageFormat = CCamera::EFormatFbsBitmapColor16M; const TInt KMaxImageNames = 100; // After this limits file naming start again from 0. _LIT(KImagesSaveName, "CptImg"); _LIT(KImagesSearchName, "CptImg??"); _LIT(KBmpFileExtension, ".mbm"); """ appui.inc_src += [ '' ] appui.use_camera() appui.members['ConstructL'].code += """ SearchImageFormatIndex( CCamera::EFormatFbsBitmapColor16M, 160, 120, NULL, ETrue ); // Ask the image root path from the environment iImagePath.Append(PathInfo::PhoneMemoryRootPath()); iImagePath.Append(PathInfo::ImagesPath()); iReserved = FALSE; iPowerOn = FALSE;""" appui.add_private( Method( 'TDesC16&', ('GetNextFileName', r"""Search for the next captured image BMP file name using the mask drive:\directory\file??.bmp."""), [Arg('TDes16&', 'aName'), Arg('TDesC16&', 'aSearchName')], """\ TParse fs; fs.Set((TDesC&)aSearchName, NULL, NULL); TFindFile fileFinder( CEikonEnv::Static()->FsSession() ); TBuf<100> scanDir = fs.DriveAndPath(); CDir* fileList; TInt fileCount = 0; TInt err = fileFinder.FindWildByDir( aSearchName, scanDir, fileList ); if (err==KErrNone) { fileCount = fileList->Count(); delete fileList; } if ((fileCount < 0) || (fileCount > (KMaxImageNames - 1))) { fileCount = 0; } aName.Format(_L("%S%S%02d%S"), &scanDir, (TDesC*)&KImagesSaveName, fileCount, (TDesC*)&KBmpFileExtension); return ((TDesC16&) aName);""" ) ) appui.add_private( Method( 'void', ('SaveCapturedImageL', 'Saves captured image to a BMP file.'), [], r""" CFbsBitmap* bitMap = iAppView->GetBitmap(); if ( !bitMap ) { ErrorNotifyL(_L("Capture Image not ready: "), KErrNotFound, ETrue); return; } TFileName* imageName = new(ELeave) TFileName; CleanupStack::PushL(imageName); TFileName* searchName = new(ELeave) TFileName; searchName->Format(_L("%S%S%S"), (TDesC*)&iImagePath, (TDesC*)&KImagesSearchName, (TDesC*)&KBmpFileExtension); GetNextFileName( (TDes16&)*imageName, (TDesC16&)*searchName ); delete( searchName ); TRAPD(err,bitMap->Save((TDesC&)*imageName)); if (err) // A some system-wide error codes. { ErrorNotifyL(_L("Image save err: "), err, EFalse); } else { TInt pos = imageName->LocateReverse('\\'); TBufC<15> name( imageName->Right(imageName->Length() - (pos + 1)) ); TBuf<50> buf; buf.Format(_L("Image %S saved successful."), &name); InfoNotifyL( buf ); } CleanupStack::PopAndDestroy(imageName);""" ) ) appui.members['StopViewFinder'].code += """ // Capture default image PrepareCaptureImage(); TRAP(err, iCamera->CaptureImage()); ErrorNotifyL(_L("Image capture err: "), err, EFalse);""" appui.add_private( Method( 'void', ('PrepareCaptureImage', 'Prepare for a still image capture.'), [], """\ iAppView->SetBitmap(NULL); // Reset captured image TRAPD(err, iCamera->PrepareImageCaptureL(iImageFormat, iImageIndex)); ErrorNotifyL(_L("Prepare capture err: "), err, EFalse);""" ) ) appui.members['ReserveComplete'].code += '\n iReserved = TRUE;' appui.members['PowerOnComplete'].code += '\n iPowerOn = TRUE;' appui.members['ImageReady'].code += """ if (aData) { ErrorNotifyL(_L("Image capture err: aData not NULL"), 0, ETrue); } iCamera->StopViewFinder(); if (aBitmap) { iAppView->SetBitmap(aBitmap); iAppView->DrawImage(aBitmap); }""" appui.add_private( Method( 'void', 'SetImageFormat', [Arg('CCamera::TFormat', 'aImageFormat')], 'iImageFormat = aImageFormat;' ) ) appui.add_private( Method( 'CCamera::TFormat', ('GetImageFormat', ''), [], 'return iImageFormat;' ) ) appui.add_private( Method( 'void', ('SetImageIndex', ''), [Arg('TInt', 'aImageIndex')], 'iImageIndex = aImageIndex;') ) appui.add_private( Method( 'TInt', ('GetImageIndex', ''), [], 'return iImageIndex;' ) ) appui.add_private( Method( 'TInt', ('SearchImageFormatIndex', 'Search the still image index for given format and resolution.'), [Arg('CCamera::TFormat','aFormat'), Arg('TInt','aWidth'), Arg('TInt','aHeight'), Arg('TInt*','aIndex'), Arg('TBool','aSetValues')], """\ TCameraInfo info; iCamera->CameraInfo(info); TSize size(0, 0); // Checks all supported image sizes. for (TInt i = 0; i < info.iNumImageSizesSupported; i++) { iCamera->EnumerateCaptureSizes(size, i, aFormat); if ((size.iWidth == aWidth) && (size.iHeight == aHeight)) { if (aIndex != NULL) { *aIndex = i; } if (aSetValues) { SetImageFormat (aFormat); SetImageIndex (i); } return KErrNone; } } return KErrNotFound;""" ) ) appui.add_private( Method( 'void', ('LaunchMediaGallery', ''), [], """\ // Gets viewId to Activate media Gallery view MG ID and MG view ID TVwsViewId id = TVwsViewId( TUid::Uid(0x101F4D8F), TUid::Uid(0x00000001) ); // TParsePtrC parse(KImagesSavePath); TParsePtrC parse(iImagePath); TFileName rootPath( parse.DriveAndPath() ); //Pass the 16-bit filename around in an 8-bit descriptor TPtrC8 ptr8( ( TText8* )rootPath.Ptr(), rootPath.Size() ); // Media Gallery moves focus to the root path. ActivateViewL( id, TUid::Uid( 0x00000001 ), ptr8 );""" ) ) appui.add_private( Var( 'TBuf<50>', 'iImagePath' ) ) appui.add_private( Var( 'CCamera::TFormat', 'iImageFormat' ) ) appui.add_private( Var( 'TInt', 'iImageIndex' ) ) appui.add_private( Var( 'TBool', 'iReserved' ) ) appui.add_private( Var( 'TBool', 'iPowerOn' ) ) appview.add_public( Method( 'void', ('SetBitmap', 'Set new value for iBitmap. Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda'), [Arg('CFbsBitmap*', 'aBitmap', 'The new bitmap. Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda')], """\ if (iBitmap) { delete (iBitmap); iBitmap = NULL; } if (aBitmap) { iBitmap = aBitmap; }""" ) ) #appview.add_public( Method( ('CFbsBitmap*', 'A pointer to the current bitmap'), ('GetBitmap', 'Return the current bitmap'), [], 'return iBitmap;' ) ) /*! @function GetBitmap @discussion @result */ CFbsBitmap* GetBitmap( void ); appview.add_public( Method( 'CFbsBitmap*', 'GetBitmap', [], 'return iBitmap;' ) ) appview.members['Draw'].code += """ // Draw the captured still image bitmap on the display if (iBitmap) { gc.DrawBitmap( rect, iBitmap ); }""" appview.add_private( Var( 'CFbsBitmap*', 'iBitmap', 'The current image' ), destroy_var = True )