camerauis/cameraapp/generic/src/cameracontroller/cambuffer.cpp
changeset 19 d9aefe59d544
parent 3 8b2d6d0384b0
child 21 fa6d9f75d6a6
child 28 3075d9b614e6
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
     1 /*
       
     2 * Copyright (c) 2007 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:  Implementation of CCamBuffer class.
       
    15 *                Temporary own implementation of MCameraBuffer. 
       
    16 *                To be replaced by ECam CCameraBuffer.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include <fbs.h>
       
    23 
       
    24 #include "camlogging.h"
       
    25 #include "cambuffer.h"
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // NewL
       
    30 // Takes ownership of aData, but not aBitmap
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CCamBuffer* 
       
    34 CCamBuffer::NewL( const CFbsBitmap& aBitmap, 
       
    35                         HBufC8*     aData )
       
    36   {
       
    37   CCamBuffer* self = CCamBuffer::NewLC( aBitmap, aData );
       
    38   CleanupStack::Pop( self );
       
    39   return self;
       
    40   }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // NewLC
       
    44 // Takes ownership of aData, but not aBitmap
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CCamBuffer* 
       
    48 CCamBuffer::NewLC( const CFbsBitmap& aBitmap, 
       
    49                          HBufC8*     aData )
       
    50   {
       
    51   CCamBuffer* self = new (ELeave) CCamBuffer;
       
    52   CleanupStack::PushL( self );
       
    53   self->ConstructL( aBitmap, aData );
       
    54   return self;
       
    55   }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // NewL
       
    60 // Takes ownership of both objects.
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CCamBuffer* 
       
    64 CCamBuffer::NewL( CFbsBitmap* aBitmap, 
       
    65                   HBufC8*     aData )
       
    66   {
       
    67   CCamBuffer* self = CCamBuffer::NewLC( aBitmap, aData );
       
    68   CleanupStack::Pop( self );
       
    69   return self;
       
    70   }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // NewLC
       
    74 // Takes ownership of both objects.
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CCamBuffer* 
       
    78 CCamBuffer::NewLC( CFbsBitmap* aBitmap, 
       
    79                    HBufC8*     aData )
       
    80   {
       
    81   CCamBuffer* self = new (ELeave) CCamBuffer;
       
    82   CleanupStack::PushL( self );
       
    83   self->ConstructL( aBitmap, aData );
       
    84   return self;
       
    85   }
       
    86 
       
    87         
       
    88 // ---------------------------------------------------------------------------
       
    89 // NumFrames
       
    90 //
       
    91 // Number of frames available in the buffer.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 TInt 
       
    95 CCamBuffer::NumFrames()
       
    96   {
       
    97   return 1;
       
    98   }
       
    99 
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // DataL
       
   103 //
       
   104 // Frame data as descriptor.
       
   105 // *not supported here*
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TDesC8* 
       
   109 CCamBuffer::DataL( TInt aFrameIndex )
       
   110   {
       
   111   if( aFrameIndex != 0 || !iImageData )
       
   112     User::Leave( KErrNotSupported );
       
   113 
       
   114   return iImageData; 
       
   115   }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // BitmapL
       
   119 //
       
   120 // Frame data as bitmap.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 CFbsBitmap& 
       
   124 CCamBuffer::BitmapL( TInt aFrameIndex )
       
   125   {
       
   126   if( aFrameIndex != 0 || !iBitmap )
       
   127     User::Leave( KErrNotFound );
       
   128 
       
   129   return *iBitmap;
       
   130   }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // DataL
       
   134 //
       
   135 // Frame data as chunk.
       
   136 // *not supported here*
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 RChunk& 
       
   140 CCamBuffer::ChunkL()
       
   141   {
       
   142   User::Leave( KErrNotSupported );
       
   143   
       
   144   return iChunk;
       
   145   }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // ChunkOffsetL
       
   149 //
       
   150 // Frame data offset in chunk.
       
   151 // *not supported here*
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TInt 
       
   155 CCamBuffer::ChunkOffsetL( TInt /*aFrameIndex*/ )
       
   156   {
       
   157   User::Leave( KErrNotSupported );
       
   158   
       
   159   return 0;
       
   160   }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // FrameSize
       
   164 //
       
   165 // Frame data size.
       
   166 // *not supported here, as only bitmap supported*
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 TInt 
       
   170 CCamBuffer::FrameSize( TInt /*aFrameIndex*/ )
       
   171   {
       
   172   return -1;
       
   173   }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Release
       
   177 //
       
   178 // Release this buffer.
       
   179 // Simply deletes this object.
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void 
       
   183 CCamBuffer::Release()
       
   184   {
       
   185   delete this;
       
   186   }
       
   187 
       
   188 // ===========================================================================
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // ConstructL
       
   192 //
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void 
       
   196 CCamBuffer::ConstructL( const CFbsBitmap& aBitmap, 
       
   197                               HBufC8*     aData )
       
   198   {
       
   199   PRINT( _L("CamTest => CCamBuffer::ConstructL") );
       
   200     
       
   201   
       
   202   iBitmap = new (ELeave) CFbsBitmap;
       
   203   TInt error = iBitmap->Duplicate( aBitmap.Handle() );
       
   204 
       
   205   iImageData = aData;
       
   206 
       
   207   PRINT1( _L("CamTest <> duplicate bitmap status(%d)"), error );
       
   208 
       
   209   User::LeaveIfError( error );
       
   210 
       
   211   PRINT( _L("CamTest <= CCamBuffer::ConstructL") );
       
   212   }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // ConstructL
       
   216 //
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void 
       
   220 CCamBuffer::ConstructL( CFbsBitmap* aBitmap, 
       
   221                         HBufC8*     aData )
       
   222   {
       
   223   PRINT( _L("CamTest => CCamBuffer::ConstructL") );
       
   224     
       
   225   iImageData = aData;
       
   226   iBitmap    = aBitmap;
       
   227 
       
   228   PRINT( _L("CamTest <= CCamBuffer::ConstructL") );
       
   229   }
       
   230 
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // Constructor
       
   234 //
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 CCamBuffer::CCamBuffer()
       
   238   : iBitmap( NULL ),
       
   239     iImageData( NULL ),
       
   240     iOwnBitmap( ETrue ),
       
   241     iOwnData( ETrue )
       
   242   {
       
   243   }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // Destructor
       
   247 // *private, because Release() is supposed to be used.*
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 CCamBuffer::~CCamBuffer()
       
   251   {
       
   252   PRINT( _L("CamTest => ~CCamBuffer") );
       
   253 
       
   254   PRINT( _L("CamTest <> ~CCamBuffer: Close RChunk..") );
       
   255   iChunk.Close();
       
   256   PRINT( _L("CamTest <> ~CCamBuffer: delete CFbsBitmap..") );
       
   257   delete iBitmap;
       
   258   PRINT( _L("CamTest <> ~CCamBuffer: delete HBufC8*..") );
       
   259   delete iImageData;
       
   260 
       
   261   PRINT( _L("CamTest <= ~CCamBuffer") );
       
   262   }
       
   263 
       
   264 
       
   265 // end of file