|
1 // Copyright (c) 2008-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 "sgutils.h" |
|
17 |
|
18 |
|
19 // Helper function used to transfer a scanline in 64K to the various formats of the destination. |
|
20 LOCAL_C void TransferScanLine64K(TUint8* aDest, const TUint16* aSrc, TUidPixelFormat aPixelFormatDest, TInt aPixelLength) |
|
21 { |
|
22 switch (aPixelFormatDest) |
|
23 { |
|
24 case EUidPixelFormatRGB_565: |
|
25 { |
|
26 Mem::Copy(aDest, aSrc, aPixelLength << 1); |
|
27 break; |
|
28 } |
|
29 case EUidPixelFormatARGB_8888_PRE: |
|
30 { |
|
31 TUint32* dest = reinterpret_cast<TUint32*>(aDest); |
|
32 const TUint16* srcEnd = aSrc + aPixelLength; |
|
33 while (aSrc < srcEnd) |
|
34 { |
|
35 *dest++ = TRgb::Color64K(*aSrc++).Color16MAP(); |
|
36 } |
|
37 break; |
|
38 } |
|
39 case EUidPixelFormatARGB_8888: |
|
40 { |
|
41 TUint32* dest = reinterpret_cast<TUint32*>(aDest); |
|
42 const TUint16* srcEnd = aSrc + aPixelLength; |
|
43 while (aSrc < srcEnd) |
|
44 { |
|
45 *dest++ = TRgb::Color64K(*aSrc++).Color16MA(); |
|
46 } |
|
47 break; |
|
48 } |
|
49 case EUidPixelFormatXRGB_8888: |
|
50 { |
|
51 TUint32* dest = reinterpret_cast<TUint32*>(aDest); |
|
52 const TUint16* srcEnd = aSrc + aPixelLength; |
|
53 while (aSrc < srcEnd) |
|
54 { |
|
55 *dest++ = (TRgb::Color64K(*aSrc++).Color16MU() | 0xff000000); |
|
56 } |
|
57 break; |
|
58 } |
|
59 case EUidPixelFormatRGB_888: |
|
60 { |
|
61 const TUint16* srcEnd = aSrc + aPixelLength; |
|
62 while (aSrc < srcEnd) |
|
63 { |
|
64 TInt col = TRgb::Color64K(*aSrc++).Color16M(); |
|
65 *aDest++ = col; |
|
66 *aDest++ = col >> 8; |
|
67 *aDest++ = col >> 16; |
|
68 } |
|
69 break; |
|
70 } |
|
71 case EUidPixelFormatXRGB_4444: |
|
72 { |
|
73 TUint16* dest = reinterpret_cast<TUint16*>(aDest); |
|
74 const TUint16* srcEnd = aSrc + aPixelLength; |
|
75 while (aSrc < srcEnd) |
|
76 { |
|
77 *dest++ = TRgb::Color64K(*aSrc++).Color4K(); |
|
78 } |
|
79 break; |
|
80 } |
|
81 case EUidPixelFormatP_8: |
|
82 { |
|
83 const TUint16* srcEnd = aSrc + aPixelLength; |
|
84 while (aSrc < srcEnd) |
|
85 { |
|
86 *aDest++ = TRgb::Color64K(*aSrc++).Color256(); |
|
87 } |
|
88 break; |
|
89 } |
|
90 case EUidPixelFormatL_8: |
|
91 { |
|
92 const TUint16* srcEnd = aSrc + aPixelLength; |
|
93 while (aSrc < srcEnd) |
|
94 { |
|
95 *aDest++ = TRgb::Color64K(*aSrc++).Gray256(); |
|
96 } |
|
97 break; |
|
98 } |
|
99 case EUidPixelFormatL_4: |
|
100 { |
|
101 const TUint16* srcEnd = aSrc + aPixelLength; |
|
102 while (aSrc < srcEnd) |
|
103 { |
|
104 *aDest = 0; |
|
105 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 4) |
|
106 { |
|
107 TInt col = TRgb::Color64K(*aSrc++).Gray16(); |
|
108 col <<= index; |
|
109 *aDest |= col; |
|
110 } |
|
111 aDest++; |
|
112 } |
|
113 break; |
|
114 } |
|
115 case EUidPixelFormatP_4: |
|
116 { |
|
117 const TUint16* srcEnd = aSrc + aPixelLength; |
|
118 while (aSrc < srcEnd) |
|
119 { |
|
120 *aDest = 0; |
|
121 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 4) |
|
122 { |
|
123 TInt col = TRgb::Color64K(*aSrc++).Color16(); |
|
124 col <<= index; |
|
125 *aDest |= col; |
|
126 } |
|
127 aDest++; |
|
128 } |
|
129 break; |
|
130 } |
|
131 case EUidPixelFormatL_2: |
|
132 { |
|
133 const TUint16* srcEnd = aSrc + aPixelLength; |
|
134 while (aSrc < srcEnd) |
|
135 { |
|
136 *aDest = 0; |
|
137 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 2) |
|
138 { |
|
139 TInt col = TRgb::Color64K(*aSrc++).Gray4(); |
|
140 col <<= index; |
|
141 *aDest |= col; |
|
142 } |
|
143 aDest++; |
|
144 } |
|
145 break; |
|
146 } |
|
147 case EUidPixelFormatL_1: |
|
148 { |
|
149 const TUint16* srcEnd = aSrc + aPixelLength; |
|
150 while (aSrc < srcEnd) |
|
151 { |
|
152 *aDest = 0; |
|
153 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index++) |
|
154 { |
|
155 TInt col = TRgb::Color64K(*aSrc++).Gray2(); |
|
156 col <<= index; |
|
157 *aDest |= col; |
|
158 } |
|
159 aDest++; |
|
160 } |
|
161 break; |
|
162 } |
|
163 default: |
|
164 break; |
|
165 } |
|
166 } |
|
167 |
|
168 // Helper function used to transfer a scanline in 16MAP to the various formats of the destination. |
|
169 LOCAL_C void TransferScanLine16MAP(TUint8* aDest, const TUint32* aSrc, TUidPixelFormat aPixelFormatDest, TInt aPixelLength) |
|
170 { |
|
171 switch (aPixelFormatDest) |
|
172 { |
|
173 case EUidPixelFormatARGB_8888_PRE: |
|
174 { |
|
175 Mem::Copy(aDest, aSrc, aPixelLength << 2); |
|
176 break; |
|
177 } |
|
178 case EUidPixelFormatARGB_8888: |
|
179 { |
|
180 TUint32* dest = reinterpret_cast<TUint32*>(aDest); |
|
181 const TUint32* srcEnd = aSrc + aPixelLength; |
|
182 while (aSrc < srcEnd) |
|
183 { |
|
184 *dest++ = TRgb::Color16MAP(*aSrc++).Color16MA(); |
|
185 } |
|
186 break; |
|
187 } |
|
188 case EUidPixelFormatXRGB_8888: |
|
189 { |
|
190 TUint32* dest = reinterpret_cast<TUint32*>(aDest); |
|
191 const TUint32* srcEnd = aSrc + aPixelLength; |
|
192 while (aSrc < srcEnd) |
|
193 { |
|
194 *dest++ = (TRgb::Color16MAP(*aSrc++).Color16MU() | 0xff000000); |
|
195 } |
|
196 break; |
|
197 } |
|
198 case EUidPixelFormatRGB_888: |
|
199 { |
|
200 const TUint32* srcEnd = aSrc + aPixelLength; |
|
201 while (aSrc < srcEnd) |
|
202 { |
|
203 TInt col = TRgb::Color16MAP(*aSrc++).Color16M(); |
|
204 *aDest++ = col; |
|
205 *aDest++ = col >> 8; |
|
206 *aDest++ = col >> 16; |
|
207 } |
|
208 break; |
|
209 } |
|
210 case EUidPixelFormatRGB_565: |
|
211 { |
|
212 TUint16* dest = reinterpret_cast<TUint16*>(aDest); |
|
213 const TUint32* srcEnd = aSrc + aPixelLength; |
|
214 while (aSrc < srcEnd) |
|
215 { |
|
216 *dest++ = TRgb::Color16MAP(*aSrc++).Color64K(); |
|
217 } |
|
218 break; |
|
219 } |
|
220 case EUidPixelFormatXRGB_4444: |
|
221 { |
|
222 TUint16* dest = reinterpret_cast<TUint16*>(aDest); |
|
223 const TUint32* srcEnd = aSrc + aPixelLength; |
|
224 while (aSrc < srcEnd) |
|
225 { |
|
226 *dest++ = TRgb::Color16MAP(*aSrc++).Color4K(); |
|
227 } |
|
228 break; |
|
229 } |
|
230 case EUidPixelFormatP_8: |
|
231 { |
|
232 const TUint32* srcEnd = aSrc + aPixelLength; |
|
233 while (aSrc < srcEnd) |
|
234 { |
|
235 *aDest++ = TRgb::Color16MAP(*aSrc++).Color256(); |
|
236 } |
|
237 break; |
|
238 } |
|
239 case EUidPixelFormatL_8: |
|
240 { |
|
241 const TUint32* srcEnd = aSrc + aPixelLength; |
|
242 while (aSrc < srcEnd) |
|
243 { |
|
244 *aDest++ = TRgb::Color16MAP(*aSrc++).Gray256(); |
|
245 } |
|
246 break; |
|
247 } |
|
248 case EUidPixelFormatL_4: |
|
249 { |
|
250 const TUint32* srcEnd = aSrc + aPixelLength; |
|
251 while (aSrc < srcEnd) |
|
252 { |
|
253 *aDest = 0; |
|
254 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 4) |
|
255 { |
|
256 TInt col = TRgb::Color16MAP(*aSrc++).Gray16(); |
|
257 col <<= index; |
|
258 *aDest |= col; |
|
259 } |
|
260 aDest++; |
|
261 } |
|
262 break; |
|
263 } |
|
264 case EUidPixelFormatP_4: |
|
265 { |
|
266 const TUint32* srcEnd = aSrc + aPixelLength; |
|
267 while (aSrc < srcEnd) |
|
268 { |
|
269 *aDest = 0; |
|
270 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 4) |
|
271 { |
|
272 TInt col = TRgb::Color16MAP(*aSrc++).Color16(); |
|
273 col <<= index; |
|
274 *aDest |= col; |
|
275 } |
|
276 aDest++; |
|
277 } |
|
278 break; |
|
279 } |
|
280 case EUidPixelFormatL_2: |
|
281 { |
|
282 const TUint32* srcEnd = aSrc + aPixelLength; |
|
283 while (aSrc < srcEnd) |
|
284 { |
|
285 *aDest = 0; |
|
286 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index+= 2) |
|
287 { |
|
288 TInt col = TRgb::Color16MAP(*aSrc++).Gray4(); |
|
289 col <<= index; |
|
290 *aDest |= col; |
|
291 } |
|
292 aDest++; |
|
293 } |
|
294 break; |
|
295 } |
|
296 case EUidPixelFormatL_1: |
|
297 { |
|
298 const TUint32* srcEnd = aSrc + aPixelLength; |
|
299 while (aSrc < srcEnd) |
|
300 { |
|
301 *aDest = 0; |
|
302 for (TInt index = 0; (index < 8) && (aSrc < srcEnd); index++) |
|
303 { |
|
304 TInt col = TRgb::Color16MAP(*aSrc++).Gray2(); |
|
305 col <<= index; |
|
306 *aDest |= col; |
|
307 } |
|
308 aDest++; |
|
309 } |
|
310 } |
|
311 default: |
|
312 break; |
|
313 } |
|
314 } |
|
315 |
|
316 // Helper function used to copy a buffer in 64K to the various formats of the destination. |
|
317 LOCAL_C TInt TransferPixels64K(TAny* aDataAddressDest, TInt aDataStrideDest, TUidPixelFormat aPixelFormatDest, |
|
318 const TUint16* aDataAddressSrc, TInt aDataStrideSrc, const TRect& aRectSource) |
|
319 { |
|
320 TInt err = KErrNone; |
|
321 const TInt width = aRectSource.Width(); |
|
322 const TUint16* dataAddressSrc = PtrAdd(aDataAddressSrc + aRectSource.iTl.iX, aRectSource.iTl.iY * aDataStrideSrc); |
|
323 const TUint16* dataAddressSrcEnd = PtrAdd(dataAddressSrc, aDataStrideSrc * aRectSource.Height()); |
|
324 |
|
325 switch (aPixelFormatDest) |
|
326 { |
|
327 case EUidPixelFormatRGB_565: |
|
328 { |
|
329 TUint8* dataAddressDest = static_cast<TUint8*>(aDataAddressDest); |
|
330 const TInt dataLength = width << 1; |
|
331 while (dataAddressSrcEnd > dataAddressSrc) |
|
332 { |
|
333 Mem::Copy(dataAddressDest, dataAddressSrc, dataLength); |
|
334 dataAddressSrc = PtrAdd(dataAddressSrc, aDataStrideSrc); |
|
335 dataAddressDest += aDataStrideDest; |
|
336 } |
|
337 break; |
|
338 } |
|
339 case EUidPixelFormatARGB_8888_PRE: |
|
340 case EUidPixelFormatARGB_8888: |
|
341 case EUidPixelFormatXRGB_8888: |
|
342 case EUidPixelFormatXRGB_4444: |
|
343 case EUidPixelFormatL_1: |
|
344 case EUidPixelFormatL_2: |
|
345 case EUidPixelFormatL_4: |
|
346 case EUidPixelFormatL_8: |
|
347 case EUidPixelFormatP_4: |
|
348 case EUidPixelFormatP_8: |
|
349 case EUidPixelFormatRGB_888: |
|
350 { |
|
351 TUint8* dataAddressDest = static_cast<TUint8*>(aDataAddressDest); |
|
352 while (dataAddressSrcEnd > dataAddressSrc) |
|
353 { |
|
354 TransferScanLine64K(dataAddressDest, dataAddressSrc, aPixelFormatDest, width); |
|
355 dataAddressSrc = PtrAdd(dataAddressSrc, aDataStrideSrc); |
|
356 dataAddressDest += aDataStrideDest; |
|
357 } |
|
358 break; |
|
359 } |
|
360 default: |
|
361 err = KErrNotSupported; |
|
362 break; |
|
363 } |
|
364 return err; |
|
365 } |
|
366 |
|
367 // Helper function used to copy a buffer in 16MAP to the various formats of the destination. |
|
368 LOCAL_C TInt TransferPixels16MAP(TAny* aDataAddressDest, TInt aDataStrideDest, TUidPixelFormat aPixelFormatDest, |
|
369 const TUint32* aDataAddressSrc, TInt aDataStrideSrc, const TRect& aRectSource) |
|
370 { |
|
371 TInt err = KErrNone; |
|
372 const TInt width = aRectSource.Width(); |
|
373 const TUint32* dataAddressSrc = PtrAdd(aDataAddressSrc + aRectSource.iTl.iX, aRectSource.iTl.iY * aDataStrideSrc); |
|
374 const TUint32* dataAddressSrcEnd = PtrAdd(dataAddressSrc, aRectSource.Height() * aDataStrideSrc); |
|
375 |
|
376 switch (aPixelFormatDest) |
|
377 { |
|
378 case EUidPixelFormatARGB_8888_PRE: |
|
379 { |
|
380 TUint8* dataAddressDest = static_cast<TUint8*>(aDataAddressDest); |
|
381 const TInt dataLength = width << 2; |
|
382 while (dataAddressSrcEnd > dataAddressSrc) |
|
383 { |
|
384 Mem::Copy(dataAddressDest, dataAddressSrc, dataLength); |
|
385 dataAddressSrc = PtrAdd(dataAddressSrc, aDataStrideSrc); |
|
386 dataAddressDest += aDataStrideDest; |
|
387 } |
|
388 break; |
|
389 } |
|
390 case EUidPixelFormatXRGB_8888: |
|
391 case EUidPixelFormatARGB_8888: |
|
392 case EUidPixelFormatRGB_565: |
|
393 case EUidPixelFormatXRGB_4444: |
|
394 case EUidPixelFormatL_1: |
|
395 case EUidPixelFormatL_2: |
|
396 case EUidPixelFormatL_4: |
|
397 case EUidPixelFormatL_8: |
|
398 case EUidPixelFormatP_4: |
|
399 case EUidPixelFormatP_8: |
|
400 case EUidPixelFormatRGB_888: |
|
401 { |
|
402 TUint8* dataAddressDest = static_cast<TUint8*> (aDataAddressDest); |
|
403 while (dataAddressSrcEnd > dataAddressSrc) |
|
404 { |
|
405 TransferScanLine16MAP(dataAddressDest, dataAddressSrc, aPixelFormatDest, width); |
|
406 dataAddressSrc = PtrAdd(dataAddressSrc, aDataStrideSrc); |
|
407 dataAddressDest += aDataStrideDest; |
|
408 } |
|
409 break; |
|
410 } |
|
411 default: |
|
412 err = KErrNotSupported; |
|
413 break; |
|
414 } |
|
415 return err; |
|
416 } |
|
417 |
|
418 |
|
419 /** |
|
420 @publishedPartner |
|
421 @prototype |
|
422 @deprecated |
|
423 |
|
424 Convert from display mode to pixel format. |
|
425 |
|
426 @param aDisplayMode Display mode to convert. |
|
427 |
|
428 @return Pixel format corresponding to aDisplayMode, or EUidPixelFormatUnknown if aDisplayMode does not match any existing pixel format. |
|
429 */ |
|
430 EXPORT_C TUidPixelFormat SgUtils::DisplayModeToPixelFormat(TDisplayMode aDisplayMode) |
|
431 { |
|
432 switch (aDisplayMode) |
|
433 { |
|
434 case EGray2: |
|
435 return EUidPixelFormatL_1; |
|
436 case EGray4: |
|
437 return EUidPixelFormatL_2; |
|
438 case EGray16: |
|
439 return EUidPixelFormatL_4; |
|
440 case EGray256: |
|
441 return EUidPixelFormatL_8; |
|
442 case EColor16: |
|
443 return EUidPixelFormatP_4; |
|
444 case EColor256: |
|
445 return EUidPixelFormatP_8; |
|
446 case EColor4K: |
|
447 return EUidPixelFormatXRGB_4444; |
|
448 case EColor64K: |
|
449 return EUidPixelFormatRGB_565; |
|
450 case EColor16M: |
|
451 return EUidPixelFormatRGB_888; |
|
452 case EColor16MU: |
|
453 return EUidPixelFormatXRGB_8888; |
|
454 case ERgb: |
|
455 case EColor16MA: |
|
456 return EUidPixelFormatARGB_8888; |
|
457 case EColor16MAP: |
|
458 return EUidPixelFormatARGB_8888_PRE; |
|
459 default: |
|
460 break; |
|
461 } |
|
462 return EUidPixelFormatUnknown; |
|
463 } |
|
464 |
|
465 |
|
466 /** |
|
467 @publishedPartner |
|
468 @prototype |
|
469 @deprecated |
|
470 |
|
471 Convert from pixel format to display mode. |
|
472 |
|
473 @param aPixelFormat Pixel format to convert. |
|
474 |
|
475 @return Display mode corresponding to aPixelFormat, or ENone if aPixelFormat does not match any existing display mode. |
|
476 */ |
|
477 EXPORT_C TDisplayMode SgUtils::PixelFormatToDisplayMode(TUidPixelFormat aPixelFormat) |
|
478 { |
|
479 switch (aPixelFormat) |
|
480 { |
|
481 case EUidPixelFormatL_1: |
|
482 return EGray2; |
|
483 case EUidPixelFormatL_2: |
|
484 return EGray4; |
|
485 case EUidPixelFormatL_4: |
|
486 return EGray16; |
|
487 case EUidPixelFormatL_8: |
|
488 return EGray256; |
|
489 case EUidPixelFormatP_4: |
|
490 return EColor16; |
|
491 case EUidPixelFormatP_8: |
|
492 return EColor256; |
|
493 case EUidPixelFormatXRGB_4444: |
|
494 return EColor4K; |
|
495 case EUidPixelFormatRGB_565: |
|
496 return EColor64K; |
|
497 case EUidPixelFormatRGB_888: |
|
498 return EColor16M; |
|
499 case EUidPixelFormatXRGB_8888: |
|
500 return EColor16MU; |
|
501 case EUidPixelFormatARGB_8888: |
|
502 return EColor16MA; |
|
503 case EUidPixelFormatARGB_8888_PRE: |
|
504 return EColor16MAP; |
|
505 default: |
|
506 break; |
|
507 } |
|
508 return ENone; |
|
509 } |
|
510 |
|
511 |
|
512 /** |
|
513 @publishedPartner |
|
514 @prototype |
|
515 @deprecated |
|
516 |
|
517 Calculates the minimum number of bytes between rows of data in a bi-dimensional pixel buffer. |
|
518 The returned value is not guaranteed to be aligned onto any boundary. |
|
519 |
|
520 @param aWidth Width in pixels of the buffer. |
|
521 @param aPixelFormat Pixel format of the buffer. |
|
522 @return The minimum number of bytes between rows of data in a buffer with the given width and pixel format, |
|
523 or KErrNotSupported if aPixelFormat is not recognized. |
|
524 */ |
|
525 EXPORT_C TInt SgUtils::MinDataStride(TInt aWidth, TUidPixelFormat aPixelFormat) |
|
526 { |
|
527 switch (aPixelFormat) |
|
528 { |
|
529 case EUidPixelFormatXRGB_8888: |
|
530 case EUidPixelFormatBGRX_8888: |
|
531 case EUidPixelFormatXBGR_8888: |
|
532 case EUidPixelFormatBGRA_8888: |
|
533 case EUidPixelFormatARGB_8888: |
|
534 case EUidPixelFormatABGR_8888: |
|
535 case EUidPixelFormatARGB_8888_PRE: |
|
536 case EUidPixelFormatABGR_8888_PRE: |
|
537 case EUidPixelFormatBGRA_8888_PRE: |
|
538 case EUidPixelFormatARGB_2101010: |
|
539 case EUidPixelFormatABGR_2101010: |
|
540 return aWidth << 2; |
|
541 case EUidPixelFormatBGR_888: |
|
542 case EUidPixelFormatRGB_888: |
|
543 return aWidth * 3; |
|
544 case EUidPixelFormatRGB_565: |
|
545 case EUidPixelFormatBGR_565: |
|
546 case EUidPixelFormatARGB_1555: |
|
547 case EUidPixelFormatXRGB_1555: |
|
548 case EUidPixelFormatARGB_4444: |
|
549 case EUidPixelFormatARGB_8332: |
|
550 case EUidPixelFormatBGRX_5551: |
|
551 case EUidPixelFormatBGRA_5551: |
|
552 case EUidPixelFormatBGRA_4444: |
|
553 case EUidPixelFormatBGRX_4444: |
|
554 case EUidPixelFormatAP_88: |
|
555 case EUidPixelFormatXRGB_4444: |
|
556 case EUidPixelFormatXBGR_4444: |
|
557 return aWidth << 1; |
|
558 case EUidPixelFormatRGB_332: |
|
559 case EUidPixelFormatA_8: |
|
560 case EUidPixelFormatBGR_332: |
|
561 case EUidPixelFormatP_8: |
|
562 case EUidPixelFormatL_8: |
|
563 return aWidth; |
|
564 case EUidPixelFormatP_4: |
|
565 case EUidPixelFormatL_4: |
|
566 return (aWidth + 1) >> 1; |
|
567 case EUidPixelFormatP_2: |
|
568 case EUidPixelFormatL_2: |
|
569 return (aWidth + 3) >> 2; |
|
570 case EUidPixelFormatP_1: |
|
571 case EUidPixelFormatL_1: |
|
572 return (aWidth + 7) >> 3; |
|
573 default: |
|
574 return KErrNotSupported; |
|
575 } |
|
576 } |
|
577 |
|
578 |
|
579 /** |
|
580 @publishedPartner |
|
581 @prototype |
|
582 @deprecated |
|
583 |
|
584 Transfer data from one bi-dimensional pixel buffer to another bi-dimensional pixel buffer with a different pixel format. |
|
585 The pixel format conversion may involve some data loss. This function currently supports the following pixel formats. |
|
586 - For the source: EUidPixelFormatRGB_565, EUidPixelFormatARGB_8888_PRE. |
|
587 - For the destination: EUidPixelFormatARGB_8888_PRE, EUidPixelFormatARGB_8888, EUidPixelFormatXRGB_8888, EUidPixelFormatRGB_888, |
|
588 EUidPixelFormatRGB_565, EUidPixelFormatXRGB_4444, EUidPixelFormatP_8, EUidPixelFormatL_8, EUidPixelFormatL_4, EUidPixelFormatP_4, |
|
589 EUidPixelFormatL_2, EUidPixelFormatL_1. |
|
590 |
|
591 @param aDataAddressDest The base address of the destination pixel buffer. |
|
592 @param aDataStrideDest The number of bytes between rows of data in the destination pixel buffer. |
|
593 @param aPixelFormatDest Pixel format of the destination buffer. |
|
594 @param aDataAddressSrc The base address of the source pixel buffer. |
|
595 @param aDataStrideSrc The number of bytes between rows of data in the source pixel buffer. |
|
596 @param aPixelFormatSrc Pixel format of the source buffer. |
|
597 @param aRectSource Rectangle of the source pixel buffer which will be transferred to the destination pixel buffer. |
|
598 |
|
599 @return KErrNone if successful. |
|
600 @return KErrArgument If arguments do not lie within expected range. |
|
601 @return KErrNotSupported If source or destination format is not supported. |
|
602 */ |
|
603 EXPORT_C TInt SgUtils::TransferPixels(TAny* aDataAddressDest, TInt aDataStrideDest, TUidPixelFormat aPixelFormatDest, |
|
604 const TAny* aDataAddressSrc, TInt aDataStrideSrc, TUidPixelFormat aPixelFormatSrc, |
|
605 const TRect& aRectSource) |
|
606 { |
|
607 if (aRectSource.IsEmpty() || !aDataAddressDest || !aDataAddressSrc || (aDataStrideDest <= 0) || (aDataStrideSrc <= 0) |
|
608 || (SgUtils::MinDataStride(aRectSource.iBr.iX, aPixelFormatSrc) > aDataStrideSrc) |
|
609 || (SgUtils::MinDataStride(aRectSource.Width(), aPixelFormatDest) > aDataStrideDest)) |
|
610 { |
|
611 return KErrArgument; |
|
612 } |
|
613 |
|
614 TInt err = KErrNotSupported; |
|
615 switch (aPixelFormatSrc) |
|
616 { |
|
617 case EUidPixelFormatRGB_565: |
|
618 { |
|
619 err = TransferPixels64K(aDataAddressDest, aDataStrideDest, aPixelFormatDest, |
|
620 static_cast<const TUint16*>(aDataAddressSrc), aDataStrideSrc, aRectSource); |
|
621 break; |
|
622 } |
|
623 case EUidPixelFormatARGB_8888_PRE: |
|
624 { |
|
625 err = TransferPixels16MAP(aDataAddressDest, aDataStrideDest, aPixelFormatDest, |
|
626 static_cast<const TUint32*>(aDataAddressSrc), aDataStrideSrc, aRectSource); |
|
627 break; |
|
628 } |
|
629 default: |
|
630 break; |
|
631 } |
|
632 return err; |
|
633 } |