Ejemplo n.º 1
0
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;
	}
/**
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;
	}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
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
}
Ejemplo n.º 5
0
void CTTSprite::PointerCursorVisibleL()
    {
    if (!TestBase()->ConfigurationSupportsPointerEventTesting())
        {
        INFO_PRINTF1(_L("Test skipped because config does not support pointer event testing"));
        return;
        }
    
    // The pointer events need time to have an affect on the wserv
    static const TInt eventPropagationDelay = 100 * 1000; // 100 ms
    
    TInt screenNumber = TheClient->iScreen->GetScreenNumber();
    
    if(screenNumber != 0) // pointer events only supported on emulator screen 0
        {
        LOG_MESSAGE(_L("Pointer Cursor Visible only runs on screen 0"));
        return;
        }
    
    // set up objects used in test
    // 50x50 red rectangle colour 24
    CFbsBitmap bitmap;
    User::LeaveIfError(bitmap.Load(TEST_BITMAP_NAME, 8));
    
    TSize bmSize = bitmap.SizeInPixels();
    TPoint bmSample = TPoint(bmSize.iWidth / 2, bmSize.iHeight / 2);
    TRgb bmColour;
    bitmap.GetPixel(bmColour, bmSample);
    TEST(bmColour == KRgbRed);

    // single window, size of screen
    RWindow win(TheClient->iWs);
    User::LeaveIfError(win.Construct(*TheClient->iGroup->GroupWin(),1));
    win.Activate();

    // setup cursor mode
    TheClient->iWs.SetPointerCursorMode(EPointerCursorWindow);
    
    // setup cursor to contain single 50x50 red bitmap
    RWsPointerCursor iCursor1 = RWsPointerCursor(TheClient->iWs);
    TSpriteMember member;
    SetUpMember(member);
    member.iBitmap=&bitmap;
    User::LeaveIfError(iCursor1.Construct(0));
    User::LeaveIfError(iCursor1.AppendMember(member));
    User::LeaveIfError(iCursor1.Activate());
    win.SetCustomPointerCursor(iCursor1);
    iCursor1.UpdateMember(0);

    // draw a green rect, size of screen as defined background and wait till it is rendered
    win.BeginRedraw();
    TheGc->Activate(win);
    TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
    TheGc->SetBrushColor(KRgbGreen);
    TSize wSize = win.Size();
    TheGc->DrawRect(TRect(TPoint(0,0), wSize));
    TheGc->Deactivate();
    win.EndRedraw();
    TheClient->iWs.Finish();
    
    // #### do test ####
    // define locations of simulated pointer events and sample positions of where we expect to see the cursor
    // The cursor will be moved and a check will be made to see if this has actually happened
    
    TPoint pos1(wSize.iWidth / 2, wSize.iHeight / 2); // top left of cursor at centre screen
    TPoint sample1(pos1 + bmSample); // centre of sprite at pos1
    TPoint pos2 = pos1 - bmSize; // bottom right of cursor at centre screen
    TPoint sample2 = pos2 + bmSample;  // centre of sprite at pos2

    TRgb pixel;
    
    // check initial state of screen at both sample positions
    TheClient->iScreen->GetPixel(pixel, sample1);
    TEST(pixel == KRgbGreen);

    TheClient->iScreen->GetPixel(pixel, sample2);
    TEST(pixel == KRgbGreen);
    
    TRawEvent e; // to simulate pointer events

    // simulate button 1 down event at pos1
    e.Set(TRawEvent::EButton1Down, pos1.iX, pos1.iY);
    e.SetDeviceNumber(screenNumber);
    UserSvr::AddEvent(e);

    User::After(eventPropagationDelay);
    
    // check red cursor visible on top of background
    TheClient->iScreen->GetPixel(pixel, sample1);
    TEST(pixel == KRgbRed);
    
    // simulate button 1 up event
    e.Set(TRawEvent::EButton1Up, pos1.iX, pos1.iY);
    UserSvr::AddEvent(e);
    User::After(eventPropagationDelay);
    
    // Move cursor away to pos2 
    e.Set(TRawEvent::EButton1Down, pos2.iX, pos2.iY);
    e.SetDeviceNumber(screenNumber);
    UserSvr::AddEvent(e);
    
    User::After(eventPropagationDelay);
    
    // check cursor has left this position ...
    TheClient->iScreen->GetPixel(pixel, sample1);
    TEST(pixel == KRgbGreen);
    // and arrived at the correct place
    TheClient->iScreen->GetPixel(pixel, sample2);
    TEST(pixel == KRgbRed);

    // simulate button 1 up event
    e.Set(TRawEvent::EButton1Up, pos2.iX, pos2.iY);
    UserSvr::AddEvent(e);
    User::After(eventPropagationDelay);
    
    // remove the cursor
    win.ClearPointerCursor();
    User::After(eventPropagationDelay);
    
    // check it has gone
    TheClient->iScreen->GetPixel(pixel, sample2);
    TEST(pixel == KRgbGreen);
    
    // #### clean up ####
    iCursor1.Close();
    win.Close();
    }
void S60ImageUtil::calculateVisibleRect(Image* aImage)
{
   if (aImage->iHasMask) {
      CFbsBitmap* mask = aImage->GetMask();
      TInt xmin = aImage->iWidth;
      TInt xmax = 0;
      TInt ymin = aImage->iHeight;
      TInt ymax = 0;
#if defined USE_AKN_LIB
      //Iterating the pixels with GetPixel() works for sure on all symbian,
      //but it's pretty slow and we have to look at every one pixel.
      //On a 800 x 800 image we do 640 000 GetPixel() iterations.
      TRgb color;
      TRgb white(255, 255, 255);
      for (TInt y = 0; y < aImage->iHeight; y++) {
         for (TInt x = 0; x < aImage->iWidth; x++) {
            mask->GetPixel(color, TPoint(x, y));
            if (color == white) {
               if (xmin > x) {
                  xmin = x;
               }
               if (xmax < x) {
                  xmax = x;
               }
               if (ymin > y) {
                  ymin = y;
               }
               if (ymax < y) {
                  ymax = y;
               }
            }
         }
      }
#else
      //Iterating the pixels by hand in memory probably works on all symbian,
      //it's much faster since we look at 8 pixels at a time, 
      //It needs some testing and verification.
      //On a 800 x 800 image we do roughly 83 000 iterations.
      TDisplayMode dMode = mask->DisplayMode();
      if (dMode == EGray2) {
# ifndef NAV2_CLIENT_SERIES60_V1
         mask->LockHeap();
# endif
         TUint32* imgPtr = mask->DataAddress();
         TSize imgSize = mask->SizeInPixels();
         TInt imgByteWidth = imgSize.iWidth >> 3;
         TInt imgBitsLeft = imgSize.iWidth % 8;
         TInt lineLength = CFbsBitmap::ScanLineLength(imgSize.iWidth, dMode);
         TUint8* pCurrByteLine = (TUint8*) imgPtr;
         TUint8 currByte;
         TInt currXPixelOffset;
         TInt currXPixel;
         for (TInt y = 0; y < imgSize.iHeight; y++) {
            for (TInt x = 0; x < imgByteWidth; x++) {
               currByte = pCurrByteLine[x];
               //If currByte is != 0, it contains at least one white pixel.
               if (currByte) {
                  if (ymin > y) {
                     ymin = y;
                  }
                  if (ymax < y) {
                     ymax = y;
                  }
                  currXPixelOffset = x << 3;
                  //Check if this byte of pixels might contain xmin or xmax.
                  if ((currXPixelOffset < xmin) || 
                      ((currXPixelOffset + 7) > xmax)) {
                     for (TInt b = 0; b < 8; b++) {
                        //Some of the 8 pixels in the byte are visible.
                        //Find which ones that mather for the x-axis.
                        if  (currByte & (1 << b)) {
                           currXPixel = currXPixelOffset + b;
                           if (xmin > currXPixel) {
                              xmin = currXPixel;
                           }
                           if (xmax < currXPixel) {
                              xmax = currXPixel;
                           }
                        }
                     }
                  }
               }
            }
            //Here we take care of bit padded bytes when the
            //image width is not evenly dividable by a byte.
            if (imgBitsLeft != 0) {
               currByte = pCurrByteLine[imgByteWidth];
               currXPixelOffset = imgByteWidth << 3;
               for (TInt b = 0; b < imgBitsLeft; b++) {
                  if  (currByte & (1 << b)) {
                     currXPixel = currXPixelOffset + b;
                     if (xmax < currXPixel) {
                        xmax = currXPixel;
                     }
                  }
               }
            }
            //Move to next line in image.
            pCurrByteLine = pCurrByteLine + lineLength;
         }
      }