vtprotocolplugins/DisplaySink/src/CVtImageConverter.cpp
changeset 0 ed9695c8bcbe
child 3 b1602a5ab0a3
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     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:  YUV to bitmap and bitmap to YUV conversion routines for VT
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <e32svr.h>
       
    22 #include <fbs.h>
       
    23 #include "CVtImageConverter.h"
       
    24 
       
    25 // LOCAL CONSTANTS AND MACROS
       
    26 
       
    27 #ifdef _DEBUG
       
    28 #	define __IF_DEBUG(t) {RDebug::t;}
       
    29 #else
       
    30 #	define __IF_DEBUG(t)
       
    31 #endif
       
    32 
       
    33 // Calculates average for two integer values
       
    34 #define AVG( a, b ) ( ( a + b ) >> 1 )
       
    35 
       
    36 // MODULE DATA STRUCTURES
       
    37 
       
    38 /**
       
    39 *  Holds data for one YUV pixel
       
    40 *
       
    41 *  @lib VTImageConverter.lib
       
    42 */
       
    43 struct TVSYCrCb
       
    44 	{
       
    45 	public:
       
    46 		// Y data
       
    47 		TInt iY;
       
    48 
       
    49 		// Cb (U) data
       
    50 		TInt iCb;
       
    51 
       
    52 		// Cr (V) data
       
    53 		TInt iCr;
       
    54 	};
       
    55 
       
    56 // LOCAL FUNCTION PROTOTYPES
       
    57 
       
    58 // FORWARD DECLARATIONS
       
    59 
       
    60 // ============================= LOCAL FUNCTIONS ===============================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // RGBtoYCbCr( TVSYCrCb* aYuv, const TRgb& aColor )
       
    64 // (other items were commented in a header).
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 TUint8 RGBtoYCbCr( TVSYCrCb* aYuv, const TRgb& aColor )
       
    68 	{
       
    69 	const TInt YRedFactor = 19595; // 0.299 << 16
       
    70 	const TInt YGreenFactor = 38470; // 0.587 << 16
       
    71 	const TInt YBlueFactor = 7471; // 0.114 << 16
       
    72 	const TInt CbRedFactor = 11056; // 0.1687 << 16
       
    73 	const TInt CbGreenFactor = 21712; // 0.3313 << 16
       
    74 	const TInt CrGreenFactor = 27440; // 0.4187 << 16
       
    75 	const TInt CrBlueFactor = 5328; // 0.0813 << 16
       
    76 
       
    77 	TInt red = aColor.Red();
       
    78 	TInt green = aColor.Green();
       
    79 	TInt blue = aColor.Blue();
       
    80 
       
    81 	aYuv->iY = ( YRedFactor * red ) +
       
    82 	    ( YGreenFactor * green ) +
       
    83 	    ( YBlueFactor * blue );
       
    84 	aYuv->iCb = - ( CbRedFactor * red ) -
       
    85 	    ( CbGreenFactor * green ) +
       
    86 	    ( blue << 15 );
       
    87 	aYuv->iCr = ( red << 15 ) -
       
    88 	    ( CrGreenFactor * green ) -
       
    89 	    ( CrBlueFactor * blue );
       
    90 
       
    91 	aYuv->iY >>= 16;
       
    92 	aYuv->iCb >>= 16;
       
    93 	aYuv->iCr >>= 16;
       
    94 
       
    95 	aYuv->iCb += 128;
       
    96 	aYuv->iCr += 128;
       
    97 
       
    98 	return static_cast< TUint8 >( aYuv->iY );
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // VSReadColor4K( TAny*& aSource )
       
   103 // (other items were commented in a header).
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TRgb VSReadColor4K( TAny*& aSource )
       
   107 	{
       
   108 	TUint16* s = static_cast< TUint16* >( aSource );
       
   109 	TRgb rgb( TRgb::Color4K( *s++ ) );
       
   110 	aSource = s;
       
   111 	return rgb;
       
   112 	}
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // VSReadColor64K( TAny*& aSource )
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TRgb VSReadColor64K( TAny*& aSource )
       
   120 	{
       
   121 	TUint16* s = static_cast< TUint16* >( aSource );
       
   122 	TRgb rgb( TRgb::Color64K( *s++ ) );
       
   123 	aSource = s;
       
   124 	return rgb;
       
   125 	}
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // VSReadColor16M( TAny*& aSource )
       
   129 // (other items were commented in a header).
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TRgb VSReadColor16M( TAny*& aSource )
       
   133 	{
       
   134 	TUint8* s = static_cast< TUint8* >( aSource );
       
   135 	TRgb rgb( s[ 2 ], s[ 1 ], s[ 0 ] );
       
   136 	aSource = s + 3;
       
   137 	return rgb;
       
   138 	}
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // VSReadColor16MU( TAny*& aSource )
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TRgb VSReadColor16MU( TAny*& aSource )
       
   146 	{
       
   147 	TUint32* s = static_cast< TUint32* >( aSource );
       
   148 	TRgb rgb( TRgb::Color16MU( *s++ ) );
       
   149 	aSource = s;
       
   150 	return rgb;
       
   151 	}
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // VSReadColor16MA( TAny*& aSource )
       
   155 // (other items were commented in a header).
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 TRgb VSReadColor16MA( TAny*& aSource )
       
   159 	{
       
   160 	TUint32* s = static_cast< TUint32* >( aSource );
       
   161 	TRgb rgb( TRgb::Color16MA( *s++ ) );
       
   162 	aSource = s;
       
   163 	return rgb;
       
   164 	}
       
   165 
       
   166 // ============================ MEMBER FUNCTIONS ===============================
       
   167 
       
   168 /**
       
   169 *
       
   170 */
       
   171 const TUint8 CVTYUVFbsBitmapConverter::COFF_TBL_4K[ 80 ]=
       
   172 	{
       
   173     0xe9,0x66,0x01,0x00,    // KRedCrFactor
       
   174     0x1a,0x58,0x00,0x00,    // KGreenCbFactor
       
   175     0xd2,0xb6,0x00,0x00,    // KGreenCrFactor
       
   176     0xa2,0xc5,0x01,0x00,    // KBlueCbFactor
       
   177 
       
   178     0x00,0x00,0x00,0x00,    // 4-bit
       
   179     0x00,0x00,0x00,0x00,
       
   180     0x00,0x00,0x00,0x00,
       
   181     0x00,0x00,0x00,0x00,
       
   182     0x00,0x00,0x00,0x00,    // 5
       
   183     0x00,0x00,0x00,0x00,
       
   184     0x00,0x01,0x02,0x03,
       
   185     0x04,0x05,0x06,0x07,
       
   186     0x08,0x09,0x0a,0x0b,
       
   187     0x0c,0x0d,0x0e,0x0f,    // 10
       
   188     0x0f,0x0f,0x0f,0x0f,
       
   189     0x0f,0x0f,0x0f,0x0f,
       
   190     0x0f,0x0f,0x0f,0x0f,
       
   191     0x0f,0x0f,0x0f,0x0f,
       
   192     0x0f,0x0f,0x0f,0x0f,    // 15
       
   193     0x0f,0x0f,0x0f,0x0f
       
   194     };
       
   195 
       
   196 /**
       
   197 *
       
   198 */
       
   199 const TUint8 CVTYUVFbsBitmapConverter::COFF_TBL_64K[ 220 ]=
       
   200 	{
       
   201     0xe9,0x66,0x01,0x00,    // KRedCrFactor
       
   202     0x1a,0x58,0x00,0x00,    // KGreenCbFactor
       
   203     0xd2,0xb6,0x00,0x00,    // KGreenCrFactor
       
   204     0xa2,0xc5,0x01,0x00,    // KBlueCbFactor
       
   205 
       
   206     0x00,0x00,0x00,0x00,    // 5-bit
       
   207     0x00,0x00,0x00,0x00,
       
   208     0x00,0x00,0x00,0x00,
       
   209     0x00,0x00,0x00,0x00,
       
   210     0x00,0x00,0x00,0x00,
       
   211     0x00,0x00,0x00,0x00,
       
   212     0x00,0x01,0x02,0x03,
       
   213     0x04,0x05,0x06,0x07,
       
   214     0x08,0x09,0x0a,0x0b,
       
   215     0x0c,0x0d,0x0e,0x0f,
       
   216     0x10,0x11,0x12,0x13,
       
   217     0x14,0x15,0x16,0x17,
       
   218     0x18,0x19,0x1a,0x1b,
       
   219     0x1c,0x1d,0x1e,0x1f,
       
   220     0x1f,0x1f,0x1f,0x1f,
       
   221     0x1f,0x1f,0x1f,0x1f,
       
   222     0x1f,0x1f,0x1f,0x1f,
       
   223     0x1f,0x1f,0x1f,0x1f,
       
   224     0x1f,0x1f,0x1f,0x1f,
       
   225 
       
   226     0x00,0x00,0x00,0x00,    // 6-bit
       
   227     0x00,0x00,0x00,0x00,
       
   228     0x00,0x00,0x00,0x00,
       
   229     0x00,0x00,0x00,0x00,
       
   230     0x00,0x00,0x00,0x00,
       
   231     0x00,0x01,0x02,0x03,
       
   232     0x04,0x05,0x06,0x07,
       
   233     0x08,0x09,0x0a,0x0b,
       
   234     0x0c,0x0d,0x0e,0x0f,
       
   235     0x10,0x11,0x12,0x13,
       
   236     0x14,0x15,0x16,0x17,
       
   237     0x18,0x19,0x1a,0x1b,
       
   238     0x1c,0x1d,0x1e,0x1f,
       
   239     0x20,0x21,0x22,0x23,
       
   240     0x24,0x25,0x26,0x27,
       
   241     0x28,0x29,0x2a,0x2b,
       
   242     0x2c,0x2d,0x2e,0x2f,
       
   243     0x30,0x31,0x32,0x33,
       
   244     0x34,0x35,0x36,0x37,
       
   245     0x38,0x39,0x3a,0x3b,
       
   246     0x3c,0x3d,0x3e,0x3f,
       
   247     0x3f,0x3f,0x3f,0x3f,
       
   248     0x3f,0x3f,0x3f,0x3f,
       
   249     0x3f,0x3f,0x3f,0x3f,
       
   250     0x3f,0x3f,0x3f,0x3f,
       
   251     0x3f,0x3f,0x3f,0x3f,
       
   252     0x3f,0x3f,0x3f,0x3f,
       
   253     0x3f,0x3f,0x3f,0x3f,
       
   254     0x3f,0x3f,0x3f,0x3f,
       
   255     0x3f,0x3f,0x3f,0x3f,
       
   256     0x3f,0x3f,0x3f,0x3f,
       
   257     0x3f,0x3f,0x3f,0x3f
       
   258 	};
       
   259 
       
   260 /**
       
   261 *
       
   262 */
       
   263 const TUint8 CVTYUVFbsBitmapConverter::COFF_TBL_16M[ 528 ] =
       
   264 	{
       
   265     0xe9,0x66,0x01,0x00,    // KRedCrFactor
       
   266     0x1a,0x58,0x00,0x00,    // KGreenCbFactor
       
   267     0xd2,0xb6,0x00,0x00,    // KGreenCrFactor
       
   268     0xa2,0xc5,0x01,0x00,    // KBlueCbFactor
       
   269 
       
   270     0x00,0x00,0x00,0x00,
       
   271     0x00,0x00,0x00,0x00,
       
   272     0x00,0x00,0x00,0x00,
       
   273     0x00,0x00,0x00,0x00,
       
   274 
       
   275     0x00,0x00,0x00,0x00,
       
   276     0x00,0x00,0x00,0x00,
       
   277     0x00,0x00,0x00,0x00,
       
   278     0x00,0x00,0x00,0x00,
       
   279 
       
   280     0x00,0x00,0x00,0x00,
       
   281     0x00,0x00,0x00,0x00,
       
   282     0x00,0x00,0x00,0x00,
       
   283     0x00,0x00,0x00,0x00,
       
   284 
       
   285     0x00,0x00,0x00,0x00,
       
   286     0x00,0x00,0x00,0x00,
       
   287     0x00,0x00,0x00,0x00,
       
   288     0x00,0x00,0x00,0x00,
       
   289 
       
   290     0x00,0x00,0x00,0x00,
       
   291     0x00,0x00,0x00,0x00,
       
   292     0x00,0x00,0x00,0x00,
       
   293     0x00,0x00,0x00,0x00,
       
   294 
       
   295     0x00,0x00,0x00,0x00,
       
   296     0x00,0x00,0x00,0x00,
       
   297     0x00,0x00,0x00,0x00,
       
   298     0x00,0x00,0x00,0x00,
       
   299 
       
   300     0x00,0x00,0x00,0x00,
       
   301     0x00,0x00,0x00,0x00,
       
   302     0x00,0x00,0x00,0x00,
       
   303     0x00,0x00,0x00,0x00,
       
   304 
       
   305     0x00,0x00,0x00,0x00,
       
   306     0x00,0x00,0x00,0x00,
       
   307     0x00,0x00,0x00,0x00,
       
   308     0x00,0x00,0x00,0x00,
       
   309 
       
   310     0x00,0x01,0x02,0x03,    // 8-bit
       
   311     0x04,0x05,0x06,0x07,
       
   312     0x08,0x09,0x0a,0x0b,
       
   313     0x0c,0x0d,0x0e,0x0f,
       
   314 
       
   315     0x10,0x11,0x12,0x13,
       
   316     0x14,0x15,0x16,0x17,
       
   317     0x18,0x19,0x1a,0x1b,
       
   318     0x1c,0x1d,0x1e,0x1f,
       
   319 
       
   320     0x20,0x21,0x22,0x23,
       
   321     0x24,0x25,0x26,0x27,
       
   322     0x28,0x29,0x2a,0x2b,
       
   323     0x2c,0x2d,0x2e,0x2f,
       
   324 
       
   325     0x30,0x31,0x32,0x33,
       
   326     0x34,0x35,0x36,0x37,
       
   327     0x38,0x39,0x3a,0x3b,
       
   328     0x3c,0x3d,0x3e,0x3f,
       
   329 
       
   330     0x40,0x41,0x42,0x43,
       
   331     0x44,0x45,0x46,0x47,
       
   332     0x48,0x49,0x4a,0x4b,
       
   333     0x4c,0x4d,0x4e,0x4f,
       
   334 
       
   335     0x50,0x51,0x52,0x53,
       
   336     0x54,0x55,0x56,0x57,
       
   337     0x58,0x59,0x5a,0x5b,
       
   338     0x5c,0x5d,0x5e,0x5f,
       
   339 
       
   340     0x60,0x61,0x62,0x63,
       
   341     0x64,0x65,0x66,0x67,
       
   342     0x68,0x69,0x6a,0x6b,
       
   343     0x6c,0x6d,0x6e,0x6f,
       
   344 
       
   345     0x70,0x71,0x72,0x73,
       
   346     0x74,0x75,0x76,0x77,
       
   347     0x78,0x79,0x7a,0x7b,
       
   348     0x7c,0x7d,0x7e,0x7f,
       
   349 
       
   350     0x80,0x81,0x82,0x83,
       
   351     0x84,0x85,0x86,0x87,
       
   352     0x88,0x89,0x8a,0x8b,
       
   353     0x8c,0x8d,0x8e,0x8f,
       
   354 
       
   355     0x90,0x91,0x92,0x93,
       
   356     0x94,0x95,0x96,0x97,
       
   357     0x98,0x99,0x9a,0x9b,
       
   358     0x9c,0x9d,0x9e,0x9f,
       
   359 
       
   360     0xa0,0xa1,0xa2,0xa3,
       
   361     0xa4,0xa5,0xa6,0xa7,
       
   362     0xa8,0xa9,0xaa,0xab,
       
   363     0xac,0xad,0xae,0xaf,
       
   364 
       
   365     0xb0,0xb1,0xb2,0xb3,
       
   366     0xb4,0xb5,0xb6,0xb7,
       
   367     0xb8,0xb9,0xba,0xbb,
       
   368     0xbc,0xbd,0xbe,0xbf,
       
   369 
       
   370     0xc0,0xc1,0xc2,0xc3,
       
   371     0xc4,0xc5,0xc6,0xc7,
       
   372     0xc8,0xc9,0xca,0xcb,
       
   373     0xcc,0xcd,0xce,0xcf,
       
   374 
       
   375     0xd0,0xd1,0xd2,0xd3,
       
   376     0xd4,0xd5,0xd6,0xd7,
       
   377     0xd8,0xd9,0xda,0xdb,
       
   378     0xdc,0xdd,0xde,0xdf,
       
   379 
       
   380     0xe0,0xe1,0xe2,0xe3,
       
   381     0xe4,0xe5,0xe6,0xe7,
       
   382     0xe8,0xe9,0xea,0xeb,
       
   383     0xec,0xed,0xee,0xef,
       
   384 
       
   385     0xf0,0xf1,0xf2,0xf3,
       
   386     0xf4,0xf5,0xf6,0xf7,
       
   387     0xf8,0xf9,0xfa,0xfb,
       
   388     0xfc,0xfd,0xfe,0xff,
       
   389 
       
   390     0xff,0xff,0xff,0xff,
       
   391     0xff,0xff,0xff,0xff,
       
   392     0xff,0xff,0xff,0xff,
       
   393     0xff,0xff,0xff,0xff,
       
   394 
       
   395     0xff,0xff,0xff,0xff,
       
   396     0xff,0xff,0xff,0xff,
       
   397     0xff,0xff,0xff,0xff,
       
   398     0xff,0xff,0xff,0xff,
       
   399 
       
   400     0xff,0xff,0xff,0xff,
       
   401     0xff,0xff,0xff,0xff,
       
   402     0xff,0xff,0xff,0xff,
       
   403     0xff,0xff,0xff,0xff,
       
   404 
       
   405     0xff,0xff,0xff,0xff,
       
   406     0xff,0xff,0xff,0xff,
       
   407     0xff,0xff,0xff,0xff,
       
   408     0xff,0xff,0xff,0xff,
       
   409 
       
   410     0xff,0xff,0xff,0xff,
       
   411     0xff,0xff,0xff,0xff,
       
   412     0xff,0xff,0xff,0xff,
       
   413     0xff,0xff,0xff,0xff,
       
   414 
       
   415     0xff,0xff,0xff,0xff,
       
   416     0xff,0xff,0xff,0xff,
       
   417     0xff,0xff,0xff,0xff,
       
   418     0xff,0xff,0xff,0xff,
       
   419 
       
   420     0xff,0xff,0xff,0xff,
       
   421     0xff,0xff,0xff,0xff,
       
   422     0xff,0xff,0xff,0xff,
       
   423     0xff,0xff,0xff,0xff
       
   424     };
       
   425 
       
   426 // ============================ CVTYUVFbsBitmapConverter =======================
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // CVTYUVFbsBitmapConverter::CVTYUVFbsBitmapConverter(
       
   430 //  const TSize& aSourceSize )
       
   431 // (other items were commented in a header).
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 CVTYUVFbsBitmapConverter::CVTYUVFbsBitmapConverter( const TSize& aSourceSize )
       
   435 : iSourceSize( aSourceSize )
       
   436 	{
       
   437 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::CVTYUVFbsBitmapConverter() >>"), RThread().Id().operator TUint()));
       
   438 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::CVTYUVFbsBitmapConverter() <<"), RThread().Id().operator TUint()));
       
   439 	}
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CVTYUVFbsBitmapConverter::~CVTYUVFbsBitmapConverter()
       
   443 // (other items were commented in a header).
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 EXPORT_C CVTYUVFbsBitmapConverter::~CVTYUVFbsBitmapConverter()
       
   447 	{
       
   448 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::~CVTYUVFbsBitmapConverter() >>"), RThread().Id().operator TUint()));
       
   449 	delete iDestination;
       
   450 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::~CVTYUVFbsBitmapConverter() <<"), RThread().Id().operator TUint()));
       
   451 	}
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CVTYUVFbsBitmapConverter::ProcessL()
       
   455 // (other items were commented in a header).
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 EXPORT_C void CVTYUVFbsBitmapConverter::ProcessL()
       
   459 	{
       
   460 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ProcessL() >>"), RThread().Id().operator TUint()));
       
   461 	switch( iDestination->DisplayMode() )
       
   462 		{
       
   463 		case EColor4K:
       
   464 			DoProcess4K();
       
   465 			break;
       
   466 
       
   467 		case EColor64K:
       
   468 			DoProcess64K();
       
   469 			break;
       
   470 
       
   471 		case EColor16M:
       
   472 			DoProcess16M();
       
   473 			break;
       
   474 
       
   475         case EColor16MU:
       
   476         case EColor16MA:    // 16MU and 16MA are handled equally
       
   477 			DoProcess16MU16MA();
       
   478             break;
       
   479 
       
   480 		default:
       
   481 			User::Leave( KErrNotSupported );
       
   482 			break;
       
   483 		};
       
   484 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ProcessL() <<"), RThread().Id().operator TUint()));
       
   485 	}
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CVTYUVFbsBitmapConverter::SetDestinationL(
       
   489 //  const CFbsBitmap& aDestinationBitmap )
       
   490 // (other items were commented in a header).
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 EXPORT_C void CVTYUVFbsBitmapConverter::SetDestinationL(
       
   494     const CFbsBitmap& aDestinationBitmap )
       
   495 	{
       
   496 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SetDestinationL() >>"), RThread().Id().operator TUint()));
       
   497 	SetDestinationL( aDestinationBitmap.Handle() );
       
   498 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SetDestinationL() <<"), RThread().Id().operator TUint()));
       
   499 	}
       
   500 
       
   501 // -----------------------------------------------------------------------------
       
   502 // CVTYUVFbsBitmapConverter::SetDestinationL( TInt aHandle )
       
   503 // (other items were commented in a header).
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 EXPORT_C void CVTYUVFbsBitmapConverter::SetDestinationL( TInt aHandle )
       
   507 	{
       
   508 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SetDestinationL() >>"), RThread().Id().operator TUint()));
       
   509 	ReConstructL( aHandle );
       
   510 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SetDestinationL() <<"), RThread().Id().operator TUint()));
       
   511 	}
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CVTYUVFbsBitmapConverter::ConstructL( TInt aBitmapHandle )
       
   515 // (other items were commented in a header).
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CVTYUVFbsBitmapConverter::ConstructL( TInt aBitmapHandle )
       
   519 	{
       
   520 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ConstructL() >>"), RThread().Id().operator TUint()));
       
   521 	iDestination = new (ELeave) CFbsBitmap();
       
   522 	ReConstructL( aBitmapHandle );
       
   523 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ConstructL() <<"), RThread().Id().operator TUint()));
       
   524 	}
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // CVTYUVFbsBitmapConverter::ReConstructL( TInt aBitmapHandle )
       
   528 // (other items were commented in a header).
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 void CVTYUVFbsBitmapConverter::ReConstructL( TInt aBitmapHandle )
       
   532 	{
       
   533 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ReConstructL() >>"), RThread().Id().operator TUint()));
       
   534 	User::LeaveIfError( iDestination->Duplicate( aBitmapHandle ) );
       
   535 	// make sure that destination bitmap's displaymode is supported
       
   536 	if( ( iDestination->DisplayMode() != EColor4K ) &&
       
   537 	    ( iDestination->DisplayMode() != EColor64K ) &&
       
   538 	    ( iDestination->DisplayMode() != EColor16M ) &&
       
   539 	    ( iDestination->DisplayMode() != EColor16MU ) &&
       
   540 	    ( iDestination->DisplayMode() != EColor16MA )
       
   541         )
       
   542 		{
       
   543 		User::Leave( KErrNotSupported );
       
   544 		}
       
   545 	iDestinationSize = iDestination->SizeInPixels();
       
   546 	SizeUpdateL();
       
   547 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::ReConstructL() <<"), RThread().Id().operator TUint()));
       
   548 	}
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CVTYUVFbsBitmapConverter::SizeUpdateL()
       
   552 // (other items were commented in a header).
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 void CVTYUVFbsBitmapConverter::SizeUpdateL()
       
   556 	{
       
   557 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SizeUpdate() >>"), RThread().Id().operator TUint()));
       
   558 	if( ( SourceSize().iWidth < 2 ) || ( DestinationSize().iWidth < 2 ) )
       
   559 		{
       
   560 		User::Leave( KErrNotSupported ); // !!!!
       
   561 		}
       
   562 
       
   563     iVSkipReal = TReal32( SourceSize().iHeight ) /
       
   564 	    TReal32( DestinationSize().iHeight );
       
   565 	iHSkipReal = TReal32( SourceSize().iWidth ) /
       
   566 	    TReal32( DestinationSize().iWidth );
       
   567 
       
   568 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVFbsBitmapConverter::SizeUpdate() <<"), RThread().Id().operator TUint()));
       
   569 	}
       
   570 
       
   571 // ============================ CVTYUVPlanarFbsBitmapConverter ===============================
       
   572 
       
   573 // -----------------------------------------------------------------------------
       
   574 // CVTYUVPlanarFbsBitmapConverter::SetSourceSizeL( const TSize& aSize )
       
   575 // (other items were commented in a header).
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 EXPORT_C void CVTYUVPlanarFbsBitmapConverter::SetSourceSizeL(
       
   579     const TSize& aSize )
       
   580 	{
       
   581 	iSourceSize = aSize;
       
   582 	SizeUpdateL();
       
   583 	}
       
   584 
       
   585 // -----------------------------------------------------------------------------
       
   586 // CVTYUVPlanarFbsBitmapConverter::SetSourceL(
       
   587 //  const TSize& aSize, const TDesC8& aSourceData )
       
   588 // (other items were commented in a header).
       
   589 // -----------------------------------------------------------------------------
       
   590 //
       
   591 EXPORT_C void CVTYUVPlanarFbsBitmapConverter::SetSourceL(
       
   592     const TSize& aSize,
       
   593     const TDesC8& aSourceData )
       
   594 	{
       
   595 	iSourceSize = aSize;
       
   596 	SetSourceL( aSourceData );
       
   597 	SizeUpdateL();
       
   598 	}
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CVTYUVPlanarFbsBitmapConverter::CVTYUVPlanarFbsBitmapConverter(
       
   602 //  const TSize& aSourceSize )
       
   603 // (other items were commented in a header).
       
   604 // -----------------------------------------------------------------------------
       
   605 //
       
   606 CVTYUVPlanarFbsBitmapConverter::CVTYUVPlanarFbsBitmapConverter(
       
   607     const TSize& aSourceSize )
       
   608 : CVTYUVFbsBitmapConverter( aSourceSize )
       
   609 	{
       
   610 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::CVTYUVPlanarFbsBitmapConverter() >>"), RThread().Id().operator TUint()));
       
   611 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::CVTYUVPlanarFbsBitmapConverter() <<"), RThread().Id().operator TUint()));
       
   612 	}
       
   613 
       
   614 // -----------------------------------------------------------------------------
       
   615 // CVTYUVPlanarFbsBitmapConverter::DoProcess4K()
       
   616 // (other items were commented in a header).
       
   617 // -----------------------------------------------------------------------------
       
   618 //
       
   619 void CVTYUVPlanarFbsBitmapConverter::DoProcess4K()
       
   620 	{
       
   621 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4K() >>"), RThread().Id().operator TUint()));
       
   622 
       
   623 	// Vertical scaling needed?
       
   624 	if( ( iVSkipReal == 1 ) && ( iHSkipReal == 1 ) )
       
   625 		{
       
   626 		// NO: Use really fast conversion
       
   627 		DoProcess4KNoScale();
       
   628 		}
       
   629 	else
       
   630 		{
       
   631 
       
   632 		// YES: Use slower conversion method
       
   633 		const TUint8* y = iY;
       
   634 		const TUint8* u = iU;
       
   635 		const TUint8* v = iV;
       
   636 	    const TUint8* clip = COFF_TBL_4K + 40;
       
   637 
       
   638 		TInt height = DestinationSize().iHeight;
       
   639 		TInt width = DestinationSize().iWidth;
       
   640 
       
   641 		iDestination->LockHeap();
       
   642 		TUint32* d = iDestination->DataAddress();
       
   643 
       
   644 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4K(): [%d, %d] for >>"), RThread().Id().operator TUint(), width, height ));
       
   645 
       
   646 		for( TInt h = 0; h < height; h++ )
       
   647 			{
       
   648 			TInt sourceY = TInt( TReal32( h ) * iVSkipReal );
       
   649 			TInt hTimesW =  sourceY * SourceSize().iWidth;
       
   650 			TInt uvIdx = ( sourceY >> 1 ) * ( SourceSize().iWidth >> 1 );
       
   651 			for( TInt w = 0; w < width; w++ )
       
   652 				{
       
   653 				TInt sourceX = TInt( TReal32( w ) * iHSkipReal );
       
   654 			    TInt uvIdxW( uvIdx + ( sourceX >> 1 ) );
       
   655 
       
   656                 TInt ay = y[ hTimesW + sourceX ];
       
   657 				TInt cb = u[ uvIdxW ] - 128;
       
   658 				TInt cr = v[ uvIdxW ] - 128;
       
   659 
       
   660                  TInt greenCbCr =
       
   661                     (
       
   662                     cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   663                     cb * *reinterpret_cast< const TInt32* >( clip - 36 )
       
   664                     ) >> 16;
       
   665 			    cr =
       
   666                     (
       
   667                     cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   668                     ) >> 16;
       
   669 			    cb =
       
   670                     (
       
   671                     cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   672                     ) >> 16;
       
   673 
       
   674 				TInt red = ay + cr;
       
   675 				TInt green = ay - greenCbCr;
       
   676 				TInt blue = ay + cb;
       
   677 
       
   678 				red = clip[ red >> 4 ];
       
   679 				green = clip[ green >> 4 ];
       
   680 				blue = clip[ blue >> 4 ];
       
   681 
       
   682 				// RGB_444
       
   683 				TUint32 s = green | ( red << 4 );
       
   684 				s = blue | ( s << 4 );
       
   685 
       
   686 				w++;
       
   687 				sourceX = TInt( TReal32( w ) * iHSkipReal );
       
   688 				uvIdxW = uvIdx + ( sourceX >> 1 );
       
   689 
       
   690 				ay = y[ hTimesW + sourceX ];
       
   691 				cb = u[ uvIdxW ] - 128;
       
   692 				cr = v[ uvIdxW ] - 128;
       
   693 
       
   694                 greenCbCr =
       
   695                     (
       
   696                     cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   697                     cb * *reinterpret_cast< const TInt32* >( clip - 36 )
       
   698                     ) >> 16;
       
   699 			    cr =
       
   700                     (
       
   701                     cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   702                     ) >> 16;
       
   703 			    cb =
       
   704                     (
       
   705                     cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   706                     ) >> 16;
       
   707 
       
   708 				red = ay + cr;
       
   709 				green = ay - greenCbCr;
       
   710 				blue = ay + cb;
       
   711 
       
   712 				red = clip[ red >> 4 ];
       
   713 				green = clip[ green >> 4 ];
       
   714 				blue = clip[ blue >> 4 ];
       
   715 
       
   716 				// RGB_444
       
   717                 s |= ( ( green | ( red << 4 ) ) << 4 | blue ) << 16;
       
   718 
       
   719 				*d++ = s;
       
   720 				}
       
   721 			}
       
   722 
       
   723 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4K(): for <<"), RThread().Id().operator TUint()));
       
   724 
       
   725 		iDestination->UnlockHeap();
       
   726 		}
       
   727 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4K() <<"), RThread().Id().operator TUint()));
       
   728 	}
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CVTYUVPlanarFbsBitmapConverter::DoProcess4KNoScale()
       
   732 // When vertical and horizontal scaling is not required we can do two vertical
       
   733 // lines in parallel in that case we need to calculate Cr and Cb values only
       
   734 // once for four pixels.
       
   735 // (other items were commented in a header).
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 void CVTYUVPlanarFbsBitmapConverter::DoProcess4KNoScale()
       
   739 	{
       
   740 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4KNoScale() >>"), RThread().Id().operator TUint()));
       
   741 
       
   742    	TInt height( SourceSize().iHeight >> 1 );
       
   743     TInt width( SourceSize().iWidth );
       
   744 
       
   745 	const TUint32* y1 = reinterpret_cast< const TUint32* >( iY );
       
   746     const TUint32* u = reinterpret_cast< const TUint32* >( iU );
       
   747     const TUint32* v = reinterpret_cast< const TUint32* >( iV );
       
   748 
       
   749     iDestination->LockHeap();
       
   750 
       
   751 	TUint32 uintsPerDestRow = CFbsBitmap::ScanLineLength
       
   752         ( DestinationSize().iWidth, EColor4K ) >> 2;
       
   753 
       
   754     TUint32* d1 = iDestination->DataAddress();
       
   755 
       
   756     TUint32 ywidth = width >> 2;
       
   757 
       
   758     width >>= 3;
       
   759 
       
   760     TInt32 cb;
       
   761     TInt32 cr;
       
   762     TInt32 greenCbCr;
       
   763     TInt32 yy;
       
   764     TInt32 red;
       
   765     TInt32 green;
       
   766     TInt32 blue;
       
   767     TUint32 r1;
       
   768 	const TUint8* clip = COFF_TBL_4K + 40;
       
   769 
       
   770     for( TInt y = 0; y < height; y++ )
       
   771         {
       
   772         for( TInt x = 0; x < width; x++ )
       
   773             {
       
   774             TUint32 u1 = *u++;
       
   775             TUint32 v1 = *v++;
       
   776 
       
   777             for( TInt c2 = 0; c2 < 2; c2++ )
       
   778                 {
       
   779                 TUint32 yy2 = y1[ ywidth ];
       
   780                 TUint32 yy1 = *y1++;
       
   781 
       
   782                 for( TInt c = 0; c < 2; c++ )
       
   783                     {
       
   784                     cb = TInt32( u1 & 0xff ) - 128;
       
   785                     u1 >>= 8;
       
   786 			        cr = TInt32( v1 & 0xff ) - 128;
       
   787                     v1 >>= 8;
       
   788 
       
   789                     greenCbCr =
       
   790                         (
       
   791                         cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   792                         cb * *reinterpret_cast< const TInt32* >( clip - 36 )
       
   793                         ) >> 16;
       
   794 			        cr =
       
   795                         (
       
   796                         cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   797                         ) >> 16;
       
   798 			        cb =
       
   799                         (
       
   800                         cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   801                         ) >> 16;
       
   802 
       
   803                     // lower left
       
   804                     yy = ( yy2 & 0xff );
       
   805                     yy2 >>= 8;
       
   806 
       
   807 				    red = yy + cr;
       
   808 				    green = yy - greenCbCr;
       
   809 				    blue = yy + cb;
       
   810 
       
   811 				    red = clip[ red >> 4 ];
       
   812 				    green = clip[ green >> 4 ];
       
   813 				    blue = clip[ blue >> 4 ];
       
   814 
       
   815 				    // RGB_444
       
   816 				    r1 = green | ( red << 4 );
       
   817 				    r1 = blue | ( r1 << 4 );
       
   818 
       
   819                     // lower right
       
   820                     yy = ( yy2 & 0xff );
       
   821                     yy2 >>= 8;
       
   822 
       
   823 				    red = yy + cr;
       
   824 				    green = yy - greenCbCr;
       
   825 				    blue = yy + cb;
       
   826 
       
   827 				    red = clip[ red >> 4 ];
       
   828 				    green = clip[ green >> 4 ];
       
   829 				    blue = clip[ blue >> 4 ];
       
   830 
       
   831 				    // RGB_444
       
   832 				    r1 |= ( ( green | ( red << 4 ) ) << 4 | blue ) << 16;
       
   833 
       
   834                     d1[ uintsPerDestRow ] = r1;
       
   835 
       
   836                     // upper left
       
   837                     yy = ( yy1 & 0xff );
       
   838                     yy1 >>= 8;
       
   839 
       
   840 				    red = yy + cr;
       
   841 				    green = yy - greenCbCr;
       
   842 				    blue = yy + cb;
       
   843 
       
   844 				    red = clip[ red >> 4 ];
       
   845 				    green = clip[ green >> 4 ];
       
   846 				    blue = clip[ blue >> 4 ];
       
   847 
       
   848 				    // RGB_444
       
   849 				    r1 = green | ( red << 4 );
       
   850 				    r1 = blue | ( r1 << 4 );
       
   851 
       
   852                     // upper right
       
   853                     yy = ( yy1 & 0xff );
       
   854                     yy1 >>= 8;
       
   855 
       
   856 				    red = yy + cr;
       
   857 				    green = yy - greenCbCr;
       
   858 				    blue = yy + cb;
       
   859 
       
   860 				    red = clip[ red >> 4 ];
       
   861 				    green = clip[ green >> 4 ];
       
   862 				    blue = clip[ blue >> 4 ];
       
   863 
       
   864 				    // RGB_444
       
   865 				    r1 |= ( ( green | ( red << 4 ) ) << 4 | blue ) << 16;
       
   866 
       
   867                     *d1++ = r1;
       
   868                     }
       
   869                 }
       
   870             }
       
   871 
       
   872 	    y1 += ( width << 1 );
       
   873 	    d1 += uintsPerDestRow;
       
   874         }
       
   875 
       
   876     iDestination->UnlockHeap();
       
   877 
       
   878 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess4KNoScale() <<"), RThread().Id().operator TUint()));
       
   879 	}
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // CVTYUVPlanarFbsBitmapConverter::DoProcess64K()
       
   883 // (other items were commented in a header).
       
   884 // -----------------------------------------------------------------------------
       
   885 //
       
   886 void CVTYUVPlanarFbsBitmapConverter::DoProcess64K()
       
   887 	{
       
   888 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64K() >>"), RThread().Id().operator TUint()));
       
   889 
       
   890 	// Vertical scaling needed?
       
   891 	if( ( iVSkipReal == 1 ) && ( iHSkipReal == 1 ) )	// !!!
       
   892 		{
       
   893 		// NO: Use really fast conversion
       
   894 		DoProcess64KNoScale();
       
   895 		return;
       
   896 		}
       
   897 	else
       
   898 		{
       
   899 		// YES: Use slower conversion method
       
   900 		const TUint8* y = iY;
       
   901 		const TUint8* u = iU;
       
   902 		const TUint8* v = iV;
       
   903 	    const TUint8* clip = COFF_TBL_64K + 40;
       
   904 
       
   905 		TInt height = DestinationSize().iHeight;
       
   906 		TInt width = DestinationSize().iWidth;
       
   907 
       
   908 		iDestination->LockHeap();
       
   909 		TUint32* d = iDestination->DataAddress();
       
   910 
       
   911 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64K(): [%d, %d] for >>"), RThread().Id().operator TUint(), width, height ));
       
   912 
       
   913 		for( TInt h = 0; h < height; h++ )
       
   914 			{
       
   915 			TInt sourceY = TInt( TReal32( h ) * iVSkipReal );
       
   916 			TInt hTimesW =  sourceY * SourceSize().iWidth;
       
   917 			TInt uvIdx = ( sourceY >> 1 ) * ( SourceSize().iWidth >> 1 );
       
   918 			for( TInt w = 0; w < width; w++ )
       
   919 				{
       
   920 				TInt sourceX = TInt( TReal32( w ) * iHSkipReal );
       
   921 
       
   922 				TInt uvIdxW( uvIdx + ( sourceX >> 1 ) );
       
   923 
       
   924 				TInt ay = y[ hTimesW + sourceX ];
       
   925 				TInt cb = u[ uvIdxW ] - 128;
       
   926 				TInt cr = v[ uvIdxW ] - 128;
       
   927 
       
   928                 TInt greenCbCr =
       
   929                     (
       
   930                     cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   931                     cb * *reinterpret_cast< const TInt32* >( clip - 36 ) -
       
   932                     0x1200000
       
   933                     ) >> 16;
       
   934 			    cr =
       
   935                     (
       
   936                     cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   937                     ) >> 16;
       
   938 			    cb =
       
   939                     (
       
   940                     cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   941                     ) >> 16;
       
   942 
       
   943 				TInt red = ay + cr;
       
   944 				TInt green = ay - greenCbCr;
       
   945 				TInt blue = ay + cb;
       
   946 
       
   947 				red = clip[ red >> 3 ];
       
   948 				green = clip[ green >> 2 ];
       
   949 				blue = clip[ blue >> 3 ];
       
   950 
       
   951                 // RGB_565
       
   952 				TUint32 s = green | ( red << 6 );
       
   953 				s = blue | ( s << 5 );
       
   954 
       
   955 				w++;
       
   956 				sourceX = TInt( TReal32( w ) * iHSkipReal );
       
   957 
       
   958 				uvIdxW = uvIdx + ( sourceX >> 1 );
       
   959 
       
   960 				ay = y[ hTimesW + sourceX ];
       
   961 				cb = u[ uvIdxW ] - 128;
       
   962 				cr = v[ uvIdxW ] - 128;
       
   963 
       
   964                 greenCbCr =
       
   965                     (
       
   966                     cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
   967                     cb * *reinterpret_cast< const TInt32* >( clip - 36 ) -
       
   968                     0x1200000
       
   969                     ) >> 16;
       
   970 			    cr =
       
   971                     (
       
   972                     cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
   973                     ) >> 16;
       
   974 			    cb =
       
   975                     (
       
   976                     cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
   977                     ) >> 16;
       
   978 
       
   979 				red = ay + cr;
       
   980 				green = ay - greenCbCr;
       
   981 				blue = ay + cb;
       
   982 
       
   983 				red = clip[ red >> 3 ];
       
   984 				green = clip[ green >> 2 ];
       
   985 				blue = clip[ blue >> 3 ];
       
   986 
       
   987                 s |= ( ( green | ( red << 6 ) ) << 5 | blue ) << 16;
       
   988 
       
   989 				*d++ = s;
       
   990 				}
       
   991 			}
       
   992 
       
   993 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64K(): for <<"), RThread().Id().operator TUint()));
       
   994 
       
   995 		iDestination->UnlockHeap();
       
   996 		}
       
   997 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64K() <<"), RThread().Id().operator TUint()));
       
   998 	}
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CVTYUVPlanarFbsBitmapConverter::DoProcess64KNoScale()
       
  1002 // Source YUV image must be even divisible by 8.
       
  1003 // -----------------------------------------------------------------------------
       
  1004 //
       
  1005 void CVTYUVPlanarFbsBitmapConverter::DoProcess64KNoScale()
       
  1006 	{
       
  1007 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64KNoScale() >>"), RThread().Id().operator TUint()));
       
  1008 
       
  1009    	TInt height( SourceSize().iHeight >> 1 );
       
  1010     TInt width( SourceSize().iWidth );
       
  1011 
       
  1012 	const TUint32* y1 = reinterpret_cast< const TUint32* >( iY );
       
  1013     const TUint32* u = reinterpret_cast< const TUint32* >( iU );
       
  1014     const TUint32* v = reinterpret_cast< const TUint32* >( iV );
       
  1015 
       
  1016     iDestination->LockHeap();
       
  1017 
       
  1018 	TUint32 uintsPerDestRow = CFbsBitmap::ScanLineLength
       
  1019         ( DestinationSize().iWidth, EColor64K ) >> 2;
       
  1020 
       
  1021     TUint32* d1 = iDestination->DataAddress();
       
  1022 
       
  1023     TUint32 ywidth = width >> 2;
       
  1024 
       
  1025     width >>= 3;
       
  1026 
       
  1027     TInt32 cb;
       
  1028     TInt32 cr;
       
  1029     TInt32 greenCbCr;
       
  1030     TInt32 yy;
       
  1031     TInt32 red;
       
  1032     TInt32 green;
       
  1033     TInt32 blue;
       
  1034     TUint32 r1;
       
  1035 	const TUint8* clip = COFF_TBL_64K + 40;
       
  1036 
       
  1037     for( TInt y = 0; y < height; y++ )
       
  1038         {
       
  1039         for( TInt x = 0; x < width; x++ )
       
  1040             {
       
  1041             TUint32 u1 = *u++;
       
  1042             TUint32 v1 = *v++;
       
  1043 
       
  1044             for( TInt c2 = 0; c2 < 2; c2++ )
       
  1045                 {
       
  1046                 TUint32 yy2 = y1[ ywidth ];
       
  1047                 TUint32 yy1 = *y1++;
       
  1048 
       
  1049                 for( TInt c = 0; c < 2; c++ )
       
  1050                     {
       
  1051                     cb = TInt32( u1 & 0xff ) - 128;
       
  1052                     u1 >>= 8;
       
  1053 			        cr = TInt32( v1 & 0xff ) - 128;
       
  1054                     v1 >>= 8;
       
  1055 
       
  1056                     greenCbCr =
       
  1057                         (
       
  1058                         cr * *reinterpret_cast< const TInt32* >( clip - 32 ) +
       
  1059                         cb * *reinterpret_cast< const TInt32* >( clip - 36 ) -
       
  1060                         0x1200000
       
  1061                         ) >> 16;
       
  1062 			        cr =
       
  1063                         (
       
  1064                         cr * *reinterpret_cast< const TInt32* >( clip - 40 )
       
  1065                         ) >> 16;
       
  1066 			        cb =
       
  1067                         (
       
  1068                         cb * *reinterpret_cast< const TInt32* >( clip - 28 )
       
  1069                         ) >> 16;
       
  1070 
       
  1071                     // lower left
       
  1072                     yy = ( yy2 & 0xff );
       
  1073                     yy2 >>= 8;
       
  1074 
       
  1075 				    red = yy + cr;
       
  1076 				    green = yy - greenCbCr;
       
  1077 				    blue = yy + cb;
       
  1078 
       
  1079 				    red = clip[ red >> 3 ];
       
  1080 				    green = clip[ green >> 2 ];
       
  1081 				    blue = clip[ blue >> 3 ];
       
  1082 
       
  1083 				    // RGB_565
       
  1084 				    r1 = green | ( red << 6 );
       
  1085 				    r1 = blue | ( r1 << 5 );
       
  1086 
       
  1087                     // lower right
       
  1088                     yy = ( yy2 & 0xff );
       
  1089                     yy2 >>= 8;
       
  1090 
       
  1091 				    red = yy + cr;
       
  1092 				    green = yy - greenCbCr;
       
  1093 				    blue = yy + cb;
       
  1094 
       
  1095                     // clear lowest 3 bits
       
  1096 				    red = clip[ red >> 3 ];
       
  1097 				    green = clip[ green >> 2 ];
       
  1098 				    blue = clip[ blue >> 3 ];
       
  1099 
       
  1100 				    // RGB_565
       
  1101 				    r1 |= ( ( green | ( red << 6 ) ) << 5 | blue ) << 16;
       
  1102 
       
  1103                     d1[ uintsPerDestRow ] = r1;
       
  1104 
       
  1105                     // upper left
       
  1106                     yy = ( yy1 & 0xff );
       
  1107                     yy1 >>= 8;
       
  1108 
       
  1109 				    red = yy + cr;
       
  1110 				    green = yy - greenCbCr;
       
  1111 				    blue = yy + cb;
       
  1112 
       
  1113 				    red = clip[ red >> 3 ];
       
  1114 				    green = clip[ green >> 2 ];
       
  1115 				    blue = clip[ blue >> 3 ];
       
  1116 
       
  1117 				    // RGB_565
       
  1118 				    r1 = green | ( red << 6 );
       
  1119 				    r1 = blue | ( r1 << 5 );
       
  1120 
       
  1121                     // upper right
       
  1122                     yy = ( yy1 & 0xff );
       
  1123                     yy1 >>= 8;
       
  1124 
       
  1125 				    red = yy  + cr;
       
  1126 				    green = yy - greenCbCr;
       
  1127 				    blue = yy + cb;
       
  1128 
       
  1129 				    red = clip[ red >> 3 ];
       
  1130 				    green = clip[ green >> 2 ];
       
  1131 				    blue = clip[ blue >> 3 ];
       
  1132 
       
  1133 				    // RGB_565
       
  1134 				    r1 |= ( ( green | ( red << 6 ) ) << 5 | blue ) << 16;
       
  1135 
       
  1136                     *d1++ = r1;
       
  1137                     }
       
  1138                 }
       
  1139             }
       
  1140 
       
  1141 	    y1 += ( width << 1 );
       
  1142 	    d1 += uintsPerDestRow;
       
  1143         }
       
  1144 
       
  1145     iDestination->UnlockHeap();
       
  1146 
       
  1147     __IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess64KNoScale() <<"), RThread().Id().operator TUint()));
       
  1148 	}
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CVTYUVPlanarFbsBitmapConverter::DoProcess16M()
       
  1152 // (other items were commented in a header).
       
  1153 // -----------------------------------------------------------------------------
       
  1154 //
       
  1155 void CVTYUVPlanarFbsBitmapConverter::DoProcess16M()
       
  1156 	{
       
  1157 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16M() >>"), RThread().Id().operator TUint()));
       
  1158 
       
  1159 	// Vertical scaling needed?
       
  1160 	if( ( iVSkipReal == 1 ) && ( iHSkipReal == 1 ) )
       
  1161 		{
       
  1162 		// NO: Use really fast conversion
       
  1163 		DoProcess16MNoScale();
       
  1164 		}
       
  1165 	else
       
  1166 		{
       
  1167 		// YES: Use slower conversion method
       
  1168 
       
  1169 		// YES: Use slower conversion method
       
  1170 		const TUint8* y = iY;
       
  1171 		const TUint8* u = iU;
       
  1172 		const TUint8* v = iV;
       
  1173 	    const TUint8* clip = COFF_TBL_16M + 144;
       
  1174 
       
  1175 		TInt height = DestinationSize().iHeight;
       
  1176 		TInt width = DestinationSize().iWidth;
       
  1177 
       
  1178 		iDestination->LockHeap();
       
  1179 
       
  1180         TUint8* d = reinterpret_cast<TUint8*>( iDestination->DataAddress() );
       
  1181         TUint32 dPitch = iDestination->ScanLineLength( width, iDestination->DisplayMode() );
       
  1182 
       
  1183         __IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16M(): [%d, %d] for >>"), RThread().Id().operator TUint(), width, height ));
       
  1184 
       
  1185 		for( TInt h = 0; h < height; h++ )
       
  1186 			{
       
  1187 			TInt sourceY = TInt( TReal32( h ) * iVSkipReal );
       
  1188 			TInt hTimesW =  sourceY * SourceSize().iWidth;
       
  1189 			TInt uvIdx = ( sourceY >> 1 ) * ( SourceSize().iWidth >> 1 );
       
  1190             TUint8* dTemp = d;
       
  1191 			for( TInt w = 0; w < width; w++ )
       
  1192 				{
       
  1193 				TInt sourceX = TInt( TReal32( w ) * iHSkipReal );
       
  1194 
       
  1195 				TInt uvIdxW( uvIdx + ( sourceX >> 1 ) );
       
  1196 
       
  1197 				TInt ay = y[ hTimesW + sourceX ];
       
  1198 				TInt cb = u[ uvIdxW ] - 128;
       
  1199 				TInt cr = v[ uvIdxW ] - 128;
       
  1200 
       
  1201                 TInt greenCbCr =
       
  1202                     (
       
  1203                     cr * *reinterpret_cast< const TInt32* >( clip - 136 ) +
       
  1204                     cb * *reinterpret_cast< const TInt32* >( clip - 140 )
       
  1205                     ) >> 16;
       
  1206 			    cr =
       
  1207                     (
       
  1208                     cr * *reinterpret_cast< const TInt32* >( clip - 144 )
       
  1209                     ) >> 16;
       
  1210 			    cb =
       
  1211                     (
       
  1212                     cb * *reinterpret_cast< const TInt32* >( clip - 132 )
       
  1213                     ) >> 16;
       
  1214 
       
  1215 				*dTemp++ = clip[ ay + cb ];
       
  1216 				*dTemp++ = clip[ ay - greenCbCr ];
       
  1217                 *dTemp++ = clip[ ay + cr ];
       
  1218 				}
       
  1219             d += dPitch;
       
  1220 			}
       
  1221 
       
  1222 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16M(): for <<"), RThread().Id().operator TUint()));
       
  1223 
       
  1224 		iDestination->UnlockHeap();
       
  1225 		}
       
  1226 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16M() <<"), RThread().Id().operator TUint()));
       
  1227 	}
       
  1228 
       
  1229 // -----------------------------------------------------------------------------
       
  1230 // CVTYUVPlanarFbsBitmapConverter::DoProcess16MNoScale()
       
  1231 // When vertical and horizontal scaling is not required we can do two vertical
       
  1232 // lines in parallel in that case we need to calculate Cr and Cb values only
       
  1233 // once for four pixels.
       
  1234 // (other items were commented in a header).
       
  1235 // -----------------------------------------------------------------------------
       
  1236 //
       
  1237 void CVTYUVPlanarFbsBitmapConverter::DoProcess16MNoScale()
       
  1238 	{
       
  1239 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MNoScale() >>"), RThread().Id().operator TUint()));
       
  1240 
       
  1241    	TInt height( SourceSize().iHeight >> 1 );
       
  1242     TInt width( SourceSize().iWidth );
       
  1243 
       
  1244 	const TUint32* y1 = reinterpret_cast< const TUint32* >( iY );
       
  1245     const TUint32* u = reinterpret_cast< const TUint32* >( iU );
       
  1246     const TUint32* v = reinterpret_cast< const TUint32* >( iV );
       
  1247 
       
  1248     iDestination->LockHeap();
       
  1249 
       
  1250 	TUint32 bytesPerDestRow = CFbsBitmap::ScanLineLength
       
  1251         ( DestinationSize().iWidth, EColor16M );
       
  1252 
       
  1253     TUint8* d1 = reinterpret_cast< TUint8* >( iDestination->DataAddress() );
       
  1254 
       
  1255     TUint32 ywidth = width >> 2;
       
  1256 
       
  1257     width >>= 3;
       
  1258 
       
  1259     TInt32 cb;
       
  1260     TInt32 cr;
       
  1261     TInt32 greenCbCr;
       
  1262     TInt32 yy;
       
  1263     TInt32 idx1;
       
  1264     TInt32 idx2;
       
  1265 	const TUint8* clip = COFF_TBL_16M + 144;
       
  1266 
       
  1267     for( TInt y = 0; y < height; y++ )
       
  1268         {
       
  1269         idx1 = 0;
       
  1270         idx2 = bytesPerDestRow;
       
  1271 
       
  1272         for( TInt x = 0; x < width; x++ )
       
  1273             {
       
  1274             TUint32 u1 = *u++;
       
  1275             TUint32 v1 = *v++;
       
  1276 
       
  1277             for( TInt c2 = 0; c2 < 2; c2++ )
       
  1278                 {
       
  1279                 TUint32 yy2 = y1[ ywidth ];
       
  1280                 TUint32 yy1 = *y1++;
       
  1281 
       
  1282                 for( TInt c = 0; c < 2; c++ )
       
  1283                     {
       
  1284                     cb = TInt32( u1 & 0xff ) - 128;
       
  1285                     u1 >>= 8;
       
  1286 			        cr = TInt32( v1 & 0xff ) - 128;
       
  1287                     v1 >>= 8;
       
  1288 
       
  1289                     greenCbCr =
       
  1290                         (
       
  1291                         cr * *reinterpret_cast< const TInt32* >( clip - 136 ) +
       
  1292                         cb * *reinterpret_cast< const TInt32* >( clip - 140 )
       
  1293                         ) >> 16;
       
  1294 			        cr =
       
  1295                         (
       
  1296                         cr * *reinterpret_cast< const TInt32* >( clip - 144 )
       
  1297                         ) >> 16;
       
  1298 			        cb =
       
  1299                         (
       
  1300                         cb * *reinterpret_cast< const TInt32* >( clip - 132 )
       
  1301                         ) >> 16;
       
  1302 
       
  1303                     // lower left
       
  1304                     yy = ( yy2 & 0xff );
       
  1305                     yy2 >>= 8;
       
  1306 
       
  1307 				    d1[ idx2++ ] = clip[ yy + cb ];
       
  1308 				    d1[ idx2++ ] = clip[ yy - greenCbCr ];
       
  1309                     d1[ idx2++ ] = clip[ yy + cr ];
       
  1310 
       
  1311                     // lower right
       
  1312                     yy = ( yy2 & 0xff );
       
  1313                     yy2 >>= 8;
       
  1314 
       
  1315 				    d1[ idx2++ ] = clip[ yy + cb ];
       
  1316 				    d1[ idx2++ ] = clip[ yy - greenCbCr ];
       
  1317 				    d1[ idx2++ ] = clip[ yy + cr ];
       
  1318 
       
  1319                     // upper left
       
  1320                     yy = ( yy1 & 0xff );
       
  1321                     yy1 >>= 8;
       
  1322 
       
  1323 				    d1[ idx1++ ] = clip[ yy + cb ];
       
  1324 				    d1[ idx1++ ] = clip[ yy - greenCbCr ];
       
  1325 				    d1[ idx1++ ] = clip[ yy + cr ];
       
  1326 
       
  1327                     // upper right
       
  1328                     yy = ( yy1 & 0xff );
       
  1329                     yy1 >>= 8;
       
  1330 
       
  1331 				    d1[ idx1++ ] = clip[ yy + cb ];
       
  1332 				    d1[ idx1++ ] = clip[ yy - greenCbCr ];
       
  1333 				    d1[ idx1++ ] = clip[ yy + cr ];
       
  1334                     }
       
  1335                 }
       
  1336             }
       
  1337 
       
  1338 	    y1 += ( width << 1 );
       
  1339 	    d1 += bytesPerDestRow * 2;
       
  1340         }
       
  1341 
       
  1342     iDestination->UnlockHeap();
       
  1343 
       
  1344 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MNoScale() <<"), RThread().Id().operator TUint()));
       
  1345 	}
       
  1346 
       
  1347 // -----------------------------------------------------------------------------
       
  1348 // CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA()
       
  1349 // (other items were commented in a header).
       
  1350 // -----------------------------------------------------------------------------
       
  1351 //
       
  1352 void CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA()
       
  1353 	{
       
  1354 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA() >>"), RThread().Id().operator TUint()));
       
  1355 
       
  1356 	// Vertical scaling needed?
       
  1357 	if( ( iVSkipReal == 1 ) && ( iHSkipReal == 1 ) )
       
  1358 		{
       
  1359 		// NO: Use really fast conversion
       
  1360 		DoProcess16MU16MANoScale();
       
  1361 		}
       
  1362 	else
       
  1363 		{
       
  1364 		// YES: Use slower conversion method
       
  1365 		const TUint8* y = iY;
       
  1366 		const TUint8* u = iU;
       
  1367 		const TUint8* v = iV;
       
  1368     	const TUint8* clip = COFF_TBL_16M + 144;
       
  1369 
       
  1370 		TInt height = DestinationSize().iHeight;
       
  1371 		TInt width = DestinationSize().iWidth;
       
  1372 
       
  1373 		iDestination->LockHeap();
       
  1374 		TUint32* d = iDestination->DataAddress();
       
  1375 
       
  1376 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA(): [%d, %d] for >>"), RThread().Id().operator TUint(), width, height ));
       
  1377 
       
  1378 		for( TInt h = 0; h < height; h++ )
       
  1379 			{
       
  1380 			TInt sourceY = TInt( TReal32( h ) * iVSkipReal );
       
  1381 			TInt hTimesW =  sourceY * SourceSize().iWidth;
       
  1382 			TInt uvIdx = ( sourceY >> 1 ) * ( SourceSize().iWidth >> 1 );
       
  1383 			for( TInt w = 0; w < width; w++ )
       
  1384 				{
       
  1385 				TInt sourceX = TInt( TReal32( w ) * iHSkipReal );
       
  1386 
       
  1387 				TInt uvIdxW( uvIdx + ( sourceX >> 1 ) );
       
  1388 
       
  1389 				TInt ay = y[ hTimesW + sourceX ];
       
  1390 				TInt cb = u[ uvIdxW ] - 128;
       
  1391 				TInt cr = v[ uvIdxW ] - 128;
       
  1392 
       
  1393                 TInt greenCbCr =
       
  1394                     (
       
  1395                     cr * *reinterpret_cast< const TInt32* >( clip - 136 ) +
       
  1396                     cb * *reinterpret_cast< const TInt32* >( clip - 140 )
       
  1397                     ) >> 16;
       
  1398 			    cr =
       
  1399                     (
       
  1400                     cr * *reinterpret_cast< const TInt32* >( clip - 144 )
       
  1401                     ) >> 16;
       
  1402 			    cb =
       
  1403                     (
       
  1404                     cb * *reinterpret_cast< const TInt32* >( clip - 132 )
       
  1405                     ) >> 16;
       
  1406 
       
  1407 
       
  1408                 // 0xffBBGG
       
  1409                 TUint32 p = 0xff0000 |
       
  1410                     ( clip[ ay + cr ] << 8 ) | clip[ ay - greenCbCr ];
       
  1411                 // 0xffBBGGRR
       
  1412                 *d++ = clip[ ay + cb ] | ( p << 8 );
       
  1413 				}
       
  1414 			}
       
  1415 
       
  1416 		__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA(): for <<"), RThread().Id().operator TUint()));
       
  1417 
       
  1418 		iDestination->UnlockHeap();
       
  1419 		}
       
  1420 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MA() <<"), RThread().Id().operator TUint()));
       
  1421 	}
       
  1422 
       
  1423 // -----------------------------------------------------------------------------
       
  1424 // CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MANoScale()
       
  1425 // When vertical and horizontal scaling is not required we can do two vertical
       
  1426 // lines in parallel in that case we need to calculate Cr and Cb values only
       
  1427 // once for four pixels.
       
  1428 // (other items were commented in a header).
       
  1429 // -----------------------------------------------------------------------------
       
  1430 //
       
  1431 void CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MANoScale()
       
  1432 	{
       
  1433 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MANoScale() >>"), RThread().Id().operator TUint()));
       
  1434 
       
  1435    	TInt height( SourceSize().iHeight >> 1 );
       
  1436     TInt width( SourceSize().iWidth );
       
  1437 
       
  1438 	const TUint32* y1 = reinterpret_cast< const TUint32* >( iY );
       
  1439     const TUint32* u = reinterpret_cast< const TUint32* >( iU );
       
  1440     const TUint32* v = reinterpret_cast< const TUint32* >( iV );
       
  1441 
       
  1442     iDestination->LockHeap();
       
  1443 
       
  1444 	TUint32 uintsPerDestRow = CFbsBitmap::ScanLineLength
       
  1445         ( DestinationSize().iWidth, EColor16MU ) >> 2;
       
  1446 
       
  1447     TUint32* d1 = iDestination->DataAddress();
       
  1448 
       
  1449     TUint32 ywidth = width >> 2;
       
  1450 
       
  1451     width >>= 3;
       
  1452 
       
  1453     TInt32 cb;
       
  1454     TInt32 cr;
       
  1455     TInt32 greenCbCr;
       
  1456     TInt32 yy;
       
  1457     TUint32 p;
       
  1458 	const TUint8* clip = COFF_TBL_16M + 144;
       
  1459 
       
  1460     for( TInt y = 0; y < height; y++ )
       
  1461         {
       
  1462         for( TInt x = 0; x < width; x++ )
       
  1463             {
       
  1464             TUint32 u1 = *u++;
       
  1465             TUint32 v1 = *v++;
       
  1466 
       
  1467             for( TInt c2 = 0; c2 < 2; c2++ )
       
  1468                 {
       
  1469                 TUint32 yy2 = y1[ ywidth ];
       
  1470                 TUint32 yy1 = *y1++;
       
  1471 
       
  1472                 for( TInt c = 0; c < 2; c++ )
       
  1473                     {
       
  1474                     cb = TInt32( u1 & 0xff ) - 128;
       
  1475                     u1 >>= 8;
       
  1476 			        cr = TInt32( v1 & 0xff ) - 128;
       
  1477                     v1 >>= 8;
       
  1478 
       
  1479                     greenCbCr =
       
  1480                         (
       
  1481                         cr * *reinterpret_cast< const TInt32* >( clip - 136 ) +
       
  1482                         cb * *reinterpret_cast< const TInt32* >( clip - 140 )
       
  1483                         ) >> 16;
       
  1484 			        cr =
       
  1485                         (
       
  1486                         cr * *reinterpret_cast< const TInt32* >( clip - 144 )
       
  1487                         ) >> 16;
       
  1488 			        cb =
       
  1489                         (
       
  1490                         cb * *reinterpret_cast< const TInt32* >( clip - 132 )
       
  1491                         ) >> 16;
       
  1492 
       
  1493                     // lower left
       
  1494                     yy = ( yy2 & 0xff );
       
  1495                     yy2 >>= 8;
       
  1496 
       
  1497                     // 0xffBBGG
       
  1498                     p = 0xff0000 |
       
  1499                         ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
  1500                     // 0xffBBGGRR
       
  1501                     d1[ uintsPerDestRow ] = clip[ yy + cb ] | ( p << 8 );
       
  1502 
       
  1503                     // lower right
       
  1504                     yy = ( yy2 & 0xff );
       
  1505                     yy2 >>= 8;
       
  1506 
       
  1507                     // 0xffBBGG
       
  1508                     p = 0xff0000 |
       
  1509                         ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
  1510                     // 0xffBBGGRR
       
  1511                     d1[ uintsPerDestRow + 1 ] = clip[ yy + cb ] | ( p << 8 );
       
  1512 
       
  1513                     // upper left
       
  1514                     yy = ( yy1 & 0xff );
       
  1515                     yy1 >>= 8;
       
  1516 
       
  1517                     // 0xffBBGG
       
  1518                     p = 0xff0000 |
       
  1519                         ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
  1520                     // 0xffBBGGRR
       
  1521                     *d1++ = clip[ yy + cb ] | ( p << 8 );
       
  1522 
       
  1523                     // upper right
       
  1524                     yy = ( yy1 & 0xff );
       
  1525                     yy1 >>= 8;
       
  1526 
       
  1527                     // 0xffBBGG
       
  1528                     p = 0xff0000 |
       
  1529                         ( clip[ yy + cr ] << 8 ) | clip[ yy - greenCbCr ];
       
  1530                     // 0xffBBGGRR
       
  1531                     *d1++ = clip[ yy + cb ] | ( p << 8 );
       
  1532                     }
       
  1533                 }
       
  1534             }
       
  1535 
       
  1536 	    y1 += ( width << 1 );
       
  1537 	    d1 += uintsPerDestRow;
       
  1538         }
       
  1539 
       
  1540     iDestination->UnlockHeap();
       
  1541 
       
  1542 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYUVPlanarFbsBitmapConverter::DoProcess16MU16MANoScale() <<"), RThread().Id().operator TUint()));
       
  1543 	}
       
  1544 
       
  1545 // -----------------------------------------------------------------------------
       
  1546 // CVTYUVPlanarFbsBitmapConverter::SetSourceL( const TDesC8& aSourceData )
       
  1547 // (other items were commented in a header).
       
  1548 // -----------------------------------------------------------------------------
       
  1549 //
       
  1550 EXPORT_C void CVTYUVPlanarFbsBitmapConverter::SetSourceL(
       
  1551     const TDesC8& aSourceData )
       
  1552 	{
       
  1553 	// make sure dimension and buffer size match
       
  1554 	if( aSourceData.Length() !=
       
  1555 	    ( ( SourceSize().iWidth * SourceSize().iHeight * 12 ) / 8 ) )
       
  1556 		{
       
  1557 		User::Leave( KErrArgument );
       
  1558 		}
       
  1559 	SetYUVPtrs( aSourceData );
       
  1560 	}
       
  1561 
       
  1562 // ============================ CVTIYUVFbsBitmapConverter ===============================
       
  1563 
       
  1564 // -----------------------------------------------------------------------------
       
  1565 // CVTIYUVFbsBitmapConverter::NewL( const TSize& aSourceSize,
       
  1566 //  const CFbsBitmap& aDestinationBitmap )
       
  1567 // (other items were commented in a header).
       
  1568 // -----------------------------------------------------------------------------
       
  1569 //
       
  1570 EXPORT_C CVTIYUVFbsBitmapConverter* CVTIYUVFbsBitmapConverter::NewL(
       
  1571     const TSize& aSourceSize,
       
  1572     const CFbsBitmap& aDestinationBitmap )
       
  1573 	{
       
  1574 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::NewL() >>"), RThread().Id().operator TUint()));
       
  1575 	CVTIYUVFbsBitmapConverter* self = NewL(
       
  1576 	    aSourceSize, aDestinationBitmap.Handle() );
       
  1577 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::NewL() <<"), RThread().Id().operator TUint()));
       
  1578 	return self;
       
  1579 	}
       
  1580 
       
  1581 // -----------------------------------------------------------------------------
       
  1582 // CVTIYUVFbsBitmapConverter::NewL( const TSize& aSourceSize,
       
  1583 //  TInt aBitmapHandle )
       
  1584 // (other items were commented in a header).
       
  1585 // -----------------------------------------------------------------------------
       
  1586 //
       
  1587 EXPORT_C CVTIYUVFbsBitmapConverter* CVTIYUVFbsBitmapConverter::NewL(
       
  1588     const TSize& aSourceSize,
       
  1589     TInt aBitmapHandle )
       
  1590 	{
       
  1591 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::NewL() >>"), RThread().Id().operator TUint()));
       
  1592 	CVTIYUVFbsBitmapConverter* self = new (ELeave)
       
  1593 	    CVTIYUVFbsBitmapConverter( aSourceSize );
       
  1594 	CleanupStack::PushL( self );
       
  1595 	self->ConstructL( aBitmapHandle );
       
  1596 	CleanupStack::Pop(); // self
       
  1597 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::NewL() <<"), RThread().Id().operator TUint()));
       
  1598 	return self;
       
  1599 	}
       
  1600 
       
  1601 // -----------------------------------------------------------------------------
       
  1602 // CVTIYUVFbsBitmapConverter::SetYUVPtrs( const TDesC8& aSourceData )
       
  1603 // (other items were commented in a header).
       
  1604 // -----------------------------------------------------------------------------
       
  1605 //
       
  1606 void CVTIYUVFbsBitmapConverter::SetYUVPtrs( const TDesC8& aSourceData )
       
  1607 	{
       
  1608 	TInt ySize = SourceSize().iWidth * SourceSize().iHeight;
       
  1609 	TInt ySizeDiv4 = ( ySize >> 2 );
       
  1610 	iY = aSourceData.Mid( 0, ySize ).Ptr();
       
  1611 	iU = aSourceData.Mid( ySize, ySizeDiv4 ).Ptr();
       
  1612 	iV = aSourceData.Mid( ySize + ySizeDiv4, ySizeDiv4 ).Ptr();
       
  1613 	}
       
  1614 
       
  1615 // -----------------------------------------------------------------------------
       
  1616 // CVTIYUVFbsBitmapConverter::CVTIYUVFbsBitmapConverter( const TSize&
       
  1617 //  aSourceSize )
       
  1618 // (other items were commented in a header).
       
  1619 // -----------------------------------------------------------------------------
       
  1620 //
       
  1621 CVTIYUVFbsBitmapConverter::CVTIYUVFbsBitmapConverter( const TSize& aSourceSize )
       
  1622 : CVTYUVPlanarFbsBitmapConverter( aSourceSize )
       
  1623 	{
       
  1624 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::CVTIYUVFbsBitmapConverter() >>"), RThread().Id().operator TUint()));
       
  1625 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTIYUVFbsBitmapConverter::CVTIYUVFbsBitmapConverter() <<"), RThread().Id().operator TUint()));
       
  1626 	}
       
  1627 
       
  1628 // ============================ CVTYV12FbsBitmapConverter ===============================
       
  1629 
       
  1630 // -----------------------------------------------------------------------------
       
  1631 // CVTYV12FbsBitmapConverter::NewL( const TSize& aSourceSize,
       
  1632 // const CFbsBitmap& aDestinationBitmap )
       
  1633 // (other items were commented in a header).
       
  1634 // -----------------------------------------------------------------------------
       
  1635 //
       
  1636 EXPORT_C CVTYV12FbsBitmapConverter* CVTYV12FbsBitmapConverter::NewL(
       
  1637     const TSize& aSourceSize,
       
  1638     const CFbsBitmap& aDestinationBitmap )
       
  1639 	{
       
  1640 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::NewL() >>"), RThread().Id().operator TUint()));
       
  1641 	CVTYV12FbsBitmapConverter* self = NewL(
       
  1642 	    aSourceSize, aDestinationBitmap.Handle() );
       
  1643 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::NewL() <<"), RThread().Id().operator TUint()));
       
  1644 	return self;
       
  1645 	}
       
  1646 
       
  1647 // -----------------------------------------------------------------------------
       
  1648 // CVTYV12FbsBitmapConverter::NewL( const TSize& aSourceSize,
       
  1649 // TInt aBitmapHandle )
       
  1650 // (other items were commented in a header).
       
  1651 // -----------------------------------------------------------------------------
       
  1652 //
       
  1653 EXPORT_C CVTYV12FbsBitmapConverter* CVTYV12FbsBitmapConverter::NewL(
       
  1654     const TSize& aSourceSize,
       
  1655     TInt aBitmapHandle )
       
  1656 	{
       
  1657 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::NewL() >>"), RThread().Id().operator TUint()));
       
  1658 	CVTYV12FbsBitmapConverter* self = new (ELeave)
       
  1659 	    CVTYV12FbsBitmapConverter( aSourceSize );
       
  1660 	CleanupStack::PushL( self );
       
  1661 	self->ConstructL( aBitmapHandle );
       
  1662 	CleanupStack::Pop(); // self
       
  1663 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::NewL() <<"), RThread().Id().operator TUint()));
       
  1664 	return self;
       
  1665 	}
       
  1666 
       
  1667 // -----------------------------------------------------------------------------
       
  1668 // CVTYV12FbsBitmapConverter::SetYUVPtrs( const TDesC8& aSourceData )
       
  1669 // (other items were commented in a header).
       
  1670 // -----------------------------------------------------------------------------
       
  1671 //
       
  1672 void CVTYV12FbsBitmapConverter::SetYUVPtrs( const TDesC8& aSourceData )
       
  1673 	{
       
  1674 	TInt ySize = SourceSize().iWidth * SourceSize().iHeight;
       
  1675 	TInt ySizeDiv4 = ( ySize >> 2 );
       
  1676 	iY = aSourceData.Mid( 0, ySize ).Ptr();
       
  1677 	iV = aSourceData.Mid( ySize, ySizeDiv4 ).Ptr();
       
  1678 	iU = aSourceData.Mid( ySize + ySizeDiv4, ySizeDiv4 ).Ptr();
       
  1679 	}
       
  1680 
       
  1681 // -----------------------------------------------------------------------------
       
  1682 // CVTYV12FbsBitmapConverter::CVTYV12FbsBitmapConverter(
       
  1683 //  const TSize& aSourceSize )
       
  1684 // (other items were commented in a header).
       
  1685 // -----------------------------------------------------------------------------
       
  1686 //
       
  1687 CVTYV12FbsBitmapConverter::CVTYV12FbsBitmapConverter( const TSize& aSourceSize )
       
  1688 : CVTYUVPlanarFbsBitmapConverter( aSourceSize )
       
  1689 	{
       
  1690 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::CVTYV12FbsBitmapConverter() >>"), RThread().Id().operator TUint()));
       
  1691 	__IF_DEBUG(Print(_L("VideoSource: [%d] CVTYV12FbsBitmapConverter::CVTYV12FbsBitmapConverter() <<"), RThread().Id().operator TUint()));
       
  1692 	}
       
  1693 
       
  1694 // ============================ CVSFbsBitmapIYUVConverter ===============================
       
  1695 
       
  1696 // -----------------------------------------------------------------------------
       
  1697 // CVSFbsBitmapIYUVConverter::CVSFbsBitmapIYUVConverter()
       
  1698 // (other items were commented in a header).
       
  1699 // -----------------------------------------------------------------------------
       
  1700 //
       
  1701 CVSFbsBitmapIYUVConverter::CVSFbsBitmapIYUVConverter()
       
  1702 	{
       
  1703 	}
       
  1704 
       
  1705 // -----------------------------------------------------------------------------
       
  1706 // CVSFbsBitmapIYUVConverter::NewL( const CFbsBitmap& aBitmap )
       
  1707 // (other items were commented in a header).
       
  1708 // -----------------------------------------------------------------------------
       
  1709 //
       
  1710 EXPORT_C CVSFbsBitmapIYUVConverter* CVSFbsBitmapIYUVConverter::NewL(
       
  1711     const CFbsBitmap& aBitmap )
       
  1712 	{
       
  1713 	CVSFbsBitmapIYUVConverter* self = new (ELeave) CVSFbsBitmapIYUVConverter();
       
  1714 	CleanupStack::PushL( self );
       
  1715 	self->ConstructL( aBitmap );
       
  1716 	CleanupStack::Pop(); // self
       
  1717 	return self;
       
  1718 	}
       
  1719 
       
  1720 // -----------------------------------------------------------------------------
       
  1721 // CVSFbsBitmapIYUVConverter::~CVSFbsBitmapIYUVConverter()
       
  1722 // (other items were commented in a header).
       
  1723 // -----------------------------------------------------------------------------
       
  1724 //
       
  1725 EXPORT_C CVSFbsBitmapIYUVConverter::~CVSFbsBitmapIYUVConverter()
       
  1726 	{
       
  1727 	delete iSource;
       
  1728 	delete iYUVData;
       
  1729 	}
       
  1730 
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // CVSFbsBitmapIYUVConverter::SetSourceL( const CFbsBitmap& aBitmap )
       
  1733 // (other items were commented in a header).
       
  1734 // -----------------------------------------------------------------------------
       
  1735 //
       
  1736 EXPORT_C void CVSFbsBitmapIYUVConverter::SetSourceL( const CFbsBitmap& aBitmap )
       
  1737 	{
       
  1738 	ReConstructL( aBitmap );
       
  1739 	}
       
  1740 
       
  1741 // -----------------------------------------------------------------------------
       
  1742 // CVSFbsBitmapIYUVConverter::ProcessL()
       
  1743 // (other items were commented in a header).
       
  1744 // -----------------------------------------------------------------------------
       
  1745 //
       
  1746 EXPORT_C void CVSFbsBitmapIYUVConverter::ProcessL()
       
  1747 	{
       
  1748 	switch( iSource->DisplayMode() )
       
  1749 		{
       
  1750 		case EColor4K:
       
  1751 			DoProcess( VSReadColor4K );
       
  1752 			break;
       
  1753 
       
  1754 		case EColor64K:
       
  1755 			DoProcess( VSReadColor64K );
       
  1756 			break;
       
  1757 
       
  1758 		case EColor16M:
       
  1759 			DoProcess( VSReadColor16M );
       
  1760 			break;
       
  1761 
       
  1762         case EColor16MU:
       
  1763 			DoProcess( VSReadColor16MU );
       
  1764 			break;
       
  1765 
       
  1766         case EColor16MA:
       
  1767 			DoProcess( VSReadColor16MA );
       
  1768 			break;
       
  1769 
       
  1770 		default:
       
  1771 			User::Leave( KErrNotSupported );
       
  1772 			break;
       
  1773 		};
       
  1774 	}
       
  1775 
       
  1776 // -----------------------------------------------------------------------------
       
  1777 // CVSFbsBitmapIYUVConverter::YUVData() const
       
  1778 // (other items were commented in a header).
       
  1779 // -----------------------------------------------------------------------------
       
  1780 //
       
  1781 EXPORT_C TPtrC8 CVSFbsBitmapIYUVConverter::YUVData() const
       
  1782 	{
       
  1783 	return *iYUVData;
       
  1784 	}
       
  1785 
       
  1786 // -----------------------------------------------------------------------------
       
  1787 // CVSFbsBitmapIYUVConverter::ConstructL( const CFbsBitmap& aBitmap )
       
  1788 // (other items were commented in a header).
       
  1789 // -----------------------------------------------------------------------------
       
  1790 //
       
  1791 void CVSFbsBitmapIYUVConverter::ConstructL( const CFbsBitmap& aBitmap )
       
  1792 	{
       
  1793 	iSource = new (ELeave) CFbsBitmap();
       
  1794 	ReConstructL( aBitmap );
       
  1795 	}
       
  1796 
       
  1797 // -----------------------------------------------------------------------------
       
  1798 // CVSFbsBitmapIYUVConverter::ReConstructL( const CFbsBitmap& aBitmap )
       
  1799 // (other items were commented in a header).
       
  1800 // -----------------------------------------------------------------------------
       
  1801 //
       
  1802 void CVSFbsBitmapIYUVConverter::ReConstructL( const CFbsBitmap& aBitmap )
       
  1803 	{
       
  1804 	User::LeaveIfError( iSource->Duplicate( aBitmap.Handle() ) );
       
  1805 
       
  1806 	// make sure that source bitmap's displaymode is supported
       
  1807 	if( ( iSource->DisplayMode() != EColor4K ) &&
       
  1808 	    ( iSource->DisplayMode() != EColor64K ) &&
       
  1809 	    ( iSource->DisplayMode() != EColor16M ) &&
       
  1810 	    ( iSource->DisplayMode() != EColor16MU ) &&
       
  1811 	    ( iSource->DisplayMode() != EColor16MA ) )
       
  1812 		{
       
  1813 		User::Leave( KErrNotSupported );
       
  1814 		}
       
  1815 
       
  1816 	if( !iYUVData || !( iSize == iSource->SizeInPixels() ) )
       
  1817 		{
       
  1818 		iSize = iSource->SizeInPixels();
       
  1819 		delete iYUVData; iYUVData = 0;
       
  1820 		TInt ySize = iSize.iWidth * iSize.iHeight;
       
  1821 		iYUVData = HBufC8::NewMaxL( ySize + ( ySize >> 1 ) );
       
  1822 		iY.Set( iYUVData->Des().Mid( 0, ySize ) );
       
  1823 		iU.Set( iYUVData->Des().Mid( ySize, ySize >> 2 ) );
       
  1824 		iV.Set( iYUVData->Des().Mid( ySize + ( ySize >> 2 ), ySize >> 2 ) );
       
  1825 		}
       
  1826 	}
       
  1827 
       
  1828 // -----------------------------------------------------------------------------
       
  1829 // CVSFbsBitmapIYUVConverter::DoProcess( TVSColorReadFunc aReadFunction )
       
  1830 // (other items were commented in a header).
       
  1831 // -----------------------------------------------------------------------------
       
  1832 //
       
  1833 void CVSFbsBitmapIYUVConverter::DoProcess( TVSColorReadFunc aReadFunction )
       
  1834 	{
       
  1835 	TUint8* pY = const_cast<TUint8*>( iY.Ptr() );
       
  1836 	TUint8* pU = const_cast<TUint8*>( iU.Ptr() );
       
  1837 	TUint8* pV = const_cast<TUint8*>( iV.Ptr() );
       
  1838 	TVSYCrCb yuv1, yuv2;
       
  1839 
       
  1840 	iSource->LockHeap();
       
  1841 	TAny* s = iSource->DataAddress();
       
  1842 	for( TInt h = 0; h < iSize.iHeight; h++ )
       
  1843 		{
       
  1844 		if( h&1 )
       
  1845 			{
       
  1846 			// Note! width must be even divisible by 2
       
  1847 			for( TInt w = 0; w < iSize.iWidth >> 1; w++ )
       
  1848 				{
       
  1849 				*pY++ = RGBtoYCbCr( &yuv1, aReadFunction( s ) );
       
  1850 				*pY++ = RGBtoYCbCr( &yuv2, aReadFunction( s ) );
       
  1851 				*pU++ = static_cast<TUint8>( AVG( yuv1.iCb, yuv2.iCb ) );
       
  1852 				*pV++ = static_cast<TUint8>( AVG( yuv1.iCr, yuv2.iCr ) );
       
  1853 				}
       
  1854 			}
       
  1855 		else
       
  1856 			{
       
  1857 			// Note! width must be even divisible by 2
       
  1858 			for( TInt w = 0; w < iSize.iWidth >> 1; w++ )
       
  1859 				{
       
  1860 				*pY++ = RGBtoYCbCr( &yuv1, aReadFunction( s ) );
       
  1861 				*pY++ = RGBtoYCbCr( &yuv2, aReadFunction( s ) );
       
  1862 				*pU++ = static_cast<TUint8>(
       
  1863 				    AVG( *pU, AVG( yuv1.iCb, yuv2.iCb ) ) );
       
  1864 				*pV++ = static_cast<TUint8>(
       
  1865 				    AVG( *pV, AVG( yuv1.iCr, yuv2.iCr ) ) );
       
  1866 				}
       
  1867 			// if even row -> decrease pU and pV, we will calculate average for
       
  1868 			// those on odd rows
       
  1869 			pU -= ( iSize.iWidth >> 1 );
       
  1870 			pV -= ( iSize.iWidth >> 1 );
       
  1871 			}
       
  1872 		}
       
  1873 	iSource->UnlockHeap();
       
  1874 	}
       
  1875 
       
  1876 //  End of File