camerauis/cameraapp/generic/src/camsnapshotrotator.cpp
changeset 1 f5ec9446e5bf
child 27 53c8aa5d97a3
equal deleted inserted replaced
0:1ddebce53859 1:f5ec9446e5bf
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Utility class to rotate bitmaps*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "camsnapshotrotator.h"
       
    21 #include "CamSyncRotatorAo.h"
       
    22 #include "CamBurstCaptureArray.h"
       
    23 #include "camlogging.h"
       
    24 #include "CamAppController.h"
       
    25           
       
    26 // CONSTANTS
       
    27 
       
    28 // MACROS
       
    29 
       
    30 // LOCAL CONSTANTS AND MACROS
       
    31 
       
    32 // MODULE DATA STRUCTURES
       
    33 
       
    34 // LOCAL FUNCTION PROTOTYPES
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 
       
    38 // ============================= LOCAL FUNCTIONS ===============================
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CCamSnapShotRotator::CCamSnapShotRotator
       
    44 // C++ constructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CCamSnapShotRotator::CCamSnapShotRotator( CCamAppController& aController ) 
       
    48     : iController(aController), iRotatedSnapshot(NULL), iRotatorAo(NULL)
       
    49     {    
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CCamSnapShotRotator::ConstructL
       
    54 // Second phase constructor.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CCamSnapShotRotator::ConstructL()
       
    58     {   
       
    59 
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCamSnapShotRotator::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CCamSnapShotRotator* CCamSnapShotRotator::NewL( CCamAppController& aController )
       
    68     {
       
    69     CCamSnapShotRotator* self = new( ELeave ) CCamSnapShotRotator( aController );
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CCamSnapShotRotator::~CCamSnapShotRotator()
       
    79 // Destructor
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CCamSnapShotRotator::~CCamSnapShotRotator()
       
    83     {
       
    84     PRINT( _L("Camera => ~CCamSnapShotRotator") );
       
    85     if ( iRotatorAo && iRotatorAo->IsActive() )
       
    86         {
       
    87         iRotatorAo->Cancel();
       
    88         }
       
    89     delete iRotatorAo;
       
    90     delete iRotatedSnapshot;
       
    91     PRINT( _L("Camera <= ~CCamSnapShotRotator") );
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CCamSnapShotRotator::RotationCompleteL
       
    96 // Notification of bitmap rotation complete events
       
    97 // ---------------------------------------------------------------------------
       
    98 //  
       
    99 void CCamSnapShotRotator::RotationCompleteL( TInt aErr )
       
   100     {
       
   101     PRINT1( _L( "Camera => CCamSnapShotRotator::RotationCompleteL aErr:%d" ), aErr );
       
   102      // Use this snapshot, even if rotation fails. 
       
   103     if ( iRotatedSnapshot )
       
   104         {
       
   105         PRINT( _L( "Camera => CCamSnapShotRotator::RotationCompleteL - ReplaceSnapshot" ) );
       
   106         iController.BurstCaptureArray()->ReplaceSnapshot( iRotatedSnapshot, 0 );
       
   107         PRINT( _L( "Camera => CCamSnapShotRotator::RotationCompleteL - delete iRotatedSnapshot" ) );
       
   108         delete iRotatedSnapshot;
       
   109         iRotatedSnapshot = NULL;
       
   110         }
       
   111             
       
   112     PRINT( _L( "Camera <= CCamSnapShotRotator::RotationCompleteL" ) );         
       
   113     }    
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CCamSnapShotRotator::Rotate
       
   117 // ---------------------------------------------------------------------------
       
   118 //  
       
   119 void CCamSnapShotRotator::RotateL( CFbsBitmap* aBitmap )
       
   120     {
       
   121     PRINT( _L( "Camera => CCamSnapShotRotator::Rotate" ) ); 
       
   122     if ( !iRotatedSnapshot )
       
   123         {
       
   124         iRotatedSnapshot = new (ELeave)CFbsBitmap();
       
   125         }
       
   126     iRotatedSnapshot->Create( aBitmap->SizeInPixels(), aBitmap->DisplayMode() );
       
   127     TRect tmpRect( TPoint( 0, 0 ), aBitmap->SizeInPixels() );
       
   128     TInt tmpLen = tmpRect.Width() * tmpRect.Height() * 4;
       
   129     //copy the snapshot data
       
   130     iRotatedSnapshot->BeginDataAccess();
       
   131     aBitmap->BeginDataAccess();
       
   132     Mem::Copy( iRotatedSnapshot->DataAddress(), aBitmap->DataAddress(), tmpLen );
       
   133     iRotatedSnapshot->EndDataAccess();
       
   134     aBitmap->EndDataAccess();
       
   135     if ( !iRotatorAo )
       
   136         {
       
   137         iRotatorAo = CCamSyncRotatorAo::NewL( *this );
       
   138         }    
       
   139     iRotatorAo->RotateL( iRotatedSnapshot, CBitmapRotator::ERotation180DegreesClockwise );
       
   140         
       
   141     PRINT( _L( "Camera <= CCamSnapShotRotator::Rotate" ) );  
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CCamSnapShotRotator::IsActive
       
   146 // ---------------------------------------------------------------------------
       
   147 //  
       
   148 TBool CCamSnapShotRotator::IsActive()
       
   149     {
       
   150     TBool ret(EFalse);
       
   151     if ( iRotatorAo )
       
   152         {
       
   153         ret = iRotatorAo->IsActive();
       
   154         }
       
   155     return ret;
       
   156     }
       
   157 
       
   158 //  End of File