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