|
1 /* |
|
2 * Copyright (c) 2005 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 "CMIDImage.h" |
|
19 #include "CMIDBitmapImage.h" |
|
20 #include "LcdImage.h" |
|
21 #include "LcdFbsImage.h" |
|
22 #include "LcdFbsImageCache.h" |
|
23 |
|
24 #ifdef _DEBUG |
|
25 static const TUint KTransparancyMapCount = 6; |
|
26 #endif |
|
27 |
|
28 const MMIDImage::TTransparencyType TransparencyMap[] = |
|
29 { |
|
30 MMIDImage::ENone, /* ETransparencyNone */ |
|
31 MMIDImage::EMask, /* ETransparencyMaskBitmap */ |
|
32 MMIDImage::EAlpha, /* ETransparencyAlphaBitmap */ |
|
33 MMIDImage::EAlpha, /* ETransparencyAlphaChannel*/ |
|
34 MMIDImage::EMask, /* ETransparencyMaskChannel */ |
|
35 MMIDImage::ENone /* ETransparencyIgnoreChannel */ |
|
36 }; |
|
37 |
|
38 |
|
39 CMIDImage::CMIDImage(CLcdFbsImageCache& aCache, MImageTypeMap& aTypeMap, CLcdImage* aImage) |
|
40 : iCache(aCache) |
|
41 , iTypeMap(aTypeMap) |
|
42 , iImage(aImage) |
|
43 { |
|
44 } |
|
45 |
|
46 void CMIDImage::ConstructL() |
|
47 { |
|
48 RegisterL(); |
|
49 } |
|
50 |
|
51 void CMIDImage::RegisterL() |
|
52 { |
|
53 CMIDBitmapImage* bitmapImage = new(ELeave) CMIDBitmapImage(*iImage->FbsImage()); |
|
54 CleanupStack::PushL(bitmapImage); |
|
55 iCache.RegisterL(this, EFalse, bitmapImage); |
|
56 CleanupStack::Pop(bitmapImage); |
|
57 } |
|
58 |
|
59 CMIDImage::~CMIDImage() |
|
60 { |
|
61 iCache.Purge(this); |
|
62 delete iImage; |
|
63 } |
|
64 |
|
65 MMIDImage::TTransparencyType |
|
66 CMIDImage::TransparencyType() const |
|
67 { |
|
68 TTransparency transparency = iImage->Transparency(); |
|
69 |
|
70 ASSERT(0 <= transparency && transparency < KTransparancyMapCount); |
|
71 |
|
72 return TransparencyMap[transparency]; |
|
73 } |
|
74 |
|
75 TInt CMIDImage::SetTransparencyType(TTransparencyType aType) |
|
76 { |
|
77 if (TransparencyType() == aType) |
|
78 { |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 if (aType != MMIDImage::EAlpha) |
|
83 { |
|
84 // |
|
85 // Only support switch to alpha for transparent mutable images. |
|
86 // Fail all other cases. |
|
87 // |
|
88 return KErrNotSupported; |
|
89 } |
|
90 |
|
91 // |
|
92 // Set new image type and fixup cache entries. Iff any of these steps |
|
93 // fail the image may be left in an inconsistent state. It is anticipated |
|
94 // that SetTransparencyType will be called once only during transparent |
|
95 // mutable image construction (the only supported use case). Hence |
|
96 // transactional error handling not required as failure will result in |
|
97 // immediate destruction of the image. |
|
98 // |
|
99 TInt err = iImage->SetImageType(iTypeMap.GetImageType(aType)); |
|
100 if (0 == err) |
|
101 { |
|
102 iCache.Purge(this); |
|
103 TRAP(err, RegisterL()); |
|
104 } |
|
105 |
|
106 return err; |
|
107 } |
|
108 |
|
109 TInt CMIDImage::CopyRegion |
|
110 ( |
|
111 MMIDImage* aSource, |
|
112 const TRect& aRect, |
|
113 TInt aTransform |
|
114 ) |
|
115 { |
|
116 CMIDImage& proxy = *static_cast<CMIDImage*>(aSource); |
|
117 CLcdImage& source = proxy.Image(); |
|
118 CLcdImage& target = Image(); |
|
119 |
|
120 TDrawRegion region; |
|
121 TRect clipRect(target.Size()); // clip to target, not source. |
|
122 |
|
123 region.iAnchor = EAnchorTop|EAnchorLeft; |
|
124 region.iDstPoint = TPoint(); |
|
125 region.iSrcRect = aRect; |
|
126 region.iTransform = aTransform; |
|
127 |
|
128 target.CopyRegion(source, region, clipRect); |
|
129 |
|
130 return KErrNone; |
|
131 } |
|
132 |
|
133 TInt CMIDImage::SetPixels |
|
134 ( |
|
135 const TUint32* aPixelBuffer, |
|
136 TInt aLength, |
|
137 TInt aOffset, |
|
138 TInt aScanLength, |
|
139 const TRect& aRect, |
|
140 TBool aProcessAlpha |
|
141 ) |
|
142 { |
|
143 iImage->SetPixels(aRect, aPixelBuffer, aLength, aOffset, aScanLength, aRect.Size(), aProcessAlpha); |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 TInt CMIDImage::GetPixels |
|
148 ( |
|
149 TUint32* aPixelBuffer, |
|
150 TInt aLength, |
|
151 TInt aOffset, // in words |
|
152 TInt aScanLength, |
|
153 const TRect& aRect |
|
154 ) |
|
155 { |
|
156 iImage->GetPixels(aRect, aPixelBuffer, aLength, aOffset, aScanLength, aRect.Size()); |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 void CMIDImage::Dispose() |
|
161 { |
|
162 delete this; |
|
163 } |
|
164 |
|
165 MMIDComponent::TType CMIDImage::Type() const |
|
166 { |
|
167 return EImage; |
|
168 } |
|
169 |
|
170 TSize CMIDImage::Size() const |
|
171 { |
|
172 return iImage->Size(); |
|
173 } |
|
174 |
|
175 CLcdImage& CMIDImage::Image() const |
|
176 { |
|
177 return *iImage; |
|
178 } |
|
179 |
|
180 TBool CMIDImage::DetectCollision |
|
181 ( |
|
182 const TRect& aRect1, TInt aTransform1, const TPoint& aPoint1, |
|
183 MMIDImage* aImage2, |
|
184 const TRect& aRect2, TInt aTransform2, const TPoint& aPoint2 |
|
185 ) |
|
186 { |
|
187 CMIDImage& proxy = *static_cast<CMIDImage*>(aImage2); |
|
188 CLcdImage& image2 = proxy.Image(); |
|
189 |
|
190 return iImage->DetectCollision |
|
191 ( |
|
192 aRect1, |
|
193 aTransform1, |
|
194 aPoint1, |
|
195 image2, |
|
196 aRect2, |
|
197 aTransform2, |
|
198 aPoint2 |
|
199 ); |
|
200 } |
|
201 |
|
202 /** |
|
203 *@return the primary mode bitmap representation of this image - i.e. the representation |
|
204 * that Graphics would render from or to, as opposed to the representation used by |
|
205 * high level components such as Form Items. |
|
206 * |
|
207 * IMPROVEMENT: consider keeping pointer to the CMIDBitmapImage instance constructed in |
|
208 * RegisterL() and return that here since it will always be the primary representation. |
|
209 */ |
|
210 MMIDBitmapImage* CMIDImage::BitmapImage() |
|
211 { |
|
212 return (MMIDBitmapImage*)iCache.GetBitmapImage(this); |
|
213 } |
|
214 |
|
215 MMIDBitmapImage* CMIDImage::BitmapImage(TInt aColorMode, TInt aAlphaMode, TBool aInvert) |
|
216 { |
|
217 return (MMIDBitmapImage*)iCache.GetBitmapImage(this, aColorMode, aAlphaMode, aInvert); |
|
218 } |
|
219 |
|
220 MMIDBitmapImage* CMIDImage::BitmapImageL(TInt aColorMode, TInt aAlphaMode, TBool aInvert) |
|
221 { |
|
222 return (MMIDBitmapImage*)iCache.GetBitmapImageL(this, aColorMode, aAlphaMode, aInvert); |
|
223 } |