os/boardsupport/haitest/bspsvs/suite/common/src/DrawUtils.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/common/src/DrawUtils.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,257 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#include "DrawUtils.h"
    1.22 +
    1.23 +//These are for masks and shifts for rgb 332 data format.
    1.24 +const 	TUint Blue_Mask                 =0x03;
    1.25 +const	TUint Green_Mask                =0x1C;
    1.26 +const	TUint Red_Mask                  =0xE0;
    1.27 +const	TUint BBP8_GreenShift           =2;
    1.28 +const	TUint BBP8_RedShift             =5;
    1.29 +
    1.30 +//Number of bits per pixel
    1.31 +const TInt	BPP8                    =8;
    1.32 +const TInt	BPP12                   =12;
    1.33 +const TInt	BPP16                   =16;
    1.34 +const TInt	BPP24                   =24;
    1.35 +const TInt	BPP32                   =32;
    1.36 +
    1.37 +//16BPP has rgb565 format rrrrrggggggbbbbb.
    1.38 +const TInt 	BPP16RedShift           =13;
    1.39 +const TInt	BPP16GreenShift         =8;
    1.40 +const TInt	BPP16BlueShift          =3;
    1.41 +
    1.42 +//12 bpp has rgb 444 format rrrrggggbbbb.
    1.43 +const TInt	BPP12RedShift           =9;
    1.44 +const TInt	BPP12GreenShift         =5;
    1.45 +const TInt	BPP12BlueShift          =2;
    1.46 +	
    1.47 +//24bpp has rgb888 format and 32 bpp has AlRGB 8888 format where Al is alpha.
    1.48 +const TInt	BPP32RedShift           =21;
    1.49 +const TInt	BPP32GreenShift         =13;
    1.50 +const TInt	BPP32BlueShift          =6;
    1.51 +	
    1.52 +
    1.53 +void CDrawUtils::ColourFillUtility(TUint8 aColorVal,const TPoint& aPos)
    1.54 +/**
    1.55 +*
    1.56 +*  Utility Function that fills required colour in at the given x,y positions on the screen,
    1.57 +*  in a 16 pixels *	16 pixels lines area 
    1.58 +*
    1.59 +* 		@param 				aColorVal:  The Colour to be filled in .
    1.60 +*							Scenarios:
    1.61 +* 							1) 	4 bits per pixel mode
    1.62 +* 							   	aColorVal contains empty upper
    1.63 +* 							   	4 bits & only contains 4 bits of info, 
    1.64 +* 							2)	8 bits per pixel  mode
    1.65 +* 								all 8 bits in aColorVal are filled and the value,
    1.66 +* 								is taken from the standard  OS palette.
    1.67 +* 							3)	Other modes: all other modes aColorVal
    1.68 +*			 					holds data in rgb 332 format.
    1.69 +*
    1.70 +* 		@param 				aPos  		The position of the pixel 
    1.71 +*
    1.72 +* 
    1.73 +*/
    1.74 +    {
    1.75 +    //get screendriver attributes
    1.76 +    TInt displayMode;
    1.77 +    HAL::Get(HAL::EDisplayMode, displayMode);
    1.78 +    TInt displayMemoryAddress;
    1.79 +    HAL::Get(HAL::EDisplayMemoryAddress, displayMemoryAddress);
    1.80 +    TInt displayOffsetBetweenLines      =displayMode;
    1.81 +    HAL::Get(HAL::EDisplayOffsetBetweenLines, displayOffsetBetweenLines);
    1.82 +    TInt offsetToFirstPixel             =displayMode;
    1.83 +    HAL::Get(HAL::EDisplayOffsetToFirstPixel, offsetToFirstPixel);
    1.84 +    TInt displayBitsPerPixel            =displayMode;
    1.85 +    HAL::Get(HAL::EDisplayBitsPerPixel, displayBitsPerPixel);
    1.86 +	
    1.87 +    TUint       red             =(aColorVal&Red_Mask)>>BBP8_RedShift;	
    1.88 +    TUint       green           =(aColorVal&Green_Mask)>>BBP8_GreenShift;
    1.89 +    TUint       blue            =aColorVal&Blue_Mask;
    1.90 +    TUint8      color8bpp       =aColorVal; 
    1.91 +    TInt        bbp             =displayBitsPerPixel;
    1.92 +  	
    1.93 +    //Shifts to convert RGB332 into a respective formats.
    1.94 +    //12 bpp has rgb format 444, 16 bpp has rgb format 565, 24 bpp has rgb 888 format, 32 bpp has Al rgb 8888 format : Al is alpha 
    1.95 +    TUint color12bpp=(red << BPP12RedShift) | (green << BPP12GreenShift) | (blue << BPP12BlueShift);
    1.96 +    TUint color16bpp=(red << BPP16RedShift) | (green << BPP16GreenShift) | (blue << BPP16BlueShift);
    1.97 +    TUint color32bpp=(red << BPP32RedShift) | (green << BPP32GreenShift) | (blue << BPP32BlueShift);
    1.98 +    
    1.99 +    if( displayBitsPerPixel == BPP12 )
   1.100 +        {
   1.101 +        bbp = BPP16;
   1.102 +        }
   1.103 +    else if ( displayBitsPerPixel == BPP24 )
   1.104 +        {
   1.105 +        bbp = BPP32;
   1.106 +        }
   1.107 +    else
   1.108 +        {
   1.109 +        bbp = displayBitsPerPixel;
   1.110 +        }
   1.111 +		
   1.112 +    TInt baseAddress=displayMemoryAddress + offsetToFirstPixel + aPos.iY * displayOffsetBetweenLines + aPos.iX * bbp / BPP8;
   1.113 +    if ( displayBitsPerPixel==BPP8 )
   1.114 +          {
   1.115 +          TUint8 *pixelPtr=(TUint8*)baseAddress;
   1.116 +          *pixelPtr++=color8bpp;
   1.117 +          *pixelPtr=color8bpp;
   1.118 +          }
   1.119 +    else if ( displayBitsPerPixel == BPP12 )
   1.120 +          {
   1.121 +          TUint16 *pixelPtr=(TUint16*)baseAddress;
   1.122 +          *pixelPtr++=color12bpp;
   1.123 +          *pixelPtr=color12bpp;	
   1.124 +          }
   1.125 +    else if ( displayBitsPerPixel == BPP16 )
   1.126 +          {
   1.127 +          TUint16 *pixelPtr	=(TUint16*)baseAddress;
   1.128 +          *pixelPtr++=color16bpp;
   1.129 +          *pixelPtr=color16bpp;
   1.130 +          }
   1.131 +    else if ( bbp == BPP32 )
   1.132 +          {
   1.133 +          TUint32 *pixelPtr=(TUint32*)baseAddress;
   1.134 +          *pixelPtr++=color32bpp;
   1.135 +          *pixelPtr=color32bpp;
   1.136 +          }
   1.137 +    }
   1.138 +	
   1.139 +		
   1.140 +
   1.141 +
   1.142 +void  CDrawUtils::DrawSquareUtility(const TPoint& aTopLeft,const TInt aBoxLength,const TInt aBoxWidth,TUint8 aColorVal)
   1.143 +/**
   1.144 + *
   1.145 + * Draw a filled in square  according to the length and width supplied
   1.146 + *
   1.147 + * @param 		aTopLeft Pixel position of the top left corner of the box	
   1.148 + *
   1.149 + * @param 		aBoxLength length in pixels of the box to be drawn.
   1.150 + *
   1.151 + * @param 		aBoxWidth width  in pixels of the box to be drawn.
   1.152 + *
   1.153 + * @param 		aColorVal colour of the box
   1.154 + *
   1.155 + */
   1.156 + 	{
   1.157 + 	TInt 	offSet		=1;	
   1.158 +	TInt 	xOrigin		=0;
   1.159 +	TPoint 	endPos;
   1.160 +	TPoint	currentPos;
   1.161 +	if( aTopLeft.iX > xOrigin )
   1.162 +		{
   1.163 +		endPos.iX	=aTopLeft.iX + aBoxWidth - offSet;
   1.164 +		}
   1.165 +	else//TopLeft x co-ordinate is zero
   1.166 +		{
   1.167 +		endPos.iX	=aTopLeft.iX + aBoxWidth;
   1.168 +		}
   1.169 +		
   1.170 +	endPos.iY	=aTopLeft.iY;
   1.171 +	currentPos	=aTopLeft;
   1.172 +			
   1.173 +	for(TInt i=0; i<=aBoxLength; i++)
   1.174 + 		{
   1.175 + 		DrawLineUtility(currentPos,endPos,aColorVal);
   1.176 + 		currentPos.iY	=currentPos.iY + offSet;
   1.177 + 		endPos.iY		=endPos.iY + offSet;
   1.178 + 		}	
   1.179 +	}
   1.180 +	
   1.181 +	
   1.182 +void  CDrawUtils::DrawLineUtility(const TPoint& aStartPos, const TPoint& aEndPos,const TUint8 aColorVal)
   1.183 +/**
   1.184 + *
   1.185 + * Draw a line  with colour specified 
   1.186 + *
   1.187 + * @param 		aStartPos  pixel position to  start line.
   1.188 + * @param 		aEndPos    pixel position to  end line.
   1.189 + *
   1.190 + */	
   1.191 +	{	
   1.192 + 	TPoint 		step		=aEndPos-aStartPos;
   1.193 + 	TBool 		isDiagonal	=EFalse;
   1.194 + 	TInt		origin		=0;
   1.195 + 	if	(( step.iX>origin ) && ( step.iY>origin ))
   1.196 + 		{
   1.197 + 		isDiagonal	=ETrue;
   1.198 + 		}		
   1.199 + 	TPoint 		currentPos=aStartPos;	
   1.200 + 	for(TInt i=0; i<=step.iX; i++)
   1.201 + 		{
   1.202 + 		currentPos.iX	=( aStartPos.iX + i );
   1.203 + 		for(TInt j=0; j<=step.iY; j++)
   1.204 + 			{
   1.205 + 			if	( !isDiagonal )
   1.206 + 				{
   1.207 + 				currentPos.iY	=( aStartPos.iY + j );
   1.208 + 				ColourFillUtility(aColorVal, currentPos);
   1.209 + 				}
   1.210 + 			else //line is diagonal
   1.211 + 				{
   1.212 + 				currentPos.iY	=( aStartPos.iY + i );
   1.213 + 				ColourFillUtility( aColorVal,currentPos);	
   1.214 + 				break;
   1.215 + 				}
   1.216 + 			}
   1.217 + 		}
   1.218 +	}
   1.219 +	
   1.220 +void    CDrawUtils::DrawSquareOutLineUtility(const TPoint& aTopLeft,const TInt aBoxHeight,const TInt aBoxWidth,TUint8 aColorVal)
   1.221 +/**
   1.222 + *
   1.223 + * Draw an outline of a square i.e a square that has not been filled in with colour
   1.224 + * Draw a filled in square  according to the length and width supplied
   1.225 + *
   1.226 + * @param 		aTopLeft Pixel position of the top left corner of the box	
   1.227 + *
   1.228 + * @param 		aBoxLength length in pixels of the box to be drawn.
   1.229 + *
   1.230 + * @param 		aBoxWidth width  in pixels of the box to be drawn.
   1.231 + *
   1.232 + *
   1.233 + */		
   1.234 +	{
   1.235 +	TPoint startPos	=aTopLeft;
   1.236 +	TPoint endPos;
   1.237 +	//top horizontal line
   1.238 +	endPos.iX		=aTopLeft.iX + aBoxWidth;
   1.239 +	endPos.iY		=aTopLeft.iY;
   1.240 +	DrawLineUtility(startPos, endPos, aColorVal);
   1.241 +
   1.242 +	//vertical left
   1.243 +	endPos.iX		=aTopLeft.iX;
   1.244 +	endPos.iY		=aTopLeft.iY + aBoxHeight;								
   1.245 +	DrawLineUtility(startPos, endPos, aColorVal);
   1.246 +
   1.247 +	//vertical right
   1.248 +	startPos.iX 	=aTopLeft.iX + aBoxWidth;
   1.249 +	startPos.iY		=aTopLeft.iY;
   1.250 +	endPos.iX		=aTopLeft.iX + aBoxWidth;
   1.251 +	endPos.iY		=aTopLeft.iY + aBoxHeight;
   1.252 +	DrawLineUtility(startPos, endPos, aColorVal);
   1.253 +	
   1.254 +	//bottom horizontal									
   1.255 +	startPos.iX 	=aTopLeft.iX;
   1.256 +	startPos.iY 	=aTopLeft.iY + aBoxHeight;
   1.257 +	endPos.iX		=aTopLeft.iX + aBoxWidth;
   1.258 +	endPos.iY		=aTopLeft.iY + aBoxHeight;											
   1.259 +	DrawLineUtility(startPos, endPos, aColorVal);		
   1.260 +	}