|
1 // Copyright (c) 2007-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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include "rawimageprocessor.h" |
|
22 |
|
23 // The classes below are used for Gif Decoder to optimize decoded data transfer |
|
24 // to destination bitmap. The main purpose of these classes is to provide direct access |
|
25 // to bitmap memory and to remove colour transformation/not used functionality of standard image processor |
|
26 // overheads. |
|
27 |
|
28 // RawImageProcessor |
|
29 |
|
30 CRawImageProcessor* CRawImageProcessor::NewL() |
|
31 { |
|
32 return new (ELeave) CRawImageProcessor(); |
|
33 } |
|
34 |
|
35 CRawImageProcessor::CRawImageProcessor() |
|
36 { |
|
37 } |
|
38 // from the CImageProcessor // |
|
39 |
|
40 TBool CRawImageProcessor::SetPixelBlock(TRgb* /* aColorBuffer */) |
|
41 { |
|
42 ASSERT(EFalse); |
|
43 return ETrue; |
|
44 } |
|
45 |
|
46 TBool CRawImageProcessor::SetPixels(TRgb* aColorBuffer,TInt aNumOfPixels) |
|
47 { |
|
48 TInt length = aNumOfPixels * iPixelSize; |
|
49 if(iBitmapDataPtr + length > iBitmapDataPtrLimit) |
|
50 { |
|
51 if (iBitmapDataPtrLimit != iBitmapDataPtr) |
|
52 { |
|
53 if (iBitmapDataPtr < iBitmapDataPtrLimit) |
|
54 { |
|
55 Mem::Copy(iBitmapDataPtr, aColorBuffer, iBitmapDataPtrLimit - iBitmapDataPtr); |
|
56 } |
|
57 iBitmapDataPtr = iBitmapDataPtrLimit; |
|
58 return ETrue; |
|
59 } |
|
60 return EFalse; |
|
61 } |
|
62 Mem::Copy(iBitmapDataPtr, aColorBuffer, length); |
|
63 iBitmapDataPtr += length; |
|
64 return ETrue; |
|
65 } |
|
66 |
|
67 TBool CRawImageProcessor::SetMonoPixel(TInt /*aGray256*/) |
|
68 { |
|
69 ASSERT(EFalse); |
|
70 return EFalse; |
|
71 } |
|
72 |
|
73 TBool CRawImageProcessor::SetMonoPixelRun(TInt /*aGray256*/,TInt /*aCount*/) |
|
74 { |
|
75 ASSERT(EFalse); |
|
76 return EFalse; |
|
77 } |
|
78 |
|
79 TBool CRawImageProcessor::SetMonoPixels(TUint32* /*aGray256Buffer*/,TInt /*aBufferLength*/) |
|
80 { |
|
81 ASSERT(EFalse); |
|
82 return EFalse; |
|
83 } |
|
84 |
|
85 TBool CRawImageProcessor::SetMonoPixelBlock(TUint32* /*aGray256Buffer*/) |
|
86 { |
|
87 ASSERT(EFalse); |
|
88 return EFalse; |
|
89 } |
|
90 |
|
91 TBool CRawImageProcessor::SetPos(const TPoint& aPosition) |
|
92 { |
|
93 iBitmapDataPtr = iBitmapData + (aPosition.iY-iImageRect.iTl.iY) * iScanlineSize + (aPosition.iX-iImageRect.iTl.iX) * iPixelSize; |
|
94 return ETrue; |
|
95 } |
|
96 |
|
97 TBool CRawImageProcessor::FlushPixels() |
|
98 { |
|
99 return ETrue; |
|
100 } |
|
101 |
|
102 void CRawImageProcessor::PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect) |
|
103 { |
|
104 if( aImageRect.iTl.iX<0 || aImageRect.iTl.iY<0 || aImageRect.Width()>aBitmap.SizeInPixels().iWidth || aImageRect.Height()>aBitmap.SizeInPixels().iHeight ) |
|
105 User::Leave(KErrArgument); |
|
106 |
|
107 iImageRect = aImageRect; |
|
108 iBitmap = &aBitmap; |
|
109 iPixelSize = TDisplayModeUtils::NumDisplayModeBitsPerPixel( aBitmap.DisplayMode() ); |
|
110 |
|
111 if (iPixelSize & 7) // we do not support display modes with pixel size of not multiple to byte size |
|
112 { |
|
113 ASSERT(EFalse); |
|
114 User::Leave(KErrArgument); |
|
115 } |
|
116 |
|
117 iPixelSize >>= 3; |
|
118 |
|
119 iScanlineSize = iBitmap->ScanLineLength(aBitmap.SizeInPixels().iWidth, aBitmap.DisplayMode() ); |
|
120 |
|
121 iBitmapData = reinterpret_cast<TUint8*>( iBitmap->DataAddress() ); // destination bitmap data ptr, not owned |
|
122 |
|
123 if (!iBitmapData)// not sure it is possible but anyway |
|
124 { |
|
125 User::Leave(KErrArgument); |
|
126 } |
|
127 |
|
128 iBitmapDataPtr = iBitmapData; |
|
129 iBitmapDataPtrLimit = iBitmapDataPtr + iScanlineSize * aBitmap.SizeInPixels().iHeight; |
|
130 } |
|
131 |
|
132 void CRawImageProcessor::PrepareL(CFbsBitmap& /*aBitmap*/,const TRect& /*aImageRect*/, const TSize& /*aRgbBlockSize*/) |
|
133 { |
|
134 ASSERT(EFalse); |
|
135 } |
|
136 |
|
137 void CRawImageProcessor::SetYPosIncrement(TInt /*aYInc*/) |
|
138 { |
|
139 ASSERT(EFalse); |
|
140 } |
|
141 |
|
142 void CRawImageProcessor::SetLineRepeat(TInt /*aLineRepeat*/) |
|
143 { |
|
144 ASSERT(EFalse); |
|
145 } |
|
146 |
|
147 void CRawImageProcessor::SetPixelPadding(TInt /*aNumberOfPixels*/) |
|
148 { |
|
149 ASSERT(EFalse); |
|
150 } |
|
151 |
|
152 TBool CRawImageProcessor::SetPixelRun(TRgb /*aColor*/,TInt /*aCount*/) |
|
153 { |
|
154 ASSERT(EFalse); |
|
155 return EFalse; |
|
156 } |
|
157 |
|
158 TBool CRawImageProcessor::SetPixel(TRgb /*aColor*/) |
|
159 { |
|
160 ASSERT(EFalse); |
|
161 return EFalse; |
|
162 } |
|
163 |
|
164 // RawImageUtilProcessor |
|
165 |
|
166 CRawImageUtilProcessor* CRawImageUtilProcessor::NewL() |
|
167 { |
|
168 return new (ELeave) CRawImageUtilProcessor(); |
|
169 } |
|
170 |
|
171 // from the CImageProcessor // |
|
172 |
|
173 TBool CRawImageUtilProcessor::SetPixels(TRgb* aColorBuffer,TInt aNumOfPixels) |
|
174 { |
|
175 TPoint pos; |
|
176 pos.iX = iPosition.iX; |
|
177 pos.iY = iPosition.iY; |
|
178 |
|
179 TInt width = iSize.iWidth; |
|
180 TInt height = iSize.iHeight; |
|
181 TInt pixelToWrite = 0; |
|
182 |
|
183 while (aNumOfPixels && pos.iY < height) |
|
184 { |
|
185 pixelToWrite = Min(width-pos.iX, aNumOfPixels); |
|
186 iUtil.SetPixels(reinterpret_cast<TUint32*>(aColorBuffer), pixelToWrite); |
|
187 aNumOfPixels -= pixelToWrite; |
|
188 aColorBuffer += pixelToWrite; |
|
189 pos.iX += pixelToWrite; |
|
190 if (pos.iX == width) |
|
191 { |
|
192 pos.iX = 0; |
|
193 pos.iY++; |
|
194 } |
|
195 } |
|
196 |
|
197 iPosition.iX = pos.iX; |
|
198 iPosition.iY = pos.iY; |
|
199 return ETrue; |
|
200 } |
|
201 |
|
202 TBool CRawImageUtilProcessor::SetMonoPixels(TUint32* aGray256Buffer,TInt aNumOfPixels) |
|
203 { |
|
204 TPoint pos; |
|
205 pos.iX = iPosition.iX; |
|
206 pos.iY = iPosition.iY; |
|
207 |
|
208 TInt width = iSize.iWidth; |
|
209 TInt height = iSize.iHeight; |
|
210 TInt pixelToWrite = 0; |
|
211 |
|
212 while (aNumOfPixels && pos.iY < height) |
|
213 { |
|
214 pixelToWrite = Min(width-pos.iX, aNumOfPixels); |
|
215 iUtil.SetPixels(aGray256Buffer, pixelToWrite); |
|
216 aNumOfPixels -= pixelToWrite; |
|
217 aGray256Buffer += pixelToWrite; |
|
218 pos.iX += pixelToWrite; |
|
219 if (pos.iX == width) |
|
220 { |
|
221 pos.iX = 0; |
|
222 pos.iY++; |
|
223 } |
|
224 } |
|
225 |
|
226 iPosition.iX = pos.iX; |
|
227 iPosition.iY = pos.iY; |
|
228 return ETrue; |
|
229 } |
|
230 |
|
231 TBool CRawImageUtilProcessor::SetPos(const TPoint& aPosition) |
|
232 { |
|
233 iPosition.iX = aPosition.iX - iImageRect.iTl.iX; |
|
234 iPosition.iY = aPosition.iY - iImageRect.iTl.iY; |
|
235 return iUtil.SetPos(iPosition); |
|
236 } |
|
237 |
|
238 void CRawImageUtilProcessor::PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect) |
|
239 { |
|
240 iImageRect = aImageRect; |
|
241 iSize = iImageRect.Size(); |
|
242 iPosition = TPoint(0, 0); |
|
243 iUtil.SetBitmapL(&aBitmap); |
|
244 iUtil.Begin(iPosition); |
|
245 iUtil.End(); |
|
246 } |
|
247 |