sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "DrawUtils.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
//These are for masks and shifts for rgb 332 data format.
|
sl@0
|
21 |
const TUint Blue_Mask =0x03;
|
sl@0
|
22 |
const TUint Green_Mask =0x1C;
|
sl@0
|
23 |
const TUint Red_Mask =0xE0;
|
sl@0
|
24 |
const TUint BBP8_GreenShift =2;
|
sl@0
|
25 |
const TUint BBP8_RedShift =5;
|
sl@0
|
26 |
|
sl@0
|
27 |
//Number of bits per pixel
|
sl@0
|
28 |
const TInt BPP8 =8;
|
sl@0
|
29 |
const TInt BPP12 =12;
|
sl@0
|
30 |
const TInt BPP16 =16;
|
sl@0
|
31 |
const TInt BPP24 =24;
|
sl@0
|
32 |
const TInt BPP32 =32;
|
sl@0
|
33 |
|
sl@0
|
34 |
//16BPP has rgb565 format rrrrrggggggbbbbb.
|
sl@0
|
35 |
const TInt BPP16RedShift =13;
|
sl@0
|
36 |
const TInt BPP16GreenShift =8;
|
sl@0
|
37 |
const TInt BPP16BlueShift =3;
|
sl@0
|
38 |
|
sl@0
|
39 |
//12 bpp has rgb 444 format rrrrggggbbbb.
|
sl@0
|
40 |
const TInt BPP12RedShift =9;
|
sl@0
|
41 |
const TInt BPP12GreenShift =5;
|
sl@0
|
42 |
const TInt BPP12BlueShift =2;
|
sl@0
|
43 |
|
sl@0
|
44 |
//24bpp has rgb888 format and 32 bpp has AlRGB 8888 format where Al is alpha.
|
sl@0
|
45 |
const TInt BPP32RedShift =21;
|
sl@0
|
46 |
const TInt BPP32GreenShift =13;
|
sl@0
|
47 |
const TInt BPP32BlueShift =6;
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
void CDrawUtils::ColourFillUtility(TUint8 aColorVal,const TPoint& aPos)
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* Utility Function that fills required colour in at the given x,y positions on the screen,
|
sl@0
|
54 |
* in a 16 pixels * 16 pixels lines area
|
sl@0
|
55 |
*
|
sl@0
|
56 |
* @param aColorVal: The Colour to be filled in .
|
sl@0
|
57 |
* Scenarios:
|
sl@0
|
58 |
* 1) 4 bits per pixel mode
|
sl@0
|
59 |
* aColorVal contains empty upper
|
sl@0
|
60 |
* 4 bits & only contains 4 bits of info,
|
sl@0
|
61 |
* 2) 8 bits per pixel mode
|
sl@0
|
62 |
* all 8 bits in aColorVal are filled and the value,
|
sl@0
|
63 |
* is taken from the standard OS palette.
|
sl@0
|
64 |
* 3) Other modes: all other modes aColorVal
|
sl@0
|
65 |
* holds data in rgb 332 format.
|
sl@0
|
66 |
*
|
sl@0
|
67 |
* @param aPos The position of the pixel
|
sl@0
|
68 |
*
|
sl@0
|
69 |
*
|
sl@0
|
70 |
*/
|
sl@0
|
71 |
{
|
sl@0
|
72 |
//get screendriver attributes
|
sl@0
|
73 |
TInt displayMode;
|
sl@0
|
74 |
HAL::Get(HAL::EDisplayMode, displayMode);
|
sl@0
|
75 |
TInt displayMemoryAddress;
|
sl@0
|
76 |
HAL::Get(HAL::EDisplayMemoryAddress, displayMemoryAddress);
|
sl@0
|
77 |
TInt displayOffsetBetweenLines =displayMode;
|
sl@0
|
78 |
HAL::Get(HAL::EDisplayOffsetBetweenLines, displayOffsetBetweenLines);
|
sl@0
|
79 |
TInt offsetToFirstPixel =displayMode;
|
sl@0
|
80 |
HAL::Get(HAL::EDisplayOffsetToFirstPixel, offsetToFirstPixel);
|
sl@0
|
81 |
TInt displayBitsPerPixel =displayMode;
|
sl@0
|
82 |
HAL::Get(HAL::EDisplayBitsPerPixel, displayBitsPerPixel);
|
sl@0
|
83 |
|
sl@0
|
84 |
TUint red =(aColorVal&Red_Mask)>>BBP8_RedShift;
|
sl@0
|
85 |
TUint green =(aColorVal&Green_Mask)>>BBP8_GreenShift;
|
sl@0
|
86 |
TUint blue =aColorVal&Blue_Mask;
|
sl@0
|
87 |
TUint8 color8bpp =aColorVal;
|
sl@0
|
88 |
TInt bbp =displayBitsPerPixel;
|
sl@0
|
89 |
|
sl@0
|
90 |
//Shifts to convert RGB332 into a respective formats.
|
sl@0
|
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
|
sl@0
|
92 |
TUint color12bpp=(red << BPP12RedShift) | (green << BPP12GreenShift) | (blue << BPP12BlueShift);
|
sl@0
|
93 |
TUint color16bpp=(red << BPP16RedShift) | (green << BPP16GreenShift) | (blue << BPP16BlueShift);
|
sl@0
|
94 |
TUint color32bpp=(red << BPP32RedShift) | (green << BPP32GreenShift) | (blue << BPP32BlueShift);
|
sl@0
|
95 |
|
sl@0
|
96 |
if( displayBitsPerPixel == BPP12 )
|
sl@0
|
97 |
{
|
sl@0
|
98 |
bbp = BPP16;
|
sl@0
|
99 |
}
|
sl@0
|
100 |
else if ( displayBitsPerPixel == BPP24 )
|
sl@0
|
101 |
{
|
sl@0
|
102 |
bbp = BPP32;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else
|
sl@0
|
105 |
{
|
sl@0
|
106 |
bbp = displayBitsPerPixel;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
TInt baseAddress=displayMemoryAddress + offsetToFirstPixel + aPos.iY * displayOffsetBetweenLines + aPos.iX * bbp / BPP8;
|
sl@0
|
110 |
if ( displayBitsPerPixel==BPP8 )
|
sl@0
|
111 |
{
|
sl@0
|
112 |
TUint8 *pixelPtr=(TUint8*)baseAddress;
|
sl@0
|
113 |
*pixelPtr++=color8bpp;
|
sl@0
|
114 |
*pixelPtr=color8bpp;
|
sl@0
|
115 |
}
|
sl@0
|
116 |
else if ( displayBitsPerPixel == BPP12 )
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TUint16 *pixelPtr=(TUint16*)baseAddress;
|
sl@0
|
119 |
*pixelPtr++=color12bpp;
|
sl@0
|
120 |
*pixelPtr=color12bpp;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
else if ( displayBitsPerPixel == BPP16 )
|
sl@0
|
123 |
{
|
sl@0
|
124 |
TUint16 *pixelPtr =(TUint16*)baseAddress;
|
sl@0
|
125 |
*pixelPtr++=color16bpp;
|
sl@0
|
126 |
*pixelPtr=color16bpp;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
else if ( bbp == BPP32 )
|
sl@0
|
129 |
{
|
sl@0
|
130 |
TUint32 *pixelPtr=(TUint32*)baseAddress;
|
sl@0
|
131 |
*pixelPtr++=color32bpp;
|
sl@0
|
132 |
*pixelPtr=color32bpp;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
|
sl@0
|
137 |
|
sl@0
|
138 |
|
sl@0
|
139 |
void CDrawUtils::DrawSquareUtility(const TPoint& aTopLeft,const TInt aBoxLength,const TInt aBoxWidth,TUint8 aColorVal)
|
sl@0
|
140 |
/**
|
sl@0
|
141 |
*
|
sl@0
|
142 |
* Draw a filled in square according to the length and width supplied
|
sl@0
|
143 |
*
|
sl@0
|
144 |
* @param aTopLeft Pixel position of the top left corner of the box
|
sl@0
|
145 |
*
|
sl@0
|
146 |
* @param aBoxLength length in pixels of the box to be drawn.
|
sl@0
|
147 |
*
|
sl@0
|
148 |
* @param aBoxWidth width in pixels of the box to be drawn.
|
sl@0
|
149 |
*
|
sl@0
|
150 |
* @param aColorVal colour of the box
|
sl@0
|
151 |
*
|
sl@0
|
152 |
*/
|
sl@0
|
153 |
{
|
sl@0
|
154 |
TInt offSet =1;
|
sl@0
|
155 |
TInt xOrigin =0;
|
sl@0
|
156 |
TPoint endPos;
|
sl@0
|
157 |
TPoint currentPos;
|
sl@0
|
158 |
if( aTopLeft.iX > xOrigin )
|
sl@0
|
159 |
{
|
sl@0
|
160 |
endPos.iX =aTopLeft.iX + aBoxWidth - offSet;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
else//TopLeft x co-ordinate is zero
|
sl@0
|
163 |
{
|
sl@0
|
164 |
endPos.iX =aTopLeft.iX + aBoxWidth;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
endPos.iY =aTopLeft.iY;
|
sl@0
|
168 |
currentPos =aTopLeft;
|
sl@0
|
169 |
|
sl@0
|
170 |
for(TInt i=0; i<=aBoxLength; i++)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
DrawLineUtility(currentPos,endPos,aColorVal);
|
sl@0
|
173 |
currentPos.iY =currentPos.iY + offSet;
|
sl@0
|
174 |
endPos.iY =endPos.iY + offSet;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
|
sl@0
|
179 |
void CDrawUtils::DrawLineUtility(const TPoint& aStartPos, const TPoint& aEndPos,const TUint8 aColorVal)
|
sl@0
|
180 |
/**
|
sl@0
|
181 |
*
|
sl@0
|
182 |
* Draw a line with colour specified
|
sl@0
|
183 |
*
|
sl@0
|
184 |
* @param aStartPos pixel position to start line.
|
sl@0
|
185 |
* @param aEndPos pixel position to end line.
|
sl@0
|
186 |
*
|
sl@0
|
187 |
*/
|
sl@0
|
188 |
{
|
sl@0
|
189 |
TPoint step =aEndPos-aStartPos;
|
sl@0
|
190 |
TBool isDiagonal =EFalse;
|
sl@0
|
191 |
TInt origin =0;
|
sl@0
|
192 |
if (( step.iX>origin ) && ( step.iY>origin ))
|
sl@0
|
193 |
{
|
sl@0
|
194 |
isDiagonal =ETrue;
|
sl@0
|
195 |
}
|
sl@0
|
196 |
TPoint currentPos=aStartPos;
|
sl@0
|
197 |
for(TInt i=0; i<=step.iX; i++)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
currentPos.iX =( aStartPos.iX + i );
|
sl@0
|
200 |
for(TInt j=0; j<=step.iY; j++)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
if ( !isDiagonal )
|
sl@0
|
203 |
{
|
sl@0
|
204 |
currentPos.iY =( aStartPos.iY + j );
|
sl@0
|
205 |
ColourFillUtility(aColorVal, currentPos);
|
sl@0
|
206 |
}
|
sl@0
|
207 |
else //line is diagonal
|
sl@0
|
208 |
{
|
sl@0
|
209 |
currentPos.iY =( aStartPos.iY + i );
|
sl@0
|
210 |
ColourFillUtility( aColorVal,currentPos);
|
sl@0
|
211 |
break;
|
sl@0
|
212 |
}
|
sl@0
|
213 |
}
|
sl@0
|
214 |
}
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
void CDrawUtils::DrawSquareOutLineUtility(const TPoint& aTopLeft,const TInt aBoxHeight,const TInt aBoxWidth,TUint8 aColorVal)
|
sl@0
|
218 |
/**
|
sl@0
|
219 |
*
|
sl@0
|
220 |
* Draw an outline of a square i.e a square that has not been filled in with colour
|
sl@0
|
221 |
* Draw a filled in square according to the length and width supplied
|
sl@0
|
222 |
*
|
sl@0
|
223 |
* @param aTopLeft Pixel position of the top left corner of the box
|
sl@0
|
224 |
*
|
sl@0
|
225 |
* @param aBoxLength length in pixels of the box to be drawn.
|
sl@0
|
226 |
*
|
sl@0
|
227 |
* @param aBoxWidth width in pixels of the box to be drawn.
|
sl@0
|
228 |
*
|
sl@0
|
229 |
*
|
sl@0
|
230 |
*/
|
sl@0
|
231 |
{
|
sl@0
|
232 |
TPoint startPos =aTopLeft;
|
sl@0
|
233 |
TPoint endPos;
|
sl@0
|
234 |
//top horizontal line
|
sl@0
|
235 |
endPos.iX =aTopLeft.iX + aBoxWidth;
|
sl@0
|
236 |
endPos.iY =aTopLeft.iY;
|
sl@0
|
237 |
DrawLineUtility(startPos, endPos, aColorVal);
|
sl@0
|
238 |
|
sl@0
|
239 |
//vertical left
|
sl@0
|
240 |
endPos.iX =aTopLeft.iX;
|
sl@0
|
241 |
endPos.iY =aTopLeft.iY + aBoxHeight;
|
sl@0
|
242 |
DrawLineUtility(startPos, endPos, aColorVal);
|
sl@0
|
243 |
|
sl@0
|
244 |
//vertical right
|
sl@0
|
245 |
startPos.iX =aTopLeft.iX + aBoxWidth;
|
sl@0
|
246 |
startPos.iY =aTopLeft.iY;
|
sl@0
|
247 |
endPos.iX =aTopLeft.iX + aBoxWidth;
|
sl@0
|
248 |
endPos.iY =aTopLeft.iY + aBoxHeight;
|
sl@0
|
249 |
DrawLineUtility(startPos, endPos, aColorVal);
|
sl@0
|
250 |
|
sl@0
|
251 |
//bottom horizontal
|
sl@0
|
252 |
startPos.iX =aTopLeft.iX;
|
sl@0
|
253 |
startPos.iY =aTopLeft.iY + aBoxHeight;
|
sl@0
|
254 |
endPos.iX =aTopLeft.iX + aBoxWidth;
|
sl@0
|
255 |
endPos.iY =aTopLeft.iY + aBoxHeight;
|
sl@0
|
256 |
DrawLineUtility(startPos, endPos, aColorVal);
|
sl@0
|
257 |
}
|