1 /* |
|
2 * Copyright (c) 2004 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: Image conversion library for VideoTelephony. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef CVTIMAGECONVERTER_H |
|
23 #define CVTIMAGECONVERTER_H |
|
24 |
|
25 // INCLUDE FILES |
|
26 |
|
27 #include <e32base.h> |
|
28 #include <gdi.h> |
|
29 |
|
30 // CLASS FORWARDS |
|
31 |
|
32 class CFbsBitmap; |
|
33 class CVTYUVFbsBitmapConverter; |
|
34 class CVSFbsBitmapIYUVConverter; |
|
35 |
|
36 // DATA TYPES |
|
37 |
|
38 typedef TRgb ( *TVSColorReadFunc ) ( TAny*& ); |
|
39 |
|
40 // CLASS DECLARATIONS |
|
41 |
|
42 /** |
|
43 * Base class for all YUV to CFbsBitmap converters. |
|
44 * |
|
45 * @lib VTImageConverter.lib |
|
46 */ |
|
47 class CVTYUVFbsBitmapConverter : public CBase |
|
48 { |
|
49 public: // Constructors and destructor |
|
50 |
|
51 /** |
|
52 * C++ destructor. |
|
53 */ |
|
54 IMPORT_C ~CVTYUVFbsBitmapConverter(); |
|
55 |
|
56 public: // New functions |
|
57 |
|
58 /** |
|
59 * Starts image conversion from YUV to CFbsBitmap. |
|
60 * @exception Can leave with one of the system wide error codes. |
|
61 */ |
|
62 IMPORT_C virtual void ProcessL(); |
|
63 |
|
64 /** |
|
65 * Sets size of the source YUV image in pixels. This must be implemented |
|
66 * in derived classes. |
|
67 * @param "aSize" Size of source YUV image in pixels. |
|
68 * @exception Can leave with one of the system wide error codes. |
|
69 */ |
|
70 virtual void SetSourceSizeL( const TSize& aSize ) = 0; |
|
71 |
|
72 /** |
|
73 * Sets source YUV image data. This method must be implemented in derived |
|
74 * classes. |
|
75 * @param "aSourceData" 8-bit descriptor containing the YUV data. As |
|
76 * data is referenced and not copied, given reference must be still |
|
77 * valid when ProcessL() is called. |
|
78 * @exception Can leave with one of the system wide error codes. |
|
79 */ |
|
80 virtual void SetSourceL( const TDesC8& aSourceData ) = 0; |
|
81 |
|
82 /** |
|
83 * Sets size of the source YUV image in pixels and image data. |
|
84 * This method must be implemented in derived classes. |
|
85 * @param "aSize" Size of source YUV image in pixels. |
|
86 * @param "aSourceData" 8-bit descriptor containing the YUV data. |
|
87 * As data is referenced and not copied, given reference must be still |
|
88 * valid when ProcessL() is called. |
|
89 * @exception Can leave with one of the system wide error codes. |
|
90 */ |
|
91 virtual void SetSourceL( |
|
92 const TSize& aSize, |
|
93 const TDesC8& aSourceData ) = 0; |
|
94 |
|
95 /** |
|
96 * Sets destination bitmap into which conversion will be made. |
|
97 * @param "aDestinationBitmap" Reference to destination bitmap. |
|
98 * @exception Can leave with one of the system wide error codes. |
|
99 */ |
|
100 IMPORT_C virtual void SetDestinationL( |
|
101 const CFbsBitmap& aDestinationBitmap ); |
|
102 |
|
103 /** |
|
104 * Sets destination bitmap into which conversion will be made. |
|
105 * Bitmap is given as handle to existing bitmap. |
|
106 * @param "aHandle" Handle to existing bitmap. |
|
107 * @exception Can leave with one of the system wide error codes. |
|
108 */ |
|
109 IMPORT_C virtual void SetDestinationL( TInt aHandle ); |
|
110 |
|
111 public: // Functions from base classes |
|
112 |
|
113 protected: // New functions |
|
114 |
|
115 /** |
|
116 * Updates iY, iU and iV member variables. Must be implemented in |
|
117 * derived classes. |
|
118 * @param "aSourceData" 8-bit descriptor to source YUV data. |
|
119 */ |
|
120 virtual void SetYUVPtrs( const TDesC8& aSourceData ) = 0; |
|
121 |
|
122 /** |
|
123 * Second phase constructor. |
|
124 * @param "aBitmapHandle" Handle to destination bitmap. |
|
125 * @exception Can leave with one of the system wide error codes. |
|
126 */ |
|
127 virtual void ConstructL( TInt aBitmapHandle ); |
|
128 |
|
129 /** |
|
130 * Second phase constructor that will be called when destination is |
|
131 * changed. |
|
132 * @param "aBitmapHandle" Handle to destination bitmap. |
|
133 * @exception Can leave with one of the system wide error codes. |
|
134 */ |
|
135 virtual void ReConstructL( TInt aBitmapHandle ); |
|
136 |
|
137 /** |
|
138 * Updates internal variables. |
|
139 * @exception Can leave with one of the system wide error codes. |
|
140 */ |
|
141 virtual void SizeUpdateL(); |
|
142 |
|
143 /** |
|
144 * C++ constructor. |
|
145 * @param "aSourceSize" Source size in pixels. |
|
146 */ |
|
147 CVTYUVFbsBitmapConverter( const TSize& aSourceSize ); |
|
148 |
|
149 /** |
|
150 * Returns source size in pixels. |
|
151 * @return Source size in pixels, as constant reference. |
|
152 */ |
|
153 inline const TSize& SourceSize() const; |
|
154 |
|
155 /** |
|
156 * Returns source size in pixels. |
|
157 * @return Source size in pixels, as reference. |
|
158 */ |
|
159 inline TSize& SourceSize(); |
|
160 |
|
161 /** |
|
162 * Returns destination size in pixels. |
|
163 * @return Destination size in pixels, as constant reference. |
|
164 */ |
|
165 inline const TSize& DestinationSize() const; |
|
166 |
|
167 /** |
|
168 * Returns destination size in pixels. |
|
169 * @return Destination size in pixels, as reference. |
|
170 */ |
|
171 inline TSize& DestinationSize(); |
|
172 |
|
173 /** |
|
174 * Main process loop for Color4K mode. This must be implemented in |
|
175 * derived classes. |
|
176 * @param "aWriteFunction" Pointer to function that writes one pixel to |
|
177 * destination. |
|
178 */ |
|
179 virtual void DoProcess4K() = 0; |
|
180 |
|
181 /** |
|
182 * Main process loop for Color64K mode. This must be implemented in |
|
183 * derived classes. |
|
184 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
185 * to destination. |
|
186 */ |
|
187 virtual void DoProcess64K() = 0; |
|
188 |
|
189 /** |
|
190 * Main process loop for Color16M mode. This must be implemented in |
|
191 * derived classes. |
|
192 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
193 * to destination. |
|
194 */ |
|
195 virtual void DoProcess16M() = 0; |
|
196 |
|
197 /** |
|
198 * Main process loop for Color16MU mode. This must be implemented in |
|
199 * derived classes. |
|
200 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
201 * to destination. |
|
202 */ |
|
203 virtual void DoProcess16MU16MA() = 0; |
|
204 |
|
205 protected: // Functions from base classes |
|
206 |
|
207 private: // New functions |
|
208 |
|
209 /** |
|
210 * C++ default constructor. |
|
211 */ |
|
212 CVTYUVFbsBitmapConverter(); |
|
213 |
|
214 private: // Functions from base classes |
|
215 |
|
216 public: // Data |
|
217 |
|
218 protected: // Data |
|
219 |
|
220 // Table of coefficients for EColor4K |
|
221 static const TUint8 COFF_TBL_4K[ 80 ]; |
|
222 |
|
223 // Table of coefficients for EColor64K |
|
224 static const TUint8 COFF_TBL_64K[ 220 ]; |
|
225 |
|
226 // Table of coefficients for EColor16M |
|
227 static const TUint8 COFF_TBL_16M[ 528 ]; |
|
228 |
|
229 // Source size in pixels. |
|
230 TSize iSourceSize; |
|
231 |
|
232 // Target size in pixels. |
|
233 TSize iDestinationSize; |
|
234 |
|
235 // Pointer to destination bitmap. |
|
236 CFbsBitmap* iDestination; // owned, duplicate |
|
237 |
|
238 // Pointer descriptor that points to Y data of the YUV image. |
|
239 const TUint8* iY; |
|
240 |
|
241 // Pointer descriptor that points to Cr (U) data of the YUV image. |
|
242 const TUint8* iU; |
|
243 |
|
244 // Pointer descriptor that points to Cb (V) data of the YUV image. |
|
245 const TUint8* iV; |
|
246 |
|
247 // Horizontal skip real value. After every pixel this valus is added |
|
248 // to X index in conversion loop. |
|
249 TReal32 iVSkipReal; |
|
250 |
|
251 // Vertical skip real value. After every pixel this valus is added |
|
252 // to Y index in conversion loop. |
|
253 TReal32 iHSkipReal; |
|
254 |
|
255 private: // Data |
|
256 }; |
|
257 |
|
258 /** |
|
259 * Base class for YUV 4:2:0 planar image to CFbsBitmap converters. |
|
260 * |
|
261 * @lib VTImageConverter.lib |
|
262 */ |
|
263 class CVTYUVPlanarFbsBitmapConverter : public CVTYUVFbsBitmapConverter |
|
264 { |
|
265 public: // New functions |
|
266 |
|
267 public: // Functions from base classes |
|
268 |
|
269 /** |
|
270 * Sets size of the source YUV image in pixels. |
|
271 * @param "aSize" Size of source YUV image in pixels. |
|
272 * @exception Can leave with one of the system wide error codes. |
|
273 */ |
|
274 IMPORT_C void SetSourceSizeL( const TSize& aSize ); |
|
275 |
|
276 /** |
|
277 * Sets source YUV image data. |
|
278 * @param "aSourceData" 8-bit descriptor containing the YUV data. As |
|
279 * data is referenced and |
|
280 * not copied, given reference must be still valid when ProcessL() is |
|
281 * called. |
|
282 * @exception Can leave with one of the system wide error codes. |
|
283 */ |
|
284 IMPORT_C void SetSourceL( const TDesC8& aSourceData ); |
|
285 |
|
286 /** |
|
287 * Sets size of the source YUV image in pixels and image data. This |
|
288 * method must be |
|
289 * implemented in derived classes. |
|
290 * @param "aSize" Size of source YUV image in pixels. |
|
291 * @param "aSourceData" 8-bit descriptor containing the YUV data. As |
|
292 * data is referenced and |
|
293 * not copied, given reference must be still valid when ProcessL() is |
|
294 * called. |
|
295 * @exception Can leave with one of the system wide error codes. |
|
296 */ |
|
297 IMPORT_C void SetSourceL( |
|
298 const TSize& aSize, |
|
299 const TDesC8& aSourceData ); |
|
300 |
|
301 protected: // Constructors and destructor |
|
302 |
|
303 /** |
|
304 * C++ constructor. |
|
305 * @param "aSourceSize" Source size in pixels. |
|
306 */ |
|
307 CVTYUVPlanarFbsBitmapConverter( const TSize& aSourceSize ); |
|
308 |
|
309 protected: // New functions |
|
310 |
|
311 protected: // Functions from base classes |
|
312 |
|
313 /** |
|
314 * Main process loop for Color4K mode. |
|
315 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
316 * to destination. |
|
317 */ |
|
318 void DoProcess4K(); |
|
319 |
|
320 /** |
|
321 * Main process loop for Color4K mode when scaling is not required. |
|
322 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
323 * to destination. |
|
324 */ |
|
325 void DoProcess4KNoScale(); |
|
326 |
|
327 /** |
|
328 * Main process loop for Color64K mode. |
|
329 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
330 * to destination. |
|
331 */ |
|
332 void DoProcess64K(); |
|
333 |
|
334 /** |
|
335 * Main process loop for Color64K mode when scaling is not required. |
|
336 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
337 * to destination. |
|
338 */ |
|
339 void DoProcess64KNoScale(); |
|
340 |
|
341 /** |
|
342 * Main process loop for Color16M mode. |
|
343 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
344 * to destination. |
|
345 */ |
|
346 void DoProcess16M(); |
|
347 |
|
348 /** |
|
349 * Main process loop for Color16M mode when scaling is not required. |
|
350 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
351 * to destination. |
|
352 */ |
|
353 void DoProcess16MNoScale(); |
|
354 |
|
355 /** |
|
356 * Main process loop for Color16MU and Color16MA modes. |
|
357 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
358 * to destination. |
|
359 */ |
|
360 void DoProcess16MU16MA(); |
|
361 |
|
362 /** |
|
363 * Main process loop for Color16MU and Color16MA modes when scaling is |
|
364 * not required. |
|
365 * @param "aWriteFunction" Pointer to function that writes one pixel |
|
366 * to destination. |
|
367 */ |
|
368 void DoProcess16MU16MANoScale(); |
|
369 |
|
370 private: // New functions |
|
371 |
|
372 /** |
|
373 * C++ default constructor. |
|
374 */ |
|
375 CVTYUVPlanarFbsBitmapConverter(); |
|
376 |
|
377 private: // Functions from base classes |
|
378 }; |
|
379 |
|
380 /** |
|
381 * FourCC IYUV image to CFbsBitmap converter (see IYUV description below). |
|
382 * |
|
383 * All Y samples are found first in memory as an array of unsigned char |
|
384 * (possibly with a larger stride for memory alignment), followed immediately |
|
385 * by all Cr (U) samples (with half the stride of the Y lines, and half the |
|
386 * number of lines), then followed immediately by all Cb (V) samples in a |
|
387 * similar fashion. |
|
388 * |
|
389 * @lib VTImageConverter.lib |
|
390 */ |
|
391 class CVTIYUVFbsBitmapConverter : public CVTYUVPlanarFbsBitmapConverter |
|
392 { |
|
393 public: // Constructors and destructor |
|
394 |
|
395 /** |
|
396 * Static factory function to create instance of this class. |
|
397 * @param "aSourceSize" Size of source image in pixels. |
|
398 * @param "aDestination" Reference to destination bitmap. |
|
399 * @exception Can leave with one of the system wide error codes. |
|
400 * @return Pointer to newly created instance. |
|
401 */ |
|
402 IMPORT_C static CVTIYUVFbsBitmapConverter* NewL( |
|
403 const TSize& aSourceSize, |
|
404 const CFbsBitmap& aDestination ); |
|
405 |
|
406 /** |
|
407 * Static factory function to create instance of this class. |
|
408 * @param "aSourceSize" Size of source image in pixels. |
|
409 * @param "aBitmapHandle" Handle to destination bitmap. |
|
410 * @exception Can leave with one of the system wide error codes. |
|
411 * @return Pointer to newly created instance. |
|
412 */ |
|
413 IMPORT_C static CVTIYUVFbsBitmapConverter* NewL( |
|
414 const TSize& aSourceSize, |
|
415 TInt aBitmapHandle ); |
|
416 |
|
417 public: // New functions |
|
418 |
|
419 public: // Functions from base classes |
|
420 |
|
421 protected: // New functions |
|
422 |
|
423 protected: // Functions from base classes |
|
424 |
|
425 private: // New functions |
|
426 |
|
427 private: // Functions from base classes |
|
428 |
|
429 /** |
|
430 * Updates iY, iU and iV member variables. |
|
431 * @param "aSourceData" 8-bit descriptor to source YUV data. |
|
432 */ |
|
433 void SetYUVPtrs( const TDesC8& aSourceData ); |
|
434 |
|
435 private: // Constructors and destructor |
|
436 |
|
437 /** |
|
438 * C++ destructor. |
|
439 * @param "aSourceSize" Source size in pixels. |
|
440 */ |
|
441 CVTIYUVFbsBitmapConverter( const TSize& aSourceSize ); |
|
442 |
|
443 /** |
|
444 * C++ default constructor. |
|
445 */ |
|
446 CVTIYUVFbsBitmapConverter(); |
|
447 }; |
|
448 |
|
449 /** |
|
450 * FourCC YV12 image to CFbsBitmap converter (see YV12 description below). |
|
451 * |
|
452 * All Y samples are found first in memory as an array of unsigned char |
|
453 * (possibly with a larger stride for memory alignment), followed immediately |
|
454 * by all Cb (V) samples (with half the stride of the Y lines, and half the |
|
455 * number of lines), then followed immediately by all Cr (U) samples in a |
|
456 * similar fashion. |
|
457 * |
|
458 * @lib VTImageConverter.lib |
|
459 */ |
|
460 class CVTYV12FbsBitmapConverter : public CVTYUVPlanarFbsBitmapConverter |
|
461 { |
|
462 public: // Constructors and destructor |
|
463 /** |
|
464 * Static factory function to create instance of this class. |
|
465 * @param "aSourceSize" Size of source image in pixels. |
|
466 * @param "aDestination" Reference to destination bitmap. |
|
467 * @exception Can leave with one of the system wide error codes. |
|
468 * @return Pointer to newly created instance. |
|
469 */ |
|
470 IMPORT_C static CVTYV12FbsBitmapConverter* NewL( |
|
471 const TSize& aSourceSize, |
|
472 const CFbsBitmap& aDestination ); |
|
473 |
|
474 /** |
|
475 * Static factory function to create instance of this class. |
|
476 * @param "aSourceSize" Size of source image in pixels. |
|
477 * @param "aBitmapHandle" Handle to destination bitmap. |
|
478 * @exception Can leave with one of the system wide error codes. |
|
479 * @return Pointer to newly created instance. |
|
480 */ |
|
481 IMPORT_C static CVTYV12FbsBitmapConverter* NewL( |
|
482 const TSize& aSourceSize, |
|
483 TInt aBitmapHandle ); |
|
484 |
|
485 public: // New functions |
|
486 |
|
487 public: // Functions from base classes |
|
488 |
|
489 protected: // New functions |
|
490 |
|
491 protected: // Functions from base classes |
|
492 |
|
493 private: // New functions |
|
494 |
|
495 private: // Functions from base classes |
|
496 |
|
497 /** |
|
498 * Updates iY, iU and iV member variables. |
|
499 * @param "aSourceData" 8-bit descriptor to source YUV data. |
|
500 */ |
|
501 void SetYUVPtrs( const TDesC8& aSourceData ); |
|
502 |
|
503 private: // Constructors and destructor |
|
504 |
|
505 /** |
|
506 * C++ destructor. |
|
507 * @param "aSourceSize" Source size in pixels. |
|
508 */ |
|
509 CVTYV12FbsBitmapConverter( const TSize& aSourceSize ); |
|
510 |
|
511 /** |
|
512 * C++ default constructor. |
|
513 */ |
|
514 CVTYV12FbsBitmapConverter(); |
|
515 }; |
|
516 |
|
517 /** |
|
518 * CFbsBitmap to FourCC IYUV image converter (see IYUV description below). |
|
519 * |
|
520 * All Y samples are found first in memory as an array of unsigned char |
|
521 * (possibly with a larger stride for memory alignment), followed immediately |
|
522 * by all Cr (U) samples (with half the stride of the Y lines, and half the |
|
523 * number of lines), then followed immediately by all Cb (V) samples in a |
|
524 * similar fashion. |
|
525 * |
|
526 * @lib VTImageConverter.lib |
|
527 */ |
|
528 class CVSFbsBitmapIYUVConverter : public CBase |
|
529 { |
|
530 public: // Constructors and destructor |
|
531 |
|
532 /** |
|
533 * Static factory function to create instance of this class. |
|
534 * @param "aBitmap" Reference to source bitmap. |
|
535 * @exception Can leave with one of the system wide error codes. |
|
536 * @return Pointer to newly created instance. |
|
537 */ |
|
538 IMPORT_C static CVSFbsBitmapIYUVConverter* NewL( |
|
539 const CFbsBitmap& aBitmap ); |
|
540 |
|
541 /** |
|
542 * C++ destructor. |
|
543 */ |
|
544 IMPORT_C ~CVSFbsBitmapIYUVConverter(); |
|
545 |
|
546 public: // New functions |
|
547 |
|
548 /** |
|
549 * Sets new source bitmap. |
|
550 * @param "aBitmap" Reference to new source bitmap. |
|
551 */ |
|
552 IMPORT_C void SetSourceL( const CFbsBitmap& aBitmap ); |
|
553 |
|
554 /** |
|
555 * Starts image conversion from CFbsBitmap to YUV. |
|
556 * @exception Can leave with one of the system wide error codes. |
|
557 */ |
|
558 IMPORT_C void ProcessL(); |
|
559 |
|
560 /** |
|
561 * After successfull ProcessL() call converted YUV image data can be |
|
562 * fetched using this method. |
|
563 * @return 8-bit pointer descriptor (constant) to YUV image data. |
|
564 */ |
|
565 IMPORT_C TPtrC8 YUVData() const; |
|
566 |
|
567 public: // Functions from base classes |
|
568 |
|
569 protected: // New functions |
|
570 |
|
571 protected: // Functions from base classes |
|
572 |
|
573 private: // Constructors and destructor |
|
574 |
|
575 /** |
|
576 * C++ default constructor. |
|
577 */ |
|
578 CVSFbsBitmapIYUVConverter(); |
|
579 |
|
580 /** |
|
581 * Second phase constructor. |
|
582 * @param "aBitmap" Reference to source bitmap. |
|
583 * @exception Can leave with one of the system wide error codes. |
|
584 */ |
|
585 void ConstructL( const CFbsBitmap& aBitmap ); |
|
586 |
|
587 private: // New functions |
|
588 |
|
589 /** |
|
590 * Second phase constructor that is called when source is changed. |
|
591 * @param "aBitmap" Reference to source bitmap. |
|
592 * @exception Can leave with one of the system wide error codes. |
|
593 */ |
|
594 void ReConstructL( const CFbsBitmap& aBitmap ); |
|
595 |
|
596 /** |
|
597 * Main process loop. |
|
598 * @param "aReadFunction" Pointer to function that reads one pixel from |
|
599 * source. |
|
600 */ |
|
601 void DoProcess( TVSColorReadFunc aReadFunction ); |
|
602 |
|
603 private: // Functions from base classes |
|
604 |
|
605 public: // Data |
|
606 |
|
607 protected: // Data |
|
608 |
|
609 private: // Data |
|
610 |
|
611 // Destination size in pixels. |
|
612 TSize iSize; |
|
613 |
|
614 // Pointer to source bitmap. |
|
615 CFbsBitmap* iSource; // owned, duplicate |
|
616 |
|
617 // Heap descriptor that contains converted YUV data. |
|
618 HBufC8* iYUVData; // owned |
|
619 |
|
620 // Pointer descriptor that points to Y data of the YUV image. |
|
621 TPtrC8 iY; |
|
622 |
|
623 // Pointer descriptor that points to Cr (U) data of the YUV image. |
|
624 TPtrC8 iU; |
|
625 |
|
626 // Pointer descriptor that points to Cb (V) data of the YUV image. |
|
627 TPtrC8 iV; |
|
628 }; |
|
629 |
|
630 // INLINE METHODS |
|
631 #include "cvtimageconverter.inl" |
|
632 |
|
633 |
|
634 #endif // CVTIMAGECONVERTER_H |
|
635 |
|
636 // End of File |
|
637 |
|
638 |
|