os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/pixelutil.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/pixelutil.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1222 @@
     1.4 +// Copyright (c) 2007-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 <graphics/lookuptable.h>
    1.20 +#include <graphics/blendingalgorithms.h>
    1.21 +
    1.22 +#include "pixelutil.h"
    1.23 +#include "directgdiadapter.h"
    1.24 +#include "directgditypes.h"
    1.25 +
    1.26 +TBool PixelFormatUtil::HasAlpha(TUidPixelFormat aPixelFormat)
    1.27 +	{
    1.28 +	const TBool hasAlpha = 
    1.29 +		// short circuit format equivalent to legacy TDisplayMode with alpha channel
    1.30 +		aPixelFormat == EUidPixelFormatARGB_8888 ||
    1.31 +		aPixelFormat == EUidPixelFormatARGB_8888_PRE ||
    1.32 +
    1.33 +		aPixelFormat == EUidPixelFormatBGRA_8888 ||
    1.34 +		aPixelFormat == EUidPixelFormatABGR_8888 ||
    1.35 +		aPixelFormat == EUidPixelFormatABGR_8888_PRE ||
    1.36 +		aPixelFormat == EUidPixelFormatBGRA_8888_PRE ||
    1.37 +		aPixelFormat == EUidPixelFormatARGB_2101010 ||
    1.38 +		aPixelFormat == EUidPixelFormatABGR_2101010 ||
    1.39 +		aPixelFormat == EUidPixelFormatARGB_1555 ||
    1.40 +		aPixelFormat == EUidPixelFormatARGB_4444 ||
    1.41 +		aPixelFormat == EUidPixelFormatARGB_8332 ||
    1.42 +		aPixelFormat == EUidPixelFormatBGRA_5551 ||
    1.43 +		aPixelFormat == EUidPixelFormatBGRA_4444 ||
    1.44 +		aPixelFormat == EUidPixelFormatAP_88 ||
    1.45 +		aPixelFormat == EUidPixelFormatA_8;
    1.46 +	
    1.47 +	return hasAlpha;
    1.48 +	}
    1.49 +
    1.50 +TUidPixelFormat PixelFormatUtil::ConvertToPixelFormat(TDisplayMode aDisplayMode)
    1.51 +	{
    1.52 +	switch (aDisplayMode)
    1.53 +		{
    1.54 +		case EGray2:
    1.55 +			return EUidPixelFormatL_1;
    1.56 +		case EGray4:
    1.57 +			return EUidPixelFormatL_2;
    1.58 +		case EGray16:
    1.59 +			return EUidPixelFormatL_4;
    1.60 +		case EGray256:
    1.61 +			return EUidPixelFormatL_8;
    1.62 +		case EColor16:
    1.63 +			return EUidPixelFormatP_4;
    1.64 +		case EColor256:
    1.65 +			return EUidPixelFormatP_8;
    1.66 +		case EColor4K:
    1.67 +			return EUidPixelFormatXRGB_4444;
    1.68 +		case EColor64K:
    1.69 +			return EUidPixelFormatRGB_565;
    1.70 +		case EColor16M:
    1.71 +			return EUidPixelFormatRGB_888;		
    1.72 +		case EColor16MU:
    1.73 +			return EUidPixelFormatXRGB_8888;
    1.74 +		case EColor16MA:
    1.75 +			return EUidPixelFormatARGB_8888;
    1.76 +		case EColor16MAP:
    1.77 +			return EUidPixelFormatARGB_8888_PRE;
    1.78 +		default:
    1.79 +			return EUidPixelFormatUnknown;
    1.80 +		};	
    1.81 +	}
    1.82 +
    1.83 +TDisplayMode PixelFormatUtil::ConvertToDisplayMode(TUidPixelFormat aPixelFormat)
    1.84 +	{
    1.85 +	switch (aPixelFormat)	
    1.86 +		{
    1.87 +		case EUidPixelFormatL_1:
    1.88 +			return EGray2;
    1.89 +		case EUidPixelFormatL_2:
    1.90 +			return EGray4;
    1.91 +		case EUidPixelFormatL_4:
    1.92 +			return EGray16;
    1.93 +		case EUidPixelFormatL_8:
    1.94 +			return EGray256;
    1.95 +		case EUidPixelFormatP_4:
    1.96 +			return EColor16;
    1.97 +		case EUidPixelFormatP_8:
    1.98 +			return EColor256;
    1.99 +		case EUidPixelFormatXRGB_4444:
   1.100 +			return EColor4K;
   1.101 +		case EUidPixelFormatRGB_565:
   1.102 +			return EColor64K;
   1.103 +		case EUidPixelFormatRGB_888:
   1.104 +			return EColor16M;
   1.105 +		case EUidPixelFormatXRGB_8888:
   1.106 +			return EColor16MU;
   1.107 +		case EUidPixelFormatARGB_8888:
   1.108 +			return EColor16MA;
   1.109 +		case EUidPixelFormatARGB_8888_PRE:
   1.110 +			return EColor16MAP;
   1.111 +		default:
   1.112 +			return ENone;
   1.113 +		}
   1.114 +	}
   1.115 +
   1.116 +TInt PixelFormatUtil::BitsPerPixel(TUidPixelFormat aPixelFormat)
   1.117 +	{
   1.118 +	switch (aPixelFormat)
   1.119 +		{
   1.120 +		case EUidPixelFormatP_1:
   1.121 +		case EUidPixelFormatL_1:
   1.122 +			return 1;
   1.123 +		case EUidPixelFormatP_2:
   1.124 +		case EUidPixelFormatL_2:
   1.125 +			return 2;
   1.126 +		case EUidPixelFormatP_4:
   1.127 +		case EUidPixelFormatL_4:
   1.128 +			return 4;
   1.129 +		case EUidPixelFormatRGB_332:
   1.130 +		case EUidPixelFormatA_8:
   1.131 +		case EUidPixelFormatBGR_332:
   1.132 +		case EUidPixelFormatP_8:
   1.133 +		case EUidPixelFormatL_8:
   1.134 +			return 8;
   1.135 +		case EUidPixelFormatRGB_565:
   1.136 +		case EUidPixelFormatBGR_565:
   1.137 +		case EUidPixelFormatARGB_1555:
   1.138 +		case EUidPixelFormatXRGB_1555:
   1.139 +		case EUidPixelFormatARGB_4444:
   1.140 +		case EUidPixelFormatARGB_8332:
   1.141 +		case EUidPixelFormatBGRX_5551:
   1.142 +		case EUidPixelFormatBGRA_5551:
   1.143 +		case EUidPixelFormatBGRA_4444:
   1.144 +		case EUidPixelFormatBGRX_4444:
   1.145 +		case EUidPixelFormatAP_88:
   1.146 +		case EUidPixelFormatXRGB_4444:
   1.147 +		case EUidPixelFormatXBGR_4444:
   1.148 +			return 16;
   1.149 +		case EUidPixelFormatBGR_888:
   1.150 +		case EUidPixelFormatRGB_888:
   1.151 +			return 24;
   1.152 +		case EUidPixelFormatXRGB_8888:
   1.153 +		case EUidPixelFormatBGRX_8888:
   1.154 +		case EUidPixelFormatXBGR_8888:
   1.155 +		case EUidPixelFormatBGRA_8888:
   1.156 +		case EUidPixelFormatARGB_8888:
   1.157 +		case EUidPixelFormatABGR_8888:
   1.158 +		case EUidPixelFormatARGB_8888_PRE:
   1.159 +		case EUidPixelFormatABGR_8888_PRE:
   1.160 +		case EUidPixelFormatBGRA_8888_PRE:
   1.161 +		case EUidPixelFormatARGB_2101010:
   1.162 +		case EUidPixelFormatABGR_2101010:
   1.163 +			return 32;
   1.164 +		default:
   1.165 +			GRAPHICS_ASSERT_DEBUG(EFalse, EDirectGdiPanicInvalidDisplayMode);
   1.166 +			return 0;
   1.167 +		};	
   1.168 +	}
   1.169 +
   1.170 +/**
   1.171 +Create pixel buffer reader from a given pixel buffer by specifying its buffer addres and properties.
   1.172 +Supported format are:
   1.173 +-EUidPixelFormatRGB_565
   1.174 +-EUidPixelFormatXRGB_8888
   1.175 +-EUidPixelFormatARGB_8888
   1.176 +-EUidPixelFormatARGB_8888_PRE
   1.177 +*/
   1.178 +TPixelBufferReader::TPixelBufferReader(const TUint32* aPixelBuffer, const TSize& aSize, TInt aStride, TUidPixelFormat aFormat):
   1.179 +	iBuffer(aPixelBuffer),
   1.180 +	iSize(aSize),
   1.181 +	iStride(aStride),
   1.182 +	iFormat(aFormat)
   1.183 +	{
   1.184 +	GRAPHICS_ASSERT_DEBUG(iBuffer && iStride!=0, EDirectGdiPanicInvalidBitmap);
   1.185 +	GRAPHICS_ASSERT_DEBUG(iSize.iWidth!=0 && iSize.iHeight!=0, EDirectGdiPanicOutOfBounds);
   1.186 +	GRAPHICS_ASSERT_DEBUG(
   1.187 +		iFormat==EUidPixelFormatRGB_565 ||
   1.188 +		iFormat==EUidPixelFormatXRGB_8888 ||
   1.189 +		iFormat==EUidPixelFormatARGB_8888 ||
   1.190 +		iFormat==EUidPixelFormatARGB_8888_PRE,
   1.191 +		EDirectGdiPanicInvalidDisplayMode);
   1.192 +	}
   1.193 +
   1.194 +/**
   1.195 +Copies pixels into user buffer starting and ending based on the given read position and 
   1.196 +read length (in pixels). Convert data into user pixel format if requested.
   1.197 +Copying will be done forward or backward (from a given read position) based on read direction parameter.
   1.198 +
   1.199 +@pre	TPixelBufferReader object was constructed with valid pixel buffer and its properties.
   1.200 +		Starting and ending read position is within the pixel buffer area.
   1.201 +		Supported read format:
   1.202 +			RGB_565
   1.203 +			XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
   1.204 +@post	Pixels copied into user buffer.
   1.205 +*/
   1.206 +void TPixelBufferReader::GetScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
   1.207 +		TUidPixelFormat aReadFormat, TReadDirection aReadDir) const
   1.208 +	{
   1.209 +	GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
   1.210 +		aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
   1.211 +	GRAPHICS_ASSERT_DEBUG(
   1.212 +		aReadFormat==EUidPixelFormatRGB_565 ||
   1.213 +		aReadFormat==EUidPixelFormatXRGB_8888 ||
   1.214 +		aReadFormat==EUidPixelFormatARGB_8888 ||
   1.215 +		aReadFormat==EUidPixelFormatARGB_8888_PRE,
   1.216 +		EDirectGdiPanicInvalidDisplayMode);
   1.217 +
   1.218 +#ifdef _DEBUG
   1.219 +	switch (aReadDir)
   1.220 +		{
   1.221 +		case EReadHorizontal:
   1.222 +		GRAPHICS_ASSERT_DEBUG(aReadPos.iX+aReadLen<=iSize.iWidth, EDirectGdiPanicOutOfBounds);
   1.223 +		break;
   1.224 +
   1.225 +		case EReadHorizontalReverse:
   1.226 +		GRAPHICS_ASSERT_DEBUG(aReadPos.iX-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
   1.227 +		break;
   1.228 +		
   1.229 +		case EReadVertical:
   1.230 +  		GRAPHICS_ASSERT_DEBUG(aReadPos.iY+aReadLen<=iSize.iHeight, EDirectGdiPanicOutOfBounds);
   1.231 +		break;
   1.232 +		
   1.233 +		case EReadVerticalReverse:
   1.234 +  		GRAPHICS_ASSERT_DEBUG(aReadPos.iY-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
   1.235 +		break;
   1.236 +		}
   1.237 +#endif
   1.238 +
   1.239 +	switch(aReadFormat)
   1.240 +		{
   1.241 +		case EUidPixelFormatRGB_565:
   1.242 +			GetScanLineRGB_565(aReadBuf, aReadPos, aReadLen,  aReadDir);
   1.243 +			break;
   1.244 +		case EUidPixelFormatXRGB_8888:
   1.245 +			GetScanLineXRGB_8888(aReadBuf, aReadPos, aReadLen,  aReadDir);
   1.246 +			break;
   1.247 +		case EUidPixelFormatARGB_8888:
   1.248 +			GetScanLineARGB_8888(aReadBuf, aReadPos, aReadLen,  aReadDir);
   1.249 +			break;
   1.250 +		case EUidPixelFormatARGB_8888_PRE:
   1.251 +			GetScanLineARGB_8888_PRE(aReadBuf, aReadPos, aReadLen,  aReadDir);
   1.252 +			break;
   1.253 +		default:
   1.254 +			aReadBuf.SetLength(0);
   1.255 +			break;
   1.256 +		};
   1.257 +	}
   1.258 +
   1.259 +/**
   1.260 +Copies pixels into user buffer starting and ending based on the given read position and 
   1.261 +read length (in pixels). Converts data into user pixel format and scales up or down depending
   1.262 +on the specified parameters. Copying will be done forward or backward (from a given read position)
   1.263 +based on read direction parameter.
   1.264 +
   1.265 +@pre	TPixelBufferReader object was constructed with valid pixel buffer and its properties.
   1.266 +		Starting and ending read position is within the pixel buffer area.
   1.267 +		Supported read format:
   1.268 +			RGB_565
   1.269 +			XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
   1.270 +@post	Pixels copied into user buffer.
   1.271 +*/
   1.272 +void TPixelBufferReader::GetScaledScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipPos,
   1.273 +		TInt aClipLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
   1.274 +		TReadDirection aReadDir) const
   1.275 +	{
   1.276 +	GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
   1.277 +		aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
   1.278 +
   1.279 +	GRAPHICS_ASSERT_DEBUG(
   1.280 +		aReadFormat==EUidPixelFormatRGB_565 ||
   1.281 +		aReadFormat==EUidPixelFormatXRGB_8888 ||
   1.282 +		aReadFormat==EUidPixelFormatARGB_8888 ||
   1.283 +		aReadFormat==EUidPixelFormatARGB_8888_PRE,
   1.284 +		EDirectGdiPanicInvalidDisplayMode);
   1.285 +
   1.286 +	if (aReadDir == EReadHorizontal || aReadDir == EReadHorizontalReverse)
   1.287 +		{
   1.288 +		GetScaledScanLineH(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
   1.289 +		}
   1.290 +	else
   1.291 +		{
   1.292 +		GetScaledScanLineV(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
   1.293 +		}
   1.294 +	}
   1.295 +
   1.296 +/**
   1.297 +Gets pixel address in arbitrary position within the buffer
   1.298 +*/
   1.299 +const TUint32* TPixelBufferReader::GetPixelAddr(const TPoint& aPos) const
   1.300 +	{
   1.301 +	const TUint32* slptr = GetScanLineAddr(aPos.iY);
   1.302 +	return PixelFormatUtil::BitsPerPixel(iFormat)==32? slptr+aPos.iX : (TUint32*)((TUint16*)slptr+aPos.iX);
   1.303 +	}
   1.304 +
   1.305 +/**
   1.306 +Gets scanline address for a give row poisition
   1.307 +*/
   1.308 +const TUint32* TPixelBufferReader::GetScanLineAddr(TInt aRow) const
   1.309 +	{
   1.310 +	return (iBuffer + (aRow * iStride >> 2));
   1.311 +	}
   1.312 +
   1.313 +/**
   1.314 +Copies from 16-bit src to 32-bit dest
   1.315 +*/
   1.316 +void TPixelBufferReader::CopyFromRGB_565(TUint32* aDstPtr, const TUint16* aSrcPtr,
   1.317 +		TInt aNumOfPixels, TInt aAdvance) const
   1.318 +	{
   1.319 +	const TUint16* lowAdd = Convert16to32bppLow();
   1.320 +	const TUint32* highAdd = Convert16to32bppHigh();
   1.321 +
   1.322 +	while (aNumOfPixels--)
   1.323 +		{
   1.324 +		const TUint8 low = *aSrcPtr & 0xff;
   1.325 +		const TUint8 high = *aSrcPtr >> 8;
   1.326 +		*aDstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
   1.327 +		
   1.328 +		aSrcPtr += aAdvance;
   1.329 +		}
   1.330 +	}
   1.331 +
   1.332 +/**
   1.333 +Calculates pixel position increment based on a given read direction and buffer pixel format.
   1.334 +*/
   1.335 +TInt TPixelBufferReader::GetAdvance(TReadDirection aReadDir) const
   1.336 +	{
   1.337 +	TInt advance = 0;
   1.338 +	// supported pixel buffer is either 16-bit or 32-bit
   1.339 +	//
   1.340 +	switch (aReadDir)
   1.341 +		{
   1.342 +		case EReadHorizontal:
   1.343 +			advance = 1;
   1.344 +			break;
   1.345 +		case EReadHorizontalReverse:
   1.346 +			advance = -1;
   1.347 +			break;
   1.348 +		case EReadVertical:
   1.349 +			advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? iStride >> 1 : iStride >> 2;
   1.350 +			break;
   1.351 +		case EReadVerticalReverse:
   1.352 +			advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? -(iStride >> 1) : -(iStride >> 2);
   1.353 +			break;
   1.354 +		}
   1.355 +
   1.356 +	return advance;
   1.357 +	}
   1.358 +
   1.359 +/**
   1.360 +Reads and converts scanline into RGB_565.
   1.361 +*/
   1.362 +void TPixelBufferReader::GetScanLineRGB_565(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
   1.363 +		TReadDirection aReadDir) const
   1.364 +	{
   1.365 +	// read as much as buffer can hold
   1.366 +	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 1);
   1.367 +	aReadBuf.SetLength(aReadLen << 1);
   1.368 +
   1.369 +	TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
   1.370 +	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
   1.371 +	TInt posX = aReadPos.iX;
   1.372 +	const TInt advance = GetAdvance(aReadDir);
   1.373 +
   1.374 +	// supported pixel buffer:
   1.375 +	// RGB_565
   1.376 +	// XRGB_8888
   1.377 +	// ARGB_8888
   1.378 +	// ARGB_8888_PRE
   1.379 +	//
   1.380 +	switch (iFormat)		
   1.381 +		{
   1.382 +		case EUidPixelFormatRGB_565:
   1.383 +			{
   1.384 +			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
   1.385 +			while (aReadLen--)
   1.386 +				{
   1.387 +				*dstPtr++ = *srcPtr;
   1.388 +				srcPtr += advance;
   1.389 +				}
   1.390 +			}
   1.391 +			break;
   1.392 +
   1.393 +		case EUidPixelFormatXRGB_8888:
   1.394 +			{
   1.395 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.396 +			while (aReadLen--)
   1.397 +				{
   1.398 +				*dstPtr++ = TUint16(TRgb::Color16MU(*srcPtr).Color64K());
   1.399 +				srcPtr += advance;
   1.400 +				}
   1.401 +			}
   1.402 +			break;
   1.403 +
   1.404 +		case EUidPixelFormatARGB_8888:
   1.405 +			{
   1.406 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.407 +			while (aReadLen--)
   1.408 +				{
   1.409 +				*dstPtr++ = TUint16(TRgb::Color16MA(*srcPtr).Color64K());
   1.410 +				srcPtr += advance;
   1.411 +				}
   1.412 +			}
   1.413 +			break;
   1.414 +
   1.415 +		case EUidPixelFormatARGB_8888_PRE:
   1.416 +			{
   1.417 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.418 +			while (aReadLen--)
   1.419 +				{
   1.420 +				*dstPtr++ = TUint16(TRgb::Color16MAP(*srcPtr).Color64K());
   1.421 +				srcPtr += advance;
   1.422 +				}
   1.423 +			}
   1.424 +			break;
   1.425 +		}
   1.426 +	}
   1.427 +
   1.428 +/**
   1.429 +Reads and converts scanline into XRGB_8888.
   1.430 +*/
   1.431 +void TPixelBufferReader::GetScanLineXRGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
   1.432 +		TReadDirection aReadDir) const
   1.433 +	{
   1.434 +	// read as much as buffer can hold
   1.435 +	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
   1.436 +	aReadBuf.SetLength(aReadLen << 2);
   1.437 +
   1.438 +	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.439 +	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
   1.440 +	TInt posX = aReadPos.iX;
   1.441 +	const TInt advance = GetAdvance(aReadDir);
   1.442 +
   1.443 +	// supported pixel buffer:
   1.444 +	// RGB_565
   1.445 +	// XRGB_8888
   1.446 +	// ARGB_8888
   1.447 +	// ARGB_8888_PRE
   1.448 +	//
   1.449 +	switch (iFormat)
   1.450 +		{
   1.451 +		case EUidPixelFormatRGB_565:
   1.452 +			{
   1.453 +			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
   1.454 +			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
   1.455 +			}
   1.456 +			break;
   1.457 +
   1.458 +		case EUidPixelFormatXRGB_8888:
   1.459 +		case EUidPixelFormatARGB_8888:
   1.460 +			{
   1.461 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.462 +			while (aReadLen--)
   1.463 +				{
   1.464 +				*dstPtr++ = *srcPtr;
   1.465 +				srcPtr += advance;
   1.466 +				}
   1.467 +			}
   1.468 +			break;
   1.469 +
   1.470 +		case EUidPixelFormatARGB_8888_PRE:
   1.471 +			{
   1.472 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.473 +			const TUint16* normTable = PtrTo16BitNormalisationTable();
   1.474 +			while(aReadLen--)
   1.475 +				{
   1.476 +				*dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
   1.477 +				srcPtr += advance;
   1.478 +				}			
   1.479 +			}
   1.480 +			break;
   1.481 +		}
   1.482 +	}
   1.483 +
   1.484 +/**
   1.485 +Reads and converts scanline into ARGB_8888.
   1.486 +*/
   1.487 +void TPixelBufferReader::GetScanLineARGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
   1.488 +		TReadDirection aReadDir) const
   1.489 +	{
   1.490 +	// read as much as buffer can hold
   1.491 +	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
   1.492 +	aReadBuf.SetLength(aReadLen << 2);
   1.493 +
   1.494 +	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.495 +	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
   1.496 +	TInt posX = aReadPos.iX;
   1.497 +	const TInt advance = GetAdvance(aReadDir);
   1.498 +
   1.499 +	// supported pixel buffer:
   1.500 +	// RGB_565
   1.501 +	// XRGB_8888
   1.502 +	// ARGB_8888
   1.503 +	// ARGB_8888_PRE
   1.504 +	//
   1.505 +	switch (iFormat)
   1.506 +		{
   1.507 +		case EUidPixelFormatRGB_565:
   1.508 +			{
   1.509 +			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
   1.510 +			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
   1.511 +			}
   1.512 +			break;
   1.513 +
   1.514 +		case EUidPixelFormatXRGB_8888:
   1.515 +			{
   1.516 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.517 +			while (aReadLen--)
   1.518 +				{
   1.519 +				*dstPtr++ = 0xff000000 | *srcPtr;
   1.520 +				srcPtr += advance;
   1.521 +				}
   1.522 +			}
   1.523 +			break;
   1.524 +		
   1.525 +		case EUidPixelFormatARGB_8888:
   1.526 +			{
   1.527 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.528 +			while (aReadLen--)
   1.529 +				{
   1.530 +				*dstPtr++ = *srcPtr;
   1.531 +				srcPtr += advance;
   1.532 +				}
   1.533 +			}
   1.534 +			break;
   1.535 +
   1.536 +		case EUidPixelFormatARGB_8888_PRE:
   1.537 +			{
   1.538 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.539 +			const TUint16* normTable = PtrTo16BitNormalisationTable();
   1.540 +			while(aReadLen--)
   1.541 +				{
   1.542 +				*dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
   1.543 +				srcPtr += advance;
   1.544 +				}			
   1.545 +			}
   1.546 +			break;
   1.547 +		}
   1.548 +	}
   1.549 +
   1.550 +/**
   1.551 +Read and convert scanline into ARGB_8888_PRE.
   1.552 +*/
   1.553 +void TPixelBufferReader::GetScanLineARGB_8888_PRE(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
   1.554 +		TReadDirection aReadDir) const
   1.555 +	{
   1.556 +	// read as much as buffer can hold
   1.557 +	aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
   1.558 +	aReadBuf.SetLength(aReadLen << 2);
   1.559 +
   1.560 +	TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.561 +	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
   1.562 +	TInt posX = aReadPos.iX;
   1.563 +	const TInt advance = GetAdvance(aReadDir);
   1.564 +
   1.565 +	// supported pixel buffer:
   1.566 +	// RGB_565
   1.567 +	// XRGB_8888
   1.568 +	// ARGB_8888
   1.569 +	// ARGB_8888_PRE
   1.570 +	//
   1.571 +	switch (iFormat)
   1.572 +		{
   1.573 +		case EUidPixelFormatRGB_565:
   1.574 +			{
   1.575 +			const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
   1.576 +			CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
   1.577 +			}
   1.578 +			break;
   1.579 +
   1.580 +		case EUidPixelFormatXRGB_8888:
   1.581 +			{
   1.582 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.583 +			while (aReadLen--)
   1.584 +				{
   1.585 +				*dstPtr++ = 0xff000000 | *srcPtr;
   1.586 +				srcPtr += advance;
   1.587 +				}
   1.588 +			}
   1.589 +			break;
   1.590 +
   1.591 +		case EUidPixelFormatARGB_8888:
   1.592 +			{
   1.593 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.594 +			while (aReadLen--)
   1.595 +				{
   1.596 +				TUint32 argb = *srcPtr;
   1.597 +				Convert2PMA(argb);
   1.598 +				*dstPtr++ = argb;
   1.599 +
   1.600 +				srcPtr += advance;
   1.601 +				}
   1.602 +			}
   1.603 +			break;
   1.604 +
   1.605 +		case EUidPixelFormatARGB_8888_PRE:
   1.606 +			{
   1.607 +			const TUint32* srcPtr = scanLinePtr + posX;
   1.608 +			while (aReadLen--)
   1.609 +				{
   1.610 +				*dstPtr++ = *srcPtr;
   1.611 +				srcPtr += advance;
   1.612 +				}
   1.613 +			}
   1.614 +			break;
   1.615 +		}
   1.616 +	}
   1.617 +
   1.618 +/**
   1.619 +Reads and scales pixels horizontally from either left or right. Converts to other pixel format if
   1.620 +requested.
   1.621 +*/
   1.622 +void TPixelBufferReader::GetScaledScanLineH(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
   1.623 +		TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
   1.624 +		TReadDirection aReadDir) const
   1.625 +	{
   1.626 +	// setup DDA for scaling in X direction, use read pos as starting point and move right or left
   1.627 +	// depending on the read direction
   1.628 +	//
   1.629 +	TLinearDDA xScaler;
   1.630 +	TPoint xPos(aReadPos.iX, 0);
   1.631 +	const TPoint delta = aReadDir==EReadHorizontal? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
   1.632 +	xScaler.Construct(xPos, xPos + delta, TLinearDDA::ELeft);
   1.633 +
   1.634 +	// jump to dest X position and return the corresponding src X position
   1.635 +	xPos.iY = aClipDestPos;
   1.636 +	if (aClipDestPos > 0)
   1.637 +		{
   1.638 +		xScaler.JumpToYCoord(xPos.iX, xPos.iY);
   1.639 +		}
   1.640 +	else
   1.641 +		{
   1.642 +		xScaler.NextStep(xPos);
   1.643 +		}
   1.644 +
   1.645 +	const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
   1.646 +
   1.647 +	// supported pixel buffer:
   1.648 +	// RGB_565
   1.649 +	// XRGB_8888
   1.650 +	// ARGB_8888
   1.651 +	// ARGB_8888_PRE
   1.652 +
   1.653 +	// supported read format
   1.654 +	// RGB_565
   1.655 +	// XRGB_8888
   1.656 +	// ARGB_8888
   1.657 +	// ARGB_8888_PRE
   1.658 +
   1.659 +	switch(aReadFormat)
   1.660 +		{
   1.661 +		case EUidPixelFormatRGB_565:
   1.662 +			{
   1.663 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
   1.664 +			aReadBuf.SetLength(aClipDestLen << 1);
   1.665 +
   1.666 +			TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
   1.667 +			TUint16* dstLimit = dstPtr + aClipDestLen;
   1.668 +			
   1.669 +			switch (iFormat)
   1.670 +				{
   1.671 +				case EUidPixelFormatRGB_565:
   1.672 +					{
   1.673 +					const TUint16* srcPtr = (TUint16*) scanLinePtr;					
   1.674 +					while(dstPtr < dstLimit)
   1.675 +						{
   1.676 +						*dstPtr++ = *(srcPtr + xPos.iX);
   1.677 +						xScaler.NextStep(xPos);
   1.678 +						}
   1.679 +					}
   1.680 +					break;
   1.681 +
   1.682 +				case EUidPixelFormatXRGB_8888:
   1.683 +					{
   1.684 +					const TUint32* srcPtr = scanLinePtr;
   1.685 +					while (dstPtr < dstLimit)
   1.686 +						{
   1.687 +						*dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + xPos.iX)).Color64K());
   1.688 +						xScaler.NextStep(xPos);
   1.689 +						}
   1.690 +					}
   1.691 +					break;
   1.692 +
   1.693 +				case EUidPixelFormatARGB_8888:
   1.694 +					{
   1.695 +					const TUint32* srcPtr = scanLinePtr;
   1.696 +					while (dstPtr < dstLimit)
   1.697 +						{
   1.698 +						*dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + xPos.iX)).Color64K());
   1.699 +						xScaler.NextStep(xPos);
   1.700 +						}
   1.701 +					}
   1.702 +					break;
   1.703 +
   1.704 +				case EUidPixelFormatARGB_8888_PRE:
   1.705 +					{
   1.706 +					const TUint32* srcPtr = scanLinePtr;
   1.707 +					while (dstPtr < dstLimit)
   1.708 +						{
   1.709 +						*dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + xPos.iX)).Color64K());
   1.710 +						xScaler.NextStep(xPos);
   1.711 +						}
   1.712 +					}
   1.713 +					break;
   1.714 +				}
   1.715 +			}
   1.716 +			break;
   1.717 +
   1.718 +		case EUidPixelFormatXRGB_8888:
   1.719 +			{
   1.720 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
   1.721 +			aReadBuf.SetLength(aClipDestLen << 2);
   1.722 +
   1.723 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.724 +			TUint32* dstLimit = dstPtr + aClipDestLen;
   1.725 +			
   1.726 +			switch (iFormat)
   1.727 +				{
   1.728 +				case EUidPixelFormatRGB_565:
   1.729 +					{
   1.730 +					const TUint16* srcPtr = (TUint16*)scanLinePtr;
   1.731 +
   1.732 +					const TUint16* lowAdd = Convert16to32bppLow();
   1.733 +					const TUint32* highAdd = Convert16to32bppHigh();
   1.734 +
   1.735 +					while (dstPtr < dstLimit)
   1.736 +						{
   1.737 +						TUint16 c = *(srcPtr + xPos.iX);
   1.738 +						const TUint8 low = c & 0xff;
   1.739 +						const TUint8 high = c >> 8;
   1.740 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
   1.741 +						
   1.742 +						xScaler.NextStep(xPos);
   1.743 +						}
   1.744 +					}
   1.745 +					break;
   1.746 +
   1.747 +				case EUidPixelFormatXRGB_8888:
   1.748 +				case EUidPixelFormatARGB_8888:
   1.749 +					{
   1.750 +					const TUint32* srcPtr = scanLinePtr;
   1.751 +					while(dstPtr < dstLimit)
   1.752 +						{
   1.753 +						*dstPtr++ = *(srcPtr + xPos.iX);
   1.754 +						xScaler.NextStep(xPos);
   1.755 +						}
   1.756 +					}
   1.757 +					break;
   1.758 +
   1.759 +				case EUidPixelFormatARGB_8888_PRE:
   1.760 +					{
   1.761 +					const TUint32* srcPtr = scanLinePtr;
   1.762 +					const TUint16* normTable = PtrTo16BitNormalisationTable();
   1.763 +					while(dstPtr < dstLimit)
   1.764 +						{
   1.765 +						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
   1.766 +						xScaler.NextStep(xPos);
   1.767 +						}			
   1.768 +					}
   1.769 +					break;
   1.770 +				}
   1.771 +			}
   1.772 +			break;
   1.773 +		
   1.774 +		case EUidPixelFormatARGB_8888:
   1.775 +			{
   1.776 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
   1.777 +			aReadBuf.SetLength(aClipDestLen << 2);
   1.778 +
   1.779 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.780 +			TUint32* dstLimit = dstPtr + aClipDestLen;
   1.781 +			
   1.782 +			switch (iFormat)
   1.783 +				{
   1.784 +				case EUidPixelFormatRGB_565:
   1.785 +					{
   1.786 +					const TUint16* srcPtr = (TUint16*)scanLinePtr;
   1.787 +
   1.788 +					const TUint16* lowAdd = Convert16to32bppLow();
   1.789 +					const TUint32* highAdd = Convert16to32bppHigh();
   1.790 +
   1.791 +					while (dstPtr < dstLimit)
   1.792 +						{
   1.793 +						TUint16 c = *(srcPtr + xPos.iX);
   1.794 +						const TUint8 low = c & 0xff;
   1.795 +						const TUint8 high = c >> 8;
   1.796 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
   1.797 +						
   1.798 +						xScaler.NextStep(xPos);
   1.799 +						}
   1.800 +					}
   1.801 +					break;
   1.802 +					
   1.803 +				case EUidPixelFormatXRGB_8888:
   1.804 +					{
   1.805 +					const TUint32* srcPtr = scanLinePtr;
   1.806 +					while(dstPtr < dstLimit)
   1.807 +						{
   1.808 +						*dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
   1.809 +						xScaler.NextStep(xPos);
   1.810 +						}
   1.811 +					}
   1.812 +					break;
   1.813 +				
   1.814 +				case EUidPixelFormatARGB_8888:
   1.815 +					{
   1.816 +					const TUint32* srcPtr = scanLinePtr;
   1.817 +					while(dstPtr < dstLimit)
   1.818 +						{
   1.819 +						*dstPtr++ = *(srcPtr + xPos.iX);
   1.820 +						xScaler.NextStep(xPos);
   1.821 +						}
   1.822 +					}
   1.823 +					break;
   1.824 +
   1.825 +				case EUidPixelFormatARGB_8888_PRE:
   1.826 +					{
   1.827 +					const TUint32* srcPtr = scanLinePtr;
   1.828 +					const TUint16* normTable = PtrTo16BitNormalisationTable();
   1.829 +					while(dstPtr < dstLimit)
   1.830 +						{
   1.831 +						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
   1.832 +						xScaler.NextStep(xPos);
   1.833 +						}			
   1.834 +					}
   1.835 +					break;
   1.836 +				}
   1.837 +			}
   1.838 +			break;
   1.839 +
   1.840 +		case EUidPixelFormatARGB_8888_PRE:
   1.841 +			{
   1.842 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
   1.843 +			aReadBuf.SetLength(aClipDestLen << 2);
   1.844 +
   1.845 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
   1.846 +			TUint32* dstLimit = dstPtr + aClipDestLen;
   1.847 +			
   1.848 +			switch (iFormat)
   1.849 +				{
   1.850 +				case EUidPixelFormatRGB_565:
   1.851 +					{
   1.852 +					const TUint16* srcPtr = (TUint16*)scanLinePtr;
   1.853 +
   1.854 +					const TUint16* lowAdd = Convert16to32bppLow();
   1.855 +					const TUint32* highAdd = Convert16to32bppHigh();
   1.856 +
   1.857 +					while (dstPtr < dstLimit)
   1.858 +						{
   1.859 +						TUint16 c = *(srcPtr + xPos.iX);
   1.860 +						const TUint8 low = c & 0xff;
   1.861 +						const TUint8 high = c >> 8;
   1.862 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
   1.863 +						
   1.864 +						xScaler.NextStep(xPos);
   1.865 +						}
   1.866 +					}
   1.867 +					break;
   1.868 +
   1.869 +				case EUidPixelFormatXRGB_8888:
   1.870 +					{
   1.871 +					const TUint32* srcPtr = scanLinePtr;
   1.872 +					while(dstPtr < dstLimit)
   1.873 +						{
   1.874 +						*dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
   1.875 +						xScaler.NextStep(xPos);
   1.876 +						}
   1.877 +					}
   1.878 +					break;
   1.879 +
   1.880 +				case EUidPixelFormatARGB_8888_PRE:
   1.881 +					{
   1.882 +					const TUint32* srcPtr = scanLinePtr;
   1.883 +					while(dstPtr < dstLimit)
   1.884 +						{
   1.885 +						*dstPtr++ = *(srcPtr + xPos.iX);
   1.886 +						xScaler.NextStep(xPos);
   1.887 +						}
   1.888 +					}
   1.889 +					break;
   1.890 +
   1.891 +				case EUidPixelFormatARGB_8888:
   1.892 +					{
   1.893 +					const TUint32* srcPtr = scanLinePtr;
   1.894 +					while (dstPtr < dstLimit)
   1.895 +						{
   1.896 +						TUint32 argb = *(srcPtr + xPos.iX);
   1.897 +						Convert2PMA(argb);
   1.898 +						*dstPtr++ = argb;
   1.899 +
   1.900 +						xScaler.NextStep(xPos);
   1.901 +						}
   1.902 +					}
   1.903 +					break;
   1.904 +				}
   1.905 +			}
   1.906 +		break;
   1.907 +		}
   1.908 +	}
   1.909 +
   1.910 +/**
   1.911 +Reads and scales pixels vertically from either top or bottom. Converts to other pixel format 
   1.912 +if requested.
   1.913 +*/
   1.914 +void TPixelBufferReader::GetScaledScanLineV(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
   1.915 +		TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
   1.916 +		TReadDirection aReadDir) const
   1.917 +	{
   1.918 +	// setup DDA for scaling in Y direction, use read pos as starting point and move up or down
   1.919 +	// depending on the read direction
   1.920 +	//
   1.921 +	TLinearDDA yScaler;
   1.922 +	TPoint yPos(aReadPos.iY, 0);
   1.923 +	const TPoint delta = aReadDir==EReadVertical? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
   1.924 +	yScaler.Construct(yPos, yPos + delta, TLinearDDA::ELeft);
   1.925 +
   1.926 +	// jump to dest Y position and return the corresponding src Y position
   1.927 +	yPos.iY = aClipDestPos;
   1.928 +	if (aClipDestPos > 0)
   1.929 +		{
   1.930 +		yScaler.JumpToYCoord(yPos.iX, yPos.iY);
   1.931 +		}
   1.932 +	else
   1.933 +		{
   1.934 +		yScaler.NextStep(yPos);
   1.935 +		}
   1.936 +
   1.937 +	// supported pixel buffer:
   1.938 +	// RGB_565
   1.939 +	// XRGB_8888
   1.940 +	// ARGB_8888
   1.941 +	// ARGB_8888_PRE
   1.942 +
   1.943 +	// supported read format
   1.944 +	// RGB_565
   1.945 +	// XRGB_8888
   1.946 +	// ARGB_8888
   1.947 +	// ARGB_8888_PRE
   1.948 +
   1.949 +	switch(aReadFormat)
   1.950 +		{
   1.951 +		case EUidPixelFormatRGB_565:
   1.952 +			{
   1.953 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
   1.954 +			aReadBuf.SetLength(aClipDestLen << 1);
   1.955 +
   1.956 +			TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
   1.957 +			TUint16* dstLimit = dstPtr + aClipDestLen;
   1.958 +			
   1.959 +			switch (iFormat)
   1.960 +				{
   1.961 +				case EUidPixelFormatRGB_565:
   1.962 +					{
   1.963 +					const TUint16* srcPtr = (TUint16*) iBuffer + aReadPos.iX;
   1.964 +					const TInt offset = iStride >> 1;
   1.965 +					
   1.966 +					while(dstPtr < dstLimit)
   1.967 +						{
   1.968 +						*dstPtr++ = *(srcPtr + yPos.iX * offset);
   1.969 +						yScaler.NextStep(yPos);
   1.970 +						}
   1.971 +					}
   1.972 +					break;
   1.973 +
   1.974 +				case EUidPixelFormatXRGB_8888:
   1.975 +					{
   1.976 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
   1.977 +					const TInt offset = iStride >> 2;
   1.978 +					
   1.979 +					while (dstPtr < dstLimit)
   1.980 +						{
   1.981 +						*dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + yPos.iX * offset)).Color64K());
   1.982 +						yScaler.NextStep(yPos);
   1.983 +						}
   1.984 +					}
   1.985 +					break;
   1.986 +
   1.987 +				case EUidPixelFormatARGB_8888:
   1.988 +					{
   1.989 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
   1.990 +					const TInt offset = iStride >> 2;
   1.991 +					
   1.992 +					while (dstPtr < dstLimit)
   1.993 +						{
   1.994 +						*dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + yPos.iX * offset)).Color64K());
   1.995 +						yScaler.NextStep(yPos);
   1.996 +						}
   1.997 +					}
   1.998 +					break;
   1.999 +
  1.1000 +				case EUidPixelFormatARGB_8888_PRE:
  1.1001 +					{
  1.1002 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1003 +					const TInt offset = iStride >> 2;
  1.1004 +					
  1.1005 +					while (dstPtr < dstLimit)
  1.1006 +						{
  1.1007 +						*dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + yPos.iX * offset)).Color64K());
  1.1008 +						yScaler.NextStep(yPos);
  1.1009 +						}
  1.1010 +					}
  1.1011 +					break;
  1.1012 +				}
  1.1013 +			}
  1.1014 +			break;
  1.1015 +
  1.1016 +		case EUidPixelFormatXRGB_8888:
  1.1017 +			{
  1.1018 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
  1.1019 +			aReadBuf.SetLength(aClipDestLen << 2);
  1.1020 +
  1.1021 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
  1.1022 +			TUint32* dstLimit = dstPtr + aClipDestLen;
  1.1023 +			
  1.1024 +			switch (iFormat)
  1.1025 +				{
  1.1026 +				case EUidPixelFormatRGB_565:
  1.1027 +					{
  1.1028 +					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
  1.1029 +					const TInt offset = iStride >> 1;
  1.1030 +
  1.1031 +					const TUint16* lowAdd = Convert16to32bppLow();
  1.1032 +					const TUint32* highAdd = Convert16to32bppHigh();
  1.1033 +
  1.1034 +					while (dstPtr < dstLimit)
  1.1035 +						{
  1.1036 +						TUint16 c = *(srcPtr + yPos.iX * offset);
  1.1037 +						const TUint8 low = c & 0xff;
  1.1038 +						const TUint8 high = c >> 8;
  1.1039 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
  1.1040 +						
  1.1041 +						yScaler.NextStep(yPos);
  1.1042 +						}
  1.1043 +					}
  1.1044 +					break;
  1.1045 +
  1.1046 +				case EUidPixelFormatXRGB_8888:
  1.1047 +				case EUidPixelFormatARGB_8888:				
  1.1048 +					{
  1.1049 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1050 +					const TInt offset = iStride >> 2;
  1.1051 +					
  1.1052 +					while(dstPtr < dstLimit)
  1.1053 +						{
  1.1054 +						*dstPtr++ = *(srcPtr + yPos.iX * offset);
  1.1055 +						yScaler.NextStep(yPos);
  1.1056 +						}
  1.1057 +					}
  1.1058 +					break;
  1.1059 +
  1.1060 +				case EUidPixelFormatARGB_8888_PRE:
  1.1061 +					{
  1.1062 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1063 +					const TInt offset = iStride >> 2;
  1.1064 +					const TUint16* normTable = PtrTo16BitNormalisationTable();
  1.1065 +					
  1.1066 +					while(dstPtr < dstLimit)
  1.1067 +						{
  1.1068 +						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
  1.1069 +						yScaler.NextStep(yPos);
  1.1070 +						}			
  1.1071 +					}
  1.1072 +					break;
  1.1073 +				}
  1.1074 +			}
  1.1075 +			break;
  1.1076 +		
  1.1077 +		case EUidPixelFormatARGB_8888:
  1.1078 +			{
  1.1079 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
  1.1080 +			aReadBuf.SetLength(aClipDestLen << 2);
  1.1081 +
  1.1082 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
  1.1083 +			TUint32* dstLimit = dstPtr + aClipDestLen;
  1.1084 +			
  1.1085 +			switch (iFormat)
  1.1086 +				{
  1.1087 +				case EUidPixelFormatRGB_565:
  1.1088 +					{
  1.1089 +					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
  1.1090 +					const TInt offset = iStride >> 1;
  1.1091 +
  1.1092 +					const TUint16* lowAdd = Convert16to32bppLow();
  1.1093 +					const TUint32* highAdd = Convert16to32bppHigh();
  1.1094 +
  1.1095 +					while (dstPtr < dstLimit)
  1.1096 +						{
  1.1097 +						TUint16 c = *(srcPtr + yPos.iX * offset);
  1.1098 +						const TUint8 low = c & 0xff;
  1.1099 +						const TUint8 high = c >> 8;
  1.1100 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
  1.1101 +						
  1.1102 +						yScaler.NextStep(yPos);
  1.1103 +						}
  1.1104 +					}
  1.1105 +					break;
  1.1106 +					
  1.1107 +				case EUidPixelFormatXRGB_8888:
  1.1108 +					{
  1.1109 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1110 +					const TInt offset = iStride >> 2;
  1.1111 +					
  1.1112 +					while(dstPtr < dstLimit)
  1.1113 +						{
  1.1114 +						*dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
  1.1115 +						yScaler.NextStep(yPos);
  1.1116 +						}
  1.1117 +					}
  1.1118 +					break;
  1.1119 +				
  1.1120 +				case EUidPixelFormatARGB_8888:
  1.1121 +					{
  1.1122 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1123 +					const TInt offset = iStride >> 2;
  1.1124 +					
  1.1125 +					while(dstPtr < dstLimit)
  1.1126 +						{
  1.1127 +						*dstPtr++ = *(srcPtr + yPos.iX * offset);
  1.1128 +						yScaler.NextStep(yPos);
  1.1129 +						}
  1.1130 +					}
  1.1131 +					break;
  1.1132 +
  1.1133 +				case EUidPixelFormatARGB_8888_PRE:
  1.1134 +					{
  1.1135 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1136 +					const TInt offset = iStride >> 2;
  1.1137 +					const TUint16* normTable = PtrTo16BitNormalisationTable();
  1.1138 +					
  1.1139 +					while(dstPtr < dstLimit)
  1.1140 +						{
  1.1141 +						*dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
  1.1142 +						yScaler.NextStep(yPos);
  1.1143 +						}			
  1.1144 +					}
  1.1145 +					break;
  1.1146 +				}
  1.1147 +			}
  1.1148 +			break;
  1.1149 +
  1.1150 +		case EUidPixelFormatARGB_8888_PRE:
  1.1151 +			{
  1.1152 +			aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
  1.1153 +			aReadBuf.SetLength(aClipDestLen << 2);
  1.1154 +
  1.1155 +			TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
  1.1156 +			TUint32* dstLimit = dstPtr + aClipDestLen;
  1.1157 +			
  1.1158 +			switch (iFormat)
  1.1159 +				{
  1.1160 +				case EUidPixelFormatRGB_565:
  1.1161 +					{
  1.1162 +					const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
  1.1163 +					const TInt offset = iStride >> 1;
  1.1164 +
  1.1165 +					const TUint16* lowAdd = Convert16to32bppLow();
  1.1166 +					const TUint32* highAdd = Convert16to32bppHigh();
  1.1167 +
  1.1168 +					while (dstPtr < dstLimit)
  1.1169 +						{
  1.1170 +						TUint16 c = *(srcPtr + yPos.iX * offset);
  1.1171 +						const TUint8 low = c & 0xff;
  1.1172 +						const TUint8 high = c >> 8;
  1.1173 +						*dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
  1.1174 +						
  1.1175 +						yScaler.NextStep(yPos);
  1.1176 +						}
  1.1177 +					}
  1.1178 +					break;
  1.1179 +
  1.1180 +				case EUidPixelFormatXRGB_8888:
  1.1181 +					{
  1.1182 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1183 +					const TInt offset = iStride >> 2;
  1.1184 +					
  1.1185 +					while(dstPtr < dstLimit)
  1.1186 +						{
  1.1187 +						*dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
  1.1188 +						yScaler.NextStep(yPos);
  1.1189 +						}
  1.1190 +					}
  1.1191 +					break;
  1.1192 +				
  1.1193 +				case EUidPixelFormatARGB_8888_PRE:
  1.1194 +					{
  1.1195 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1196 +					const TInt offset = iStride >> 2;
  1.1197 +					
  1.1198 +					while(dstPtr < dstLimit)
  1.1199 +						{
  1.1200 +						*dstPtr++ = *(srcPtr + yPos.iX * offset);
  1.1201 +						yScaler.NextStep(yPos);
  1.1202 +						}
  1.1203 +					}
  1.1204 +					break;
  1.1205 +
  1.1206 +				case EUidPixelFormatARGB_8888:
  1.1207 +					{
  1.1208 +					const TUint32* srcPtr = iBuffer + aReadPos.iX;
  1.1209 +					const TInt offset = iStride >> 2;
  1.1210 +					
  1.1211 +					while (dstPtr < dstLimit)
  1.1212 +						{
  1.1213 +						TUint32 argb = *(srcPtr + yPos.iX * offset);
  1.1214 +						Convert2PMA(argb);
  1.1215 +						*dstPtr++ = argb;
  1.1216 +
  1.1217 +						yScaler.NextStep(yPos);
  1.1218 +						}
  1.1219 +					}
  1.1220 +					break;
  1.1221 +				}
  1.1222 +			}
  1.1223 +		break;
  1.1224 +		}
  1.1225 +	}