vtprotocolplugins/DisplaySink/src/vtyuvconverter.cpp
changeset 0 ed9695c8bcbe
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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 format transcoder.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "vtyuvconverter.h"
       
    20 
       
    21 #ifdef _DEBUG
       
    22     #include <e32debug.h>
       
    23     #define PRINT RDebug::Print
       
    24     #define _IFDBG(a) a
       
    25 #else
       
    26     #define PRINT
       
    27     #define _IFDBG(a)
       
    28 #endif
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // VtYuvConverter::ConvertFrom420PlanarTo422Interleaved
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 TInt VtYuvConverter::ConvertFrom420PlanarTo422Interleaved(
       
    37     const TDesC8& aSource,
       
    38     const TSize& aSize,
       
    39     TDes8& aTarget,
       
    40     TInt aStride )
       
    41     {
       
    42     _IFDBG(PRINT( _L( "VtYuvConverter::ConvertFrom420PlanarTo422Interleaved<" ) ));
       
    43 
       
    44     if ( aTarget.MaxLength() < ByteSize422Interleaved( aSize ) )
       
    45         {
       
    46         _IFDBG(PRINT( _L( "VtYuvConverter::ConvertFrom420PlanarTo422Interleaved> TargetMaxLength < ByteSize422" ) ));
       
    47         return KErrUnderflow;
       
    48         }
       
    49 
       
    50     if ( aSource.Size() != ByteSize420Planar( aSize ) )
       
    51         {
       
    52         _IFDBG(PRINT( _L( "VtYuvConverter::ConvertFrom420PlanarTo422Interleaved> 420SourceSize != ByteSize420" ) ));
       
    53         return KErrArgument;
       
    54         }
       
    55 
       
    56     TInt planeSize( aSize.iWidth * aSize.iHeight );
       
    57     const TUint8* sy = aSource.Ptr();
       
    58     const TUint8* su = sy + planeSize;
       
    59     const TUint8* sv = su + ( planeSize >> 2 );
       
    60     TUint8* t = const_cast< TUint8* >( aTarget.Ptr() );
       
    61 
       
    62     TUint8* tsave = t;
       
    63     for ( TInt y = ( aSize.iHeight >> 1 ) - 1; y >= 0; y-- )
       
    64         {
       
    65         const TUint8* susave = su;
       
    66         const TUint8* svsave = sv;
       
    67         for ( TInt x = ( aSize.iWidth >> 1 ) - 1; x >= 0; x-- )
       
    68             {
       
    69             *t++ = *su++;
       
    70             *t++ = *sy++;
       
    71             *t++ = *sv++;
       
    72             *t++ = *sy++;
       
    73             }
       
    74         tsave = t = tsave + aStride;
       
    75         su = susave;
       
    76         sv = svsave;
       
    77         for ( TInt x = ( aSize.iWidth >> 1 ) - 1; x >= 0; x-- )
       
    78             {
       
    79             *t++ = *su++;
       
    80             *t++ = *sy++;
       
    81             *t++ = *sv++;
       
    82             *t++ = *sy++;
       
    83             }
       
    84         tsave = t = tsave + aStride;
       
    85         }
       
    86 
       
    87     _IFDBG(PRINT( _L( "VtYuvConverter::ConvertFrom420PlanarTo422Interleaved>" ) ));
       
    88     return KErrNone;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // VtYuvConverter::ByteSize420Planar
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TInt VtYuvConverter::ByteSize420Planar( const TSize& aSizeInPixels )
       
    96     {
       
    97     TInt planeSize( aSizeInPixels.iWidth * aSizeInPixels.iHeight );
       
    98     return planeSize + planeSize / 2;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // VtYuvConverter::ByteSize422Interleaved
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 TInt VtYuvConverter::ByteSize422Interleaved( const TSize& aSizeInPixels )
       
   106     {
       
   107     TInt planeSize( aSizeInPixels.iWidth * aSizeInPixels.iHeight );
       
   108     return planeSize * 2;
       
   109     }