static void DrawIconL(CWindowGc& aGc, CGulIcon& aIcon, const TJuikLayoutItem& aL, TBool aDoCenter=ETrue) 
{
	CALLSTACKITEMSTATIC_N(_CL(""), _CL("DrawIconL"));
	CFbsBitmap* bmp = aIcon.Bitmap();
	CFbsBitmap* mask = aIcon.Mask();
	
	aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
	// center 
	TInt bmpW = bmp->SizeInPixels().iWidth;
	TInt areaW = aL.Size().iWidth;
	
	TInt dx = 0;
	TInt dy = 0;
	if ( aDoCenter && bmpW < areaW )
		{
			dx = (areaW - bmpW) / 2;
		}


	TPoint tl = aL.TopLeft();
	tl += TPoint(dx,dy);
	TRect r(TPoint(0,0), bmp->SizeInPixels());
 	if ( mask )
 		{
 			aGc.BitBltMasked( tl, bmp, r, mask, ETrue);
 		}
 	else
 		{
			aGc.BitBlt( tl, bmp, r);
  		}
}
void AConvolute64KBlurGauss( CFbsBitmap& aTarget,
                             const CFbsBitmap& aSource,
                             const TInt aBlendFactor )
    {
    TInt width  = aTarget.SizeInPixels().iWidth;
    TInt height = aTarget.SizeInPixels().iHeight;

    // CFbsBitmap::ScanLineLength returns bytes 
    TInt targetScanW  = CFbsBitmap::ScanLineLength(
                                aTarget.SizeInPixels().iWidth,
                                aTarget.DisplayMode());
    TInt sourceScanW  = CFbsBitmap::ScanLineLength(
                                aSource.SizeInPixels().iWidth,
                                aSource.DisplayMode());

    TInt combinedScanW = (targetScanW << 16) + sourceScanW;

    // Prepare the data addresses
    aTarget.LockHeap( ETrue ); // Lock the global bitmap heap
    TUint* targetAddr = reinterpret_cast<TUint*>( aTarget.DataAddress() );
    TUint* sourceAddr = reinterpret_cast<TUint*>( aSource.DataAddress() );

    ADoConvolute64KBlurGauss(targetAddr, sourceAddr, combinedScanW, width, height, aBlendFactor);

    aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap
    }
TBool CWsGceCscBase::Compare(CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2)
	{
	if ((aBitmap1.SizeInPixels() == aBitmap2.SizeInPixels()) &&
		(aBitmap1.DisplayMode() == aBitmap2.DisplayMode()))
		{
		TSize size = aBitmap1.SizeInPixels();
		TInt width = size.iWidth;
		TInt height = size.iHeight;
		TRgb color1, color2;
		
		for (TInt i = 0; i < width; i++)
			{
			for (TInt j = 0; j < height; j++)
				{
				aBitmap1.GetPixel(color1, TPoint(i, j));
				aBitmap2.GetPixel(color2, TPoint(i, j));
				if (color1 != color2)
					{
					return EFalse;
					}
				}
			}
		
		return ETrue;
		}
	return EFalse;
	}
void QGLPixmapData::fromNativeType(void* pixmap, NativeType type)
{
    if (type == QPixmapData::SgImage && pixmap) {
#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL)
        RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap);

        m_sgImage = new RSgImage;
        m_sgImage->Open(sgImage->Id());

        TSgImageInfo info;
        sgImage->GetInfo(info);

        w = info.iSizeInPixels.iWidth;
        h = info.iSizeInPixels.iHeight;
        d = symbianPixeFormatBitsPerPixel((TUidPixelFormat)info.iPixelFormat);

        m_source = QVolatileImage();
        m_hasAlpha = true;
        m_hasFillColor = false;
        m_dirty = true;
        is_null = (w <= 0 || h <= 0);
#endif
    } else if (type == QPixmapData::FbsBitmap && pixmap) {
        CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap);
        QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight);
        if (size.width() == w && size.height() == h)
            setSerialNumber(++qt_gl_pixmap_serial);
        resize(size.width(), size.height());
        m_source = QVolatileImage(bitmap);
        if (pixelType() == BitmapType) {
            m_source.ensureFormat(QImage::Format_MonoLSB);
        } else if (!knownGoodFormat(m_source.format())) {
            m_source.beginDataAccess();
            QImage::Format format = idealFormat(m_source.imageRef(), Qt::AutoColor);
            m_source.endDataAccess(true);
            m_source.ensureFormat(format);
        }
        m_hasAlpha = m_source.hasAlphaChannel();
        m_hasFillColor = false;
        m_dirty = true;
        d = m_source.depth();
    } else if (type == QPixmapData::VolatileImage && pixmap) {
        // Support QS60Style in more efficient skin graphics retrieval.
        QVolatileImage *img = static_cast<QVolatileImage *>(pixmap);
        if (img->width() == w && img->height() == h)
            setSerialNumber(++qt_gl_pixmap_serial);
        resize(img->width(), img->height());
        m_source = *img;
        m_hasAlpha = m_source.hasAlphaChannel();
        m_hasFillColor = false;
        m_dirty = true;
        d = m_source.depth();
    } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) {
        destroyTexture();
        nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap);
        // Cannot defer the retrieval, we need at least the size right away.
        createFromNativeImageHandleProvider();
    }
}
    //------------------------------------------------------------------------
    static void ProcessRgbToRgb( const CFbsBitmap& aTarget,
                                 const CFbsBitmap& aSource,
                                 const TInt aTreshold,
                                 const TInt aBlendFactor )
        {
        // ScanLineLength returns bytes, but width must match the Type
        TInt width  = CFbsBitmap::ScanLineLength( aSource.SizeInPixels().iWidth,
                                                  aSource.DisplayMode() ) / sizeof(Type);
        TInt height = aSource.SizeInPixels().iHeight;

        TInt pixelCount = width * height;
        TInt shade;
        TInt r,g,b;

        aTarget.LockHeap( ETrue ); // Lock the global bitmap heap
        Type* dataT = reinterpret_cast<Type*>( aTarget.DataAddress() );
        Type* dataS = reinterpret_cast<Type*>( aSource.DataAddress() );

        for( TInt index = 0; index < pixelCount; ++index )
            {
            r = AknsRlRgb<Type,X,R,G,B>::R8(*dataS);
            g = AknsRlRgb<Type,X,R,G,B>::G8(*dataS);
            b = AknsRlRgb<Type,X,R,G,B>::B8(*dataS);

            // Pixel intensity = grayscale value
            shade = AknsRlUtil::Grayscale( TUint8(r), TUint8(g), TUint8(b) );

            // Convert to B&W
            if( shade < aTreshold )
                shade = 0;
            else
                shade = 255;

            // Exposure blending
            // Note: It is assumed that arithmetic shifting is supported
            // -> negative values are shifted correctly
            r = (shade * aBlendFactor + (255 - aBlendFactor) * r) >> 8;
            g = (shade * aBlendFactor + (255 - aBlendFactor) * g) >> 8;
            b = (shade * aBlendFactor + (255 - aBlendFactor) * b) >> 8;

            if( r < 0 ) r = 0; else if( r > 255 ) r = 255;
            if( g < 0 ) g = 0; else if( g > 255 ) g = 255;
            if( b < 0 ) b = 0; else if( b > 255 ) b = 255;

            AknsRlRgb<Type,X,R,G,B>::SetRgb8( dataT, TUint8(r), TUint8(g), TUint8(b) );

            dataT++;
            dataS++;
            }

        aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap
        }
Exemple #6
0
void QVGPixmapData::fromNativeType(void* pixmap, NativeType type)
{
    if (type == QPixmapData::SgImage && pixmap) {
#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL)
        RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap);
        destroyImages();
        prevSize = QSize();

        vgImage = sgImageToVGImage(context, *sgImage);
        if (vgImage != VG_INVALID_HANDLE) {
            w = vgGetParameteri(vgImage, VG_IMAGE_WIDTH);
            h = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT);
            d = 32; // We always use ARGB_Premultiplied for VG pixmaps.
        }

        is_null = (w <= 0 || h <= 0);
        source = QVolatileImage(); // readback will be done later, only when needed
        recreate = false;
        prevSize = QSize(w, h);
        updateSerial();
#endif
    } else if (type == QPixmapData::FbsBitmap && pixmap) {
        CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap *>(pixmap);
        QSize size(bitmap->SizeInPixels().iWidth, bitmap->SizeInPixels().iHeight);
        resize(size.width(), size.height());
        source = QVolatileImage(bitmap); // duplicates only, if possible
        if (source.isNull())
            return;
        if (!conversionLessFormat(source.format())) {
            // Here we may need to copy if the formats do not match.
            // (e.g. for display modes other than EColor16MAP and EColor16MU)
            source.beginDataAccess();
            QImage::Format format = idealFormat(&source.imageRef(), Qt::AutoColor);
            source.endDataAccess(true);
            source.ensureFormat(format);
        }
        recreate = true;
    } else if (type == QPixmapData::VolatileImage && pixmap) {
        QVolatileImage *img = static_cast<QVolatileImage *>(pixmap);
        resize(img->width(), img->height());
        source = *img;
        recreate = true;
    } else if (type == QPixmapData::NativeImageHandleProvider && pixmap) {
        destroyImages();
        nativeImageHandleProvider = static_cast<QNativeImageHandleProvider *>(pixmap);
        // Cannot defer the retrieval, we need at least the size right away.
        createFromNativeImageHandleProvider();
    }
}
void CAlfPerfAppAvkonTestCaseBasic::ConstructL( 
        CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea )
    {
    CAlfPerfAppBaseTestCaseControl::ConstructL( aEnv, aCaseId, aVisibleArea );   
    
    iWinRect = aVisibleArea;
    
    iAvkonControl = new(ELeave) CAvkonTestCoeControl();
    iAvkonControl->ConstructL(iWinRect);

    iAnimTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    
    TFontSpec myFontSpec(_L("Arial"), 3*120);
    CCoeEnv::Static()->ScreenDevice()->GetNearestFontInTwips(iFont, myFontSpec);
    
    // Find my private path
    TFileName pathWithoutDrive;
    TFileName driveAndPath;
    CEikonEnv::Static()->FsSession().PrivatePath( pathWithoutDrive );
    driveAndPath.Copy(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName().Left(2));
    driveAndPath.Append(pathWithoutDrive);
    
    // Create pictures
    iPictureBm = new(ELeave) CFbsBitmap;
    driveAndPath.Append(_L("alfperfapp_test1.mbm"));
    User::LeaveIfError(iPictureBm->Load(driveAndPath));
    iMaskBm = new(ELeave) CFbsBitmap;
    User::LeaveIfError(iMaskBm->Create(iPictureBm->SizeInPixels(), EGray256));
 
    iTestCaseStartTime_ys.UniversalTime();
    iTestCaseFrameCount = 0;
   }
TBool CScreenCaptureUtil::VerifyBitmapFormatL(const CFbsBitmap& aBitmap)
	{
  RSurfaceManager::TInfoBuf infoBuf;
	RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
  User::LeaveIfError(iSurfaceManager.SurfaceInfo(iLocalSurface, infoBuf));
    		
	return ((info.iSize == aBitmap.SizeInPixels()) && (EColor16MU == aBitmap.DisplayMode()));
	}
// -----------------------------------------------------------------------------
// CMaskedBitmap::Copy
// -----------------------------------------------------------------------------
TInt CMaskedBitmap::Copy( const CFbsBitmap& aBitmap, const CFbsBitmap& aMask, TBool aDuplicate )
    {
    Reset();

    TInt bitmapHandle( aBitmap.Handle() );
    TInt maskHandle( aMask.Handle() );
    if( bitmapHandle && maskHandle &&
        aBitmap.SizeInPixels() != aMask.SizeInPixels() )
        {
        return KErrArgument;
        }

    TInt err( KErrNone );
    if( bitmapHandle )
        {
        if( aDuplicate )
            {
            err = iBitmap->Duplicate( bitmapHandle );
            }
        else
            {
            err = BitmapUtil::CopyBitmap( aBitmap, *iBitmap );
            }
        }

    if( !err && maskHandle )
        {
        if( aDuplicate )
            {
            err = iMask->Duplicate( maskHandle );
            }
        else
            {
            err = BitmapUtil::CopyBitmap( aMask, *iMask );
            }
        if( err )
            {
            iBitmap->Reset();
            }
        }
    return err;
    }
Exemple #10
0
void CPointerCursorWindow::Draw()
	{
	iGc->Reset();
	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
	iGc->DrawRect(Size());
	if (iBitmap)
		{
		TPoint point(3,3);
		if (!iTop)
			point.iY=Size().iHeight-iBitmap->SizeInPixels().iHeight-3;
		iGc->BitBlt(point,iBitmap);
		}
	}
void CUploadContainer::Draw(const TRect& aRect) const
{
	CALLSTACKITEM_N(_CL("CUploadContainer"), _CL("Draw"));

	CWindowGc& gc = SystemGc();
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	gc.SetBrushColor(KRgbWhite);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRect(aRect);

	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	gc.SetBrushStyle(CGraphicsContext::ENullBrush);

	TGulBorder border(TGulBorder::ESingleGray);
	TRect edit_rect=iTagEdit->Rect();
	edit_rect.Resize(4, 4);
	edit_rect.Move(-2, -2);
	border.Draw(gc, edit_rect);

	if (iDescriptionEdit) {
		edit_rect=iDescriptionEdit->Rect();
		edit_rect.Resize(4, 4);
		edit_rect.Move(-2, -2);
		border.Draw(gc, edit_rect);
	}

	if (iSelected) {
		TGulBorder border(TGulBorder::ESingleBlack);
		//gc.SetPenColor(KRgbBlack);
		TRect edit_rect=iSelected->Rect();
		edit_rect.Resize(4, 4);
		edit_rect.Move(-2, -2);
		border.Draw(gc, edit_rect);
	}
	if (iActive) {
		TGulBorder border(TGulBorder::EFocusedSunkenControl);
		//gc.SetPenColor(KRgbBlack);
		TRect edit_rect=iActive->Rect();
		edit_rect.Resize(4, 4);
		edit_rect.Move(-2, -2);
		border.Draw(gc, edit_rect);
	}

	if (scaled) {
		TSize s=iScaledBitmap->SizeInPixels();
		TPoint lt=TPoint( (Rect().Width()-s.iWidth)/2, 4);
		TRect r( lt, s);
		gc.DrawBitmap(r, iScaledBitmap);
	}
}
void CTestStepVidPlayerDRMGetFrame::MvpuoFrameReady(CFbsBitmap& aFrame, TInt aError)
	{
	iError = aError;
	if (aError==KErrNone)
		{
		if (aFrame.Handle() == NULL || aFrame.SizeInPixels() != TSize(KFrameWidth,KFrameHeight) )
			iError = KErrArgument;
		else
			{
				iError = KErrNone;
				INFO_PRINTF1(_L("MvpuoFrameReady: GetFrameL() COMPLETED OK"));
			}
		}
	CActiveScheduler::Stop();
	}
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CMaskedBitmap::CopyBitmap
// -----------------------------------------------------------------------------
TInt BitmapUtil::CopyBitmap( const CFbsBitmap& aSource, CFbsBitmap& aDestination )
    {
    TSize size( aSource.SizeInPixels() );
    TDisplayMode displayMode( aSource.DisplayMode() );
    TInt err( aDestination.Create( size, displayMode ) );
    if( !err )
        {
        err = BitmapUtil::CopyBitmapData( aSource, aDestination, size, displayMode );
        if( err )
            {
            aDestination.Reset();
            }
        }
    return err;
    }
/**
@SYMTestCaseID
GRAPHICS-UI-BENCH-0151

@SYMPREQ PREQ39

@SYMREQ REQ9236 
@SYMREQ REQ9237

@SYMTestCaseDesc
Measures the performance of DrawBitmap() for the current screen mode, for various bitmap pixel formats.
The bitmap is drawn without scaling.

@SYMTestActions
Create a copy of the bitmap, and scale to the required size, prior to running the test.
For each required source pixel format, use DrawBitmap() to tile a bitmap across the target, avoiding any
clipping or overlap. 

@SYMTestExpectedResults
The performance to be logged as a pixel rate, per bitmap.
*/
void CTBitBltPerfDirectGdi::SimpleDrawBitmapL()
	{
	INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::SimpleDrawBitmap"));
	
	_LIT(KTestName, "DirectGdiDrawBitmap");

	for (TInt source = 0; source < iBitmapImage.Count(); ++source)
		{
		// Use a bitmap that needs no scaling.
		CFbsBitmap* bitmapBitBltImage = CopyIntoNewBitmapL(iBitmapImage[source], iBitmapImage[source]->DisplayMode());
		CleanupStack::PushL(bitmapBitBltImage);
		bitmapBitBltImage->Resize(KCropTo.Size());
		BitBltBitmapTestL(EDrawBitmap, bitmapBitBltImage, NULL, bitmapBitBltImage->SizeInPixels(), KTestName, iContext);
		CleanupStack::PopAndDestroy(1, bitmapBitBltImage);
		}
	}
void AknBitmapMirrorUtils::LoadPartialBitmapL(CFbsBitmap* aBitmap, const TDesC& aFileName,TInt32 aId, TRect aRect, TBool aMirrorHorizontally)
    {
    CFbsBitmap* destinationBitmap = aBitmap;
    User::LeaveIfNull(destinationBitmap);

    CFbsBitmap* sourceBitmap = new (ELeave) CFbsBitmap();   
    CleanupStack::PushL(sourceBitmap);   
    User::LeaveIfError(sourceBitmap->Load(aFileName, aId, ETrue));    
    TSize sourceBitmapSize = sourceBitmap->SizeInPixels();
    
    TRect sourceRect = TRect(aRect);
    if (sourceRect == KWholeBitmapRect)
        {
        sourceRect.iTl.iX = 0;
        sourceRect.iTl.iY = 0;
        sourceRect.iBr.iX = sourceBitmapSize.iWidth;
        sourceRect.iBr.iY = sourceBitmapSize.iHeight;
        }
      
    TSize destinationBitmapSize(sourceRect.Width(), sourceRect.Height()); 
    User::LeaveIfError(destinationBitmap->Create(destinationBitmapSize, sourceBitmap->DisplayMode()));

    CFbsBitmapDevice* destinationDevice = CFbsBitmapDevice::NewL( destinationBitmap );
    CleanupStack::PushL(destinationDevice);

    CFbsBitGc* destinationGc;
    User::LeaveIfError( destinationDevice->CreateContext( destinationGc ) );

    if (aMirrorHorizontally)
        {
        TRect sourceBitmapBlittingRect( sourceRect.iTl.iX,sourceRect.iTl.iY,sourceRect.iTl.iX + 1,sourceRect.iBr.iY );  
    
        for ( TInt xPos=destinationBitmapSize.iWidth-1; xPos >= 0; xPos-- )
            {
            destinationGc->BitBlt( TPoint(xPos,0), sourceBitmap, sourceBitmapBlittingRect );
            sourceBitmapBlittingRect.iTl.iX++;
            sourceBitmapBlittingRect.iBr.iX++;
            }
        }
    else
        {
        destinationGc->BitBlt( TPoint(0,0), sourceBitmap, sourceRect );
        }

    delete destinationGc;  
    CleanupStack::PopAndDestroy(2); // sourceBitmap, destinationDevice
    }
    //------------------------------------------------------------------------
    static void ProcessRgbToGray( const CFbsBitmap& aTarget,
                                  const CFbsBitmap& aSource,
                                  const TInt aTreshold )
        {
        TInt width  = aSource.SizeInPixels().iWidth;
        TInt height = aSource.SizeInPixels().iHeight;

        // ScanLineLength returns bytes, but width must match the Type
        TInt scanT = CFbsBitmap::ScanLineLength(width, aTarget.DisplayMode());
        TInt scanS = CFbsBitmap::ScanLineLength(width, aSource.DisplayMode()) / sizeof(Type);

        TInt shade;

        TInt pitchT = scanT - width;
        TInt pitchS = scanS - width;

        aTarget.LockHeap( ETrue ); // Lock the global bitmap heap
        TUint8* dataT = reinterpret_cast<TUint8*>( aTarget.DataAddress() );
        Type* dataS = reinterpret_cast<Type*>( aSource.DataAddress() );

        TInt x, y;
        for( y=0; y < height; y++ )
            {
            for( x=0; x < width; x++ )
                {
                // Pixel intensity = grayscale value
                shade = AknsRlUtil::Grayscale( AknsRlRgb<Type,X,R,G,B>::R8(*dataS),
                                               AknsRlRgb<Type,X,R,G,B>::G8(*dataS),
                                               AknsRlRgb<Type,X,R,G,B>::B8(*dataS) );

                // Convert to B&W
                if( shade < aTreshold )
                    *dataT = 0;
                else
                    *dataT = 255;

                dataT++;
                dataS++;
                }

            dataT = dataT + pitchT;
            dataS = dataS + pitchS;
            }

        aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap
        }
void CZXingBarcodeReaderAppView::MceoViewFinderFrameReady( CFbsBitmap& aFrame )
	{
	if (iBackBufferContext)
		{
	TSize bmpSizeInPixels = aFrame.SizeInPixels();
	TInt xDelta = (Rect().Width() - bmpSizeInPixels.iWidth) / 2;
	TInt yDelta = (Rect().Height() - bmpSizeInPixels.iHeight) / 2;
	TPoint pos( xDelta, yDelta );

	// Copy received viewfinder picture to back buffer
	iBackBufferContext->BitBlt( pos, &aFrame, TRect( TPoint( 0, 0 ), bmpSizeInPixels ));

	// Update backbuffer into screen 
	DrawNow();
		}
	if (iCameraWrapper)
		iCameraWrapper->ReleaseViewFinderBuffer();
	}
TInt CScreenCaptureUtil::CopySurfaceToBitmapL(CFbsBitmap& aCopyToBitmap)
	{
	RSurfaceManager::TInfoBuf infoBuf;
	RSurfaceManager::TSurfaceInfoV01& info = infoBuf();

	User::LeaveIfError(iSurfaceManager.SurfaceInfo(iLocalSurface, infoBuf));
	
	TInt bytesPerPixel=0;
	TDisplayMode	bitmapMode = ENone;
	
	switch (info.iPixelFormat)
		{
		case EUidPixelFormatXRGB_8888:
			{
			bitmapMode = EColor16MU;
			bytesPerPixel = 4;
			break;
			}
		default:
			{
			return KErrCorrupt;
			}
		}
	
	if ((aCopyToBitmap.SizeInPixels() != info.iSize) || (aCopyToBitmap.DisplayMode() != bitmapMode))
		{
		return KErrCorrupt;
		}
	
	RChunk chunk;
	CleanupClosePushL(chunk);
	User::LeaveIfError(iSurfaceManager.MapSurface(iLocalSurface, chunk));
	TUint8* surfacePtr = chunk.Base();
	TUint8* bitmapPtr = (TUint8*)aCopyToBitmap.DataAddress();
	TInt copyBytes=info.iSize.iWidth*bytesPerPixel;
	for (TInt y=0; y<info.iSize.iHeight; y++)
		{
		Mem::Copy(bitmapPtr,surfacePtr,copyBytes);
		surfacePtr += info.iStride;
		bitmapPtr += aCopyToBitmap.DataStride();
		}
	CleanupStack::PopAndDestroy(&chunk);
	return KErrNone;
	}
/**
Adds a VGImage to the cache using the associated CFbsBitmap as a reference.

A new image cache item is created which stores the VGImage, the size of the image in pixels,
the serial number of the CFbsBitmap (which acts as a unique identifier) and the touch count
of the CFbsBitmap.  The touch count determines the number of times the underlying data of
the CFbsBitmap has changed.

The least-recently used items will be removed from the cache to create space for the new item, if needed.

@param aBitmap	The bitmap from which the VGImage was created.
@param aImage	The VGImage to store in the cache.
@param aOrigin	The origin used to create a tiled VGImage.

@return ETrue if the VGImage was successfully added to the cache, EFalse if not.
 */
TBool CVgImageCache::AddImage(const CFbsBitmap& aBitmap, VGImage& aImage, const TPoint& aOrigin)
	{
	// Calculate approximate size in bytes of image
	TDisplayMode vgCompatibleDisplayMode = ClosestVgCompatibleDisplayMode(aBitmap.DisplayMode());
	TSize imageSize = aBitmap.SizeInPixels();
	TInt dataStride = CFbsBitmap::ScanLineLength(imageSize.iWidth, vgCompatibleDisplayMode);
	TInt imageSizeInBytes = imageSize.iHeight * dataStride;
	// if size of image is too large to fit in cache 
	if(imageSizeInBytes > iMaxCacheSizeInBytes)
		{
		return EFalse;
		}
	
	CVgImageCacheItem* newItem = new CVgImageCacheItem;
	if (newItem == NULL)
		{
		return EFalse;
		}

	// check there is enough room in the cache
	// i.e. less than user-specified max memory allowed for cache
	// if not enough space, remove items from end of cache until enough space is available.
	while(iMaxCacheSizeInBytes < iCacheSizeInBytes + imageSizeInBytes)
		{
		DeleteItem(iVgImageCache.Last());
		}
	newItem->iSerialNumber = aBitmap.SerialNumber();
	newItem->iImage = aImage;
	newItem->iTouchCount = aBitmap.TouchCount();
	newItem->iOrigin = aOrigin;
	newItem->iImageSizeInBytes = imageSizeInBytes;
	TInt err = iCacheItemMap.Insert(newItem->iSerialNumber, newItem);
	if (err != KErrNone)
		{
		delete newItem;
		return EFalse;
		}
	iVgImageCache.AddFirst(*newItem);
	iCacheSizeInBytes += newItem->iImageSizeInBytes;
	return ETrue;
	}
//-----------------------------------------------------------------------------
//  CBrowserViewImagesListBox::CreateIconL(
//                                      CFbsBitmap* aBitmap, TBool aShrinkIt )
//-----------------------------------------------------------------------------
//
CGulIcon* CBrowserViewImagesListBox::CreateIconL(
                                        CFbsBitmap* aBitmap, TBool aShrinkIt)
    {
    CGulIcon* icon = NULL;

    // create icon
    if(aShrinkIt)
        {
        CFbsBitmap* bmp = new(ELeave)CFbsBitmap;
        CleanupStack::PushL(bmp);
        User::LeaveIfError(bmp->Create(TSize(42,32), EColor16M));
    
        // create bitmap device
        CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(bmp);
        CleanupStack::PushL(dev);
    
        // create graphics context for bitmap device
        CGraphicsContext* ctx = NULL;
        User::LeaveIfError( dev->CreateContext(ctx) );
        CleanupStack::PushL(ctx);
    
        // calculate aspect ratio
        TSize targetSize = Fit(aBitmap->SizeInPixels(), bmp->SizeInPixels());
        // copy bitmap to temporary bitmap
        ctx->DrawBitmap(TRect(TPoint(0,0), targetSize), aBitmap, TRect(TPoint(0,0), aBitmap->SizeInPixels()));

        CleanupStack::PopAndDestroy(2);   // ctx, dev

        icon = CGulIcon::NewL(bmp); // bmp is owned, no mask used
        CleanupStack::Pop();  // bmp
        delete aBitmap;
        } 
    else 
        {
        icon = CGulIcon::NewL(aBitmap); // bitmap is owned, no mask used
        }

    return icon;
    }
    //------------------------------------------------------------------------
    static void ProcessGrayToRgb( const CFbsBitmap& aTarget,
                                  const CFbsBitmap& aSource,
                                  const TInt aTreshold )
        {
        TInt width  = aSource.SizeInPixels().iWidth;
        TInt height = aSource.SizeInPixels().iHeight;

        // ScanLineLength returns bytes, but width must match the Type
        TInt scanT = CFbsBitmap::ScanLineLength(width, aTarget.DisplayMode()) / sizeof(Type);
        TInt scanS = CFbsBitmap::ScanLineLength(width, aSource.DisplayMode());

        TInt pitchT = scanT - width;
        TInt pitchS = scanS - width;

        aTarget.LockHeap( ETrue ); // Lock the global bitmap heap
        Type* dataT = reinterpret_cast<Type*>( aTarget.DataAddress() );
        TUint8* dataS = reinterpret_cast<TUint8*>( aSource.DataAddress() );

        TInt x, y;
        for( y=0; y < height; y++ )
            {
            for( x=0; x < width; x++ )
                {
                // Convert to B&W
                if( *dataS < aTreshold )
                    AknsRlRgb<Type,X,R,G,B>::SetRgb8( dataT, TUint8(0), TUint8(0), TUint8(0) );
                else
                    AknsRlRgb<Type,X,R,G,B>::SetRgb8( dataT, TUint8(255), TUint8(255), TUint8(255) );

                dataT++;
                dataS++;
                }

            dataT = dataT + pitchT;
            dataS = dataS + pitchS;
            }

        aTarget.UnlockHeap( ETrue ); // Unlock the global bitmap heap
        }
// ---------------------------------------------------------------------------
// CAknBatteryStrength::DrawInStaconPane
// ---------------------------------------------------------------------------
//
void CAknBatteryStrength::DrawInStaconPane( const TRect& /*aRect*/ ) const
    {
    CWindowGc& gc = SystemGc();

    CFbsBitmap* bitmap = NULL;
    CFbsBitmap* mask   = NULL;

    TRect rect( Rect() );

    if ( AknStatuspaneUtils::StaconSoftKeysLeft() )
        {
        bitmap = iStaconRightSideBatteryIndicatorBitmap;
        mask   = iStaconRightSideBatteryIndicatorBitmapMask;
        }
    else
        {
        bitmap = iStaconLeftSideBatteryIndicatorBitmap;
        mask   = iStaconLeftSideBatteryIndicatorBitmapMask;
        }

    TPoint point( rect.iTl );
    if ( AknStatuspaneUtils::StaconSoftKeysLeft() && bitmap )
        {
        point = TPoint( rect.iBr.iX - bitmap->SizeInPixels().iWidth,
                        rect.iTl.iY );
        }

    if ( bitmap && mask )
        {
        gc.BitBltMasked(
            point,
            bitmap,
            TRect( 0, 0, rect.Width(), iStaconBatteryBitmapOffset ),
            mask,
            ETrue );
        }

    }
// ---------------------------------------------------------
// CRecognizerContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CRecognizerContainer::Draw(const TRect& aRect) const
{
	CALLSTACKITEM_N(_CL("CRecognizerContainer"), _CL("Draw"));

	CWindowGc& gc = SystemGc();

	if (iBitmap != NULL) {
		TRect drawRect(0,1,176,133); // keep aspect ratio 160/120 = 640/480 = 4/3
		gc.DrawBitmap(drawRect, iBitmap);
		ShowCodes(drawRect, iBitmap->SizeInPixels());
	} else {
		CWindowGc& gc = SystemGc();
		gc.SetPenStyle(CGraphicsContext::ENullPen);
		if (!started) {
			gc.SetBrushColor(KRgbGray);
		} else {
			gc.SetBrushColor(KRgbWhite);
		}
		gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
		gc.DrawRect(aRect);
	}

}
void CEglTest_EGL_Image_Multi_Thread_Sibling_VGImage::doThreadFunctionL(TInt aIdx)
	{	
	INFO_PRINTF2(_L("CEglTest_EGL_Image_Multi_Thread_Sibling_VGImage::doThreadFunctionL, Thread %d"),aIdx);
	CTestEglSession* eglSess = CTestEglSession::NewLC(Logger(), iDisplay, aIdx);
	eglSess->InitializeL();
	eglSess->OpenSgDriverL();

	INFO_PRINTF2(_L("Thread %d, Creating a Surface and a Context bound to OpenVG"),aIdx);
	TUidPixelFormat pixelFormat = EglTestConversion::VgFormatToSgPixelFormat(KDefaultSurfaceFormat);
	TSgImageInfoOpenVgTarget imageInfo = TSgImageInfoOpenVgTarget(pixelFormat, KPixmapSize);
	// Create a pixmap surface matching the native image pixel format
	eglSess->CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo,CTestEglSession::EResourceCloseSgImageEarly);
	
	// Create a VGImage from the EGLImage
	INFO_PRINTF2(_L("Thread %d, Creating one VGImage from the shared EGLImage"),aIdx);
	VGImage vgImageLocal = eglSess->vgCreateImageTargetKHR((VGeglImageKHR)iEGLImageShared);	
	ASSERT_VG_TRUE(vgImageLocal != VG_INVALID_HANDLE);
	
	Rendezvous(aIdx);
		
	if(aIdx == 0)
		{
		INFO_PRINTF2(_L("Thread %d, Updating contents of the VGImage from the shared EGLImage"),aIdx);
		TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(KDefaultSourceFormat);
		CFbsBitmap* bitmap = eglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
    	// Add pixel data to the VGImage reference from the bitmap reference. 
        // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
		TSize bitmapSize = bitmap->SizeInPixels();
    	TUint8* address = reinterpret_cast<TUint8*>(bitmap->DataAddress());
    	TInt stride = bitmap->DataStride();
    	address += (bitmapSize.iHeight - 1) * stride;
        vgImageSubData(vgImageLocal, address, -stride, KDefaultSurfaceFormat, 0,0, bitmapSize.iWidth, bitmapSize.iHeight);
		delete bitmap;
        bitmap = NULL;
		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
		eglWaitClient();
		}

	Rendezvous(aIdx);
	
	if(aIdx == 1)
		{
		INFO_PRINTF2(_L("Thread %d, Drawing the VGImage to the current surface"),aIdx);
		// Copy the source VGImage to the surface
    	vgSetPixels(0, 0, vgImageLocal, 0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
		ASSERT_TRUE(vgGetError()==VG_NO_ERROR);
		eglWaitClient();

		// we can now compare the VgImage to the one we expect after changing it in the other thread
		TDisplayMode bitmapMode = EglTestConversion::PixelFormatToDisplayMode(KDefaultSourceFormat);
		CFbsBitmap* refBitmap = eglSess->CreateReferenceBitmapL(bitmapMode, KPixmapSize, 8);
		CleanupStack::PushL(refBitmap);
		eglSess->CheckVgDrawingL(KDefaultSurfaceFormat, refBitmap);
		CleanupStack::PopAndDestroy(refBitmap);
		INFO_PRINTF2(_L("Thread %d, Drawing successful"),aIdx);
		}		
	
	// cleanup
	vgDestroyImage(vgImageLocal);
	ASSERT_TRUE(vgGetError() == VG_NO_ERROR);
	eglSess->CloseSgDriver();
	CleanupStack::PopAndDestroy(eglSess);
	}
// ---------------------------------------------------------------------------
// CAknBatteryStrength::DrawInFlatStatusPane
// ---------------------------------------------------------------------------
//
void CAknBatteryStrength::DrawInFlatStatusPane( const TRect& /*aRect*/ ) const
    {
    CWindowGc& gc = SystemGc();

    TRect rect( Rect() );
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();

    // Draws battery strength bar
    CAknsMaskedBitmapItemData* bitmapData = NULL;

    if ( skin )
        {
        bitmapData = static_cast<CAknsMaskedBitmapItemData*>(
            skin->GetCachedItemData(
                KAknsIIDQgnIndiBatteryStrength, EAknsITMaskedBitmap ) );
        if ( bitmapData )
            {
            CFbsBitmap* bitmap = bitmapData->Bitmap();

            if ( bitmap )
                AknIconUtils::SetSize( bitmap,
                                       TSize( rect.Width(),
                                              rect.Height() ),
                                              EAspectRatioNotPreserved );

            TPoint point( 0, iFlatBatteryBitmapOffset );
            if ( bitmap && !AknLayoutUtils::LayoutMirrored() )
                {
                point = TPoint( rect.iBr.iX - bitmap->SizeInPixels().iWidth,
                                iFlatBatteryBitmapOffset);
                }

            gc.BitBltMasked(
                point,
                bitmap, TRect(0,iFlatBatteryBitmapOffset,
                rect.Width(),
                rect.Height()),
                bitmapData->Mask(), ETrue );
            }
        }

    if ( !bitmapData )
        {
        if ( iFlatBatteryIndicatorBitmap && iFlatBatteryIndicatorBitmapMask )
            {
            TPoint point( 0, iFlatBatteryBitmapOffset );
            if ( !AknLayoutUtils::LayoutMirrored() )
                {
                point = TPoint(
                    rect.iBr.iX - iFlatBatteryIndicatorBitmap->SizeInPixels().iWidth,
                    iFlatBatteryBitmapOffset );
                }
            gc.BitBltMasked(
                point,
                iFlatBatteryIndicatorBitmap,
                TRect( 0,
                       iFlatBatteryBitmapOffset,
                       rect.Width(),
                       rect.Height() ),
                iFlatBatteryIndicatorBitmapMask,
                ETrue );
            }
        }

    }
/*
-------------------------------------------------------------------------------
internal icon re-sizer function
-------------------------------------------------------------------------------
*/   
CGulIcon* CYBRecognizer1::GetListIconL(const TDesC& aFileName,TInt aImage,TInt aMask, TSize aSize)
{
	CGulIcon* RetIcon(NULL);
	TBool OkToAdd(EFalse);
	
	CFbsBitmap* MyBitmap = new(ELeave)CFbsBitmap();
	CleanupStack::PushL(MyBitmap);
	CFbsBitmap* MyMask = new(ELeave)CFbsBitmap();
	CleanupStack::PushL(MyMask);
	
	if(KErrNone == MyBitmap->Load(aFileName,aImage))
	{
		if(KErrNone == MyMask->Load(aFileName,aMask))
		{
			OkToAdd = ETrue;
		}
	}
	
	if(OkToAdd)
	{
		TSize ImgSiz = MyBitmap->SizeInPixels();
		if(aSize.iWidth != ImgSiz.iWidth
		|| aSize.iHeight!= ImgSiz.iHeight)
		{
			CFbsBitmap* TmpBackBitmap = new(ELeave)CFbsBitmap();
			CleanupStack::PushL(TmpBackBitmap);
			
			if(KErrNone == TmpBackBitmap->Create(aSize,MyBitmap->DisplayMode()))
			{	
				CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(TmpBackBitmap);
				CleanupStack::PushL(bitmapDevice);

				CFbsBitGc* graphicsContext = NULL;
				User::LeaveIfError(bitmapDevice->CreateContext(graphicsContext));
				CleanupStack::PushL(graphicsContext);

				graphicsContext->DrawBitmap(TRect(0,0,aSize.iWidth,aSize.iHeight),MyBitmap);
				
				CleanupStack::PopAndDestroy(2);//graphicsContext,bitmapDevice,
			}
			
			CFbsBitmap* TmpBackMask = new(ELeave)CFbsBitmap();
			CleanupStack::PushL(TmpBackMask);
			if(KErrNone == TmpBackMask->Create(aSize,MyMask->DisplayMode()))
			{	
				CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(TmpBackMask);
				CleanupStack::PushL(bitmapDevice);

				CFbsBitGc* graphicsContext = NULL;
				User::LeaveIfError(bitmapDevice->CreateContext(graphicsContext));
				CleanupStack::PushL(graphicsContext);

				graphicsContext->DrawBitmap(TRect(0,0,aSize.iWidth,aSize.iHeight),MyMask);
				
				CleanupStack::PopAndDestroy(2);//graphicsContext,bitmapDevice,
			}
		
			CleanupStack::Pop(2);//TmpBackBitmap, TmpBackMask
			RetIcon = CGulIcon::NewL(TmpBackBitmap, TmpBackMask);
		}
	}
	
	if(!RetIcon && OkToAdd)
	{
		CleanupStack::Pop(2);//MyBitmap, MyMask
		RetIcon = CGulIcon::NewL(MyBitmap, MyMask);
	}
	else
	{
		CleanupStack::PopAndDestroy(2);//MyBitmap, MyMask
	}
		
	return RetIcon;
}
Exemple #27
0
void CAknScrollIndicator::ConstructL()
    {
    iIsWindowOwningScrollBar = EFalse;
    if( AknLayoutUtils::PenEnabled() && (iTypeOfScrollBar == CAknScrollButton::ENormal) )
        {
        // TODO: Load bitmaps for double span scroll bar buttons when they become available
        // Get the correct sizes from LAF when the support for the buttons is available
        // Initalize the bitmap devices and graphics contexts correctly        
        TInt err;         
        TAknsItemID indicator; 
        TAknWindowComponentLayout buttonLayout;
        TAknWindowComponentLayout scrollpaneLayout;
        
        switch( iType )
            {
            case CAknScrollButton::ENudgeUp:        	        
                buttonLayout = AknLayoutScalable_Avkon::scroll_sc2_up_pane( 1 );  
                indicator = KAknsIIDQgnGrafScrollArrowUp;
                scrollpaneLayout = AknLayoutScalable_Avkon::scroll_pane();
                break;
            case CAknScrollButton::ENudgeDown:
                buttonLayout = AknLayoutScalable_Avkon::scroll_sc2_down_pane( 1 );  
                indicator = KAknsIIDQgnGrafScrollArrowDown;
                scrollpaneLayout = AknLayoutScalable_Avkon::scroll_pane();
                break;
            case CAknScrollButton::ENudgeLeft:
                buttonLayout = AknLayoutScalable_Avkon::scroll_sc2_left_pane();  
                indicator = KAknsIIDQgnGrafScrollArrowLeft;
                scrollpaneLayout = AknLayoutScalable_Avkon::scroll_pane(1);
                break;
            case CAknScrollButton::ENudgeRight:
                buttonLayout = AknLayoutScalable_Avkon::scroll_sc2_right_pane();
                indicator = KAknsIIDQgnGrafScrollArrowRight;
                scrollpaneLayout = AknLayoutScalable_Avkon::scroll_pane(1);
                break;
            default:
                return;
            }
        
        TAknLayoutRect scrollpaneLayoutRect, buttonLayoutRect;
        
        // Using mainpanerect only for counting the size of button bitmap
        TRect mainpaneRect;
        AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainpaneRect );
        scrollpaneLayoutRect.LayoutRect( mainpaneRect, scrollpaneLayout.LayoutLine() ); 
        buttonLayoutRect.LayoutRect( scrollpaneLayoutRect.Rect(), buttonLayout.LayoutLine() ); 
        
        // trapping possible leave in this phase when there's no bitmaps in other skins        
        
        TRAP( err, iIcon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(), 
                            indicator, EFalse ) );
        
        if( err == KErrNone )
            {
            AknIconUtils::SetSize( iIcon->Bitmap(),  buttonLayoutRect.Rect().Size() );    
            AknIconUtils::SetSize( iIcon->Mask(),  buttonLayoutRect.Rect().Size() );    
            }             
        }
    else
        {
        TInt indicator;
        TSize indiSize;


        // screen
        TRect screenRect = iAvkonAppUi->ApplicationRect();
    
        //TAknWindowLineLayout screenLayout = AknLayout::screen();
        //TRect screenRect = screenLayout.Rect();

        // app window
        TAknWindowLineLayout applicationWindowLayout =
            AknLayout::application_window(screenRect);
    
        TAknLayoutRect applicationWindowLayoutRect;
        applicationWindowLayoutRect.LayoutRect(screenRect, applicationWindowLayout);
        TRect applicationWindowRect = applicationWindowLayoutRect.Rect(); 

        // control pane
        TAknWindowLineLayout controlPaneLayout =
            AknLayout::control_pane(applicationWindowRect);

        TAknLayoutRect controlPaneLayoutRect;
        controlPaneLayoutRect.LayoutRect(applicationWindowRect, controlPaneLayout);
        TRect controlPaneRect = controlPaneLayoutRect.Rect(); 

    
        if (iType == CAknScrollButton::ENudgeUp)
            {
            // scroll up
            TAknWindowLineLayout scrollLayout =
                AknLayout::Control_pane_elements_Line_1();
            TAknLayoutRect scrollLayoutRect;
            scrollLayoutRect.LayoutRect(controlPaneRect, scrollLayout);
            TRect scrollRect = scrollLayoutRect.Rect(); 

            indicator=EMbmAvkonQgn_indi_scroll_a;        
            indiSize = scrollRect.Size();
            }
        else
            {
            // scroll down
            TAknWindowLineLayout scrollLayout =
                AknLayout::Control_pane_elements_Line_2();
            TAknLayoutRect scrollLayoutRect;
            scrollLayoutRect.LayoutRect(controlPaneRect, scrollLayout);
            TRect scrollRect = scrollLayoutRect.Rect(); 

            indicator=EMbmAvkonQgn_indi_scroll_b;
            indiSize = scrollRect.Size();
            }

//  iBitmap = new (ELeave) CFbsBitmap();
//  User::LeaveIfError(iBitmap->Load(KAvkonBitmapFile,
//      indicator,ETrue));

//    iBitmap = AknIconUtils::CreateIconL(KAvkonBitmapFile, indicator);
    
        iBitmap = new (ELeave) CEikImage();    
        CFbsBitmap* mask = NULL;
        CFbsBitmap* bitmap = NULL;
    
        // Use bitmap id for both mask and bitmap because of 1-bit icons.
        AknIconUtils::CreateIconL(
            bitmap, mask, KAvkonBitmapFile, indicator, indicator ); 
        AknIconUtils::SetSize(bitmap,indiSize);
        // Also note that in the drawing time mask is used as bitmap. We store the bitmap
        // only because AknIconUtils requires to do so.
        iBitmap->SetBitmap(bitmap);
        iBitmap->SetMask(mask);

        iColorBitmap = new (ELeave) CFbsBitmap();
        User::LeaveIfError( iColorBitmap->Create( bitmap->SizeInPixels(),
            iEikonEnv->ScreenDevice()->DisplayMode() ) );
        iColorBmpDev = CFbsBitmapDevice::NewL( iColorBitmap );
//      User::LeaveIfError( iColorBmpDev->Resize( bitmap->SizeInPixels()));
        iColorBmpGc = CFbsBitGc::NewL();
        iColorBmpGc->Activate( iColorBmpDev );

        iMaskBitmap = new (ELeave) CFbsBitmap();
        //8-bit bitmap
        User::LeaveIfError( iMaskBitmap->Create( bitmap->SizeInPixels(),
            EGray256 ));
        iMaskBmpDev = CFbsBitmapDevice::NewL( iMaskBitmap );
//      User::LeaveIfError( iMaskBmpDev->Resize( bitmap->SizeInPixels()));
        iMaskBmpGc = CFbsBitGc::NewL();
        iMaskBmpGc->Activate( iMaskBmpDev );
        }
    }
void CAlfPerfAppAvkonTestCaseBasic::NextAnimFrameL()
    {
    // Begin drawing
    RWindow& window = static_cast< RWindow& >( *iAvkonControl->DrawableWindow() );
    CWindowGc& gc = iAvkonControl->SystemGc();
    TRect updateRect(iAvkonControl->Rect());
    window.Invalidate( updateRect );
    window.BeginRedraw( updateRect );
    gc.Activate(window);

    // Draw background
    TRgb color (KRgbWhite);
    gc.SetBrushColor(color);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    gc.SetPenSize(TSize(10,10));
    gc.SetPenColor(color);    
    gc.DrawRect(updateRect);  
       
    // Calc timeline
    TTime now;
    now.UniversalTime();
    TUint millisecondFromCycleStart = now.MicroSecondsFrom(iCycleStartTime).Int64() / 1000;
    double timelinePercentage = (double)millisecondFromCycleStart / KCycleDurationMs; 
    timelinePercentage *= 0.5; // scale it a bit...
   
    // Calc rect
    TRect fullRect(updateRect);
    TSize size(fullRect.Width()*(1.0 - timelinePercentage), fullRect.Height()*(1.0 - timelinePercentage));
    TPoint windowCenter = fullRect.Center();
    TPoint tl(windowCenter.iX - size.iWidth/2, windowCenter.iY - size.iHeight/2);
    TRect rect(tl, size);
        
    // Draw
    gc.SetPenColor(KRgbBlue);
    gc.SetBrushColor(KRgbRed);
    const TPoint Point1(rect.iTl);
    const TPoint Point2(rect.iBr.iX, rect.iTl.iY);
    const TPoint Point3(rect.iBr);
    const TPoint Point4(rect.iTl.iX, rect.iBr.iY);
    const TPoint center(rect.Center());

    switch (iCycleCounter)
        {
        case 1: // DrawEllipse
            {
            gc.DrawEllipse(rect);   
            break;
            }
        case 2: // DrawRect
            {
            gc.DrawRect(rect);    
            break;
            }
        case 3: // DrawRoundRect
            {
            TSize corner(rect.Width()/5, rect.Height()/5);
            gc.DrawRoundRect(rect, corner);   
            break;
            }
        case 4: // Draw lines
            {
            gc.SetPenColor(TRgb(255,0,0));
            gc.DrawLine(Point1, Point2);       
            
            gc.SetPenColor(TRgb(200,50,0));
            gc.DrawLineTo(Point3);
            
            gc.SetPenColor(TRgb(150,100,0));
            gc.DrawLineTo(Point4);
            
            gc.SetPenColor(TRgb(100,150,0));
            gc.DrawLineBy(TPoint(0, -rect.Height()));
            
            gc.SetPenColor(TRgb(50,200,0));
            gc.MoveTo(Point2);
            gc.DrawLineTo(Point4);
                       
            gc.SetPenColor(TRgb(0,255,0));
            gc.MoveBy(TPoint(0, -rect.Height()));
            gc.DrawLineTo(Point3);
            
            gc.SetPenColor(TRgb(255,0,0));
            gc.Plot(center);
            
            break;
           }
            
        case 5: // Draw 
            {
            gc.SetPenColor(TRgb(255,0,0));
            gc.DrawArc(rect, Point2, Point1);
            gc.DrawPie(rect, Point4, Point3);
            break;
            }
            
        case 6: // Draw polygons
            {
            const TInt KNumPoints = 9;
            TPoint pointList[KNumPoints];
            pointList[0] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
            pointList[1] = TPoint(Point1.iX+rect.Width()*0.75, Point1.iY);
            pointList[2] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.25);
            pointList[3] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.75);
            pointList[4] = TPoint(Point3.iX-rect.Width()*0.25, Point3.iY);
            pointList[5] = TPoint(Point3.iX-rect.Width()*0.75, Point3.iY);
            pointList[6] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.25);
            pointList[7] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.75);
            pointList[8] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
            
            CArrayFix<TPoint>* mypoints = new CArrayFixFlat<TPoint>(KNumPoints);
            CleanupStack::PushL(mypoints);
            for(TInt i=0; i<KNumPoints; i++)
                {
                mypoints->AppendL(pointList[i]);
                }

            gc.SetPenColor(TRgb(255,0,0));
            gc.SetPenSize(TSize(20,20));
            gc.DrawPolyLine(mypoints);
            
            gc.SetPenColor(TRgb(0,255,0));
            gc.SetPenSize(TSize(15,15));
            gc.DrawPolyLine(pointList, KNumPoints);
            
            gc.SetPenColor(TRgb(255,255,0));
            gc.SetPenSize(TSize(10,10));
            gc.DrawPolygon(mypoints);
            
            gc.SetPenColor(TRgb(0,0,255));
            gc.SetPenSize(TSize(5,5));
            gc.DrawPolygon(pointList, KNumPoints);
            
            CleanupStack::PopAndDestroy(); // mypoints           
            break;
            }
            
        case 7: // Draw texts
            {
            gc.UseFont(iFont);
            gc.SetDrawMode(CGraphicsContext::EDrawModePEN);
            gc.SetPenStyle(CGraphicsContext::ESolidPen);
            gc.SetBrushStyle(CGraphicsContext::ESolidBrush);    
            
            TInt h = rect.Height() / 3;
            TInt y = rect.iTl.iY;
            TRect tinyBox(rect);
            tinyBox.SetHeight(h);
            TInt fontDescent=iFont->DescentInPixels();
            gc.SetBrushColor(TRgb(0, 0, 255)); // blue
            
            gc.SetPenColor(TRgb(0,255,0)); // green
            gc.DrawText(_L("Ilves"), tinyBox.iTl+TPoint(0, fontDescent));
            
            tinyBox.Move(0,h);
            TInt posY = tinyBox.Height()-fontDescent;
            gc.SetPenColor(TRgb(255,0,0)); 
            gc.DrawText(_L("Tappara"), tinyBox, posY);
            
            gc.SetPenColor(TRgb(0,255,0)); // green
            gc.DrawTextVertical(_L("Ilves"), tinyBox.iTl+TPoint(fontDescent, 0 ), ETrue);
            
            tinyBox.Move(0,h);
            posY = tinyBox.Height()-fontDescent;
            gc.SetPenColor(TRgb(255,0,0)); 
            gc.DrawTextVertical(_L("Tappara"), tinyBox, posY, ETrue);
            
            break;
            }

        case 8: // Draw bitmaps
            {
            TPoint pos(rect.iTl);
            gc.BitBlt(pos, iPictureBm);
            
            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY);
            gc.BitBlt(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()));

            pos = TPoint(rect.iTl.iX + rect.Width()*2/3, rect.iTl.iY);
            gc.BitBltMasked(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);

            pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()/3);
            TRect dstRect(pos, TSize(rect.Width()/3, rect.Height()/3));
            gc.DrawBitmap(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()));

            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()/3);
            dstRect =  TRect(pos, dstRect.Size());
            gc.DrawBitmap(dstRect, iPictureBm);

            pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()*2/3);
            gc.DrawBitmap(pos, iPictureBm);

            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()*2/3);
            dstRect =  TRect(pos, dstRect.Size());
            gc.DrawBitmapMasked(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);

            break;
            }
            
         case 9: // Miscellanious
            {
            TRect rect1(rect);
            rect1.SetWidth(rect.Width()/2);
            rect1.SetHeight(rect.Height()/2);
            TRect rect2(rect1);
            rect2.Move(rect1.Width(),0);
            TRect rect3(rect1);
            rect3.Move(0, rect1.Height());
            TRect rect4(rect1);
            rect4.Move(rect1.Width(), rect1.Height());
            
            // Clear
            gc.Clear();
            // Brush pattern
            gc.UseBrushPattern(iPictureBm);
            gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
            gc.DrawRect(rect1);
            gc.DiscardBrushPattern();
            // Fading & copy rect
            gc.SetFaded(ETrue);
            gc.CopyRect(rect2.iTl, rect1);
            gc.SetFadingParameters(255,0);
            gc.CopyRect(rect3.iTl, rect1);
            // Map colors  
            gc.SetPenColor(KRgbBlue);
            gc.SetBrushColor(KRgbRed);
            gc.DrawRect(rect4);   
            TRgb colors[2] = {KRgbRed, KRgbGreen}; // change brush color
            gc.MapColors(rect4,colors,1,ETrue);
             
            break;
            }
            
     default:
           gc.DrawRect(rect);          
       }

    // End drawing
    gc.Deactivate();
    window.EndRedraw();
 
    iTestCaseFrameCount++;
    }
Exemple #29
0
void QVGPixmapData::fromNativeType(void* pixmap, NativeType type)
{
    if (type == QPixmapData::SgImage && pixmap) {
#if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL)
        RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap);

        destroyImages();
        prevSize = QSize();

        TInt err = 0;

        RSgDriver driver;
        err = driver.Open();
        if (err != KErrNone) {
            cleanup();
            return;
        }

        if (sgImage->IsNull()) {
            cleanup();
            driver.Close();
            return;
        }

        TSgImageInfo sgImageInfo;
        err = sgImage->GetInfo(sgImageInfo);
        if (err != KErrNone) {
            cleanup();
            driver.Close();
            return;
        }

        pfnVgCreateEGLImageTargetKHR vgCreateEGLImageTargetKHR = (pfnVgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR");

        if (eglGetError() != EGL_SUCCESS || !(QEgl::hasExtension("EGL_KHR_image") || QEgl::hasExtension("EGL_KHR_image_pixmap")) || !vgCreateEGLImageTargetKHR) {
            cleanup();
            driver.Close();
            return;
        }

        const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE};
        EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(),
                EGL_NO_CONTEXT,
                EGL_NATIVE_PIXMAP_KHR,
                (EGLClientBuffer)sgImage,
                (EGLint*)KEglImageAttribs);

        if (eglGetError() != EGL_SUCCESS) {
            cleanup();
            driver.Close();
            return;
        }

        vgImage = vgCreateEGLImageTargetKHR(eglImage);
        if (vgGetError() != VG_NO_ERROR) {
            cleanup();
            QEgl::eglDestroyImageKHR(QEgl::display(), eglImage);
            driver.Close();
            return;
        }

        w = sgImageInfo.iSizeInPixels.iWidth;
        h = sgImageInfo.iSizeInPixels.iHeight;
        d = 32; // We always use ARGB_Premultiplied for VG pixmaps.
        is_null = (w <= 0 || h <= 0);
        source = QImage();
        recreate = false;
        prevSize = QSize(w, h);
        setSerialNumber(++qt_vg_pixmap_serial);
        // release stuff
        QEgl::eglDestroyImageKHR(QEgl::display(), eglImage);
        driver.Close();
#endif
    } else if (type == QPixmapData::FbsBitmap) {
        CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap*>(pixmap);

        bool deleteSourceBitmap = false;

#ifdef Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE

        // Rasterize extended bitmaps

        TUid extendedBitmapType = bitmap->ExtendedBitmapType();
        if (extendedBitmapType != KNullUid) {
            bitmap = createBlitCopy(bitmap);
            deleteSourceBitmap = true;
        }
#endif

        if (bitmap->IsCompressedInRAM()) {
            bitmap = createBlitCopy(bitmap);
            deleteSourceBitmap = true;
        }

        TDisplayMode displayMode = bitmap->DisplayMode();
        QImage::Format format = qt_TDisplayMode2Format(displayMode);

        TSize size = bitmap->SizeInPixels();

        bitmap->BeginDataAccess();
        uchar *bytes = (uchar*)bitmap->DataAddress();
        QImage img = QImage(bytes, size.iWidth, size.iHeight, format);
        img = img.copy();
        bitmap->EndDataAccess();

        if(displayMode == EGray2) {
            //Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
            //So invert mono bitmaps so that masks work correctly.
            img.invertPixels();
        } else if(displayMode == EColor16M) {
            img = img.rgbSwapped(); // EColor16M is BGR
        }

        fromImage(img, Qt::AutoColor);

        if(deleteSourceBitmap)
            delete bitmap;
    }
}
/*
-----------------------------------------------------------------------------

  ProcessL

  Process image referenced by aImage (modify aImage).
  May leave with KErrNoMemory if no memory available

  Return Values:  none

-----------------------------------------------------------------------------
*/
void CDCDithering::ProcessL(CFbsBitmap& aImage)
{
    TUint	r, g, b;	// Color components
    TUint8*	dataPtr;	// Pointer to data

    //Dithering variables, init to 0
    TInt	count=0;
    TInt16	dither=0;

    //EColor16M image is needed
    if (aImage.DisplayMode() != EColor16M || aImage.DisplayMode() != EColor16M)
        return;

    // Line Buffer and pointer to the data
    TUint imageWidth = aImage.SizeInPixels().iWidth;
    TUint scanLineLengthInBytes = aImage.ScanLineLength(imageWidth, aImage.DisplayMode());

    //Allocate buffer for scanline
    iScanLineBuffer = HBufC8::NewMaxL(scanLineLengthInBytes);
    //Pointer to scanline
    TPtr8 linePtr = iScanLineBuffer->Des();

    //Step through image lines
    for (TInt lineNo=0; lineNo<aImage.SizeInPixels().iHeight; ++lineNo)
    {
        //Get line
        aImage.GetScanLine(linePtr, TPoint(0, lineNo), imageWidth, aImage.DisplayMode());
        //CHECK! CONST_CAST not used in every algorithm which way is better?
        dataPtr = CONST_CAST(TUint8*, linePtr.Ptr());

        //Step through image pixels
        for (TUint x=0; x < imageWidth; ++x)
        {
            // Get original values
            b = *dataPtr++;
            g = *dataPtr++;
            r = *dataPtr++;

            //Compute DCDithering factor from base count
            switch (count&1)
            {
            case 0:
                dither = (TInt16)(dither*0x7ffd);
                break;
            case 1:
                dither = (TInt16)(dither+0x7f21);
                break;
            }

            //Add DCDithering factor, adjust gain according to quantization factors.
            r = Limit255((TInt)r + (dither>>13));
            g = Limit255((TInt)g - (dither>>14));
            b = Limit255((TInt)b + (dither>>13));

            //Move to the previous pixel
            dataPtr -= 3;

            /* Set the result */
            *dataPtr++ = (TUint8)b;
            *dataPtr++ = (TUint8)g;
            *dataPtr++ = (TUint8)r;

            //Increase bae count
            count++;
        }

        //Set scan line
        aImage.SetScanLine(linePtr, lineNo);
    }

    //Free allocated memory
    delete(iScanLineBuffer);
    iScanLineBuffer = 0;
}