os/graphics/fbs/fontandbitmapserver/trasterizer/test/trasterizer.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/trasterizer/test/trasterizer.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,549 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "trasterizer.h"
    1.20 +#include "testutils.h"
    1.21 +#include "examplerasterizer.h"
    1.22 +#include <fbs.h>
    1.23 +#include <gdi.h>
    1.24 +#include <s32mem.h>
    1.25 +#include <e32math.h>
    1.26 +#include <e32svr.h>
    1.27 +#include <u32hal.h>
    1.28 +
    1.29 +const TDisplayMode KDisplayModes[] = {EGray256, EColor64K, EColor16MU, EColor16MAP};
    1.30 +const TInt KNumDisplayModes = sizeof(KDisplayModes)/sizeof(KDisplayModes[0]);
    1.31 +const TRgb KStripeColours[3] = {TRgb(255,255,0), TRgb(255,0,255), TRgb(0,255,255)};
    1.32 +
    1.33 +CTRasterizer::CTRasterizer()
    1.34 +	{
    1.35 +	SetTestStepName(KTRasterizerStep);
    1.36 +	}
    1.37 +
    1.38 +/**
    1.39 +@SYMTestCaseID		
    1.40 +	GRAPHICS-FBSERV-RASTERIZER-001
    1.41 +
    1.42 +@SYMTestPriority
    1.43 +	High
    1.44 +
    1.45 +@SYMPREQ
    1.46 +	PREQ2096
    1.47 +
    1.48 +@SYMREQ
    1.49 +	REQ10860
    1.50 +	REQ10861 
    1.51 +	
    1.52 +@SYMTestCaseDesc
    1.53 +	Test that the example rasterizer dll "fbsrasterizer_test.dll" has been loaded.
    1.54 +
    1.55 +@SYMTestActions	
    1.56 +	On the emulator check that the rasterizer setting is "fbsrasterizer_test.dll".
    1.57 +	Get a pointer to the rasterizer.
    1.58 +
    1.59 +@SYMTestExpectedResults
    1.60 +	"fbsrasterizer_test.dll" has been loaded successfully
    1.61 +*/
    1.62 +void CTRasterizer::TestLoadRasterizerDllL()
    1.63 +	{
    1.64 +	INFO_PRINTF1(_L("TestLoadRasterizerDll"));
    1.65 +#ifdef __WINS__
    1.66 +	_LIT8(KTestRasterizerName, "fbsrasterizer_test.dll");
    1.67 +	TUint8* rasterizerSetting = NULL;
    1.68 +	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalStringProperty, (TAny*)"FBSRASTERIZER_DLL", &rasterizerSetting);
    1.69 +	TESTL(rasterizerSetting != NULL);
    1.70 +	TESTL(TPtrC8(rasterizerSetting).CompareF(KTestRasterizerName) == 0);
    1.71 +#endif
    1.72 +	GetExampleRasterizerL();
    1.73 +	}
    1.74 +
    1.75 +/**
    1.76 +@SYMTestCaseID		
    1.77 +	GRAPHICS-FBSERV-RASTERIZER-002
    1.78 +
    1.79 +@SYMTestPriority
    1.80 +	High
    1.81 +
    1.82 +@SYMPREQ
    1.83 +	PREQ2096
    1.84 +
    1.85 +@SYMREQ
    1.86 +	REQ10860
    1.87 +	REQ10861 
    1.88 +	
    1.89 +@SYMTestCaseDesc
    1.90 +	Test that a scanline retrieved from the example rasterizer is what we expect.
    1.91 +
    1.92 +@SYMTestActions		
    1.93 +	Create an extended bitmap and set its extended data to three colours followed by a TUint8.
    1.94 +	The example rasterizer interprets this data as the three colours in a tricolour flag drawn
    1.95 +	with either horizontal or vertical stripes depending on the value of the TUint8.	
    1.96 +	Draw a scanline of the extended bitmap by calling:
    1.97 +		- CFbsRasterizer::BeginBitmap()
    1.98 +		- CFbsRasterizer::ScanLine()
    1.99 +		- CFbsRasterizer::EndBitmap()
   1.100 +
   1.101 +@SYMTestExpectedResults
   1.102 +	The scan line returned by the example rasterizer should be exactly the same as the
   1.103 +	corresponding scanline in the test data.
   1.104 +*/
   1.105 +void CTRasterizer::TestScanLineL()
   1.106 +	{	
   1.107 +	TBuf<32> displayModeDes(TestUtils::DisplayModeToString(iDisplayMode)); 
   1.108 +	INFO_PRINTF2(_L("TestScanLine, display mode %S"), &displayModeDes);
   1.109 +	
   1.110 +	const TInt KNumBeginBitmapCalls = 5;
   1.111 +	
   1.112 +	// Get the example rasterizer
   1.113 +	GetExampleRasterizerL();	
   1.114 +	
   1.115 +	// Test for both stripe styles, 0 for vertical stripes and 1 for horizontal stripes
   1.116 +	for (TInt stripeStyle = 0; stripeStyle < 2; stripeStyle++)
   1.117 +		{
   1.118 +		if (stripeStyle == 0)
   1.119 +			{
   1.120 +			INFO_PRINTF1(_L("... Vertical stripes"));
   1.121 +			}
   1.122 +		else
   1.123 +			{
   1.124 +			INFO_PRINTF1(_L("... Horizontal stripes"));
   1.125 +			}
   1.126 +				
   1.127 +		const TSize sizeInPixels(64,32);
   1.128 +		CFbsBitmap* extendedBitmap = CreateExtendedBitmapLC(KStripeColours, stripeStyle, sizeInPixels);					
   1.129 +			
   1.130 +		// Begin scanline access to the extended bitmap
   1.131 +		CFbsRasterizer::TBitmapDesc bitmapDesc;
   1.132 +		TInt64 bitmapId = extendedBitmap->SerialNumber();
   1.133 +		bitmapDesc.iSizeInPixels = sizeInPixels;
   1.134 +		bitmapDesc.iDispMode = iDisplayMode;
   1.135 +		bitmapDesc.iDataType = KUidExampleExtendedBitmap;
   1.136 +		bitmapDesc.iData = extendedBitmap->DataAddress();
   1.137 +		bitmapDesc.iDataSize = extendedBitmap->DataSize();
   1.138 +		extendedBitmap->BeginDataAccess();
   1.139 +		// test calling BeginBitmap more than once as each additional call should just increment as reference count
   1.140 +		for (TInt i = 0; i < KNumBeginBitmapCalls; i++)
   1.141 +			{			
   1.142 +			iRasterizer->BeginBitmap(bitmapId, bitmapDesc, NULL);
   1.143 +			}				
   1.144 +		
   1.145 +		TInt scanlineLength;
   1.146 +		TPoint startPixel;
   1.147 +		TRgb bufferColour;
   1.148 +		// The width or height of a stripe in the tricolour flag that the extended bitmap rasterizer draws
   1.149 +		TInt stripeSize = (stripeStyle == 0) ? sizeInPixels.iWidth/3 : sizeInPixels.iHeight/3; 				
   1.150 +		for (TInt h = 0; h < sizeInPixels.iHeight; h++)
   1.151 +			{
   1.152 +			// Get a full scanline from the extended bitmap using the rasterizer	
   1.153 +			startPixel = TPoint(0, h);
   1.154 +			scanlineLength = sizeInPixels.iWidth;
   1.155 +			const TUint8* scanline = reinterpret_cast<const TUint8*>(iRasterizer->ScanLine(bitmapId, startPixel, scanlineLength));
   1.156 +			TESTL(scanline != NULL);								
   1.157 +			
   1.158 +			// Make sure each pixel in the scanline is the colour that we expect						
   1.159 +			TRgb compareColour;
   1.160 +			
   1.161 +			for (TInt w = 0; w < scanlineLength; w++)
   1.162 +				{																			
   1.163 +				if (((stripeStyle == 0) && (w < stripeSize)) 
   1.164 +					|| ((stripeStyle == 1) && (h < stripeSize)))
   1.165 +					{					
   1.166 +					compareColour = KStripeColours[0]; // left or top
   1.167 +					}
   1.168 +				else if (((stripeStyle == 0) && (w >= sizeInPixels.iWidth-stripeSize)) 
   1.169 +					|| ((stripeStyle == 1) && (h >= sizeInPixels.iHeight-stripeSize)))
   1.170 +					{
   1.171 +					compareColour = KStripeColours[2]; // right or bottom
   1.172 +					}
   1.173 +				else
   1.174 +					{
   1.175 +					compareColour = KStripeColours[1]; // middle
   1.176 +					}					
   1.177 +				bufferColour = ExtractRgb(scanline, w, iDisplayMode);
   1.178 +				if (((iDisplayMode != EGray256) && (bufferColour != compareColour))
   1.179 +					|| ((iDisplayMode == EGray256) && (bufferColour != TRgb::Gray256(compareColour.Gray256()))))
   1.180 +					{					
   1.181 +					INFO_PRINTF3(_L("Pixel comparison failed for pixel %d,%d"), w, h);
   1.182 +					TEST(EFalse);
   1.183 +					}			
   1.184 +				}							
   1.185 +			}
   1.186 +		
   1.187 +		// End scanline access to the extended bitmap
   1.188 +		for (TInt i = 0; i < KNumBeginBitmapCalls; i++)
   1.189 +			{
   1.190 +			iRasterizer->EndBitmap(bitmapId);			
   1.191 +			}
   1.192 +		extendedBitmap->EndDataAccess();
   1.193 +		
   1.194 +		// Clean up
   1.195 +		CleanupStack::Pop(1, extendedBitmap);
   1.196 +		}
   1.197 +	}
   1.198 +
   1.199 +/**
   1.200 +@SYMTestCaseID		
   1.201 +	GRAPHICS-FBSERV-RASTERIZER-003
   1.202 +
   1.203 +@SYMTestPriority
   1.204 +	High
   1.205 +
   1.206 +@SYMPREQ
   1.207 +	PREQ2096
   1.208 +
   1.209 +@SYMREQ
   1.210 +	REQ10860
   1.211 +	REQ10861 
   1.212 +	
   1.213 +@SYMTestCaseDesc
   1.214 +	Test that we can get scanlines from 3 extended bitmaps simultaneously using the example rasterizer.
   1.215 +
   1.216 +@SYMTestActions	
   1.217 +	Load a normal bitmap.	
   1.218 +	Create 3 extended bitmaps and set their extended data to be vertically striped colours.	
   1.219 +	Draw a scanline of each extended bitmap by calling:
   1.220 +		- CFbsRasterizer::BeginBitmap() for each extended bitmap
   1.221 +		- CFbsRasterizer::ScanLine() for each extended bitmap
   1.222 +		- CFbsRasterizer::EndBitmap() for each extended bitmap
   1.223 +	Compare the first pixel of each scanline and the last pixel of each scanline against the
   1.224 +	expected colour.
   1.225 +
   1.226 +@SYMTestExpectedResults
   1.227 +	The rasterizer should be able to handle rasterizing up to 3 extended bitmaps at once,
   1.228 +	all three scanlines should be returned with no errors.
   1.229 +	The colours compared should match exactly.
   1.230 +*/
   1.231 +void CTRasterizer::TestMultipleScanLinesL()
   1.232 +	{
   1.233 +	TBuf<32> displayModeDes(TestUtils::DisplayModeToString(iDisplayMode)); 
   1.234 +	INFO_PRINTF2(_L("TestMultipleScanLines, vertical stripes, display mode %S"), &displayModeDes);
   1.235 +	
   1.236 +	const TInt KNumBitmaps = 3;
   1.237 +	const TInt KBaseSize = 10;			
   1.238 +	RArray<CFbsBitmap*> bitmaps;
   1.239 +	CleanupClosePushL(bitmaps);	
   1.240 +	
   1.241 +	// Get the example rasterizer
   1.242 +	GetExampleRasterizerL();
   1.243 +	
   1.244 +	// Create the three differently sized extended bitmaps each coloured with vertical stripes 
   1.245 +	for (TInt i = 0; i < KNumBitmaps; i++)
   1.246 +		{
   1.247 +		const TSize KSizeInPixels = TSize(KBaseSize*(i+1), KBaseSize*(i+1));			
   1.248 +		CFbsBitmap* extendedBitmap = CreateExtendedBitmapLC(KStripeColours, EFalse, KSizeInPixels);		
   1.249 +		bitmaps.AppendL(extendedBitmap);			
   1.250 +		}
   1.251 +	
   1.252 +	// Begin scanline access to the extended bitmaps
   1.253 +	for (TInt i = 0; i < KNumBitmaps; i++)
   1.254 +		{
   1.255 +		bitmaps[i]->BeginDataAccess();
   1.256 +		
   1.257 +		CFbsRasterizer::TBitmapDesc bitmapDesc;
   1.258 +		TInt64 bitmapId = bitmaps[i]->SerialNumber();
   1.259 +		bitmapDesc.iSizeInPixels = bitmaps[i]->SizeInPixels();
   1.260 +		bitmapDesc.iDispMode = iDisplayMode;
   1.261 +		bitmapDesc.iDataType = KUidExampleExtendedBitmap;
   1.262 +		bitmapDesc.iData = bitmaps[i]->DataAddress();
   1.263 +		bitmapDesc.iDataSize = bitmaps[i]->DataSize();	
   1.264 +		iRasterizer->BeginBitmap(bitmapId, bitmapDesc, NULL);
   1.265 +		}
   1.266 +	
   1.267 +	// Get scanlines from each extended bitmap and check that the first and last pixel in each is the correct colour
   1.268 +	for (TInt h = 0; h < KBaseSize; h++)
   1.269 +		{
   1.270 +		for (TInt i = 0; i < KNumBitmaps; i++)
   1.271 +			{	
   1.272 +			const TUint8* scanline = reinterpret_cast<const TUint8*>(iRasterizer->ScanLine(bitmaps[i]->SerialNumber(), TPoint(0,h), KBaseSize*(i+1)));			
   1.273 +			TESTL(scanline != NULL);					
   1.274 +			
   1.275 +			// Test that the first pixel is the correct colour (the first pixel in each scanline should be KStripeColours[0]
   1.276 +			// as the bitmaps should have all been drawn with vertical stripes with the first stripe being KStripeColours[0]
   1.277 +			TRgb bufferColour = ExtractRgb(scanline, 0, iDisplayMode);			
   1.278 +			if (((iDisplayMode != EGray256) && (bufferColour != KStripeColours[0]))
   1.279 +				|| ((iDisplayMode == EGray256) && (bufferColour != TRgb::Gray256(KStripeColours[0].Gray256()))))	
   1.280 +				{
   1.281 +				INFO_PRINTF3(_L("Pixel comparison failed for bitmap %d, pixel 0,%d"), i, h);
   1.282 +				TEST(EFalse);
   1.283 +				}	
   1.284 +			// The last pixel should be KStripeColours[2]							
   1.285 +			bufferColour = ExtractRgb(scanline, (KBaseSize*(i+1))-1, iDisplayMode);
   1.286 +			if (((iDisplayMode != EGray256) && (bufferColour != KStripeColours[2]))
   1.287 +				|| ((iDisplayMode == EGray256) && (bufferColour != TRgb::Gray256(KStripeColours[2].Gray256()))))	
   1.288 +				{
   1.289 +				INFO_PRINTF4(_L("Pixel comparison failed for bitmap %d, pixel %d,%d"), i, (KBaseSize*(i+1))-1, h);
   1.290 +				TEST(EFalse);
   1.291 +				}
   1.292 +			}
   1.293 +		}
   1.294 +		
   1.295 +	// Unregister each extended bitmap
   1.296 +	for (TInt i = 0; i < KNumBitmaps; i++)
   1.297 +		{					
   1.298 +		iRasterizer->EndBitmap(bitmaps[i]->SerialNumber());
   1.299 +		bitmaps[i]->EndDataAccess();
   1.300 +		}
   1.301 +	
   1.302 +	// Cleanup
   1.303 +	CleanupStack::PopAndDestroy(KNumBitmaps+1);
   1.304 +	}
   1.305 +
   1.306 +/**
   1.307 +@SYMTestCaseID		
   1.308 +	GRAPHICS-FBSERV-RASTERIZER-004
   1.309 +
   1.310 +@SYMTestPriority
   1.311 +	High
   1.312 +
   1.313 +@SYMPREQ
   1.314 +	PREQ2096
   1.315 +
   1.316 +@SYMREQ
   1.317 +	REQ10860
   1.318 +	REQ10861 
   1.319 +	
   1.320 +@SYMTestCaseDesc
   1.321 +	Test that the rasterizer returns portions of scanline correctly
   1.322 +	when a region of interest is specified.
   1.323 +
   1.324 +@SYMTestActions	
   1.325 +	Create an extended bitmap.
   1.326 +	Rasterize it specifying a region of interest that has three regions that roughly
   1.327 +	form a squared off C shape.		
   1.328 +
   1.329 +@SYMTestExpectedResults
   1.330 +	Check that scanlines returned are correct in the specified region of interest.
   1.331 +	(Anything outside the region of interest does not matter).
   1.332 +*/
   1.333 +void CTRasterizer::TestRegionOfInterestL()
   1.334 +	{
   1.335 +	TBuf<32> displayModeDes(TestUtils::DisplayModeToString(iDisplayMode)); 
   1.336 +	INFO_PRINTF2(_L("TestRegionOfInterest, horizontal stripes, display mode %S"), &displayModeDes);
   1.337 +	
   1.338 +	// Get the example rasterizer
   1.339 +	GetExampleRasterizerL();	
   1.340 +	
   1.341 +	// Create an extended bitmap with horizontal stripes
   1.342 +	const TSize sizeInPixels(24,24);
   1.343 +	CFbsBitmap* extendedBitmap = CreateExtendedBitmapLC(KStripeColours, ETrue, sizeInPixels);		
   1.344 +	
   1.345 +	// Create a region of interest in the shape of a square with a hole in the middle
   1.346 +	TRegionFix<4> regionOfInterest;
   1.347 +	const TInt KStripeSize = sizeInPixels.iHeight/3;
   1.348 +	const TInt KEdgeOffset = 2;	
   1.349 +	regionOfInterest.AddRect(TRect(TPoint(KEdgeOffset,KEdgeOffset), TSize(sizeInPixels.iWidth-(KEdgeOffset*2),KStripeSize)));	// top of the square
   1.350 +	regionOfInterest.AddRect(TRect(TPoint(KEdgeOffset,sizeInPixels.iHeight-KEdgeOffset-KStripeSize), TSize(sizeInPixels.iWidth-(KEdgeOffset*2),KStripeSize)));	// bottom of the square
   1.351 +	regionOfInterest.AddRect(TRect(TPoint(KEdgeOffset,KEdgeOffset+KStripeSize), TSize(KStripeSize,sizeInPixels.iHeight-(KEdgeOffset*2)-(KStripeSize*2))));	// left of the square
   1.352 +	regionOfInterest.AddRect(TRect(TPoint(sizeInPixels.iWidth-KEdgeOffset-KStripeSize,KEdgeOffset+KStripeSize), TSize(KStripeSize,sizeInPixels.iHeight-(KEdgeOffset*2)-(KStripeSize*2)))); // right of the square		
   1.353 +	TEST(regionOfInterest.CheckError() == EFalse);
   1.354 +		
   1.355 +	// Begin scanline access to the extended bitmap
   1.356 +	CFbsRasterizer::TBitmapDesc bitmapDesc;
   1.357 +	TInt64 bitmapId = extendedBitmap->SerialNumber();
   1.358 +	bitmapDesc.iSizeInPixels = sizeInPixels;
   1.359 +	bitmapDesc.iDispMode = iDisplayMode;
   1.360 +	bitmapDesc.iDataType = KUidExampleExtendedBitmap;
   1.361 +	bitmapDesc.iData = extendedBitmap->DataAddress();
   1.362 +	bitmapDesc.iDataSize = extendedBitmap->DataSize();
   1.363 +	extendedBitmap->BeginDataAccess();
   1.364 +	iRasterizer->BeginBitmap(bitmapId, bitmapDesc, &regionOfInterest);	
   1.365 +	
   1.366 +	TInt scanlineLength;
   1.367 +	TPoint startPixel;
   1.368 +	TRgb bufferColour;
   1.369 +	 			
   1.370 +	for (TInt h = 0; h < sizeInPixels.iHeight; h++)
   1.371 +		{
   1.372 +		// Get scanlines from the extended bitmap using the rasterizer	
   1.373 +		startPixel = TPoint(0, h);
   1.374 +		scanlineLength = sizeInPixels.iWidth;
   1.375 +		const TUint8* scanline = reinterpret_cast<const TUint8*>(iRasterizer->ScanLine(bitmapId, startPixel, scanlineLength));
   1.376 +		TESTL(scanline != NULL);								
   1.377 +		
   1.378 +		// Make sure each pixel in the scanline is the colour that we expect					
   1.379 +		for (TInt w = 0; w < sizeInPixels.iWidth; w++)
   1.380 +			{										
   1.381 +			bufferColour = ExtractRgb(scanline, w, iDisplayMode);
   1.382 +			
   1.383 +			// Pixels that lie inside the region should be set to a flag stripe colour, pixels
   1.384 +			// outside of the region should be white			
   1.385 +			if (regionOfInterest.Contains(TPoint(w,h)))
   1.386 +				{				
   1.387 +				if (((iDisplayMode != EGray256) && (bufferColour != KStripeColours[h/KStripeSize]))
   1.388 +					|| ((iDisplayMode == EGray256) && (bufferColour != TRgb::Gray256(KStripeColours[h/KStripeSize].Gray256()))))
   1.389 +					{
   1.390 +					INFO_PRINTF3(_L("Pixel comparison failed for pixel %d,%d"), w, h);
   1.391 +					TEST(EFalse);
   1.392 +					}			
   1.393 +				}
   1.394 +			else
   1.395 +				{
   1.396 +				if (bufferColour != KRgbWhite)
   1.397 +					{
   1.398 +					INFO_PRINTF3(_L("Pixel comparison failed for pixel %d,%d"), w, h);
   1.399 +					TEST(EFalse);
   1.400 +					}
   1.401 +				}
   1.402 +			}		
   1.403 +		}
   1.404 +	
   1.405 +	// End scanline access to the extended bitmap	
   1.406 +	iRasterizer->EndBitmap(bitmapId);
   1.407 +	extendedBitmap->EndDataAccess();
   1.408 +	
   1.409 +	// Clean up
   1.410 +	CleanupStack::Pop(1, extendedBitmap);
   1.411 +	}
   1.412 +
   1.413 +/**
   1.414 +Override of base class pure virtual
   1.415 +Lists the tests to be run
   1.416 +*/
   1.417 +TVerdict CTRasterizer::doTestStepL()
   1.418 +	{
   1.419 +	TestLoadRasterizerDllL();
   1.420 +	
   1.421 +	// Tests that require testing in multiple display modes
   1.422 +	for (TInt i = 0; i < KNumDisplayModes; i++)
   1.423 +		{
   1.424 +		iDisplayMode = KDisplayModes[i];		
   1.425 +				
   1.426 +		TestScanLineL();
   1.427 +		TestMultipleScanLinesL();
   1.428 +		TestRegionOfInterestL();
   1.429 +		}
   1.430 +	
   1.431 +	return TestStepResult();
   1.432 +	}
   1.433 +
   1.434 +/** Helper function for getting a TRgb colour value from a buffer given a pixel offset and 
   1.435 +a display mode.
   1.436 +@param aBuffer A buffer to extract the TRgb from
   1.437 +@param aPixelOffset The pixel position in the buffer to extract the TRgb from
   1.438 +@param aDispMode The display mode of the buffer
   1.439 +@return The TRgb value found at the pixel position specified
   1.440 + */
   1.441 +TRgb CTRasterizer::ExtractRgb(const TUint8* aBuffer, TInt aPixelOffset, TDisplayMode aDispMode)
   1.442 +	{
   1.443 +	switch (aDispMode)
   1.444 +		{
   1.445 +	case EGray2:
   1.446 +		{
   1.447 +		TUint8 byte = *(aBuffer + (aPixelOffset >> 3));
   1.448 +		if (byte & (1 << (aPixelOffset & 7)))
   1.449 +			return KRgbWhite;
   1.450 +		return KRgbBlack;
   1.451 +		}
   1.452 +	case EGray4:
   1.453 +		{
   1.454 +		TUint8 byte = *(aBuffer + (aPixelOffset >> 2));
   1.455 +		byte >>= ((aPixelOffset & 3) << 1);
   1.456 +		return TRgb::Gray4(byte & 3);
   1.457 +		}
   1.458 +	case EGray16:
   1.459 +		{
   1.460 +		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
   1.461 +		if (aPixelOffset & 1)
   1.462 +			byte >>= 4;
   1.463 +		return TRgb::Gray16(byte & 0xf);
   1.464 +		}
   1.465 +	case EGray256:
   1.466 +		return TRgb::Gray256(*(aBuffer + aPixelOffset));
   1.467 +	case EColor16:
   1.468 +		{
   1.469 +		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
   1.470 +		if (aPixelOffset & 1)
   1.471 +			byte >>= 4;
   1.472 +		return TRgb::Color16(byte & 0xf);
   1.473 +		}
   1.474 +	case EColor256:
   1.475 +		return TRgb::Color256(*(aBuffer + aPixelOffset));
   1.476 +	case EColor4K:
   1.477 +		{
   1.478 +		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
   1.479 +		return TRgb::Color4K(doubleByte & 0xfff);
   1.480 +		}
   1.481 +	case EColor64K:
   1.482 +		{
   1.483 +		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
   1.484 +		return TRgb::Color64K(doubleByte);
   1.485 +		}
   1.486 +	case EColor16M:
   1.487 +		{
   1.488 +		aBuffer += aPixelOffset * 3;
   1.489 +		TInt value = *aBuffer++;
   1.490 +		value |= *aBuffer++ << 8;
   1.491 +		value |= *aBuffer << 16;
   1.492 +		return TRgb::Color16M(value);
   1.493 +		}
   1.494 +	case ERgb:
   1.495 +		return *(((TRgb*)aBuffer) + aPixelOffset);
   1.496 +	case EColor16MU:
   1.497 +		{
   1.498 +		// Note this is | with 0xFF000000 to match the example rasterizer which sets
   1.499 +		// the alpha to 0xFF when drawing using EColor16MU
   1.500 +		return TRgb::Color16MU((*(((TUint32*)aBuffer) + aPixelOffset)) | 0xFF000000);
   1.501 +		}
   1.502 +	case EColor16MA:
   1.503 +		{
   1.504 +		return TRgb::Color16MA(*(((TUint32*)aBuffer) + aPixelOffset));
   1.505 +		}	
   1.506 +	case EColor16MAP:
   1.507 +		{
   1.508 +		return TRgb::_Color16MAP(*(((TUint32*)aBuffer) + aPixelOffset));
   1.509 +		}	
   1.510 +	default:
   1.511 +		break;
   1.512 +		};
   1.513 +	return KRgbBlack;
   1.514 +	}
   1.515 +
   1.516 +/** Helper function for creating an extended bitmap. 
   1.517 +@param aColours A pointer to an array of three colours to use when creating the extended bitmap, 
   1.518 +these colours define the colours used when drawing the stripes in the extended bitmap.
   1.519 +@param aHorizontalStripe ETrue for horizontal stripes, EFalse for vertical stripes.
   1.520 +@param aSizeInPixels The size of the extended bitmap to create.
   1.521 +@return A pointer to a newly created extended bitmap that has been pushed on to the cleanup stack.
   1.522 + */
   1.523 +CFbsBitmap* CTRasterizer::CreateExtendedBitmapLC(const TRgb* aColours, TBool aHorizontalStripe, TSize aSizeInPixels)
   1.524 +	{	
   1.525 +	// Set up the buffer containing the three TRgb values and one TUint8 value that the rasterizer expects
   1.526 +	TInt dataSize = (sizeof(TRgb)*3) + sizeof(TUint8); // estimate the size to be written
   1.527 +	TUint8* data = new (ELeave)TUint8[dataSize];
   1.528 +	CleanupArrayDeletePushL(data);
   1.529 +	RMemWriteStream writeStream;
   1.530 +	writeStream.Open(data, dataSize);
   1.531 +	CleanupClosePushL(writeStream);		
   1.532 +	writeStream << aColours[0]; 		
   1.533 +	writeStream << aColours[1];		
   1.534 +	writeStream << aColours[2];
   1.535 +	TUint8 stripe = aHorizontalStripe; // EFalse is vertical stripes, ETrue is horizontal stripes
   1.536 +	writeStream << stripe;
   1.537 +	dataSize = writeStream.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
   1.538 +	CleanupStack::PopAndDestroy(&writeStream);					
   1.539 +
   1.540 +	CFbsBitmap* extendedBitmap = new(ELeave) CFbsBitmap;
   1.541 +		
   1.542 +	TInt err = extendedBitmap->CreateExtendedBitmap(aSizeInPixels, 
   1.543 +													iDisplayMode,
   1.544 +													KUidExampleExtendedBitmap,
   1.545 +													data,
   1.546 +													dataSize);
   1.547 +	CleanupStack::PopAndDestroy(data);
   1.548 +	CleanupStack::PushL(extendedBitmap);
   1.549 +	TESTL(err == KErrNone);
   1.550 +			
   1.551 +	return extendedBitmap;
   1.552 +	}