|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "DrawUtils.h" |
|
19 |
|
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; |
|
26 |
|
27 //Number of bits per pixel |
|
28 const TInt BPP8 =8; |
|
29 const TInt BPP12 =12; |
|
30 const TInt BPP16 =16; |
|
31 const TInt BPP24 =24; |
|
32 const TInt BPP32 =32; |
|
33 |
|
34 //16BPP has rgb565 format rrrrrggggggbbbbb. |
|
35 const TInt BPP16RedShift =13; |
|
36 const TInt BPP16GreenShift =8; |
|
37 const TInt BPP16BlueShift =3; |
|
38 |
|
39 //12 bpp has rgb 444 format rrrrggggbbbb. |
|
40 const TInt BPP12RedShift =9; |
|
41 const TInt BPP12GreenShift =5; |
|
42 const TInt BPP12BlueShift =2; |
|
43 |
|
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; |
|
48 |
|
49 |
|
50 void CDrawUtils::ColourFillUtility(TUint8 aColorVal,const TPoint& aPos) |
|
51 /** |
|
52 * |
|
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 |
|
55 * |
|
56 * @param aColorVal: The Colour to be filled in . |
|
57 * Scenarios: |
|
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. |
|
66 * |
|
67 * @param aPos The position of the pixel |
|
68 * |
|
69 * |
|
70 */ |
|
71 { |
|
72 //get screendriver attributes |
|
73 TInt displayMode; |
|
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); |
|
83 |
|
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; |
|
89 |
|
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); |
|
95 |
|
96 if( displayBitsPerPixel == BPP12 ) |
|
97 { |
|
98 bbp = BPP16; |
|
99 } |
|
100 else if ( displayBitsPerPixel == BPP24 ) |
|
101 { |
|
102 bbp = BPP32; |
|
103 } |
|
104 else |
|
105 { |
|
106 bbp = displayBitsPerPixel; |
|
107 } |
|
108 |
|
109 TInt baseAddress=displayMemoryAddress + offsetToFirstPixel + aPos.iY * displayOffsetBetweenLines + aPos.iX * bbp / BPP8; |
|
110 if ( displayBitsPerPixel==BPP8 ) |
|
111 { |
|
112 TUint8 *pixelPtr=(TUint8*)baseAddress; |
|
113 *pixelPtr++=color8bpp; |
|
114 *pixelPtr=color8bpp; |
|
115 } |
|
116 else if ( displayBitsPerPixel == BPP12 ) |
|
117 { |
|
118 TUint16 *pixelPtr=(TUint16*)baseAddress; |
|
119 *pixelPtr++=color12bpp; |
|
120 *pixelPtr=color12bpp; |
|
121 } |
|
122 else if ( displayBitsPerPixel == BPP16 ) |
|
123 { |
|
124 TUint16 *pixelPtr =(TUint16*)baseAddress; |
|
125 *pixelPtr++=color16bpp; |
|
126 *pixelPtr=color16bpp; |
|
127 } |
|
128 else if ( bbp == BPP32 ) |
|
129 { |
|
130 TUint32 *pixelPtr=(TUint32*)baseAddress; |
|
131 *pixelPtr++=color32bpp; |
|
132 *pixelPtr=color32bpp; |
|
133 } |
|
134 } |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 void CDrawUtils::DrawSquareUtility(const TPoint& aTopLeft,const TInt aBoxLength,const TInt aBoxWidth,TUint8 aColorVal) |
|
140 /** |
|
141 * |
|
142 * Draw a filled in square according to the length and width supplied |
|
143 * |
|
144 * @param aTopLeft Pixel position of the top left corner of the box |
|
145 * |
|
146 * @param aBoxLength length in pixels of the box to be drawn. |
|
147 * |
|
148 * @param aBoxWidth width in pixels of the box to be drawn. |
|
149 * |
|
150 * @param aColorVal colour of the box |
|
151 * |
|
152 */ |
|
153 { |
|
154 TInt offSet =1; |
|
155 TInt xOrigin =0; |
|
156 TPoint endPos; |
|
157 TPoint currentPos; |
|
158 if( aTopLeft.iX > xOrigin ) |
|
159 { |
|
160 endPos.iX =aTopLeft.iX + aBoxWidth - offSet; |
|
161 } |
|
162 else//TopLeft x co-ordinate is zero |
|
163 { |
|
164 endPos.iX =aTopLeft.iX + aBoxWidth; |
|
165 } |
|
166 |
|
167 endPos.iY =aTopLeft.iY; |
|
168 currentPos =aTopLeft; |
|
169 |
|
170 for(TInt i=0; i<=aBoxLength; i++) |
|
171 { |
|
172 DrawLineUtility(currentPos,endPos,aColorVal); |
|
173 currentPos.iY =currentPos.iY + offSet; |
|
174 endPos.iY =endPos.iY + offSet; |
|
175 } |
|
176 } |
|
177 |
|
178 |
|
179 void CDrawUtils::DrawLineUtility(const TPoint& aStartPos, const TPoint& aEndPos,const TUint8 aColorVal) |
|
180 /** |
|
181 * |
|
182 * Draw a line with colour specified |
|
183 * |
|
184 * @param aStartPos pixel position to start line. |
|
185 * @param aEndPos pixel position to end line. |
|
186 * |
|
187 */ |
|
188 { |
|
189 TPoint step =aEndPos-aStartPos; |
|
190 TBool isDiagonal =EFalse; |
|
191 TInt origin =0; |
|
192 if (( step.iX>origin ) && ( step.iY>origin )) |
|
193 { |
|
194 isDiagonal =ETrue; |
|
195 } |
|
196 TPoint currentPos=aStartPos; |
|
197 for(TInt i=0; i<=step.iX; i++) |
|
198 { |
|
199 currentPos.iX =( aStartPos.iX + i ); |
|
200 for(TInt j=0; j<=step.iY; j++) |
|
201 { |
|
202 if ( !isDiagonal ) |
|
203 { |
|
204 currentPos.iY =( aStartPos.iY + j ); |
|
205 ColourFillUtility(aColorVal, currentPos); |
|
206 } |
|
207 else //line is diagonal |
|
208 { |
|
209 currentPos.iY =( aStartPos.iY + i ); |
|
210 ColourFillUtility( aColorVal,currentPos); |
|
211 break; |
|
212 } |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 void CDrawUtils::DrawSquareOutLineUtility(const TPoint& aTopLeft,const TInt aBoxHeight,const TInt aBoxWidth,TUint8 aColorVal) |
|
218 /** |
|
219 * |
|
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 |
|
222 * |
|
223 * @param aTopLeft Pixel position of the top left corner of the box |
|
224 * |
|
225 * @param aBoxLength length in pixels of the box to be drawn. |
|
226 * |
|
227 * @param aBoxWidth width in pixels of the box to be drawn. |
|
228 * |
|
229 * |
|
230 */ |
|
231 { |
|
232 TPoint startPos =aTopLeft; |
|
233 TPoint endPos; |
|
234 //top horizontal line |
|
235 endPos.iX =aTopLeft.iX + aBoxWidth; |
|
236 endPos.iY =aTopLeft.iY; |
|
237 DrawLineUtility(startPos, endPos, aColorVal); |
|
238 |
|
239 //vertical left |
|
240 endPos.iX =aTopLeft.iX; |
|
241 endPos.iY =aTopLeft.iY + aBoxHeight; |
|
242 DrawLineUtility(startPos, endPos, aColorVal); |
|
243 |
|
244 //vertical right |
|
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); |
|
250 |
|
251 //bottom horizontal |
|
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); |
|
257 } |