graphicsdeviceinterface/directgdiadaptation/swsrc/pixelutil.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <graphics/lookuptable.h>
       
    17 #include <graphics/blendingalgorithms.h>
       
    18 
       
    19 #include "pixelutil.h"
       
    20 #include "directgdiadapter.h"
       
    21 #include "directgditypes.h"
       
    22 
       
    23 TBool PixelFormatUtil::HasAlpha(TUidPixelFormat aPixelFormat)
       
    24 	{
       
    25 	const TBool hasAlpha = 
       
    26 		// short circuit format equivalent to legacy TDisplayMode with alpha channel
       
    27 		aPixelFormat == EUidPixelFormatARGB_8888 ||
       
    28 		aPixelFormat == EUidPixelFormatARGB_8888_PRE ||
       
    29 
       
    30 		aPixelFormat == EUidPixelFormatBGRA_8888 ||
       
    31 		aPixelFormat == EUidPixelFormatABGR_8888 ||
       
    32 		aPixelFormat == EUidPixelFormatABGR_8888_PRE ||
       
    33 		aPixelFormat == EUidPixelFormatBGRA_8888_PRE ||
       
    34 		aPixelFormat == EUidPixelFormatARGB_2101010 ||
       
    35 		aPixelFormat == EUidPixelFormatABGR_2101010 ||
       
    36 		aPixelFormat == EUidPixelFormatARGB_1555 ||
       
    37 		aPixelFormat == EUidPixelFormatARGB_4444 ||
       
    38 		aPixelFormat == EUidPixelFormatARGB_8332 ||
       
    39 		aPixelFormat == EUidPixelFormatBGRA_5551 ||
       
    40 		aPixelFormat == EUidPixelFormatBGRA_4444 ||
       
    41 		aPixelFormat == EUidPixelFormatAP_88 ||
       
    42 		aPixelFormat == EUidPixelFormatA_8;
       
    43 	
       
    44 	return hasAlpha;
       
    45 	}
       
    46 
       
    47 TUidPixelFormat PixelFormatUtil::ConvertToPixelFormat(TDisplayMode aDisplayMode)
       
    48 	{
       
    49 	switch (aDisplayMode)
       
    50 		{
       
    51 		case EGray2:
       
    52 			return EUidPixelFormatL_1;
       
    53 		case EGray4:
       
    54 			return EUidPixelFormatL_2;
       
    55 		case EGray16:
       
    56 			return EUidPixelFormatL_4;
       
    57 		case EGray256:
       
    58 			return EUidPixelFormatL_8;
       
    59 		case EColor16:
       
    60 			return EUidPixelFormatP_4;
       
    61 		case EColor256:
       
    62 			return EUidPixelFormatP_8;
       
    63 		case EColor4K:
       
    64 			return EUidPixelFormatXRGB_4444;
       
    65 		case EColor64K:
       
    66 			return EUidPixelFormatRGB_565;
       
    67 		case EColor16M:
       
    68 			return EUidPixelFormatRGB_888;		
       
    69 		case EColor16MU:
       
    70 			return EUidPixelFormatXRGB_8888;
       
    71 		case EColor16MA:
       
    72 			return EUidPixelFormatARGB_8888;
       
    73 		case EColor16MAP:
       
    74 			return EUidPixelFormatARGB_8888_PRE;
       
    75 		default:
       
    76 			return EUidPixelFormatUnknown;
       
    77 		};	
       
    78 	}
       
    79 
       
    80 TDisplayMode PixelFormatUtil::ConvertToDisplayMode(TUidPixelFormat aPixelFormat)
       
    81 	{
       
    82 	switch (aPixelFormat)	
       
    83 		{
       
    84 		case EUidPixelFormatL_1:
       
    85 			return EGray2;
       
    86 		case EUidPixelFormatL_2:
       
    87 			return EGray4;
       
    88 		case EUidPixelFormatL_4:
       
    89 			return EGray16;
       
    90 		case EUidPixelFormatL_8:
       
    91 			return EGray256;
       
    92 		case EUidPixelFormatP_4:
       
    93 			return EColor16;
       
    94 		case EUidPixelFormatP_8:
       
    95 			return EColor256;
       
    96 		case EUidPixelFormatXRGB_4444:
       
    97 			return EColor4K;
       
    98 		case EUidPixelFormatRGB_565:
       
    99 			return EColor64K;
       
   100 		case EUidPixelFormatRGB_888:
       
   101 			return EColor16M;
       
   102 		case EUidPixelFormatXRGB_8888:
       
   103 			return EColor16MU;
       
   104 		case EUidPixelFormatARGB_8888:
       
   105 			return EColor16MA;
       
   106 		case EUidPixelFormatARGB_8888_PRE:
       
   107 			return EColor16MAP;
       
   108 		default:
       
   109 			return ENone;
       
   110 		}
       
   111 	}
       
   112 
       
   113 TInt PixelFormatUtil::BitsPerPixel(TUidPixelFormat aPixelFormat)
       
   114 	{
       
   115 	switch (aPixelFormat)
       
   116 		{
       
   117 		case EUidPixelFormatP_1:
       
   118 		case EUidPixelFormatL_1:
       
   119 			return 1;
       
   120 		case EUidPixelFormatP_2:
       
   121 		case EUidPixelFormatL_2:
       
   122 			return 2;
       
   123 		case EUidPixelFormatP_4:
       
   124 		case EUidPixelFormatL_4:
       
   125 			return 4;
       
   126 		case EUidPixelFormatRGB_332:
       
   127 		case EUidPixelFormatA_8:
       
   128 		case EUidPixelFormatBGR_332:
       
   129 		case EUidPixelFormatP_8:
       
   130 		case EUidPixelFormatL_8:
       
   131 			return 8;
       
   132 		case EUidPixelFormatRGB_565:
       
   133 		case EUidPixelFormatBGR_565:
       
   134 		case EUidPixelFormatARGB_1555:
       
   135 		case EUidPixelFormatXRGB_1555:
       
   136 		case EUidPixelFormatARGB_4444:
       
   137 		case EUidPixelFormatARGB_8332:
       
   138 		case EUidPixelFormatBGRX_5551:
       
   139 		case EUidPixelFormatBGRA_5551:
       
   140 		case EUidPixelFormatBGRA_4444:
       
   141 		case EUidPixelFormatBGRX_4444:
       
   142 		case EUidPixelFormatAP_88:
       
   143 		case EUidPixelFormatXRGB_4444:
       
   144 		case EUidPixelFormatXBGR_4444:
       
   145 			return 16;
       
   146 		case EUidPixelFormatBGR_888:
       
   147 		case EUidPixelFormatRGB_888:
       
   148 			return 24;
       
   149 		case EUidPixelFormatXRGB_8888:
       
   150 		case EUidPixelFormatBGRX_8888:
       
   151 		case EUidPixelFormatXBGR_8888:
       
   152 		case EUidPixelFormatBGRA_8888:
       
   153 		case EUidPixelFormatARGB_8888:
       
   154 		case EUidPixelFormatABGR_8888:
       
   155 		case EUidPixelFormatARGB_8888_PRE:
       
   156 		case EUidPixelFormatABGR_8888_PRE:
       
   157 		case EUidPixelFormatBGRA_8888_PRE:
       
   158 		case EUidPixelFormatARGB_2101010:
       
   159 		case EUidPixelFormatABGR_2101010:
       
   160 			return 32;
       
   161 		default:
       
   162 			GRAPHICS_ASSERT_DEBUG(EFalse, EDirectGdiPanicInvalidDisplayMode);
       
   163 			return 0;
       
   164 		};	
       
   165 	}
       
   166 
       
   167 /**
       
   168 Create pixel buffer reader from a given pixel buffer by specifying its buffer addres and properties.
       
   169 Supported format are:
       
   170 -EUidPixelFormatRGB_565
       
   171 -EUidPixelFormatXRGB_8888
       
   172 -EUidPixelFormatARGB_8888
       
   173 -EUidPixelFormatARGB_8888_PRE
       
   174 */
       
   175 TPixelBufferReader::TPixelBufferReader(const TUint32* aPixelBuffer, const TSize& aSize, TInt aStride, TUidPixelFormat aFormat):
       
   176 	iBuffer(aPixelBuffer),
       
   177 	iSize(aSize),
       
   178 	iStride(aStride),
       
   179 	iFormat(aFormat)
       
   180 	{
       
   181 	GRAPHICS_ASSERT_DEBUG(iBuffer && iStride!=0, EDirectGdiPanicInvalidBitmap);
       
   182 	GRAPHICS_ASSERT_DEBUG(iSize.iWidth!=0 && iSize.iHeight!=0, EDirectGdiPanicOutOfBounds);
       
   183 	GRAPHICS_ASSERT_DEBUG(
       
   184 		iFormat==EUidPixelFormatRGB_565 ||
       
   185 		iFormat==EUidPixelFormatXRGB_8888 ||
       
   186 		iFormat==EUidPixelFormatARGB_8888 ||
       
   187 		iFormat==EUidPixelFormatARGB_8888_PRE,
       
   188 		EDirectGdiPanicInvalidDisplayMode);
       
   189 	}
       
   190 
       
   191 /**
       
   192 Copies pixels into user buffer starting and ending based on the given read position and 
       
   193 read length (in pixels). Convert data into user pixel format if requested.
       
   194 Copying will be done forward or backward (from a given read position) based on read direction parameter.
       
   195 
       
   196 @pre	TPixelBufferReader object was constructed with valid pixel buffer and its properties.
       
   197 		Starting and ending read position is within the pixel buffer area.
       
   198 		Supported read format:
       
   199 			RGB_565
       
   200 			XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
       
   201 @post	Pixels copied into user buffer.
       
   202 */
       
   203 void TPixelBufferReader::GetScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
       
   204 		TUidPixelFormat aReadFormat, TReadDirection aReadDir) const
       
   205 	{
       
   206 	GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
       
   207 		aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
       
   208 	GRAPHICS_ASSERT_DEBUG(
       
   209 		aReadFormat==EUidPixelFormatRGB_565 ||
       
   210 		aReadFormat==EUidPixelFormatXRGB_8888 ||
       
   211 		aReadFormat==EUidPixelFormatARGB_8888 ||
       
   212 		aReadFormat==EUidPixelFormatARGB_8888_PRE,
       
   213 		EDirectGdiPanicInvalidDisplayMode);
       
   214 
       
   215 #ifdef _DEBUG
       
   216 	switch (aReadDir)
       
   217 		{
       
   218 		case EReadHorizontal:
       
   219 		GRAPHICS_ASSERT_DEBUG(aReadPos.iX+aReadLen<=iSize.iWidth, EDirectGdiPanicOutOfBounds);
       
   220 		break;
       
   221 
       
   222 		case EReadHorizontalReverse:
       
   223 		GRAPHICS_ASSERT_DEBUG(aReadPos.iX-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
       
   224 		break;
       
   225 		
       
   226 		case EReadVertical:
       
   227   		GRAPHICS_ASSERT_DEBUG(aReadPos.iY+aReadLen<=iSize.iHeight, EDirectGdiPanicOutOfBounds);
       
   228 		break;
       
   229 		
       
   230 		case EReadVerticalReverse:
       
   231   		GRAPHICS_ASSERT_DEBUG(aReadPos.iY-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
       
   232 		break;
       
   233 		}
       
   234 #endif
       
   235 
       
   236 	switch(aReadFormat)
       
   237 		{
       
   238 		case EUidPixelFormatRGB_565:
       
   239 			GetScanLineRGB_565(aReadBuf, aReadPos, aReadLen,  aReadDir);
       
   240 			break;
       
   241 		case EUidPixelFormatXRGB_8888:
       
   242 			GetScanLineXRGB_8888(aReadBuf, aReadPos, aReadLen,  aReadDir);
       
   243 			break;
       
   244 		case EUidPixelFormatARGB_8888:
       
   245 			GetScanLineARGB_8888(aReadBuf, aReadPos, aReadLen,  aReadDir);
       
   246 			break;
       
   247 		case EUidPixelFormatARGB_8888_PRE:
       
   248 			GetScanLineARGB_8888_PRE(aReadBuf, aReadPos, aReadLen,  aReadDir);
       
   249 			break;
       
   250 		default:
       
   251 			aReadBuf.SetLength(0);
       
   252 			break;
       
   253 		};
       
   254 	}
       
   255 
       
   256 /**
       
   257 Copies pixels into user buffer starting and ending based on the given read position and 
       
   258 read length (in pixels). Converts data into user pixel format and scales up or down depending
       
   259 on the specified parameters. Copying will be done forward or backward (from a given read position)
       
   260 based on read direction parameter.
       
   261 
       
   262 @pre	TPixelBufferReader object was constructed with valid pixel buffer and its properties.
       
   263 		Starting and ending read position is within the pixel buffer area.
       
   264 		Supported read format:
       
   265 			RGB_565
       
   266 			XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
       
   267 @post	Pixels copied into user buffer.
       
   268 */
       
   269 void TPixelBufferReader::GetScaledScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipPos,
       
   270 		TInt aClipLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
       
   271 		TReadDirection aReadDir) const
       
   272 	{
       
   273 	GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
       
   274 		aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
       
   275 
       
   276 	GRAPHICS_ASSERT_DEBUG(
       
   277 		aReadFormat==EUidPixelFormatRGB_565 ||
       
   278 		aReadFormat==EUidPixelFormatXRGB_8888 ||
       
   279 		aReadFormat==EUidPixelFormatARGB_8888 ||
       
   280 		aReadFormat==EUidPixelFormatARGB_8888_PRE,
       
   281 		EDirectGdiPanicInvalidDisplayMode);
       
   282 
       
   283 	if (aReadDir == EReadHorizontal || aReadDir == EReadHorizontalReverse)
       
   284 		{
       
   285 		GetScaledScanLineH(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		GetScaledScanLineV(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
       
   290 		}
       
   291 	}
       
   292 
       
   293 /**
       
   294 Gets pixel address in arbitrary position within the buffer
       
   295 */
       
   296 const TUint32* TPixelBufferReader::GetPixelAddr(const TPoint& aPos) const
       
   297 	{
       
   298 	const TUint32* slptr = GetScanLineAddr(aPos.iY);
       
   299 	return PixelFormatUtil::BitsPerPixel(iFormat)==32? slptr+aPos.iX : (TUint32*)((TUint16*)slptr+aPos.iX);
       
   300 	}
       
   301 
       
   302 /**
       
   303 Gets scanline address for a give row poisition
       
   304 */
       
   305 const TUint32* TPixelBufferReader::GetScanLineAddr(TInt aRow) const
       
   306 	{
       
   307 	return (iBuffer + (aRow * iStride >> 2));
       
   308 	}
       
   309 
       
   310 /**
       
   311 Copies from 16-bit src to 32-bit dest
       
   312 */
       
   313 void TPixelBufferReader::CopyFromRGB_565(TUint32* aDstPtr, const TUint16* aSrcPtr,
       
   314 		TInt aNumOfPixels, TInt aAdvance) const
       
   315 	{
       
   316 	const TUint16* lowAdd = Convert16to32bppLow();
       
   317 	const TUint32* highAdd = Convert16to32bppHigh();
       
   318 
       
   319 	while (aNumOfPixels--)
       
   320 		{
       
   321 		const TUint8 low = *aSrcPtr & 0xff;
       
   322 		const TUint8 high = *aSrcPtr >> 8;
       
   323 		*aDstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
   324 		
       
   325 		aSrcPtr += aAdvance;
       
   326 		}
       
   327 	}
       
   328 
       
   329 /**
       
   330 Calculates pixel position increment based on a given read direction and buffer pixel format.
       
   331 */
       
   332 TInt TPixelBufferReader::GetAdvance(TReadDirection aReadDir) const
       
   333 	{
       
   334 	TInt advance = 0;
       
   335 	// supported pixel buffer is either 16-bit or 32-bit
       
   336 	//
       
   337 	switch (aReadDir)
       
   338 		{
       
   339 		case EReadHorizontal:
       
   340 			advance = 1;
       
   341 			break;
       
   342 		case EReadHorizontalReverse:
       
   343 			advance = -1;
       
   344 			break;
       
   345 		case EReadVertical:
       
   346 			advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? iStride >> 1 : iStride >> 2;
       
   347 			break;
       
   348 		case EReadVerticalReverse:
       
   349 			advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? -(iStride >> 1) : -(iStride >> 2);
       
   350 			break;
       
   351 		}
       
   352 
       
   353 	return advance;
       
   354 	}
       
   355 
       
   356 /**
       
   357 Reads and converts scanline into RGB_565.
       
   358 */
       
   359 void TPixelBufferReader::GetScanLineRGB_565(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
       
   360 		TReadDirection aReadDir) const
       
   361 	{
       
   362 	// read as much as buffer can hold
       
   363 	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 1);
       
   364 	aReadBuf.SetLength(aReadLen << 1);
       
   365 
       
   366 	TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
       
   367 	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
       
   368 	TInt posX = aReadPos.iX;
       
   369 	const TInt advance = GetAdvance(aReadDir);
       
   370 
       
   371 	// supported pixel buffer:
       
   372 	// RGB_565
       
   373 	// XRGB_8888
       
   374 	// ARGB_8888
       
   375 	// ARGB_8888_PRE
       
   376 	//
       
   377 	switch (iFormat)		
       
   378 		{
       
   379 		case EUidPixelFormatRGB_565:
       
   380 			{
       
   381 			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
       
   382 			while (aReadLen--)
       
   383 				{
       
   384 				*dstPtr++ = *srcPtr;
       
   385 				srcPtr += advance;
       
   386 				}
       
   387 			}
       
   388 			break;
       
   389 
       
   390 		case EUidPixelFormatXRGB_8888:
       
   391 			{
       
   392 			const TUint32* srcPtr = scanLinePtr + posX;
       
   393 			while (aReadLen--)
       
   394 				{
       
   395 				*dstPtr++ = TUint16(TRgb::Color16MU(*srcPtr).Color64K());
       
   396 				srcPtr += advance;
       
   397 				}
       
   398 			}
       
   399 			break;
       
   400 
       
   401 		case EUidPixelFormatARGB_8888:
       
   402 			{
       
   403 			const TUint32* srcPtr = scanLinePtr + posX;
       
   404 			while (aReadLen--)
       
   405 				{
       
   406 				*dstPtr++ = TUint16(TRgb::Color16MA(*srcPtr).Color64K());
       
   407 				srcPtr += advance;
       
   408 				}
       
   409 			}
       
   410 			break;
       
   411 
       
   412 		case EUidPixelFormatARGB_8888_PRE:
       
   413 			{
       
   414 			const TUint32* srcPtr = scanLinePtr + posX;
       
   415 			while (aReadLen--)
       
   416 				{
       
   417 				*dstPtr++ = TUint16(TRgb::Color16MAP(*srcPtr).Color64K());
       
   418 				srcPtr += advance;
       
   419 				}
       
   420 			}
       
   421 			break;
       
   422 		}
       
   423 	}
       
   424 
       
   425 /**
       
   426 Reads and converts scanline into XRGB_8888.
       
   427 */
       
   428 void TPixelBufferReader::GetScanLineXRGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
       
   429 		TReadDirection aReadDir) const
       
   430 	{
       
   431 	// read as much as buffer can hold
       
   432 	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
       
   433 	aReadBuf.SetLength(aReadLen << 2);
       
   434 
       
   435 	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   436 	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
       
   437 	TInt posX = aReadPos.iX;
       
   438 	const TInt advance = GetAdvance(aReadDir);
       
   439 
       
   440 	// supported pixel buffer:
       
   441 	// RGB_565
       
   442 	// XRGB_8888
       
   443 	// ARGB_8888
       
   444 	// ARGB_8888_PRE
       
   445 	//
       
   446 	switch (iFormat)
       
   447 		{
       
   448 		case EUidPixelFormatRGB_565:
       
   449 			{
       
   450 			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
       
   451 			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
       
   452 			}
       
   453 			break;
       
   454 
       
   455 		case EUidPixelFormatXRGB_8888:
       
   456 		case EUidPixelFormatARGB_8888:
       
   457 			{
       
   458 			const TUint32* srcPtr = scanLinePtr + posX;
       
   459 			while (aReadLen--)
       
   460 				{
       
   461 				*dstPtr++ = *srcPtr;
       
   462 				srcPtr += advance;
       
   463 				}
       
   464 			}
       
   465 			break;
       
   466 
       
   467 		case EUidPixelFormatARGB_8888_PRE:
       
   468 			{
       
   469 			const TUint32* srcPtr = scanLinePtr + posX;
       
   470 			const TUint16* normTable = PtrTo16BitNormalisationTable();
       
   471 			while(aReadLen--)
       
   472 				{
       
   473 				*dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
       
   474 				srcPtr += advance;
       
   475 				}			
       
   476 			}
       
   477 			break;
       
   478 		}
       
   479 	}
       
   480 
       
   481 /**
       
   482 Reads and converts scanline into ARGB_8888.
       
   483 */
       
   484 void TPixelBufferReader::GetScanLineARGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
       
   485 		TReadDirection aReadDir) const
       
   486 	{
       
   487 	// read as much as buffer can hold
       
   488 	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
       
   489 	aReadBuf.SetLength(aReadLen << 2);
       
   490 
       
   491 	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   492 	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
       
   493 	TInt posX = aReadPos.iX;
       
   494 	const TInt advance = GetAdvance(aReadDir);
       
   495 
       
   496 	// supported pixel buffer:
       
   497 	// RGB_565
       
   498 	// XRGB_8888
       
   499 	// ARGB_8888
       
   500 	// ARGB_8888_PRE
       
   501 	//
       
   502 	switch (iFormat)
       
   503 		{
       
   504 		case EUidPixelFormatRGB_565:
       
   505 			{
       
   506 			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
       
   507 			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
       
   508 			}
       
   509 			break;
       
   510 
       
   511 		case EUidPixelFormatXRGB_8888:
       
   512 			{
       
   513 			const TUint32* srcPtr = scanLinePtr + posX;
       
   514 			while (aReadLen--)
       
   515 				{
       
   516 				*dstPtr++ = 0xff000000 | *srcPtr;
       
   517 				srcPtr += advance;
       
   518 				}
       
   519 			}
       
   520 			break;
       
   521 		
       
   522 		case EUidPixelFormatARGB_8888:
       
   523 			{
       
   524 			const TUint32* srcPtr = scanLinePtr + posX;
       
   525 			while (aReadLen--)
       
   526 				{
       
   527 				*dstPtr++ = *srcPtr;
       
   528 				srcPtr += advance;
       
   529 				}
       
   530 			}
       
   531 			break;
       
   532 
       
   533 		case EUidPixelFormatARGB_8888_PRE:
       
   534 			{
       
   535 			const TUint32* srcPtr = scanLinePtr + posX;
       
   536 			const TUint16* normTable = PtrTo16BitNormalisationTable();
       
   537 			while(aReadLen--)
       
   538 				{
       
   539 				*dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
       
   540 				srcPtr += advance;
       
   541 				}			
       
   542 			}
       
   543 			break;
       
   544 		}
       
   545 	}
       
   546 
       
   547 /**
       
   548 Read and convert scanline into ARGB_8888_PRE.
       
   549 */
       
   550 void TPixelBufferReader::GetScanLineARGB_8888_PRE(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
       
   551 		TReadDirection aReadDir) const
       
   552 	{
       
   553 	// read as much as buffer can hold
       
   554 	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
       
   555 	aReadBuf.SetLength(aReadLen << 2);
       
   556 
       
   557 	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   558 	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
       
   559 	TInt posX = aReadPos.iX;
       
   560 	const TInt advance = GetAdvance(aReadDir);
       
   561 
       
   562 	// supported pixel buffer:
       
   563 	// RGB_565
       
   564 	// XRGB_8888
       
   565 	// ARGB_8888
       
   566 	// ARGB_8888_PRE
       
   567 	//
       
   568 	switch (iFormat)
       
   569 		{
       
   570 		case EUidPixelFormatRGB_565:
       
   571 			{
       
   572 			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
       
   573 			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
       
   574 			}
       
   575 			break;
       
   576 
       
   577 		case EUidPixelFormatXRGB_8888:
       
   578 			{
       
   579 			const TUint32* srcPtr = scanLinePtr + posX;
       
   580 			while (aReadLen--)
       
   581 				{
       
   582 				*dstPtr++ = 0xff000000 | *srcPtr;
       
   583 				srcPtr += advance;
       
   584 				}
       
   585 			}
       
   586 			break;
       
   587 
       
   588 		case EUidPixelFormatARGB_8888:
       
   589 			{
       
   590 			const TUint32* srcPtr = scanLinePtr + posX;
       
   591 			while (aReadLen--)
       
   592 				{
       
   593 				TUint32 argb = *srcPtr;
       
   594 				Convert2PMA(argb);
       
   595 				*dstPtr++ = argb;
       
   596 
       
   597 				srcPtr += advance;
       
   598 				}
       
   599 			}
       
   600 			break;
       
   601 
       
   602 		case EUidPixelFormatARGB_8888_PRE:
       
   603 			{
       
   604 			const TUint32* srcPtr = scanLinePtr + posX;
       
   605 			while (aReadLen--)
       
   606 				{
       
   607 				*dstPtr++ = *srcPtr;
       
   608 				srcPtr += advance;
       
   609 				}
       
   610 			}
       
   611 			break;
       
   612 		}
       
   613 	}
       
   614 
       
   615 /**
       
   616 Reads and scales pixels horizontally from either left or right. Converts to other pixel format if
       
   617 requested.
       
   618 */
       
   619 void TPixelBufferReader::GetScaledScanLineH(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
       
   620 		TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
       
   621 		TReadDirection aReadDir) const
       
   622 	{
       
   623 	// setup DDA for scaling in X direction, use read pos as starting point and move right or left
       
   624 	// depending on the read direction
       
   625 	//
       
   626 	TLinearDDA xScaler;
       
   627 	TPoint xPos(aReadPos.iX, 0);
       
   628 	const TPoint delta = aReadDir==EReadHorizontal? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
       
   629 	xScaler.Construct(xPos, xPos + delta, TLinearDDA::ELeft);
       
   630 
       
   631 	// jump to dest X position and return the corresponding src X position
       
   632 	xPos.iY = aClipDestPos;
       
   633 	if (aClipDestPos > 0)
       
   634 		{
       
   635 		xScaler.JumpToYCoord(xPos.iX, xPos.iY);
       
   636 		}
       
   637 	else
       
   638 		{
       
   639 		xScaler.NextStep(xPos);
       
   640 		}
       
   641 
       
   642 	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
       
   643 
       
   644 	// supported pixel buffer:
       
   645 	// RGB_565
       
   646 	// XRGB_8888
       
   647 	// ARGB_8888
       
   648 	// ARGB_8888_PRE
       
   649 
       
   650 	// supported read format
       
   651 	// RGB_565
       
   652 	// XRGB_8888
       
   653 	// ARGB_8888
       
   654 	// ARGB_8888_PRE
       
   655 
       
   656 	switch(aReadFormat)
       
   657 		{
       
   658 		case EUidPixelFormatRGB_565:
       
   659 			{
       
   660 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
       
   661 			aReadBuf.SetLength(aClipDestLen << 1);
       
   662 
       
   663 			TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
       
   664 			TUint16* dstLimit = dstPtr + aClipDestLen;
       
   665 			
       
   666 			switch (iFormat)
       
   667 				{
       
   668 				case EUidPixelFormatRGB_565:
       
   669 					{
       
   670 					const TUint16* srcPtr = (TUint16*) scanLinePtr;					
       
   671 					while(dstPtr < dstLimit)
       
   672 						{
       
   673 						*dstPtr++ = *(srcPtr + xPos.iX);
       
   674 						xScaler.NextStep(xPos);
       
   675 						}
       
   676 					}
       
   677 					break;
       
   678 
       
   679 				case EUidPixelFormatXRGB_8888:
       
   680 					{
       
   681 					const TUint32* srcPtr = scanLinePtr;
       
   682 					while (dstPtr < dstLimit)
       
   683 						{
       
   684 						*dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + xPos.iX)).Color64K());
       
   685 						xScaler.NextStep(xPos);
       
   686 						}
       
   687 					}
       
   688 					break;
       
   689 
       
   690 				case EUidPixelFormatARGB_8888:
       
   691 					{
       
   692 					const TUint32* srcPtr = scanLinePtr;
       
   693 					while (dstPtr < dstLimit)
       
   694 						{
       
   695 						*dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + xPos.iX)).Color64K());
       
   696 						xScaler.NextStep(xPos);
       
   697 						}
       
   698 					}
       
   699 					break;
       
   700 
       
   701 				case EUidPixelFormatARGB_8888_PRE:
       
   702 					{
       
   703 					const TUint32* srcPtr = scanLinePtr;
       
   704 					while (dstPtr < dstLimit)
       
   705 						{
       
   706 						*dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + xPos.iX)).Color64K());
       
   707 						xScaler.NextStep(xPos);
       
   708 						}
       
   709 					}
       
   710 					break;
       
   711 				}
       
   712 			}
       
   713 			break;
       
   714 
       
   715 		case EUidPixelFormatXRGB_8888:
       
   716 			{
       
   717 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
   718 			aReadBuf.SetLength(aClipDestLen << 2);
       
   719 
       
   720 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   721 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
   722 			
       
   723 			switch (iFormat)
       
   724 				{
       
   725 				case EUidPixelFormatRGB_565:
       
   726 					{
       
   727 					const TUint16* srcPtr = (TUint16*)scanLinePtr;
       
   728 
       
   729 					const TUint16* lowAdd = Convert16to32bppLow();
       
   730 					const TUint32* highAdd = Convert16to32bppHigh();
       
   731 
       
   732 					while (dstPtr < dstLimit)
       
   733 						{
       
   734 						TUint16 c = *(srcPtr + xPos.iX);
       
   735 						const TUint8 low = c & 0xff;
       
   736 						const TUint8 high = c >> 8;
       
   737 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
   738 						
       
   739 						xScaler.NextStep(xPos);
       
   740 						}
       
   741 					}
       
   742 					break;
       
   743 
       
   744 				case EUidPixelFormatXRGB_8888:
       
   745 				case EUidPixelFormatARGB_8888:
       
   746 					{
       
   747 					const TUint32* srcPtr = scanLinePtr;
       
   748 					while(dstPtr < dstLimit)
       
   749 						{
       
   750 						*dstPtr++ = *(srcPtr + xPos.iX);
       
   751 						xScaler.NextStep(xPos);
       
   752 						}
       
   753 					}
       
   754 					break;
       
   755 
       
   756 				case EUidPixelFormatARGB_8888_PRE:
       
   757 					{
       
   758 					const TUint32* srcPtr = scanLinePtr;
       
   759 					const TUint16* normTable = PtrTo16BitNormalisationTable();
       
   760 					while(dstPtr < dstLimit)
       
   761 						{
       
   762 						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
       
   763 						xScaler.NextStep(xPos);
       
   764 						}			
       
   765 					}
       
   766 					break;
       
   767 				}
       
   768 			}
       
   769 			break;
       
   770 		
       
   771 		case EUidPixelFormatARGB_8888:
       
   772 			{
       
   773 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
   774 			aReadBuf.SetLength(aClipDestLen << 2);
       
   775 
       
   776 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   777 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
   778 			
       
   779 			switch (iFormat)
       
   780 				{
       
   781 				case EUidPixelFormatRGB_565:
       
   782 					{
       
   783 					const TUint16* srcPtr = (TUint16*)scanLinePtr;
       
   784 
       
   785 					const TUint16* lowAdd = Convert16to32bppLow();
       
   786 					const TUint32* highAdd = Convert16to32bppHigh();
       
   787 
       
   788 					while (dstPtr < dstLimit)
       
   789 						{
       
   790 						TUint16 c = *(srcPtr + xPos.iX);
       
   791 						const TUint8 low = c & 0xff;
       
   792 						const TUint8 high = c >> 8;
       
   793 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
   794 						
       
   795 						xScaler.NextStep(xPos);
       
   796 						}
       
   797 					}
       
   798 					break;
       
   799 					
       
   800 				case EUidPixelFormatXRGB_8888:
       
   801 					{
       
   802 					const TUint32* srcPtr = scanLinePtr;
       
   803 					while(dstPtr < dstLimit)
       
   804 						{
       
   805 						*dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
       
   806 						xScaler.NextStep(xPos);
       
   807 						}
       
   808 					}
       
   809 					break;
       
   810 				
       
   811 				case EUidPixelFormatARGB_8888:
       
   812 					{
       
   813 					const TUint32* srcPtr = scanLinePtr;
       
   814 					while(dstPtr < dstLimit)
       
   815 						{
       
   816 						*dstPtr++ = *(srcPtr + xPos.iX);
       
   817 						xScaler.NextStep(xPos);
       
   818 						}
       
   819 					}
       
   820 					break;
       
   821 
       
   822 				case EUidPixelFormatARGB_8888_PRE:
       
   823 					{
       
   824 					const TUint32* srcPtr = scanLinePtr;
       
   825 					const TUint16* normTable = PtrTo16BitNormalisationTable();
       
   826 					while(dstPtr < dstLimit)
       
   827 						{
       
   828 						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
       
   829 						xScaler.NextStep(xPos);
       
   830 						}			
       
   831 					}
       
   832 					break;
       
   833 				}
       
   834 			}
       
   835 			break;
       
   836 
       
   837 		case EUidPixelFormatARGB_8888_PRE:
       
   838 			{
       
   839 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
   840 			aReadBuf.SetLength(aClipDestLen << 2);
       
   841 
       
   842 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
   843 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
   844 			
       
   845 			switch (iFormat)
       
   846 				{
       
   847 				case EUidPixelFormatRGB_565:
       
   848 					{
       
   849 					const TUint16* srcPtr = (TUint16*)scanLinePtr;
       
   850 
       
   851 					const TUint16* lowAdd = Convert16to32bppLow();
       
   852 					const TUint32* highAdd = Convert16to32bppHigh();
       
   853 
       
   854 					while (dstPtr < dstLimit)
       
   855 						{
       
   856 						TUint16 c = *(srcPtr + xPos.iX);
       
   857 						const TUint8 low = c & 0xff;
       
   858 						const TUint8 high = c >> 8;
       
   859 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
   860 						
       
   861 						xScaler.NextStep(xPos);
       
   862 						}
       
   863 					}
       
   864 					break;
       
   865 
       
   866 				case EUidPixelFormatXRGB_8888:
       
   867 					{
       
   868 					const TUint32* srcPtr = scanLinePtr;
       
   869 					while(dstPtr < dstLimit)
       
   870 						{
       
   871 						*dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
       
   872 						xScaler.NextStep(xPos);
       
   873 						}
       
   874 					}
       
   875 					break;
       
   876 
       
   877 				case EUidPixelFormatARGB_8888_PRE:
       
   878 					{
       
   879 					const TUint32* srcPtr = scanLinePtr;
       
   880 					while(dstPtr < dstLimit)
       
   881 						{
       
   882 						*dstPtr++ = *(srcPtr + xPos.iX);
       
   883 						xScaler.NextStep(xPos);
       
   884 						}
       
   885 					}
       
   886 					break;
       
   887 
       
   888 				case EUidPixelFormatARGB_8888:
       
   889 					{
       
   890 					const TUint32* srcPtr = scanLinePtr;
       
   891 					while (dstPtr < dstLimit)
       
   892 						{
       
   893 						TUint32 argb = *(srcPtr + xPos.iX);
       
   894 						Convert2PMA(argb);
       
   895 						*dstPtr++ = argb;
       
   896 
       
   897 						xScaler.NextStep(xPos);
       
   898 						}
       
   899 					}
       
   900 					break;
       
   901 				}
       
   902 			}
       
   903 		break;
       
   904 		}
       
   905 	}
       
   906 
       
   907 /**
       
   908 Reads and scales pixels vertically from either top or bottom. Converts to other pixel format 
       
   909 if requested.
       
   910 */
       
   911 void TPixelBufferReader::GetScaledScanLineV(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
       
   912 		TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
       
   913 		TReadDirection aReadDir) const
       
   914 	{
       
   915 	// setup DDA for scaling in Y direction, use read pos as starting point and move up or down
       
   916 	// depending on the read direction
       
   917 	//
       
   918 	TLinearDDA yScaler;
       
   919 	TPoint yPos(aReadPos.iY, 0);
       
   920 	const TPoint delta = aReadDir==EReadVertical? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
       
   921 	yScaler.Construct(yPos, yPos + delta, TLinearDDA::ELeft);
       
   922 
       
   923 	// jump to dest Y position and return the corresponding src Y position
       
   924 	yPos.iY = aClipDestPos;
       
   925 	if (aClipDestPos > 0)
       
   926 		{
       
   927 		yScaler.JumpToYCoord(yPos.iX, yPos.iY);
       
   928 		}
       
   929 	else
       
   930 		{
       
   931 		yScaler.NextStep(yPos);
       
   932 		}
       
   933 
       
   934 	// supported pixel buffer:
       
   935 	// RGB_565
       
   936 	// XRGB_8888
       
   937 	// ARGB_8888
       
   938 	// ARGB_8888_PRE
       
   939 
       
   940 	// supported read format
       
   941 	// RGB_565
       
   942 	// XRGB_8888
       
   943 	// ARGB_8888
       
   944 	// ARGB_8888_PRE
       
   945 
       
   946 	switch(aReadFormat)
       
   947 		{
       
   948 		case EUidPixelFormatRGB_565:
       
   949 			{
       
   950 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
       
   951 			aReadBuf.SetLength(aClipDestLen << 1);
       
   952 
       
   953 			TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
       
   954 			TUint16* dstLimit = dstPtr + aClipDestLen;
       
   955 			
       
   956 			switch (iFormat)
       
   957 				{
       
   958 				case EUidPixelFormatRGB_565:
       
   959 					{
       
   960 					const TUint16* srcPtr = (TUint16*) iBuffer + aReadPos.iX;
       
   961 					const TInt offset = iStride >> 1;
       
   962 					
       
   963 					while(dstPtr < dstLimit)
       
   964 						{
       
   965 						*dstPtr++ = *(srcPtr + yPos.iX * offset);
       
   966 						yScaler.NextStep(yPos);
       
   967 						}
       
   968 					}
       
   969 					break;
       
   970 
       
   971 				case EUidPixelFormatXRGB_8888:
       
   972 					{
       
   973 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
   974 					const TInt offset = iStride >> 2;
       
   975 					
       
   976 					while (dstPtr < dstLimit)
       
   977 						{
       
   978 						*dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + yPos.iX * offset)).Color64K());
       
   979 						yScaler.NextStep(yPos);
       
   980 						}
       
   981 					}
       
   982 					break;
       
   983 
       
   984 				case EUidPixelFormatARGB_8888:
       
   985 					{
       
   986 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
   987 					const TInt offset = iStride >> 2;
       
   988 					
       
   989 					while (dstPtr < dstLimit)
       
   990 						{
       
   991 						*dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + yPos.iX * offset)).Color64K());
       
   992 						yScaler.NextStep(yPos);
       
   993 						}
       
   994 					}
       
   995 					break;
       
   996 
       
   997 				case EUidPixelFormatARGB_8888_PRE:
       
   998 					{
       
   999 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1000 					const TInt offset = iStride >> 2;
       
  1001 					
       
  1002 					while (dstPtr < dstLimit)
       
  1003 						{
       
  1004 						*dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + yPos.iX * offset)).Color64K());
       
  1005 						yScaler.NextStep(yPos);
       
  1006 						}
       
  1007 					}
       
  1008 					break;
       
  1009 				}
       
  1010 			}
       
  1011 			break;
       
  1012 
       
  1013 		case EUidPixelFormatXRGB_8888:
       
  1014 			{
       
  1015 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
  1016 			aReadBuf.SetLength(aClipDestLen << 2);
       
  1017 
       
  1018 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
  1019 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
  1020 			
       
  1021 			switch (iFormat)
       
  1022 				{
       
  1023 				case EUidPixelFormatRGB_565:
       
  1024 					{
       
  1025 					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
       
  1026 					const TInt offset = iStride >> 1;
       
  1027 
       
  1028 					const TUint16* lowAdd = Convert16to32bppLow();
       
  1029 					const TUint32* highAdd = Convert16to32bppHigh();
       
  1030 
       
  1031 					while (dstPtr < dstLimit)
       
  1032 						{
       
  1033 						TUint16 c = *(srcPtr + yPos.iX * offset);
       
  1034 						const TUint8 low = c & 0xff;
       
  1035 						const TUint8 high = c >> 8;
       
  1036 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
  1037 						
       
  1038 						yScaler.NextStep(yPos);
       
  1039 						}
       
  1040 					}
       
  1041 					break;
       
  1042 
       
  1043 				case EUidPixelFormatXRGB_8888:
       
  1044 				case EUidPixelFormatARGB_8888:				
       
  1045 					{
       
  1046 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1047 					const TInt offset = iStride >> 2;
       
  1048 					
       
  1049 					while(dstPtr < dstLimit)
       
  1050 						{
       
  1051 						*dstPtr++ = *(srcPtr + yPos.iX * offset);
       
  1052 						yScaler.NextStep(yPos);
       
  1053 						}
       
  1054 					}
       
  1055 					break;
       
  1056 
       
  1057 				case EUidPixelFormatARGB_8888_PRE:
       
  1058 					{
       
  1059 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1060 					const TInt offset = iStride >> 2;
       
  1061 					const TUint16* normTable = PtrTo16BitNormalisationTable();
       
  1062 					
       
  1063 					while(dstPtr < dstLimit)
       
  1064 						{
       
  1065 						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
       
  1066 						yScaler.NextStep(yPos);
       
  1067 						}			
       
  1068 					}
       
  1069 					break;
       
  1070 				}
       
  1071 			}
       
  1072 			break;
       
  1073 		
       
  1074 		case EUidPixelFormatARGB_8888:
       
  1075 			{
       
  1076 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
  1077 			aReadBuf.SetLength(aClipDestLen << 2);
       
  1078 
       
  1079 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
  1080 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
  1081 			
       
  1082 			switch (iFormat)
       
  1083 				{
       
  1084 				case EUidPixelFormatRGB_565:
       
  1085 					{
       
  1086 					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
       
  1087 					const TInt offset = iStride >> 1;
       
  1088 
       
  1089 					const TUint16* lowAdd = Convert16to32bppLow();
       
  1090 					const TUint32* highAdd = Convert16to32bppHigh();
       
  1091 
       
  1092 					while (dstPtr < dstLimit)
       
  1093 						{
       
  1094 						TUint16 c = *(srcPtr + yPos.iX * offset);
       
  1095 						const TUint8 low = c & 0xff;
       
  1096 						const TUint8 high = c >> 8;
       
  1097 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
  1098 						
       
  1099 						yScaler.NextStep(yPos);
       
  1100 						}
       
  1101 					}
       
  1102 					break;
       
  1103 					
       
  1104 				case EUidPixelFormatXRGB_8888:
       
  1105 					{
       
  1106 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1107 					const TInt offset = iStride >> 2;
       
  1108 					
       
  1109 					while(dstPtr < dstLimit)
       
  1110 						{
       
  1111 						*dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
       
  1112 						yScaler.NextStep(yPos);
       
  1113 						}
       
  1114 					}
       
  1115 					break;
       
  1116 				
       
  1117 				case EUidPixelFormatARGB_8888:
       
  1118 					{
       
  1119 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1120 					const TInt offset = iStride >> 2;
       
  1121 					
       
  1122 					while(dstPtr < dstLimit)
       
  1123 						{
       
  1124 						*dstPtr++ = *(srcPtr + yPos.iX * offset);
       
  1125 						yScaler.NextStep(yPos);
       
  1126 						}
       
  1127 					}
       
  1128 					break;
       
  1129 
       
  1130 				case EUidPixelFormatARGB_8888_PRE:
       
  1131 					{
       
  1132 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1133 					const TInt offset = iStride >> 2;
       
  1134 					const TUint16* normTable = PtrTo16BitNormalisationTable();
       
  1135 					
       
  1136 					while(dstPtr < dstLimit)
       
  1137 						{
       
  1138 						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
       
  1139 						yScaler.NextStep(yPos);
       
  1140 						}			
       
  1141 					}
       
  1142 					break;
       
  1143 				}
       
  1144 			}
       
  1145 			break;
       
  1146 
       
  1147 		case EUidPixelFormatARGB_8888_PRE:
       
  1148 			{
       
  1149 			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
       
  1150 			aReadBuf.SetLength(aClipDestLen << 2);
       
  1151 
       
  1152 			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
       
  1153 			TUint32* dstLimit = dstPtr + aClipDestLen;
       
  1154 			
       
  1155 			switch (iFormat)
       
  1156 				{
       
  1157 				case EUidPixelFormatRGB_565:
       
  1158 					{
       
  1159 					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
       
  1160 					const TInt offset = iStride >> 1;
       
  1161 
       
  1162 					const TUint16* lowAdd = Convert16to32bppLow();
       
  1163 					const TUint32* highAdd = Convert16to32bppHigh();
       
  1164 
       
  1165 					while (dstPtr < dstLimit)
       
  1166 						{
       
  1167 						TUint16 c = *(srcPtr + yPos.iX * offset);
       
  1168 						const TUint8 low = c & 0xff;
       
  1169 						const TUint8 high = c >> 8;
       
  1170 						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
       
  1171 						
       
  1172 						yScaler.NextStep(yPos);
       
  1173 						}
       
  1174 					}
       
  1175 					break;
       
  1176 
       
  1177 				case EUidPixelFormatXRGB_8888:
       
  1178 					{
       
  1179 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1180 					const TInt offset = iStride >> 2;
       
  1181 					
       
  1182 					while(dstPtr < dstLimit)
       
  1183 						{
       
  1184 						*dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
       
  1185 						yScaler.NextStep(yPos);
       
  1186 						}
       
  1187 					}
       
  1188 					break;
       
  1189 				
       
  1190 				case EUidPixelFormatARGB_8888_PRE:
       
  1191 					{
       
  1192 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1193 					const TInt offset = iStride >> 2;
       
  1194 					
       
  1195 					while(dstPtr < dstLimit)
       
  1196 						{
       
  1197 						*dstPtr++ = *(srcPtr + yPos.iX * offset);
       
  1198 						yScaler.NextStep(yPos);
       
  1199 						}
       
  1200 					}
       
  1201 					break;
       
  1202 
       
  1203 				case EUidPixelFormatARGB_8888:
       
  1204 					{
       
  1205 					const TUint32* srcPtr = iBuffer + aReadPos.iX;
       
  1206 					const TInt offset = iStride >> 2;
       
  1207 					
       
  1208 					while (dstPtr < dstLimit)
       
  1209 						{
       
  1210 						TUint32 argb = *(srcPtr + yPos.iX * offset);
       
  1211 						Convert2PMA(argb);
       
  1212 						*dstPtr++ = argb;
       
  1213 
       
  1214 						yScaler.NextStep(yPos);
       
  1215 						}
       
  1216 					}
       
  1217 					break;
       
  1218 				}
       
  1219 			}
       
  1220 		break;
       
  1221 		}
       
  1222 	}