Exemplo n.º 1
0
/**
Draws a stretched bitmap with or without a mask.

@param aUseMask set to ETrue to use a alpha mask. Normally used for 16MU display modes that do not store the alpha.
@param aSrcMode is the source display mode
@param aDstMode is the destination display mode
@param aSession is the windows server session
@param aWindow is a reference to the window
@param aGc is the graphics context of the window
@param aNumIterations is the number of iterations to run the test
*/
void CAlphaBlendTest::DoDrawBitmapL(TBool aUseMask, TDisplayMode aSrcMode, TDisplayMode aDstMode, RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc, TInt aNumIterations)
	{		
	const TSize bitmapSize = aWindow.Size();
	
	// Construct target bitmap.
	CFbsBitmap* bitmapTarget = CreateSoftwareBitmapLC(bitmapSize, aDstMode);
	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmapTarget);
	CleanupStack::PushL(bitmapDevice);
	
	// Construct GC.
	CFbsBitGc* bitmapGc = NULL;
	User::LeaveIfError(bitmapDevice->CreateContext(bitmapGc));
	CleanupStack::PushL(bitmapGc);
	
	// Construct source bitmap.	
	TSize smallerSize(bitmapSize.iWidth/2,  bitmapSize.iHeight/2);
	CFbsBitmap* source = CreateSoftwareBitmapLC(smallerSize, aSrcMode);
	VerticalGradientAlphaL(source, TRgb(0x00000000), TRgb(0xffffffff));	
	CFbsBitmap* sourceAlpha = CreateSoftwareBitmapLC(smallerSize, EGray256);	// match size to src
	VerticalGradientAlphaL(sourceAlpha, TRgb(0x01010101), TRgb(0xfefefefe));
		
	bitmapGc->SetBrushStyle(CGraphicsContext::ENullBrush);
	bitmapGc->SetBrushColor(TRANSPARENT_BLACK);
	bitmapGc->Clear();
	bitmapGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
	aGc->Activate(aWindow);
	TPoint point(0,0);
	bitmapGc->BitBlt(point, bitmapTarget);
	aGc->Deactivate();
	aSession.Flush();

	TBuf <20> testName;
	if (!aUseMask)
		{
		testName=_L("DrawBitmap");
		iProfiler->InitResults();
		for(int i=0; i<aNumIterations; i++)
			{
			bitmapGc->DrawBitmap(TRect(point, bitmapSize), source);
			iProfiler->MarkResultSetL();
			}
		}
	else
		{
		testName=_L("DrawBitmapMasked");
		iProfiler->InitResults();
		for(int i=0; i<aNumIterations; i++)
			{
			bitmapGc->DrawBitmapMasked(TRect(point, bitmapSize), source,TRect(point, smallerSize), sourceAlpha, EFalse);
			iProfiler->MarkResultSetL();
			}
		}
	INFO_PRINTF4(_L("%S(Stretched) with src = %S, dst = %S"), &testName, &ColorModeName(aSrcMode), &ColorModeName(aDstMode));
	iProfiler->ResultsAnalysis(testName, 0, aSrcMode, aDstMode, aNumIterations);
	// copy up to screen for sanity check
	BitBlt(aSession, aWindow, aGc, *bitmapTarget);
	CleanupStack::PopAndDestroy(5, bitmapTarget);
	}
Exemplo n.º 2
0
//Preview selected file
void QxMainWindow::preview()
{
	QListWidgetItem *pCurrentItem = m_pFileListWidget->currentItem();
	if (!pCurrentItem)
	{
		return;
	}
	QString strFileName = pCurrentItem->text();
	QFile file(strFileName);
	if (!file.open(QIODevice::ReadOnly))
	{
		return;
	}
	QByteArray rawData = file.readAll();
	file.close();

	cv::Size imageSize(640,448);	//the image used to preview some of the characters
	const unsigned uCharacterWidth = 64;	//the width of each character in the preview image
	const unsigned uCharacterHeight = 64;	//the height of each character in the preview image
	cv::Size smallerSize(54, 54);; //to guarantee a certain distance among characters, characters are presented in smaller size than they are.
	const quint32 uInterval = 5;  //this should be calculated by (characterSize.width-smallerSize.width)/2;
	quint32 uCharacterPerRow = imageSize.width / uCharacterWidth;
	quint32 uCharacterPerCol = imageSize.height / uCharacterHeight;
	cv::Mat img = 255 * cv::Mat::ones(imageSize, CV_8UC1);

	quint32 uDecodedByteNum = 0;	//As the data is read as a stream, this variable tells how many bytes are processed already
	for (quint32 i = 0; i != uCharacterPerRow; ++i)
	{
		for (quint32 j = 0; j != uCharacterPerCol; ++j)
		{
			quint32 uWidth = uchar(rawData.at(6 + uDecodedByteNum)) + quint32(uchar(rawData.at(7 + uDecodedByteNum))) * (1 << 8);
			quint32 uHeight = uchar(rawData.at(8 + uDecodedByteNum)) + quint32(uchar(rawData.at(9 + uDecodedByteNum))) * (1 << 8);
			quint32 uArcLen = uWidth > uHeight ? uWidth : uHeight;
			uDecodedByteNum += 10;

			// save data to a pre-defined white image(all pixel values are pre-defined to be 255)
			cv::Mat characterImage = 255 * cv::Mat::ones(uArcLen, uArcLen, CV_8UC1);
			quint32 uHalfPadRowNum = (uArcLen - uHeight) / 2;
			quint32 uHalfPadColNum = (uArcLen - uWidth) / 2;
			for (quint32 row = uHalfPadRowNum; row != uHeight + uHalfPadRowNum; ++row)
			{
				uchar *pRow = characterImage.ptr<uchar>(row);
				for (quint32 col = uHalfPadColNum; col != uWidth + uHalfPadColNum; ++col)
				{
					pRow[col] = uchar(rawData.at(uDecodedByteNum++));
				}
			}
			// image normalization and filling
			cv::resize(characterImage, characterImage, smallerSize);
			cv::Range rowRange(j*uCharacterWidth, (j + 1)*uCharacterWidth);
			cv::Range colRange(i*uCharacterHeight, (i + 1)*uCharacterHeight);
			cv::Mat roi = img(rowRange, colRange);
			//cv::Mat::copyTo() calls cv::Mat::create(), which breaks the original image.
			//Also, cv::Mat::clone() fails to copy the values properly somehow, thus a pixelwise copy is implemented here.
            for (int row = 0; row != smallerSize.height; ++row)
			{
				uchar *pDst = roi.ptr<uchar>(row + uInterval);
				uchar *pSrc = characterImage.ptr<uchar>(row);
                for (int col = 0; col != smallerSize.width; ++col)
				{
					pDst[col + uInterval] = pSrc[col];
				}
			}
		}
	}

	QImage previewImage(img.data, img.cols, img.rows, img.step, QImage::Format_Grayscale8);
	QPixmap pixmap = QPixmap::fromImage(previewImage);
	m_pPreviewLabel->setPixmap(pixmap);
	m_pPreviewLabel->show();
}