First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
18 #include "DrawUtils.h"
20 //These are for masks and shifts for rgb 332 data format.
21 const TUint Blue_Mask =0x03;
22 const TUint Green_Mask =0x1C;
23 const TUint Red_Mask =0xE0;
24 const TUint BBP8_GreenShift =2;
25 const TUint BBP8_RedShift =5;
27 //Number of bits per pixel
34 //16BPP has rgb565 format rrrrrggggggbbbbb.
35 const TInt BPP16RedShift =13;
36 const TInt BPP16GreenShift =8;
37 const TInt BPP16BlueShift =3;
39 //12 bpp has rgb 444 format rrrrggggbbbb.
40 const TInt BPP12RedShift =9;
41 const TInt BPP12GreenShift =5;
42 const TInt BPP12BlueShift =2;
44 //24bpp has rgb888 format and 32 bpp has AlRGB 8888 format where Al is alpha.
45 const TInt BPP32RedShift =21;
46 const TInt BPP32GreenShift =13;
47 const TInt BPP32BlueShift =6;
50 void CDrawUtils::ColourFillUtility(TUint8 aColorVal,const TPoint& aPos)
53 * Utility Function that fills required colour in at the given x,y positions on the screen,
54 * in a 16 pixels * 16 pixels lines area
56 * @param aColorVal: The Colour to be filled in .
58 * 1) 4 bits per pixel mode
59 * aColorVal contains empty upper
60 * 4 bits & only contains 4 bits of info,
61 * 2) 8 bits per pixel mode
62 * all 8 bits in aColorVal are filled and the value,
63 * is taken from the standard OS palette.
64 * 3) Other modes: all other modes aColorVal
65 * holds data in rgb 332 format.
67 * @param aPos The position of the pixel
72 //get screendriver attributes
74 HAL::Get(HAL::EDisplayMode, displayMode);
75 TInt displayMemoryAddress;
76 HAL::Get(HAL::EDisplayMemoryAddress, displayMemoryAddress);
77 TInt displayOffsetBetweenLines =displayMode;
78 HAL::Get(HAL::EDisplayOffsetBetweenLines, displayOffsetBetweenLines);
79 TInt offsetToFirstPixel =displayMode;
80 HAL::Get(HAL::EDisplayOffsetToFirstPixel, offsetToFirstPixel);
81 TInt displayBitsPerPixel =displayMode;
82 HAL::Get(HAL::EDisplayBitsPerPixel, displayBitsPerPixel);
84 TUint red =(aColorVal&Red_Mask)>>BBP8_RedShift;
85 TUint green =(aColorVal&Green_Mask)>>BBP8_GreenShift;
86 TUint blue =aColorVal&Blue_Mask;
87 TUint8 color8bpp =aColorVal;
88 TInt bbp =displayBitsPerPixel;
90 //Shifts to convert RGB332 into a respective formats.
91 //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
92 TUint color12bpp=(red << BPP12RedShift) | (green << BPP12GreenShift) | (blue << BPP12BlueShift);
93 TUint color16bpp=(red << BPP16RedShift) | (green << BPP16GreenShift) | (blue << BPP16BlueShift);
94 TUint color32bpp=(red << BPP32RedShift) | (green << BPP32GreenShift) | (blue << BPP32BlueShift);
96 if( displayBitsPerPixel == BPP12 )
100 else if ( displayBitsPerPixel == BPP24 )
106 bbp = displayBitsPerPixel;
109 TInt baseAddress=displayMemoryAddress + offsetToFirstPixel + aPos.iY * displayOffsetBetweenLines + aPos.iX * bbp / BPP8;
110 if ( displayBitsPerPixel==BPP8 )
112 TUint8 *pixelPtr=(TUint8*)baseAddress;
113 *pixelPtr++=color8bpp;
116 else if ( displayBitsPerPixel == BPP12 )
118 TUint16 *pixelPtr=(TUint16*)baseAddress;
119 *pixelPtr++=color12bpp;
120 *pixelPtr=color12bpp;
122 else if ( displayBitsPerPixel == BPP16 )
124 TUint16 *pixelPtr =(TUint16*)baseAddress;
125 *pixelPtr++=color16bpp;
126 *pixelPtr=color16bpp;
128 else if ( bbp == BPP32 )
130 TUint32 *pixelPtr=(TUint32*)baseAddress;
131 *pixelPtr++=color32bpp;
132 *pixelPtr=color32bpp;
139 void CDrawUtils::DrawSquareUtility(const TPoint& aTopLeft,const TInt aBoxLength,const TInt aBoxWidth,TUint8 aColorVal)
142 * Draw a filled in square according to the length and width supplied
144 * @param aTopLeft Pixel position of the top left corner of the box
146 * @param aBoxLength length in pixels of the box to be drawn.
148 * @param aBoxWidth width in pixels of the box to be drawn.
150 * @param aColorVal colour of the box
158 if( aTopLeft.iX > xOrigin )
160 endPos.iX =aTopLeft.iX + aBoxWidth - offSet;
162 else//TopLeft x co-ordinate is zero
164 endPos.iX =aTopLeft.iX + aBoxWidth;
167 endPos.iY =aTopLeft.iY;
168 currentPos =aTopLeft;
170 for(TInt i=0; i<=aBoxLength; i++)
172 DrawLineUtility(currentPos,endPos,aColorVal);
173 currentPos.iY =currentPos.iY + offSet;
174 endPos.iY =endPos.iY + offSet;
179 void CDrawUtils::DrawLineUtility(const TPoint& aStartPos, const TPoint& aEndPos,const TUint8 aColorVal)
182 * Draw a line with colour specified
184 * @param aStartPos pixel position to start line.
185 * @param aEndPos pixel position to end line.
189 TPoint step =aEndPos-aStartPos;
190 TBool isDiagonal =EFalse;
192 if (( step.iX>origin ) && ( step.iY>origin ))
196 TPoint currentPos=aStartPos;
197 for(TInt i=0; i<=step.iX; i++)
199 currentPos.iX =( aStartPos.iX + i );
200 for(TInt j=0; j<=step.iY; j++)
204 currentPos.iY =( aStartPos.iY + j );
205 ColourFillUtility(aColorVal, currentPos);
207 else //line is diagonal
209 currentPos.iY =( aStartPos.iY + i );
210 ColourFillUtility( aColorVal,currentPos);
217 void CDrawUtils::DrawSquareOutLineUtility(const TPoint& aTopLeft,const TInt aBoxHeight,const TInt aBoxWidth,TUint8 aColorVal)
220 * Draw an outline of a square i.e a square that has not been filled in with colour
221 * Draw a filled in square according to the length and width supplied
223 * @param aTopLeft Pixel position of the top left corner of the box
225 * @param aBoxLength length in pixels of the box to be drawn.
227 * @param aBoxWidth width in pixels of the box to be drawn.
232 TPoint startPos =aTopLeft;
234 //top horizontal line
235 endPos.iX =aTopLeft.iX + aBoxWidth;
236 endPos.iY =aTopLeft.iY;
237 DrawLineUtility(startPos, endPos, aColorVal);
240 endPos.iX =aTopLeft.iX;
241 endPos.iY =aTopLeft.iY + aBoxHeight;
242 DrawLineUtility(startPos, endPos, aColorVal);
245 startPos.iX =aTopLeft.iX + aBoxWidth;
246 startPos.iY =aTopLeft.iY;
247 endPos.iX =aTopLeft.iX + aBoxWidth;
248 endPos.iY =aTopLeft.iY + aBoxHeight;
249 DrawLineUtility(startPos, endPos, aColorVal);
252 startPos.iX =aTopLeft.iX;
253 startPos.iY =aTopLeft.iY + aBoxHeight;
254 endPos.iX =aTopLeft.iX + aBoxWidth;
255 endPos.iY =aTopLeft.iY + aBoxHeight;
256 DrawLineUtility(startPos, endPos, aColorVal);