void CTSpriteAnim::DrawL(TInt aOpcode) { CFbsBitmap *bitmap=iSpriteFunctions->GetSpriteMember(0)->iBitmap; CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(bitmap); CleanupStack::PushL(device); CFbsBitGc *gc; User::LeaveIfError(device->CreateContext(gc)); CleanupStack::PushL(gc); gc->SetBrushStyle(CGraphicsContext::ESolidBrush); gc->SetPenSize(TSize()); TSize bitmapSize=bitmap->SizeInPixels(); TSize size= bitmapSize; size.SetSize(size.iWidth/2,size.iHeight/2); TPoint point=size.AsPoint(); // according to the opcode used, a quarter of the sprite bitmap is drawn to a different colour switch(aOpcode) { case EADllDraw1: { gc->SetBrushColor(TRgb(255,0,0)); gc->DrawRect(TRect(TPoint(),size)); break; } case EADllDraw2: { gc->SetBrushColor(TRgb(0,255,0)); gc->DrawRect(TRect(TPoint(point.iX,0),size)); break; } case EADllDraw3: { gc->SetBrushColor(TRgb(0,0,255)); gc->DrawRect(TRect(TPoint(0,point.iY),size)); break; } case EADllDrawBlank: {//the whole sprite bitmap is set to blank gc->SetBrushColor(TRgb(255,255,255)); gc->DrawRect(TRect(TPoint(),bitmapSize)); break; } default:; } iSpriteFunctions->UpdateMember(0,TRect(bitmap->SizeInPixels()),ETrue); CleanupStack::PopAndDestroy(2); //gc and device }
/** Create a checked board @param aPixelFormat The pixel format for create the target bitmap @param aSize The size of the bitmap @param aChecksPerAxis Number of checks on X and Y. */ CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::CreateCheckedBoardL(TDisplayMode aDisplayMode, TSize aSize, TSize aChecksPerAxis) const { CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; CleanupStack::PushL(bitmap); bitmap->Create(aSize, aDisplayMode); CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); CleanupStack::PushL(bitmapDevice); CFbsBitGc* bitGc = NULL; User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); CleanupStack::PushL(bitGc); bitGc->Clear(); bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); bitGc->SetPenStyle(CGraphicsContext::ENullPen); TPoint point(0,0); const TSize checkerSize((TReal)aSize.iWidth/aChecksPerAxis.iWidth,(TReal)aSize.iHeight/aChecksPerAxis.iHeight); TInt brushColour = 0; for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight) { for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth) { bitGc->SetBrushColor(KColor16Table[brushColour++ & 0x0F]); TRect rect(point, checkerSize); bitGc->DrawRect(rect); } } CleanupStack::PopAndDestroy(2, bitmapDevice); CleanupStack::Pop(bitmap); return bitmap; }
/** Copy a bitmap into another bitmap (generally in a different displaymode) tiles destination bitmap with source */ void CTe_graphicsperformanceSuiteStepBase::CopyBitmapL(CFbsBitmap* aDst, CFbsBitmap* aSrc) { TSize srcSize = aSrc->SizeInPixels(); TSize dstSize = aDst->SizeInPixels(); CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(aDst); CleanupStack::PushL(dev); CFbsBitGc* gc = NULL; if ( 0 == dev->CreateContext(gc) ) { CleanupStack::PushL(gc); TPoint point; gc->SetBrushColor(TRANSPARENT_BLACK); gc->SetBrushStyle(CGraphicsContext::ENullBrush); gc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); gc->Clear(); gc->SetDrawMode(CGraphicsContext::EDrawModePEN); for(point.iY=0; point.iY<dstSize.iHeight; point.iY+=srcSize.iHeight) { for(point.iX=0; point.iX<dstSize.iWidth; point.iX+=srcSize.iWidth) { gc->BitBlt(point, aSrc); } } CleanupStack::PopAndDestroy(gc); } CleanupStack::PopAndDestroy(dev); }
/** Draws a stretched bitmap with or without a mask. @param aUseMask set to ETrue to use a alpha mask. Normally used for 16MU display modes that do not store the alpha. @param aSrcMode is the source display mode @param aDstMode is the destination display mode @param aSession is the windows server session @param aWindow is a reference to the window @param aGc is the graphics context of the window @param aNumIterations is the number of iterations to run the test */ void CAlphaBlendTest::DoDrawBitmapL(TBool aUseMask, TDisplayMode aSrcMode, TDisplayMode aDstMode, RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc, TInt aNumIterations) { const TSize bitmapSize = aWindow.Size(); // Construct target bitmap. CFbsBitmap* bitmapTarget = CreateSoftwareBitmapLC(bitmapSize, aDstMode); CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmapTarget); CleanupStack::PushL(bitmapDevice); // Construct GC. CFbsBitGc* bitmapGc = NULL; User::LeaveIfError(bitmapDevice->CreateContext(bitmapGc)); CleanupStack::PushL(bitmapGc); // Construct source bitmap. TSize smallerSize(bitmapSize.iWidth/2, bitmapSize.iHeight/2); CFbsBitmap* source = CreateSoftwareBitmapLC(smallerSize, aSrcMode); VerticalGradientAlphaL(source, TRgb(0x00000000), TRgb(0xffffffff)); CFbsBitmap* sourceAlpha = CreateSoftwareBitmapLC(smallerSize, EGray256); // match size to src VerticalGradientAlphaL(sourceAlpha, TRgb(0x01010101), TRgb(0xfefefefe)); bitmapGc->SetBrushStyle(CGraphicsContext::ENullBrush); bitmapGc->SetBrushColor(TRANSPARENT_BLACK); bitmapGc->Clear(); bitmapGc->SetDrawMode(CGraphicsContext::EDrawModePEN); aGc->Activate(aWindow); TPoint point(0,0); bitmapGc->BitBlt(point, bitmapTarget); aGc->Deactivate(); aSession.Flush(); TBuf <20> testName; if (!aUseMask) { testName=_L("DrawBitmap"); iProfiler->InitResults(); for(int i=0; i<aNumIterations; i++) { bitmapGc->DrawBitmap(TRect(point, bitmapSize), source); iProfiler->MarkResultSetL(); } } else { testName=_L("DrawBitmapMasked"); iProfiler->InitResults(); for(int i=0; i<aNumIterations; i++) { bitmapGc->DrawBitmapMasked(TRect(point, bitmapSize), source,TRect(point, smallerSize), sourceAlpha, EFalse); iProfiler->MarkResultSetL(); } } INFO_PRINTF4(_L("%S(Stretched) with src = %S, dst = %S"), &testName, &ColorModeName(aSrcMode), &ColorModeName(aDstMode)); iProfiler->ResultsAnalysis(testName, 0, aSrcMode, aDstMode, aNumIterations); // copy up to screen for sanity check BitBlt(aSession, aWindow, aGc, *bitmapTarget); CleanupStack::PopAndDestroy(5, bitmapTarget); }
/** Bitblt test @param aSrcMode is the source display mode @param aDstMode is the destination display mode @param aSession is the windows server session @param aWindow is a reference to the window @param aGc is the graphics context of the window @param aNumIterations is the number of iterations to run the test */ void CAlphaBlendTest::DoBitBltAlphaBitmapTestL(TDisplayMode aSrcMode,TDisplayMode aDstMode, RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc, TInt aNumIterations) { const TSize bitmapSize = aWindow.Size(); CFbsBitmap* bitmapTarget = CreateSoftwareBitmapLC(bitmapSize, aDstMode); CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmapTarget); CleanupStack::PushL(bitmapDevice); CFbsBitGc* bitmapGc = NULL; User::LeaveIfError(bitmapDevice->CreateContext(bitmapGc)); CleanupStack::PushL(bitmapGc); CFbsBitmap* source = CreateSoftwareBitmapLC(bitmapSize, aSrcMode); CFbsBitmap* sourceAlpha = CreateSoftwareBitmapLC(bitmapSize, EGray256); // match size to src VerticalGradientAlphaL(sourceAlpha, TRgb(0x01010101), TRgb(0xfefefefe)); VerticalGradientAlphaL(source, TRgb(0x00000000), TRgb(0xffffffff)); TPoint point(0,0); bitmapGc->SetBrushStyle(CGraphicsContext::ENullBrush); bitmapGc->SetBrushColor(TRANSPARENT_BLACK); bitmapGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); bitmapGc->Clear(); bitmapGc->SetDrawMode(CGraphicsContext::EDrawModePEN); bitmapGc->BitBlt(point, source); aGc->Activate(aWindow); aGc->BitBlt(point, bitmapTarget); aGc->Deactivate(); aSession.Flush(); iProfiler->InitResults(); for(TInt i=0; i<aNumIterations; i++) { bitmapGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); bitmapGc->Clear(); bitmapGc->SetDrawMode(CGraphicsContext::EDrawModePEN); bitmapGc->BitBlt(point, source); iProfiler->MarkResultSetL(); } iProfiler->ResultsAnalysis(_L("DoBitBltAlphaBitmapTestL"), 0, aSrcMode, aDstMode, aNumIterations); // copy up to screen for sanity check aGc->Activate(aWindow); aGc->BitBlt(TPoint(), bitmapTarget); aGc->Deactivate(); CleanupStack::PopAndDestroy(5, bitmapTarget); //sourceAlpha, source, bitmapGc, bitmapDevice, bitmapTarget }
// ============================================================================ // CIconConverter::DoProcessMaskL() // process the bitmap mask // // @since 3.1 // ============================================================================ void CIconConverter::DoProcessMaskL() { // we use white to mean transparent at this stage, simply for efficiency // since all the canvases we will copy in to begin as white if ( iOriginalBitmapMask->Handle() == 0 ) { // Create a mask that shows the whole bitmap as an icon // (all black) User::LeaveIfError( iOriginalBitmapMask->Create( iOriginalBitmap->SizeInPixels(), EGray2 ) ); CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iOriginalBitmapMask ); CleanupStack::PushL( device ); CFbsBitGc* gc; User::LeaveIfError( device->CreateContext( gc ) ); gc->SetBrushStyle( CGraphicsContext::ESolidBrush ); gc->SetDrawMode( CGraphicsContext::EDrawModePEN ); gc->SetBrushColor( KRgbBlack ); // Create a big black image gc->Clear(); delete gc; CleanupStack::PopAndDestroy( device ); } else { // Invert the mask obtained from the PNG CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( iOriginalBitmapMask ); CleanupStack::PushL(device); CFbsBitGc* gc; User::LeaveIfError( device->CreateContext( gc ) ); gc->SetDrawMode( CGraphicsContext::EDrawModeNOTSCREEN ); gc->Clear(); delete gc; CleanupStack::PopAndDestroy( device ); } // Scale the icon to the sizes required iCurrentSizeIndex = 0; DoIconScalingL(); }
// --------------------------------------------------------------------------- // CMMACameraWindow::DrawViewFinderError() // Draws the error message to specified area. // Used in cases when viewfinder is unable to start. // --------------------------------------------------------------------------- // void CMMACameraWindow::DrawViewFinderErrorL( const TInt /*aError*/, const TRect& aDrawRect) { ASSERT(iDirectAccess); TInt dcError = KErrNone; if (!iDirectAccess->IsActive()) { TRAP(dcError, iDirectAccess->StartL()); } TRect drawRect(aDrawRect); if (dcError == KErrNone) { drawRect.Intersection(iClientRect); drawRect.Move(-iWindow->AbsPosition()); CFbsBitGc* directGc = iDirectAccess->Gc(); directGc->SetClippingRect(drawRect); directGc->SetBrushColor(TRgb(128,128,128)); directGc->SetPenColor(TRgb(128,0,0)); directGc->SetBrushStyle(CGraphicsContext::ESolidBrush); directGc->SetPenStyle(CGraphicsContext::ESolidPen); directGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); directGc->DrawRect(drawRect); if (!iErrorIconBitmap || !iErrorIconMaskBitmap) { if (iErrorIconBitmap) { delete iErrorIconBitmap; iErrorIconBitmap = NULL; } if (iErrorIconMaskBitmap) { delete iErrorIconMaskBitmap; iErrorIconMaskBitmap = NULL; } /* AknsUtils::CreateIconL( AknsUtils::SkinInstance(), KAknsIIDQgnIndiCam4Camera, iErrorIconBitmap, iErrorIconMaskBitmap, KCameraAppBitmapFile, EMbmCameraappQgn_indi_cam4_camera, EMbmCameraappQgn_indi_cam4_camera_mask ); */ } //TRect iconRect drawRect.iTl.iX += KErrorIconMargin; drawRect.iTl.iY += KErrorIconMargin; drawRect.iBr.iX -= KErrorIconMargin; drawRect.iBr.iY -= KErrorIconMargin; if (iErrorIconBitmap->SizeInPixels() != drawRect.Size()) { AknIconUtils::SetSize(iErrorIconBitmap, drawRect.Size()); AknIconUtils::SetSize(iErrorIconMaskBitmap, drawRect.Size()); } directGc->BitBltMasked( drawRect.iTl, iErrorIconBitmap, TRect(iErrorIconBitmap->SizeInPixels()), iErrorIconMaskBitmap, EFalse); iDirectAccess->ScreenDevice()->Update(); } }
TBool CHuiRasterizedTextMesh::RasterizePictographLineL(const TDesC& aTextLine, CFont* aFont, SRasterizedLine & aLineOut) { if(iUsingPreRasterizedMesh) { return EFalse; } // Retrieve the used text style. THuiTextStyle* textStyle = CHuiStatic::Env().TextStyleManager().TextStyle(iTextStyleId); // Calculate line extents and assign it to texture size. TSize textureSize = textStyle->LineExtentsL(aTextLine); if(textureSize.iWidth == 0 || !iPictographInterface || !iPictographInterface->Interface()->ContainsPictographs(aTextLine)) { // This is an empty string or it does not contain pictographs. We will not rasterize it. // Just add a gap. aLineOut.iTexture = NULL; aLineOut.iGap = textureSize.iHeight; return !IsMaxLineCountReached(); } // store the actual size to be assigned as the textures logical size TSize actualsize(textureSize); if (aLineOut.iTexture == NULL) { // Create a texture for storing the pictographs into. aLineOut.iTexture = CHuiTexture::NewL(); HUI_DEBUG1(_L("CHuiRasterizedTextMesh::RasterizePictographLineL() - Registering self (0x%x) as a texture content observer."), this); // Register one content observer for the first texture that // is able to restore all lines in a single run if (iLines.Count()==1) { aLineOut.iTexture->iContentObservers.AppendL(*this); } aLineOut.iGap = 0; } // set a name for the texture // @todo is this needed, what names to use aLineOut.iTexture->SetImageFileNameL(_L("Pictographs")); TSize maxTextureSize = aLineOut.iTexture->MaxTextureSize(); textureSize.iWidth = Min(textureSize.iWidth, maxTextureSize.iWidth); textureSize.iHeight = Min(textureSize.iHeight, maxTextureSize.iHeight); if((textureSize.iWidth == 0) || (textureSize.iHeight == 0)) { // Cannot draw into this tiny texture, so leave. HUI_DEBUG2(_L("CHuiRasterizedTextMesh::RasterizePictographLineL() - texture size was too small to draw into (%i, %i)."), textureSize.iWidth, textureSize.iHeight); User::Leave(KErrAbort); } User::LeaveIfError( iPictographBitmap->Resize(textureSize) ); CFbsBitmapDevice* device = CFbsBitmapDevice::NewL(iPictographBitmap); CleanupStack::PushL(device); CFbsBitGc* gc = 0; User::LeaveIfError( device->CreateContext(gc) ); CleanupStack::PushL(gc); // Prepare the bitmap for drawing...set drawmode because of EColor16MA mode... gc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); TRgb color = KRgbWhite; color.SetAlpha(0x00); gc->SetBrushColor(color); gc->Clear(); gc->UseFont(aFont); // Draw pictorgraphs iPictographInterface->Interface()->DrawPictographsInText( *gc, *aFont, aTextLine, TPoint(0, aFont->FontMaxAscent())); CleanupStack::PopAndDestroy(gc); CleanupStack::PopAndDestroy(device); aLineOut.iTexture->UploadL(*iPictographBitmap, NULL, EHuiTextureUploadFlagRetainResolution); aLineOut.iTexture->SetSize(actualsize); return !IsMaxLineCountReached(); }
EXPORT_C void AknsUtils::CreateColorIconLC( MAknsSkinInstance* aInstance, const TAknsItemID& aID, const TAknsItemID& aColorID, const TInt aColorIndex, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask, const TDesC& aFilename, const TInt aFileBitmapId, const TInt aFileMaskId, const TRgb aDefaultColor, const TSize& aSize, const TScaleMode aScaleMode ) { CFbsBitmap* bitmap = NULL; CFbsBitmap* mask = NULL; CreateIconLC( aInstance, aID, bitmap, mask, aFilename, aFileBitmapId, aFileMaskId ); // (2) TRgb color = aDefaultColor; // Return value intentionally ignored GetCachedColor( aInstance, color, aColorID, aColorIndex ); if( AknIconUtils::IsMifIcon( bitmap ) ) { AknIconUtils::SetIconColor( bitmap, color ); aBitmap = bitmap; aMask = mask; } else // Create Own Icon { CFbsBitmap* colorBitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL( colorBitmap ); // (3) TSize size = mask->SizeInPixels(); User::LeaveIfError( colorBitmap->Create( size, CEikonEnv::Static()->ScreenDevice()->DisplayMode() ) ); CFbsBitmapDevice* colorBmpDev = CFbsBitmapDevice::NewL( colorBitmap ); CleanupStack::PushL( colorBmpDev ); // (4) User::LeaveIfError( colorBmpDev->Resize( size ) ); CFbsBitGc* colorBmpGc = CFbsBitGc::NewL(); CleanupStack::PushL( colorBmpGc ); // (5) colorBmpGc->Activate( colorBmpDev ); colorBmpGc->SetBrushColor( color ); colorBmpGc->SetPenStyle( CGraphicsContext::ENullPen ); colorBmpGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); colorBmpGc->DrawRect( TRect( TPoint(0,0), size ) ); CleanupStack::PopAndDestroy( 2 ); // colorBmpGc, colorBmpDev (3) CleanupStack::Pop( 3 ); // colorBmp, bitmap, mask (0) delete bitmap; // We don't know the order, must destroy manually aBitmap = colorBitmap; aMask = mask; // These are both safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) } if( aSize.iWidth>=0 ) { // Set the size User::LeaveIfError( AknIconUtils::SetSize( aBitmap, aSize, aScaleMode ) ); } }