Пример #1
0
//Ensure the pen colour is set in the bitmap with the correct alpha blending level
void CTransGc::SetPenColor(const TRgb &aColor)
	{
	TRgb Color = aColor;
	Color.SetAlpha(iAlpha);
	iFbsBitGc.SetPenColor(Color);
	
	}
Пример #2
0
EXPORT_C TRgb ColorUtils::ColorAdjust(TRgb aColor,TInt aPercentage)
/** Brightens or darkens a 24-bit colour by a percentage. 

If the percentage given is less than 100%, a darker colour will be returned. 
The algorithm brightens or darkens each of the R, G and B channels equally.

@param aColor Input colour. 
@param aPercentage Percentage by which to adjust the input colour. 
@return The adjusted colour. */
	{
	// Poor algorithm for the moment, but it can improve and all apps that
	// use this will benefit. (I don't think the accuracy for a 16/256 color system
	// is really relevant anyway)
	TInt red=aColor.Red();
	TInt green=aColor.Green();
	TInt blue=aColor.Blue();
	TInt alpha=aColor.Alpha();
	if (aPercentage<=100)
		{
		red=(red * aPercentage)/100;
		green=(green * aPercentage)/100;
		blue=(blue * aPercentage)/100;
		}
	else
		{
		red = 255 - (((255 - red) * 100) / aPercentage);
		green = 255 - (((255 - green) * 100) / aPercentage);
		blue = 255 - (((255 - blue) * 100) / aPercentage);
		}
	return TRgb(red,green,blue,alpha);
	}
unsigned char CameraImage::getPixel(int x, int y) const
{
	TPoint pixelPosition(x,y);
	TRgb color;
    image->GetPixel(color, pixelPosition); 
    return ((color.Red() + color.Green() + color.Blue()) / 3);
}
Пример #4
0
// -----------------------------------------------------------------------------
// Blit
//
// Blits given image to gc.
//
// -----------------------------------------------------------------------------
//
inline static TBool Blit(
    MAknsSkinInstance* aSkin, CBitmapContext& aGc, const TRect& aTrgRect,
    CAknsImageItemData* aImgData, const TAknsItemID& aIID,
    const TAknsBackground* aLayout, const TPoint& aPADelta,
    const TInt aDrawParam )
    {
    CAknsAppSkinInstance* appInstance = 
        static_cast<CAknsAppSkinInstance*>(aSkin);
        
    if ( IsBackgroundItem( aIID,appInstance ) && 
            appInstance && appInstance->AnimBackgroundState() )
        {
        if( (aDrawParam&KAknsDrawParamPrepareOnly) )
            {
            return ETrue;
            }        
        
        TRgb color = KRgbWhite;
        color.SetAlpha(0x00);
        aGc.SetPenColor(color);
        aGc.SetBrushColor(color);
        aGc.SetPenStyle(CGraphicsContext::ESolidPen);
        aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
        aGc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
        TRect layoutRect( aTrgRect );
        if( aLayout )
            {
            layoutRect = aLayout->iRect;
            }
        layoutRect.Move( -aPADelta );

        TRect drawRect = aTrgRect;
        drawRect.Intersection( layoutRect );

        aGc.Clear(drawRect);
        return ETrue;
        }

    TRect layoutRect( aTrgRect );

    const TAknsImageAttributeData* attr = NULL;

    if( aLayout )
        {
        layoutRect = aLayout->iRect;

        if( aLayout->iAttr.iAttributes != EAknsImageAttributeNone )
            {
            attr = &(aLayout->iAttr);
            }
        }

    layoutRect.Move( -aPADelta );

    TRect drawRect(aTrgRect);
    drawRect.Intersection( layoutRect );

    return DrawPartialCachedImage( aSkin, aGc, layoutRect, drawRect,
        aImgData, aIID, attr, aDrawParam );
    }
Пример #5
0
void CGameImageLoader::CreateSurface()
{
   TSize imagesize = iBitmap->SizeInPixels();

   if (iPixelFormat)
   {
	// the image must be converted to the requested pixel format
	int x, y;
	TRgb pixel;
	TPoint point;

	TRAPD(error, iSurface = new Game::Surface(iPixelFormat, imagesize.iWidth, imagesize.iHeight));

	if( error != KErrNone )
	{
		iErrorCode = error;
		return;
	}

	if (!iSurface)
	{
		iErrorCode = KErrNoMemory;
		return;
	}

	for(y=0; y<imagesize.iHeight; y++)
	for(x=0; x<imagesize.iWidth; x++)
	{
		point.iX = x;
		point.iY = y;
		iBitmap->GetPixel(pixel, point);
		iSurface->setPixel(x, y, iPixelFormat->makePixel(pixel.Red(), pixel.Green(), pixel.Blue()));
	}
   }
   else
   {
	// no pixel conversion required
	Game::PixelFormat bitmapPixelFormat(12);
    Game::Surface tmpSurface(&bitmapPixelFormat, (Game::Pixel*)iBitmap->DataAddress(), imagesize.iWidth, imagesize.iHeight);
	
//	TRAPD(error, iSurface = new Game::Surface(&bitmapPixelFormat, (Game::Pixel*)iBitmap->DataAddress(), imagesize.iWidth, imagesize.iHeight));
	TRAPD(error, iSurface = new Game::Surface(&bitmapPixelFormat, &tmpSurface));

	if( error != KErrNone )
	{
        delete iSurface;
        iSurface = NULL;
		iErrorCode = error;
		return;
	}

	if (!iSurface)
	{
		iErrorCode = KErrNoMemory;
		return;
	}
   }
}
Пример #6
0
void CButton::SetTransparentBackground(TBool aState)
	{
	TInt alpha;
	if (aState){alpha=0;}
	else {alpha=255;}
	TRgb backgroundColour = KRgbWhite; // for example
	if(KErrNone == iButton->Window().SetTransparencyAlphaChannel())
		{backgroundColour.SetAlpha(alpha);}
	iButton->Window().SetBackgroundColor(backgroundColour);
	}
Пример #7
0
void CWindowMover::ConstructL(MWindowMover* m,QmlApplicationViewer* v,RWsSession* aWs)
    {

    iWinGroup=new (ELeave) RWindowGroup(*aWs);
    iWinGroup->Construct((TUint32)&iWinGroup, EFalse);
    iWinGroup->EnableReceiptOfFocus(EFalse); // Don't capture any key events.
    iWinGroup->SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront+KAddPriority+1);

    CApaWindowGroupName* wn=CApaWindowGroupName::NewL(*aWs);
    wn->SetHidden(ETrue);
    wn->SetSystem(ETrue);
    wn->SetWindowGroupName(*iWinGroup);
    delete wn;

    iCallBack=m;
    viewer=v;
    iDragged=EFalse;
    CreateWindowL(iWinGroup);
    SetPointerCapture(ETrue);
    EnableDragEvents();
    // for transparency
    TRgb backgroundColour = KRgbWhite; // for example
//#ifndef _DEBUG
    if(KErrNone == Window().SetTransparencyAlphaChannel())
        {backgroundColour.SetAlpha(0);}
//#endif
    Window().SetBackgroundColor(backgroundColour);
    //SetSize(TSize(1,1));
    MakeVisible(EFalse);
    SetExtentToWholeScreen();

    settings=new QSettings(KConfigFile,QSettings::IniFormat);

    xAnim=new MyAnimation();
    yAnim=new MyAnimation();
    //QEasingCurve curve=new QEasingCurve(QEasingCurve::OutQuad);
    xAnim->setEasingCurve(QEasingCurve::OutQuad);
    yAnim->setEasingCurve(QEasingCurve::OutQuad);
    xAnim->setDuration(200);
    yAnim->setDuration(200);
    connect(xAnim,SIGNAL(valueChanged(QVariant)),this,SLOT(xAnimChanged(QVariant)));
    connect(yAnim,SIGNAL(valueChanged(QVariant)),this,SLOT(yAnimChanged(QVariant)));
    connect(yAnim,SIGNAL(finished()),this,SLOT(finished()));
    connect(xAnim,SIGNAL(finished()),this,SLOT(finished()));
    iTimer=new QTimer();
    iTimer->setInterval(400);
    iTimer->setSingleShot(false);
    connect(iTimer,SIGNAL(timeout()),this,SLOT(checkLaunchArea()));
    ActivateL();
    int gest=settings->value("settings/gesture").toInt();
    if (gest==0) axisSet=false;
    else if (gest==1) {axisX=1;axisY=0; axisSet=true;}
    else if (gest==2) {axisX=0;axisY=1; axisSet=true;}
    }
Пример #8
0
/**
   Auxilliary function for TestCaseID tbrdrcol-DrawColorCubeBackgroundNow
  
   This method converts a TRgb colour HSL format.
  
 */
THsl ColorConverter::RgbToHsl(TRgb aRgb)
	{
	const TInt r = aRgb.Red();
	const TInt g = aRgb.Green();
	const TInt b = aRgb.Blue();
	
	const TInt cmax = Max(r, Max(g,b));
	const TInt cmin = Min(r, Min(g,b));
	
	TInt h = 0;
	TInt l = (cmax + cmin) >> 1; // Divided with 2
	TInt s = 0;
	
	if (cmax==cmin) 
		{
		s = 0;
		h = 0; // it's really undefined
		} 
	else 
		{
		if ( l < (255/2) )
			{
			s = ((cmax-cmin)*255)/(cmax+cmin);
			}
		else
			{
			s = ((cmax-cmin)*255)/((2*255)-cmax-cmin);
			}
		
		TInt delta = cmax - cmin;
		
		if (r==cmax)
			{
			h = ((g-b)*255) / delta;
			}
		else if (g==cmax)
			{
			h = 2*255 + ((b-r)*255) / delta;
			}
		else
			{
			h = 4*255 + ((r-g)*255) / delta;
			}
		
		h /= 6;
		
		if (h<0)
			{
			h += (1*255);
			}
		}
	
	return THsl(h, s, l);
	}
Пример #9
0
void tst_NativeImageHandleProvider::bitmap()
{
#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_OPENVG)
    QPixmap tmp(10, 20);
    if (tmp.pixmapData()->classId() == QPixmapData::OpenVGClass) {
        BitmapProvider prov;

        // This should fail because of null ptr.
        QPixmap pm = pixmapFromNativeImageHandleProvider(&prov);
        QVERIFY(pm.isNull());
        pm = QPixmap();
        QCOMPARE(prov.refCount, 0);

        prov.bmp = new CFbsBitmap;
        QCOMPARE(prov.bmp->Create(TSize(prov.w, prov.h), EColor16MAP), KErrNone);
        CFbsBitmapDevice *bitmapDevice = CFbsBitmapDevice::NewL(prov.bmp);
        CBitmapContext *bitmapContext = 0;
        QCOMPARE(bitmapDevice->CreateBitmapContext(bitmapContext), KErrNone);
        TRgb symbianColor = TRgb(255, 200, 100);
        bitmapContext->SetBrushColor(symbianColor);
        bitmapContext->Clear();
        delete bitmapContext;
        delete bitmapDevice;

        pm = pixmapFromNativeImageHandleProvider(&prov);
        QVERIFY(!pm.isNull());
        QCOMPARE(pm.width(), prov.w);
        QCOMPARE(pm.height(), prov.h);
        QVERIFY(prov.refCount == 1);
        QImage img = pm.toImage();
        QVERIFY(prov.refCount == 1);
        QRgb pix = img.pixel(QPoint(1, 2));
        QCOMPARE(qRed(pix), symbianColor.Red());
        QCOMPARE(qGreen(pix), symbianColor.Green());
        QCOMPARE(qBlue(pix), symbianColor.Blue());

        pm = QPixmap(); // should result in calling release
        QCOMPARE(prov.refCount, 0);
        delete prov.bmp;
    } else {
         QSKIP("Not openvg", SkipSingle);
    }
#else
    QSKIP("Not applicable", SkipSingle);
#endif
}
Пример #10
0
EXPORT_C TInt CWsContainGraphicBitmap::UpdateColor(TRgb aColor)
	{
	if (!iIsReady)
		return KErrNotReady;
	// Send the color the server side
	TBuf8<3> cmd;
	TInt red = aColor.Red();
	TInt green = aColor.Green();
	TInt blue = aColor.Blue();
    //Append the color
	cmd.Append(red);
	cmd.Append(green);
	cmd.Append(blue);
	
	SendMessage(cmd);
	return Flush();
	}
/**
Compare the window with the bitmap.
@param aScreen The screen device object
@param aBitmap The bitmap object for comparison
@return ETrue if the window and the bitmap is identified. Otherwise return EFalse.
*/
TBool CT_WServGenericpluginStepLoad::CompareDisplayL(CWsScreenDevice* aScreen, CFbsBitmap* aBitmap)
	{
	// Capture window display to bitmap
	CFbsBitmap* screenBitmap = new(ELeave) CFbsBitmap();
	CleanupStack::PushL(screenBitmap);
	User::LeaveIfError(screenBitmap->Create(KWinRect.Size(), iDisplayMode));
	User::LeaveIfError(aScreen->CopyScreenToBitmap(screenBitmap, KWinRect));	
	
	//Compare the window bitmap with the bitmap pass in for comparison
	TBool ret = ETrue;
	
	const TReal KErrorLimit = 0.05;
	
	TInt mismatchedPixels = 0;
	TRgb testWinPix = TRgb(0,0,0,0);
	TRgb checkWinPix = TRgb(0,0,0,0);
	for (TInt x = 0; x < KWinRect.Width(); x++)
		{
		for (TInt y = 0; y < KWinRect.Height(); y++)
			{
			screenBitmap->GetPixel(testWinPix, TPoint(x,y));
			aBitmap->GetPixel(checkWinPix, TPoint(x,y));
			
			//check if there are differeces between test Window colors and check Window colors
			if(((TReal)abs(testWinPix.Red() - checkWinPix.Red())/255) > KErrorLimit || 
					((TReal)abs(testWinPix.Blue() - checkWinPix.Blue())/255) > KErrorLimit || 
					((TReal)abs(testWinPix.Green() - checkWinPix.Green())/255) > KErrorLimit || 
					((TReal)abs(testWinPix.Alpha() - checkWinPix.Alpha())/255) > KErrorLimit)
				{
				mismatchedPixels++;  // -- Useful for debugging
				ret = EFalse;
				break;
				}
			}
		}
	
	/* INFO_PRINTF2(_L("Number of different pixels: %i"), mismatchedPixels); */ // -- Useful for debugging
	

	CleanupStack::PopAndDestroy(screenBitmap);	
	
	
	
	return ret;
	}
/**
Interpolates between the two TRgb values aHi and aLo including alpha channel, with the value aX and the denoinator aN
*/	
TRgb CTe_graphicsperformanceSuiteStepBase::InterpolateColour(TRgb aLo, TRgb aHi, TInt aX, TInt aN)
	{
	TInt y = aN - aX;

	TUint8 a = (TUint8)( (aHi.Alpha()*aX + aLo.Alpha()*y)/aN );
	TUint8 r = (TUint8)( (aHi.Red()*aX + aLo.Red()*y)/aN );
	TUint8 g = (TUint8)( (aHi.Green()*aX + aLo.Green()*y)/aN );
	TUint8 b = (TUint8)( (aHi.Blue()*aX + aLo.Blue()*y)/aN );
	
	return TRgb(r, g, b, a);
	}
Пример #13
0
CGameSpriteFrame::CGameSpriteFrame(const TFileName& filename, TUint32 id, const CGameRect& r, CFbsBitmap* loader){

	loader->Load(filename, id, 0);
	
	TInt i,j;
	TInt h = loader->SizeInPixels().iHeight;
	TInt w = loader->SizeInPixels().iWidth;
	
	h = (h<r.h)?h:r.h;
	w = (w<r.w)?w:r.w;
	
	TInt H = minor2Pot(h);
	TInt W = minor2Pot(w);
	
	if(H>W)W=H;
	else H=W;
	
	this->texDim = H;
			 	    	    
	TRgb color;
	TPoint point;
	
	this->pixels = new TUint32[W*H];
		    	    
	for(i=0;i<w;i++){
		for(j=0;j<h;j++){
			point.SetXY(i,j);
			loader->GetPixel(color,point);
			this->pixels[i+j*W] = color.Value();
		}
	}
	
	glGenTextures(1, &(this->texId)); 

	glBindTexture(GL_TEXTURE_2D, this->texId);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	GLint format = GL_RGBA;

	glTexImage2D(GL_TEXTURE_2D, 0, format, W, H, 0,
	format, GL_UNSIGNED_BYTE, this->pixels);
	
}
Пример #14
0
/**
 * @brief Completes the second phase of Symbian object construction. 
 * Put initialization code that could leave here. 
 */ 
void CTap2CloseAppUi::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	
	BaseConstructL( EAknEnableSkin  | 
					 EAknEnableMSK ); 
	InitializeContainersL();
	// ]]] end generated region [Generated Contents]
	//CCoeControl
	
	iWinGroup=new (ELeave) RWindowGroup(CEikonEnv::Static()->WsSession());
	iWinGroup->Construct((TUint32)&iWinGroup, EFalse);
	iWinGroup->EnableReceiptOfFocus(EFalse); // Don't capture any key events.
	iWinGroup->SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
	
	CApaWindowGroupName* wn=CApaWindowGroupName::NewL(CEikonEnv::Static()->WsSession());
	wn->SetHidden(ETrue);
	wn->SetSystem(ETrue);
	wn->SetWindowGroupName(*iWinGroup);
	delete wn;
	iButton = CAknButton::NewL();
	iButton->ConstructFromResourceL(R_CLOSE_BUTTON);
	iButton->CreateWindowL(iWinGroup);

	TInt scrX=CEikonEnv::Static()->ScreenDevice()->SizeInPixels().iWidth;
	
	TRgb backgroundColour = KRgbWhite; // for example
	if(KErrNone == iButton->Window().SetTransparencyAlphaChannel())
		{backgroundColour.SetAlpha(0);}
	iButton->Window().SetBackgroundColor(backgroundColour);
	
	iButton->SetIconSize(KSize);
	TRect r;
	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EBatteryPane,r);
	iButton->SetRect(TRect ( TPoint(scrX-KSize.iWidth-r.Width()-5,0),KSize));
	iButton->SetObserver(this);
	iButton->MakeVisible(ETrue);
	iButton->ActivateL();
	
	CEikonEnv::Static()->RootWin().SetOrdinalPosition(-4);
	HideApplicationFromFSW(ETrue);
	
	iObserver=CGroupListObserver::NewL(this);
	}
Пример #15
0
/**
   Auxiliary function for all Test Cases
  
   This method returns a TRgb colour which is a lighter tone of colour aColor.
   
 */
TRgb CSimpleControl::LightRgb(TRgb aColor) const
	{
	TInt value = aColor.Value();

	TInt r = Min(255,((value & 0x000000ff)  ) + 30);
	TInt g = Min(255,((value & 0x0000ff00)  >> 8) + 30);
	TInt b = Min(255,((value & 0x00ff0000)  >> 16) + 30);

	return TRgb(r,g,b);
	}
Пример #16
0
/**
   Auxiliary function for all Test Cases
  
   This method returns a TRgb colour which is a darker tone of colour aColor.
   
 */
TRgb CSimpleControl::DarkRgb(TRgb aColor) const
	{
	TInt value = aColor.Value();

	TInt r = Max(0,((value & 0x000000ff)  ) - 85);
	TInt g = Max(0,((value & 0x0000ff00)  >> 8) - 85);
	TInt b = Max(0,((value & 0x00ff0000)  >> 16) - 85);

	return TRgb(r,g,b);
	}
Пример #17
0
void tst_QVolatileImage::fill()
{
    QVolatileImage img(100, 100, QImage::Format_ARGB32_Premultiplied);
    QColor col = QColor(10, 20, 30);
    img.fill(col.rgba());
    QVERIFY(img.imageRef().pixel(1, 1) == col.rgba());
    QVERIFY(img.toImage().pixel(1, 1) == col.rgba());

#ifdef Q_OS_SYMBIAN
    CFbsBitmap *bmp = static_cast<CFbsBitmap *>(img.duplicateNativeImage());
    QVERIFY(bmp);
    TRgb pix;
    bmp->GetPixel(pix, TPoint(1, 1));
    QCOMPARE(pix.Red(), col.red());
    QCOMPARE(pix.Green(), col.green());
    QCOMPARE(pix.Blue(), col.blue());
    delete bmp;
#endif
}
Пример #18
0
EXPORT_C TRgb ColorUtils::RgbDarkerColor(TRgb aRgb, TDisplayMode aMode)
/** Creates a darker color.

@param aRgb The RGB color.
@param aMode The display mode, which indicates the screen output of the colour 
e.g. 256 colour display mode (8 bpp).
@return The darker colour. */
	{
	switch (aMode)
		{
	case EColor256:
		return TRgb::Color256(color256darklutab[aRgb.Color256()]);
	default:
		TInt value = aRgb.Internal();
		TInt b = Max( 0, ((value & 0x000000ff)  ) - KDarkRgbSubtractor );
		TInt g = Max( 0, ((value & 0x0000ff00)  >> 8) - KDarkRgbSubtractor );
		TInt r = Max( 0, ((value & 0x00ff0000)  >> 16) - KDarkRgbSubtractor );
		return TRgb(r,g,b,aRgb.Alpha());
		}
	}
Пример #19
0
EXPORT_C TRgb ColorUtils::RgbLighterColor(TRgb aRgb, TDisplayMode aMode)
/** Creates a lighter colour.

@param aRgb The Rgb colour.
@param aMode The display mode, which indicates the screen output of the colour 
e.g. 256 colour display mode (8 bpp).
@return The lighter colour. */
	{
	switch (aMode)
		{
	case EColor256:
		return TRgb::Color256(color256lightlutab[aRgb.Color256()]);
	default:
		TInt value = aRgb.Internal();
		TInt b = Min( 255, ((value & 0x000000ff)  ) + KLightRgbAdder );
		TInt g = Min( 255, ((value & 0x0000ff00)  >> 8) + KLightRgbAdder );
		TInt r = Min( 255, ((value & 0x00ff0000)  >> 16) + KLightRgbAdder );
		return TRgb(r,g,b,aRgb.Alpha());
		}
	}
Пример #20
0
TBool CDataWrapperBase::GetRgbFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TRgb& aResult)
	{
	TBuf<KMaxTestExecuteCommandLength>	tempStore;

	TInt	red;
	tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbRed);
	TBool	ret=GetIntFromConfig(aSectName, tempStore, red);

	TInt	green;
	tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbGreen);
	if ( !GetIntFromConfig(aSectName, tempStore, green) )
		{
		ret=EFalse;
		}

	TInt	blue;
	tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbBlue);
	if ( !GetIntFromConfig(aSectName, tempStore, blue) )
		{
		ret=EFalse;
		}

	if ( ret )
		{
		aResult.SetRed(red);
		aResult.SetGreen(green);
		aResult.SetBlue(blue);

		TInt	alpha;
		tempStore.Format(KFormatEntryField, &aKeyName, &KTagRgbAlpha);
		if ( GetIntFromConfig(aSectName, tempStore, alpha) )
			{
			aResult.SetAlpha(alpha);
			}
		}

	return ret;
	}
/** If the display mode of iBitmapInfo is not expected, return EFalse
 * or render to the back buffer and returns ETrue
*/
TBool CCommonInterfaces::DrawColor(const TRect& aRect,const TRgb& aColour)
	{
	TRect local = TRect(aRect.iTl-iRect.iTl, aRect.Size());
	TUint16* pBuffer16;
	TUint32* pBuffer32;

	if (iBitmapInfo.iDisplayMode != iDispMode)
		{
		return EFalse;
		}
	for (TInt y = local.iTl.iY; y < local.iBr.iY; y++)
		{
		for (TInt x = local.iTl.iX; x < local.iBr.iX; x++)
			{
			switch (iDispMode)
				{
				case EColor64K:
					pBuffer16 = (TUint16*)iBitmapInfo.iAddress;
					pBuffer16[y*iBitmapInfo.iLinePitch/2+x] = aColour._Color64K();
					break;
				case EColor16M:
					pBuffer16 = (TUint16*)iBitmapInfo.iAddress;
					pBuffer16[y*iBitmapInfo.iLinePitch/2+x] = aColour._Color64K();
					break;
				case EColor16MU:
					pBuffer32 = (TUint32*)iBitmapInfo.iAddress;
					pBuffer32[y*iBitmapInfo.iLinePitch/4+x] = aColour._Color16MU();
					break;
				case EColor16MA:
					pBuffer32 = (TUint32*)iBitmapInfo.iAddress;
					pBuffer32[y*iBitmapInfo.iLinePitch/4+x] = aColour._Color16MA();
					break;
				case EColor4K:
					pBuffer16 = (TUint16*)iBitmapInfo.iAddress;
					pBuffer16[y*iBitmapInfo.iLinePitch/2+x] = aColour._Color4K();
					break;
				case EColor16MAP:
					pBuffer32 = (TUint32*)iBitmapInfo.iAddress;
					pBuffer32[y*iBitmapInfo.iLinePitch/4+x] = aColour._Color16MAP();
					break;
				default:
					break;
				}
			}
		}
	return ETrue;
	}
Пример #22
0
void CEnormousWin::DrawBitmap(CFbsBitGc* aGc, TRect& aClip, TPoint& aOrigin)
	{
	aGc->Reset();
	TPoint origin = iPos + aOrigin;
	aGc->SetOrigin(origin);
	
	TRect clip(origin, iSize);
	clip.Intersection(aClip);
	clip.Move(-origin);
	aGc->SetClippingRect(clip);

	aGc->SetPenStyle(iPenStyle);
	aGc->SetBrushStyle(iBrushStyle);

	TInt left = clip.iTl.iX / ESegmentSize;
	TInt top = clip.iTl.iY / ESegmentSize;
	TInt right = clip.iBr.iX / ESegmentSize + 1;
	TInt bottom = clip.iBr.iY / ESegmentSize + 1;
	TRgb fg;
	TRgb bg;

	for (TInt y = top; y < bottom; ++y)
		{
		TInt g = (y * 31) & 0xFF;
		for (TInt x = left; x < right; ++x)
			{
			TRect rect(x * ESegmentSize, y * ESegmentSize, (x + 1) * ESegmentSize, (y + 1) * ESegmentSize);
			TInt r = (x * 25) & 0xFF;
			TInt b = ((x + y) * 28) & 0xFF;
			TInt col = ((b << 16) + (g << 8) + r) | 0x101010;
			bg = col;
			fg = 0xFFFFFF ^ col;
			bg.SetAlpha(0xFF);
			fg.SetAlpha(0xFF);
			if (iTransparent && (x & y & 1))
				{
				bg.SetAlpha(0x80);
				fg.SetAlpha(0x80);
				}
			aGc->SetPenColor(fg);
			aGc->SetBrushColor(bg);
			aGc->DrawRect(rect);
			}
		}
	
	CCompWin::DrawBitmap(aGc, aClip, aOrigin);
	}	
Пример #23
0
void CEnormousWin::Redraw(const TRect& aRect)
	{
	iWsGc.Activate(*iWindow);
	iWsGc.Reset();
	
	iWsGc.SetPenStyle(iPenStyle);
	iWsGc.SetBrushStyle(iBrushStyle);

	TInt left = aRect.iTl.iX / ESegmentSize;
	TInt top = aRect.iTl.iY / ESegmentSize;
	TInt right = aRect.iBr.iX / ESegmentSize + 1;
	TInt bottom = aRect.iBr.iY / ESegmentSize + 1;
	TRgb fg;
	TRgb bg;

	for (TInt y = top; y < bottom; ++y)
		{
		TInt g = (y * 31) & 0xFF;
		for (TInt x = left; x < right; ++x)
			{
			TRect rect(x * ESegmentSize, y * ESegmentSize, (x + 1) * ESegmentSize, (y + 1) * ESegmentSize);
			iRedrawWindow->BeginRedraw(rect);
			TInt r = (x * 25) & 0xFF;
			TInt b = ((x + y) * 28) & 0xFF;
			TInt col = ((b << 16) + (g << 8) + r) | 0x101010;
			bg = col;
			fg = 0xFFFFFF ^ col;
			bg.SetAlpha(0xFF);
			fg.SetAlpha(0xFF);
			if (iTransparent && (x & y & 1))
				{
				bg.SetAlpha(0x80);
				fg.SetAlpha(0x80);
				}
			iWsGc.SetPenColor(fg);
			iWsGc.SetBrushColor(bg);
			iWsGc.DrawRect(rect);
			iRedrawWindow->EndRedraw();
			}
		}
	iWsGc.Deactivate();
	}
/**
Draws a VerticalGradient onto a CFbsBitmap from top/color aLo to bottom/aHi
*/
void CTe_graphicsperformanceSuiteStepBase::VerticalGradientAlphaL(CFbsBitmap* aBitmap, TRgb aLo, TRgb aHi)
	{
	const TSize size = aBitmap->SizeInPixels();
	const TDisplayMode mode = aBitmap->DisplayMode();
	const TInt scanLineLength = CFbsBitmap::ScanLineLength(size.iWidth, mode);
	HBufC8* buffer = HBufC8::NewL(scanLineLength);
	CleanupStack::PushL(buffer);
	TPtr8 des = buffer->Des();
	des.SetLength(scanLineLength);
	for(TInt i=0; i<size.iHeight; i++)
		{
		TRgb color = InterpolateColour(aLo, aHi, i, size.iHeight);
		switch(mode)
			{
			case EGray256:
				{
				TUint8  g = color.Gray256();
				TUint8* p = (TUint8*)des.Ptr();
				for(TInt j=0; j<size.iWidth; j++)
					{						
					p[j] = g;
					}
				}
				break;
			case EColor64K:
				{
				TUint16  g = color._Color64K();
				TUint16* p = (TUint16*)des.Ptr();
				for(TInt j=0; j<size.iWidth/2; j++)
					{						
					p[j] = g;
					}
				}
				break;
			case EColor16MU:
				{
				TUint32 rgba = color._Color16MU();
				TUint32* p = (TUint32*)des.Ptr();
				for(TInt j=0; j<(size.iWidth/4); j++)
					{						
					p[j] = rgba;
					}
				}
				break;
			case EColor16MA:
				{
				TUint32 rgba = color._Color16MA();
				TUint32* p = (TUint32*)des.Ptr();
				for(TInt j=0; j<(size.iWidth/4); j++)
					{						
					p[j] = rgba;
					}
				}
				break;
			case EColor16MAP:
				{
				TUint32 rgba = color._Color16MAP();
				TUint32* p = (TUint32*)des.Ptr();
				for(TInt j=0; j<(size.iWidth/4); j++)
					{						
					p[j] = rgba;
					}
				}
				break;
			default:
				ASSERT(EFalse);
				break;
			}
		aBitmap->SetScanLine(des, i);
		}
	CleanupStack::PopAndDestroy(buffer);
	}
TRect CPeninputPenTraceDecorator::DrawPoint( const TPoint& aPoint )
{
    if ( !iBitsBitmap || !iMaskBitmap || !iXSquareArray )
    {
        __ASSERT_DEBUG( EFalse, User::Panic( _L("PenTrace Decorator: invalid status"), 0 ) );
        return TRect();
    }

    TSize cvsize = iBitsBitmap->SizeInPixels();
    if ( cvsize.iWidth < 1 || cvsize.iHeight < 1 )
    {
        __ASSERT_DEBUG( EFalse, User::Panic( _L("PenTrace Decorator: invalid status"), 0 ) );
        return TRect();
    }

    TBitmapUtil bits( iBitsBitmap );
    TBitmapUtil mask( iMaskBitmap );

    TDrawLineParams params;

    bits.Begin( TPoint( 0, 0 ) );
    mask.Begin( TPoint( 0, 0 ) );

    if ( ETrue )
    {
        TDisplayMode mode = iDisplayMode;
        TRgb rgb = iPenTraceColor;
        TInt32 clr = (TInt32) Rgb2DeviceColor( mode, rgb );

        params.rtAffected = TRect();

        params.bits = &bits;
        params.mask = &mask;

        params.SqX = iXSquareArray;   // squares of X

        params.nW = cvsize.iWidth;   // width of destination
        params.nH = cvsize.iHeight;  // height of destination

        params.color = clr;
        params.bR = rgb.Red();       // value of red channel
        params.bG = rgb.Green();     // value of green channel
        params.bB = rgb.Blue();      // value of blue channel

        params.x1 = aPoint.iX << 4 ; // (x of start point) << 4
        params.y1 = aPoint.iY << 4 ; // (y of start point) << 4
        params.d1 = 1;               // width of start point

        params.x2 = aPoint.iX << 4;  // (x of end point) << 4
        params.y2 = aPoint.iY << 4;  // (y of end point) << 4
        params.d2 = 1;               // width of end point

        DrawLongSegment( &params );
    }

    mask.End();
    bits.End();

    iModified = ETrue;

    return params.rtAffected;
}
Пример #26
0
EXPORT_C void CSDL::ChangeBgColor(TRgb& aColor)
    {
    const TUint32 oldColor = gEpocEnv->iColor;
    gEpocEnv->iColor = aColor.Internal();
    aColor = TRgb(oldColor, 0xFF);
    }
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();
    }
Пример #28
0
/**
Fill a rectangle on the given surface.

@param aSurface		The surface to be filled.
@param aStartPos	Where to place the rectangle.
@param aSize		Size of the rectangle.
@param aColor		The colour to fill it with.
*/
void CSurfaceHelper::FillRectangleL(const TSurfaceId& aSurface, const TPoint& aStartPos, const TSize& aSize, const TRgb& aColor)
{
    RSurfaceManager::TInfoBuf infoBuf;
    RSurfaceManager::TSurfaceInfoV01& info = infoBuf();
    User::LeaveIfError(iManager.SurfaceInfo(aSurface, infoBuf));
    TUint32 color = 0;

    if (info.iSize.iHeight<0 || info.iSize.iWidth<0 || info.iStride<0)
    {
        User::Leave(KErrCorrupt);
    }
    if (info.iSize.iHeight==0 || info.iSize.iWidth==0 || info.iStride==0)
    {
        User::Leave(KErrNotReady);
    }

    switch (info.iPixelFormat)
    {
    case EUidPixelFormatXRGB_8888:
    {
        color = aColor.Color16MU();
#ifdef ALPHA_FIX_24BIT
        color |= ((ALPHA_FIX_24BIT)&0xff)<<24;
#endif
        break;
    }
    case EUidPixelFormatARGB_8888:
    {
        color = aColor.Color16MA();
        break;
    }
    case EUidPixelFormatARGB_8888_PRE:
    {
        color = aColor.Color16MAP();
        break;
    }
    case EUidPixelFormatRGB_565:
    {
        color = aColor.Color64K();
        break;
    }
    default:
    {
        User::Leave(KErrNotSupported);
        break;
    }
    }

    RChunk chunk;
    User::LeaveIfError(iManager.MapSurface(aSurface, chunk));
    CleanupClosePushL(chunk);
    TUint8* surfacePtr = chunk.Base();

    // Check for out of bounds
    TBool validRect = ETrue;
    TInt surfaceWidth = info.iSize.iWidth;
    TInt surfaceHeight = info.iSize.iHeight;

    // Width and Height
    if ((aStartPos.iX + aSize.iWidth) > surfaceWidth)
    {
        validRect = EFalse;
    }

    if ((aStartPos.iY + aSize.iHeight) > surfaceHeight)
    {
        validRect = EFalse;
    }

    // Starting position
    if ((aStartPos.iX < 0) || (aStartPos.iY < 0))
    {
        validRect = EFalse;
    }

    if (!validRect)
    {
        User::Leave(KErrOverflow);
    }

    if (info.iPixelFormat == EUidPixelFormatRGB_565)
    {   //2 bytes per pixel
        if ( info.iSize.iWidth*2>info.iStride)
        {
            User::Leave(KErrOverflow);
        }

        TInt offset;
        User::LeaveIfError(iManager.GetBufferOffset(aSurface, 0, offset));
        TUint16* ptr = reinterpret_cast<TUint16*>(surfacePtr + offset);

        // Fill the rectangle
        TInt yPos = aStartPos.iY;
        TInt xPos = aStartPos.iX;
        for (TInt yy = 0; yy < aSize.iHeight; ++yy)
        {
            ptr = reinterpret_cast<TUint16*>(surfacePtr + (yPos*info.iStride));
            for (TInt xx = 0; xx < aSize.iWidth; ++xx)
            {
                ptr[xPos] = color;
                xPos++;
            }
            xPos = aStartPos.iX;
            yPos++;
        }
    }
    else
    {
        if ( info.iSize.iWidth*4>info.iStride)
        {
            User::Leave(KErrOverflow);
        }

        TInt offset;
        User::LeaveIfError(iManager.GetBufferOffset(aSurface, 0, offset));
        TUint32* ptr = reinterpret_cast<TUint32*>(surfacePtr + offset);

        // Fill the rectangle
        TInt yPos = aStartPos.iY;
        TInt xPos = aStartPos.iX;
        for (TInt yy = 0; yy < aSize.iHeight; ++yy)
        {
            ptr = reinterpret_cast<TUint32*>(surfacePtr+(yPos*info.iStride));
            for (TInt xx = 0; xx < aSize.iWidth; ++xx)
            {
                ptr[xPos] = color;
                xPos++;
            }
            xPos = aStartPos.iX;
            yPos++;
        }
    }
    CleanupStack::PopAndDestroy(&chunk);
}
Color RenderThemeSymbian::platformActiveSelectionForegroundColor() const
{
    TRgb c = CEikonEnv::Static()->Color(EColorControlHighlightText);
    return Color(c.Red(),c.Green(),c.Blue());
}
Пример #30
0
void tst_QVolatileImage::bitmap()
{
#ifdef Q_OS_SYMBIAN
    CFbsBitmap *bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(100, 50), EColor64K) == KErrNone);
    QVolatileImage bmpimg(bmp);
    CFbsBitmap *dupbmp = static_cast<CFbsBitmap *>(bmpimg.duplicateNativeImage());
    QVERIFY(dupbmp);
    QVERIFY(dupbmp != bmp);
    QCOMPARE(dupbmp->DataAddress(), bmp->DataAddress());
    delete dupbmp;
    delete bmp;
    bmpimg.beginDataAccess();
    qMemSet(bmpimg.bits(), 0, bmpimg.byteCount());
    qMemSet(bmpimg.bits(), 1, bmpimg.bytesPerLine() * bmpimg.height());
    bmpimg.endDataAccess();

    // Test bgr->rgb conversion in case of EColor16M.
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16M) == KErrNone);
    bmp->BeginDataAccess();
    TUint32 *addr = bmp->DataAddress();
    uint rgb = QColor(10, 20, 30).rgb();
    qMemCopy(bmp->DataAddress(), &rgb, 3);
    bmp->EndDataAccess();
    TRgb symrgb;
    bmp->GetPixel(symrgb, TPoint(0, 0));
    QVERIFY(symrgb.Red() == 10 && symrgb.Green() == 20 && symrgb.Blue() == 30);
    bmpimg = QVolatileImage(bmp);
    QVERIFY(bmpimg.toImage().pixel(0, 0) == rgb);
    // check if there really was a conversion
    bmp->BeginDataAccess();
    bmpimg.beginDataAccess();
    qMemCopy(&rgb, bmpimg.constBits(), 3);
    uint rgb2 = rgb;
    qMemCopy(&rgb2, bmp->DataAddress(), 3);
    QVERIFY(rgb != rgb2);
    bmpimg.endDataAccess(true);
    bmp->EndDataAccess(true);
    delete bmp;

    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EGray2) == KErrNone);
    bmpimg = QVolatileImage(bmp); // inverts pixels, but should do it in place
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    QCOMPARE(bmpimg.format(), QImage::Format_MonoLSB);
    bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied);
    QVERIFY(bmpimg.constBits() != (const uchar *) bmp->DataAddress());
    QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied);
    delete bmp;

    // The following two formats must be optimal always.
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16MAP) == KErrNone);
    bmpimg = QVolatileImage(bmp);
    QCOMPARE(bmpimg.format(), QImage::Format_ARGB32_Premultiplied);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    bmpimg.ensureFormat(QImage::Format_ARGB32_Premultiplied);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    delete bmp;
    bmp = new CFbsBitmap;
    QVERIFY(bmp->Create(TSize(101, 89), EColor16MU) == KErrNone);
    bmpimg = QVolatileImage(bmp);
    QCOMPARE(bmpimg.format(), QImage::Format_RGB32);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    bmpimg.ensureFormat(QImage::Format_RGB32);
    QCOMPARE(bmpimg.constBits(), (const uchar *) bmp->DataAddress());
    delete bmp;

#else
    QSKIP("CFbsBitmap is only available on Symbian, skipping bitmap test", SkipSingle);
#endif
}