camappengine/StillConverter/Src/CaeStillDecoder.cpp
branchRCL_3
changeset 21 27fe719c32e6
parent 0 9b3e960ffc8a
equal deleted inserted replaced
20:e3cdd00b5ae3 21:27fe719c32e6
       
     1 /*
       
     2 * Copyright (c) 2003 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:  Still Image Decoder for Camera Application Engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <eikenv.h>
       
    22 
       
    23 #include "CaeStillConverter.h"
       
    24 #include "CaeStillDecoder.h"
       
    25 #include "CaeStillCommon.h"
       
    26 
       
    27 #ifdef CAE_TEST_VERSION
       
    28 #include "CaeStillConverterTestErrors.h"
       
    29 #endif
       
    30 
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------
       
    36 // CCaeStillDecoder::NewL
       
    37 // Two-phased constructor.
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 EXPORT_C CCaeStillDecoder* CCaeStillDecoder::NewL()
       
    41     {
       
    42     CCaeStillDecoder* self = new( ELeave ) CCaeStillDecoder;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CCaeStillDecoder::~CCaeStillDecoder
       
    52 // Destructor.
       
    53 // ---------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CCaeStillDecoder::~CCaeStillDecoder()
       
    56     {
       
    57     delete iDecoder;
       
    58     delete iDecodedImage;
       
    59     iFs.Close(); 
       
    60 
       
    61     // For RTRT code coverage analysis.
       
    62     // #pragma attol insert _ATCPQ_DUMP(0);
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------
       
    67 // CCaeStillDecoder::SetObserver
       
    68 // Sets Still Decoder observer.
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CCaeStillDecoder::SetObserver( 
       
    72     MCaeStillDecoderObserver* aObserver )
       
    73     {
       
    74     iObserver = aObserver;
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCaeStillDecoder::SetImageCodecL
       
    80 // Sets the specific image codec implementation to be used in decoding.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CCaeStillDecoder::SetImageCodecL( 
       
    84 	TUid aCodecUid )
       
    85     {
       
    86     iImageCodecUid = aCodecUid;
       
    87     }
       
    88 
       
    89         
       
    90 // ---------------------------------------------------------
       
    91 // CCaeStillDecoder::ConvertHBufC8ToCFbsBitmapL
       
    92 // Creates CImageItem object, places it in the internal 
       
    93 // queue and starts memory image to bitmap conversion.
       
    94 // ---------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CCaeStillDecoder::ConvertHBufC8ToCFbsBitmapL( 
       
    97     HBufC8* aImageBuffer,
       
    98     TDisplayMode aTargetBitmapMode,
       
    99     const TSize& aTargetBitmapSize,
       
   100     const TSize& aFullyScaledTargetBitmapSize )
       
   101     {
       
   102     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConvertHBufC8ToCFbsBitmapL() entering" ) );
       
   103 
       
   104     CleanupStack::PushL( aImageBuffer );
       
   105 
       
   106     // Create image item and set up image data.
       
   107 
       
   108     CImageItem* imageItem = new( ELeave ) CImageItem;
       
   109     imageItem->iBitmapDisplayMode = aTargetBitmapMode;
       
   110     imageItem->iImageBuffer = aImageBuffer;
       
   111     imageItem->iBitmapSize = aTargetBitmapSize;
       
   112     imageItem->iFullyScaledBitmapSize = aFullyScaledTargetBitmapSize;
       
   113     CleanupStack::Pop( aImageBuffer );
       
   114     CleanupStack::PushL( imageItem ); 
       
   115 
       
   116     #ifdef CAE_TEST_VERSION
       
   117     // For simulating errors when compiled as special "test version".
       
   118     CaeConvertHBufC8ToCFbsBitmapErrorL();
       
   119     #endif    
       
   120 
       
   121     // Add image to the queue.
       
   122     User::LeaveIfError ( iImageQueue->Append( imageItem ) );
       
   123 
       
   124     CleanupStack::Pop( imageItem );
       
   125 
       
   126     // Start image conversion if not busy. Busy means that e.g. conversion is currently running. 
       
   127     if ( !IsBusy() )
       
   128         {
       
   129         TRAPD( error, ConvertL() );
       
   130         if ( error != KErrNone )
       
   131             {
       
   132             ConversionComplete( error );
       
   133             }
       
   134         }
       
   135 
       
   136     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConvertHBufC8ToCFbsBitmapL() returning" ) );
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // CCaeStillDecoder::Cleanup
       
   142 // Destroy all allocations.
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 EXPORT_C void CCaeStillDecoder::Cleanup()
       
   146     {
       
   147     if ( iDecoder )
       
   148         {
       
   149         iDecoder->Cancel();
       
   150         delete iDecoder;
       
   151         iDecoder = NULL;
       
   152         }
       
   153 
       
   154     if ( iState != EIdle )
       
   155         {
       
   156         delete iDecodedImage;
       
   157         iDecodedImage = NULL;
       
   158         }
       
   159     
       
   160     if ( iImageQueue )
       
   161         {
       
   162         iImageQueue->ResetAndDestroy();
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CCaeStillDecoder::CCaeStillDecoder
       
   169 // Default constructor. 
       
   170 // This can NOT leave.
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 CCaeStillDecoder::CCaeStillDecoder()
       
   174     {
       
   175     CActiveScheduler::Add( this );
       
   176     }
       
   177 
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CCaeStillDecoder::ConstructL
       
   181 // Symbian 2nd phase constructor that can leave.
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 void CCaeStillDecoder::ConstructL()
       
   185     {
       
   186     CCaeStillConverter::ConstructL();
       
   187     User::LeaveIfError( iFs.Connect() );
       
   188     }
       
   189 
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CCaeStillDecoder::DoCancel
       
   193 // From CActive, implements cancellation of an outstanding request.
       
   194 // ---------------------------------------------------------
       
   195 //
       
   196 void CCaeStillDecoder::DoCancel()
       
   197     {
       
   198     Cleanup();
       
   199     iState = EIdle;
       
   200     }
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------
       
   204 // CCaeStillDecoder::ConvertL
       
   205 // Converts bitmap to memory JPEG image.
       
   206 // ---------------------------------------------------------
       
   207 //
       
   208 void CCaeStillDecoder::ConvertL()
       
   209     {
       
   210     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConvertL() entering" ) );
       
   211 
       
   212     iState = EConvert;
       
   213     
       
   214     // Use the default codec or the specific codec
       
   215     iDecoder = CImageDecoder::DataNewL( iFs, *(*iImageQueue)[0]->iImageBuffer, 
       
   216     	CImageDecoder::EOptionNone, KNullUid, KNullUid, iImageCodecUid );
       
   217     
       
   218     iDecodedImage = NULL;
       
   219     iDecodedImage = new( ELeave ) CFbsBitmap;
       
   220 
       
   221     // Set target bitmap size
       
   222     TSize targetBitmapSize = (*iImageQueue)[0]->iBitmapSize;
       
   223 
       
   224     const TFrameInfo& frameInfo = iDecoder->FrameInfo( 0 );
       
   225     TUid impUid = iDecoder->ImplementationUid();
       
   226     LOGTEXT3( _L( "Cae: CCaeStillDecoder::ConvertL() Requested decoder: %x, Found decoder: %x" ), iImageCodecUid.iUid, impUid.iUid );
       
   227     LOGTEXT2( _L( "Cae: CCaeStillDecoder::ConvertL() Free scaling support: %d" ), frameInfo.iFlags & TFrameInfo::EFullyScaleable );
       
   228 
       
   229     //
       
   230     // Use free scaling always with special decoder or with any decoder that supports it
       
   231     //
       
   232     if ( (( impUid == KUidSpecialFreeScalingDecoder ) || ( frameInfo.iFlags & TFrameInfo::EFullyScaleable ))  
       
   233          && ( (*iImageQueue)[0]->iFullyScaledBitmapSize != TSize( 0, 0 ) ) )
       
   234         {
       
   235         LOGTEXT( _L( "Cae: CCaeStillDecoder::ConvertL(). Use free scaling in decoding" ) );
       
   236         targetBitmapSize = (*iImageQueue)[0]->iFullyScaledBitmapSize;
       
   237         }
       
   238 
       
   239     User::LeaveIfError( iDecodedImage->Create(
       
   240         targetBitmapSize, 
       
   241         (*iImageQueue)[0]->iBitmapDisplayMode ) );
       
   242 
       
   243     #ifdef CAE_TEST_VERSION
       
   244     // For simulating errors when compiled as special "test version".
       
   245     CaeStillConvertErrorL();
       
   246     #endif    
       
   247 
       
   248     iState = EConvert;
       
   249     iStatus = KRequestPending;
       
   250     iDecoder->Convert( &iStatus, *iDecodedImage );
       
   251     SetActive();
       
   252 
       
   253     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConvertL() returning" ) );
       
   254     }
       
   255 
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CCaeStillDecoder::ConversionComplete
       
   259 // Perfoms necessary cleanup and delivers result to the client.
       
   260 // ---------------------------------------------------------
       
   261 //
       
   262 void CCaeStillDecoder::ConversionComplete( 
       
   263     TInt aError )
       
   264     {
       
   265     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConversionComplete() entering" ) );
       
   266     #ifdef _DEBUG
       
   267     if ( aError ) 
       
   268         {
       
   269         LOGTEXT( _L( "Cae: CCaeStillDecoder::ConversionComplete(): error detected" ) );
       
   270         }
       
   271     #endif
       
   272 
       
   273     // Delete the decoder object and image queue item
       
   274     if ( iDecoder )
       
   275         {
       
   276         iDecoder->Cancel();
       
   277         delete iDecoder;
       
   278         iDecoder = NULL;
       
   279         }
       
   280 
       
   281     // To be outputted via call-back.
       
   282     HBufC8* imageBuffer = NULL;
       
   283 
       
   284     if ( iImageQueue->Count() > 0 )
       
   285         {
       
   286         imageBuffer = (*iImageQueue)[0]->iImageBuffer;
       
   287 
       
   288         (*iImageQueue)[0]->iImageBuffer = NULL; // Prevent deletion of source image.
       
   289         delete ( *iImageQueue )[0];
       
   290 
       
   291         // Remove item pointer from the queue and compress the queue.
       
   292         iImageQueue->Remove( 0 ); // Remove item pointer from the queue and compress the queue.
       
   293         }
       
   294 
       
   295     iState = EIdle;
       
   296 
       
   297     const TInt KZeroImageSize = 0; // Image size argument currently not in use.
       
   298 
       
   299     // Call back the client to deliver the result image. Gives away the ownership of the imageBuffer
       
   300     // and iDecodedImage.
       
   301     iObserver->McaesdoCFbsBitmapImageReady( imageBuffer, iDecodedImage, aError, KZeroImageSize );
       
   302     iDecodedImage = NULL; // Ownership has been given away
       
   303 
       
   304     LOGTEXT( _L( "Cae: CCaeStillDecoder::ConversionComplete() returning" ) );
       
   305     }
       
   306 
       
   307 
       
   308 //  End of File