|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "BMDRAW.H" |
|
17 |
|
18 // CDrawTwelveBppBitmap |
|
19 |
|
20 TInt CDrawTwelveBppBitmap::Construct(TSize aSize) |
|
21 { |
|
22 return Construct(aSize, ((aSize.iWidth + 1) & ~1) << 1); |
|
23 } |
|
24 |
|
25 TInt CDrawTwelveBppBitmap::Construct(TSize aSize, TInt aStride) |
|
26 { |
|
27 iDispMode = EColor4K; |
|
28 return CDrawSixteenBppBitmapCommon::Construct(aSize, aStride); |
|
29 } |
|
30 |
|
31 void CDrawTwelveBppBitmap::Shadow(TRgb& aColor) |
|
32 { |
|
33 if (iShadowMode & EFade) |
|
34 aColor = FadeRgb(TRgb::_Color4K(aColor._Color4K())); |
|
35 |
|
36 if (iShadowMode & EShadow) |
|
37 aColor = TRgb::_Color4K(ShadowIndex(TUint16(aColor._Color4K()))); |
|
38 } |
|
39 |
|
40 TUint16 CDrawTwelveBppBitmap::ShadowIndex(TUint16 aColor4KIndex) |
|
41 { |
|
42 TInt red = (aColor4KIndex & 0xf00) >> 8; |
|
43 TInt green = (aColor4KIndex & 0x0f0) >> 4; |
|
44 TInt blue = aColor4KIndex & 0x00f; |
|
45 |
|
46 red = Max(0,red-5); |
|
47 green = Max(0,green-5); |
|
48 blue = Max(0,blue-5); |
|
49 |
|
50 return TUint16((red << 8) | (green << 4) | blue); |
|
51 } |
|
52 |
|
53 TUint16 CDrawTwelveBppBitmap::FadeIndex(TUint16 aColor4KIndex) |
|
54 { |
|
55 return TUint16(FadeRgb(TRgb::_Color4K(aColor4KIndex))._Color4K()); |
|
56 } |
|
57 |
|
58 TRgb CDrawTwelveBppBitmap::ReadRgbNormal(TInt aX,TInt aY) const |
|
59 { |
|
60 return TRgb::_Color4K(*PixelAddress(aX,aY)); |
|
61 } |
|
62 |
|
63 void CDrawTwelveBppBitmap::WriteRgb(TInt aX,TInt aY,TRgb aColor) |
|
64 { |
|
65 *PixelAddress(aX,aY) = TUint16(aColor._Color4K()); |
|
66 } |
|
67 |
|
68 void CDrawTwelveBppBitmap::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor) |
|
69 { |
|
70 CDrawSixteenBppBitmapCommon::WriteBinary(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color4K()); |
|
71 } |
|
72 |
|
73 void CDrawTwelveBppBitmap::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode) |
|
74 { |
|
75 CDrawSixteenBppBitmapCommon::WriteBinaryOp(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color4K(),aDrawMode); |
|
76 } |
|
77 |
|
78 void CDrawTwelveBppBitmap::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aHeight,TRgb aColor,TBool aUp) |
|
79 { |
|
80 CDrawSixteenBppBitmapCommon::WriteBinaryLineVertical(aX,aY,aData,aHeight,(TUint16)aColor._Color4K(),aUp); |
|
81 } |
|
82 |
|
83 /** |
|
84 MAlphaBlend::WriteRgbAlphaLine() implementation. |
|
85 @see MAlphaBlend::WriteRgbAlphaLine() |
|
86 */ |
|
87 void CDrawTwelveBppBitmap::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength, |
|
88 const TUint8* aRgbBuffer, |
|
89 const TUint8* aMaskBuffer, |
|
90 MAlphaBlend::TShadowing aShadowing, |
|
91 CGraphicsContext::TDrawMode /*aDrawMode*/) |
|
92 { |
|
93 DeOrientate(aX,aY); |
|
94 TUint16* pixelPtr = PixelAddress(aX,aY); |
|
95 const TInt pixelPtrInc = PixelAddressIncrement(); |
|
96 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength; |
|
97 TRgb pixelColor; |
|
98 |
|
99 while (aMaskBuffer < maskBufferPtrLimit) |
|
100 { |
|
101 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]); |
|
102 if(aShadowing == MAlphaBlend::EShdwBefore) |
|
103 { |
|
104 Shadow(srcColor); |
|
105 } |
|
106 pixelColor = ::AlphaBlend(srcColor,TRgb::_Color4K(pixelPtr[0]),aMaskBuffer[0]); |
|
107 if(aShadowing == MAlphaBlend::EShdwAfter) |
|
108 { |
|
109 Shadow(pixelColor); |
|
110 } |
|
111 MapColorToUserDisplayMode(pixelColor); |
|
112 pixelPtr[0] = TUint16(pixelColor._Color4K()); |
|
113 |
|
114 pixelPtr += pixelPtrInc; |
|
115 aRgbBuffer += 4; |
|
116 aMaskBuffer++; |
|
117 } |
|
118 } |
|
119 |
|
120 void CDrawTwelveBppBitmap::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor) |
|
121 { |
|
122 CDrawSixteenBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K()); |
|
123 } |
|
124 |
|
125 void CDrawTwelveBppBitmap::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor) |
|
126 { |
|
127 CDrawSixteenBppBitmapCommon::WriteRgbMultiXOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K()); |
|
128 } |
|
129 |
|
130 void CDrawTwelveBppBitmap::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor) |
|
131 { |
|
132 CDrawSixteenBppBitmapCommon::WriteRgbMultiAND(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K()); |
|
133 } |
|
134 |
|
135 void CDrawTwelveBppBitmap::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor) |
|
136 { |
|
137 CDrawSixteenBppBitmapCommon::WriteRgbMultiOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K()); |
|
138 } |
|
139 |
|
140 void CDrawTwelveBppBitmap::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer) |
|
141 { |
|
142 DeOrientate(aX,aY); |
|
143 TUint16* pixelPtr = PixelAddress(aX,aY); |
|
144 const TInt pixelPtrInc = PixelAddressIncrement(); |
|
145 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength; |
|
146 |
|
147 if (iShadowMode) |
|
148 Shadow(aColor); |
|
149 |
|
150 const TInt red = aColor.Red(); |
|
151 const TInt green = aColor.Green(); |
|
152 const TInt blue = aColor.Blue(); |
|
153 while (aMaskBuffer < maskBufferPtrLimit) |
|
154 { |
|
155 pixelPtr[0] = TUint16(AlphaBlend(red,green,blue,TRgb::_Color4K(pixelPtr[0]),aMaskBuffer[0])._Color4K()); |
|
156 |
|
157 pixelPtr += pixelPtrInc; |
|
158 aMaskBuffer++; |
|
159 } |
|
160 } |
|
161 |
|
162 void CDrawTwelveBppBitmap::MapColorToUserDisplayMode(TRgb& aColor) |
|
163 { |
|
164 switch (iUserDispMode) |
|
165 { |
|
166 case EGray2: |
|
167 aColor = TRgb::_Gray2(aColor._Gray2()); |
|
168 break; |
|
169 case EGray4: |
|
170 aColor = TRgb::_Gray4(aColor._Gray4()); |
|
171 break; |
|
172 case EGray16: |
|
173 aColor = TRgb::_Gray16(aColor._Gray16()); |
|
174 break; |
|
175 case EGray256: |
|
176 aColor = TRgb::_Gray256(aColor._Gray256()); |
|
177 break; |
|
178 case EColor16: |
|
179 aColor = TRgb::Color16(aColor.Color16()); |
|
180 break; |
|
181 case EColor256: |
|
182 aColor = TRgb::Color256(aColor.Color256()); |
|
183 break; |
|
184 default: |
|
185 break; |
|
186 } |
|
187 } |
|
188 |
|
189 void CDrawTwelveBppBitmap::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer) |
|
190 { |
|
191 TUint16* bufferPtr = (TUint16*)aBuffer; |
|
192 const TUint16* bufferLimit = bufferPtr + aLength; |
|
193 TRgb color; |
|
194 |
|
195 switch (iUserDispMode) |
|
196 { |
|
197 case EGray2: |
|
198 while (bufferPtr < bufferLimit) |
|
199 { |
|
200 color = TRgb::_Color4K(*bufferPtr); |
|
201 color = TRgb::_Gray2(color._Gray2()); |
|
202 *bufferPtr++ = TUint16(color._Color4K()); |
|
203 } |
|
204 break; |
|
205 case EGray4: |
|
206 while (bufferPtr < bufferLimit) |
|
207 { |
|
208 color = TRgb::_Color4K(*bufferPtr); |
|
209 color = TRgb::_Gray4(color._Gray4()); |
|
210 *bufferPtr++ = TUint16(color._Color4K()); |
|
211 } |
|
212 break; |
|
213 case EGray16: |
|
214 case EGray256: // EGray256 can't be done - nearest is EGray16 |
|
215 while (bufferPtr < bufferLimit) |
|
216 { |
|
217 color = TRgb::_Color4K(*bufferPtr); |
|
218 color = TRgb::_Gray16(color._Gray16()); |
|
219 *bufferPtr++ = TUint16(color._Color4K()); |
|
220 } |
|
221 break; |
|
222 case EColor16: |
|
223 while (bufferPtr < bufferLimit) |
|
224 { |
|
225 color = TRgb::_Color4K(*bufferPtr); |
|
226 color = TRgb::Color16(color.Color16()); |
|
227 *bufferPtr++ = TUint16(color._Color4K()); |
|
228 } |
|
229 break; |
|
230 case EColor256: |
|
231 while (bufferPtr < bufferLimit) |
|
232 { |
|
233 color = TRgb::_Color4K(*bufferPtr); |
|
234 color = TRgb::Color256(color.Color256()); |
|
235 *bufferPtr++ = TUint16(color._Color4K()); |
|
236 } |
|
237 break; |
|
238 default: |
|
239 break; |
|
240 } |
|
241 } |
|
242 |
|
243 TInt CDrawTwelveBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength, |
|
244 TUint32 aOutlinePenColor, TUint32 aShadowColor, |
|
245 TUint32 aFillColor, const TUint8* aDataBuffer) |
|
246 { |
|
247 DeOrientate(aX,aY); |
|
248 TUint16* pixelPtr = PixelAddress(aX,aY); |
|
249 const TInt pixelPtrInc = LogicalPixelAddressIncrement(); |
|
250 const TUint8* dataBufferPtrLimit = aDataBuffer + aLength; |
|
251 TInt blendedRedColor; |
|
252 TInt blendedGreenColor; |
|
253 TInt blendedBlueColor; |
|
254 TUint8 index = 0; |
|
255 TUint32 finalColor; |
|
256 |
|
257 //Get red color. Equivalent to TRgb::Red() |
|
258 const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16; |
|
259 const TInt redShadowColor = (aShadowColor & 0xff0000) >> 16; |
|
260 const TInt redFillColor = (aFillColor & 0xff0000) >> 16; |
|
261 |
|
262 //Get green color. Equivalent to TRgb::Green() |
|
263 const TInt greenOutlinePenColor = (aOutlinePenColor & 0xff00) >> 8; |
|
264 const TInt greenShadowColor = (aShadowColor & 0xff00) >> 8; |
|
265 const TInt greenFillColor = (aFillColor & 0xff00) >> 8; |
|
266 |
|
267 //Get blue color. Equivalent to TRgb::Blue() |
|
268 const TInt blueOutlinePenColor = aOutlinePenColor & 0xff; |
|
269 const TInt blueShadowColor = aShadowColor & 0xff; |
|
270 const TInt blueFillColor = aFillColor & 0xff; |
|
271 |
|
272 while (aDataBuffer < dataBufferPtrLimit) |
|
273 { |
|
274 index = *aDataBuffer++; |
|
275 |
|
276 if (255 == FourColorBlendLookup[index][KBackgroundColorIndex]) |
|
277 { |
|
278 //background colour |
|
279 //No drawing required so move on to next pixel. |
|
280 pixelPtr += pixelPtrInc; |
|
281 continue; |
|
282 } |
|
283 else if (255 == FourColorBlendLookup[index][KFillColorIndex]) |
|
284 { |
|
285 //Use fill colour to draw |
|
286 finalColor = aFillColor; |
|
287 } |
|
288 else if (255 == FourColorBlendLookup[index][KShadowColorIndex]) |
|
289 { |
|
290 //Use shadow colour to draw |
|
291 finalColor = aShadowColor; |
|
292 } |
|
293 else if (255 == FourColorBlendLookup[index][KOutlineColorIndex]) |
|
294 { |
|
295 //Use outline colour to draw |
|
296 finalColor = aOutlinePenColor; |
|
297 } |
|
298 else |
|
299 { |
|
300 //Get the background pixel colour. Equivalent to TRgb::_Color4K(TInt) |
|
301 TUint32 color = (*pixelPtr & 0xf00) << 8; |
|
302 color |= (*pixelPtr & 0x0f0) << 4; |
|
303 color |= (*pixelPtr & 0x00f); |
|
304 |
|
305 //Equivalent to TRgb::TRgb(TUint32, TInt) except that alpha is not set in background colour |
|
306 //as it is not used for calculating final colour |
|
307 TUint32 backgroundColor = (((color | (color << 4)) & 0x00ffffff)); |
|
308 |
|
309 blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + |
|
310 redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] + |
|
311 redFillColor * FourColorBlendLookup[index][KFillColorIndex] + |
|
312 ((backgroundColor & 0xff0000) >> 16) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8; |
|
313 |
|
314 blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + |
|
315 greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] + |
|
316 greenFillColor * FourColorBlendLookup[index][KFillColorIndex] + |
|
317 ((backgroundColor & 0xff00) >> 8) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8; |
|
318 |
|
319 blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + |
|
320 blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] + |
|
321 blueFillColor * FourColorBlendLookup[index][KFillColorIndex] + |
|
322 (backgroundColor & 0xff) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8; |
|
323 |
|
324 //Equivalent to TRgb::TRgb(TUint32) |
|
325 finalColor = (blendedRedColor << 16) | (blendedGreenColor << 8) | blendedBlueColor | 0xff000000; |
|
326 } |
|
327 |
|
328 //Convert 32 bit to 4K colour. Equivalent to TRgb::_Color4K(TInt) |
|
329 TInt finalColor4K = (finalColor & 0x0000f0) >> 4; |
|
330 finalColor4K |= (finalColor & 0x00f000) >> 8; |
|
331 finalColor4K |= (finalColor & 0xf00000) >> 12; |
|
332 |
|
333 //Draw the final colour |
|
334 *pixelPtr = finalColor4K; |
|
335 pixelPtr += pixelPtrInc; |
|
336 } |
|
337 return KErrNone; |
|
338 } |