imaging/imagingfws/src/imageframebody.cpp
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "imageframebody.h"
       
    17 #include "ImageClientMain.h"
       
    18 
       
    19 /**
       
    20 Destructor for CImageFrame::CBody class.
       
    21 */	
       
    22 CImageFrame::CBody::~CBody()
       
    23 	{
       
    24 	delete iFormat;
       
    25 	delete iLayout;	
       
    26 	}
       
    27 
       
    28 /**
       
    29 Returns the format of the CImageFrame::CBody.
       
    30 
       
    31 @return A const reference to the TFrameFormatBase object which describes the CImageFrame::CBody object format.
       
    32 */	    
       
    33 const TFrameFormatBase& CImageFrame::CBody::FrameFormat() const
       
    34 	{
       
    35 	return *iFormat;
       
    36 	}	
       
    37 	
       
    38 /**
       
    39 Set the format of the CImageFrame::CBody.
       
    40 
       
    41 @param aFormat
       
    42 	   A const reference to TFrameFormatBase object used to set CImageFrame::CBody format.
       
    43 */	
       
    44 void CImageFrame::CBody::SetFrameFormatL(const TFrameFormatBase& aFormat)
       
    45 	{
       
    46 	if (iFormat!=NULL)
       
    47 		{
       
    48 		delete iFormat;
       
    49 		iFormat = NULL;
       
    50 		}
       
    51 	iFormat = static_cast<TFrameFormatBase*>(aFormat.DuplicateL());	
       
    52 	}
       
    53 
       
    54 /**
       
    55 Returns the layout of the CImageFrame::CBody associated image data.
       
    56 
       
    57 @return A const reference to TFrameLayoutBase which describes CImageFrame::CBody object particular layout.
       
    58 */
       
    59 const TFrameLayoutBase& CImageFrame::CBody::FrameLayout() const
       
    60 	{
       
    61 	return *iLayout;
       
    62 	}
       
    63 
       
    64 /**
       
    65 Set the layout of the CImageFrame::CBody associated image data.
       
    66 
       
    67 @param aFrameLayout
       
    68 	   A const reference to TFrameLayoutBase object used to set CImageFrame::CBody layout.
       
    69 
       
    70 @leave KErrNoMemory.
       
    71 */		
       
    72 void CImageFrame::CBody::SetFrameLayoutL(const TFrameLayoutBase& aFrameLayout)
       
    73 	{
       
    74 	if (iLayout!=NULL)
       
    75 		{
       
    76 		delete iLayout;
       
    77 		iLayout = NULL;
       
    78 		}
       
    79 	iLayout = static_cast<TFrameLayoutBase*>(aFrameLayout.DuplicateL());
       
    80 	}
       
    81 
       
    82 /**
       
    83 Returns the size in pixels of the image the CImageFrame::CBody refers to.
       
    84 
       
    85 @return image size in pixels.
       
    86 */
       
    87 const TSize& CImageFrame::CBody::FrameSizeInPixels() const
       
    88 	{
       
    89 	return iFrameSize;
       
    90 	}
       
    91 	
       
    92 /**
       
    93 Set the size in pixels of the image CImageFrame::CBody refers to.
       
    94 
       
    95 @param aFrameSize
       
    96 	   A const reference to TSize used to set CImageFrame::CBody format.
       
    97 */	
       
    98 void CImageFrame::CBody::SetFrameSizeInPixels(const TSize& aFrameSize)
       
    99 	{
       
   100 	iFrameSize = aFrameSize;
       
   101 	}
       
   102 
       
   103 /**
       
   104 Provides a writable TDes8 reference to the data buffer. 
       
   105 Suitable both for reading and writing.
       
   106  
       
   107 @return writable TDes8 reference.
       
   108 */	
       
   109 TDes8& CImageFrame::CBody::Data()
       
   110 	{
       
   111 	return iBufferPtr;
       
   112 	}
       
   113 	
       
   114 /**
       
   115 Provides a TDesC8 reference to the data buffer. 
       
   116 Suitable for reading of the data only.
       
   117  
       
   118 @return const TDesC8 reference.
       
   119 */	
       
   120 const TDesC8& CImageFrame::CBody::Data() const
       
   121 	{
       
   122 	return iBufferPtr;
       
   123 	}
       
   124 
       
   125 /**
       
   126 Provides a RChunk reference. It will panic if the frame does not contain a chunk.
       
   127  
       
   128 @return RChunk reference.
       
   129 */	
       
   130 RChunk& CImageFrame::CBody::DataChunk()
       
   131 	{
       
   132 	__ASSERT_ALWAYS((iDataChunk!=NULL), Panic(EInvalidValue));
       
   133 	return *iDataChunk;
       
   134 	}
       
   135 
       
   136 /**
       
   137 Returns the offset of the CImageFrame::CBody specific data within the buffer object.
       
   138  
       
   139 @return  data offset from CimageFrame buffer start.
       
   140 */
       
   141 TInt CImageFrame::CBody::DataOffset() const
       
   142 	{
       
   143 	return iDataOffset;
       
   144 	}
       
   145 
       
   146 /**
       
   147 Returns whether the specific CImageFrame object contains a Chunk or not. 
       
   148 
       
   149 @return ETrue if the buffer is a chuk and EFalse of not. 
       
   150 */
       
   151 TBool CImageFrame::CBody::IsChunk() const
       
   152 	{
       
   153 	return iIsChunk;
       
   154 	}
       
   155 	
       
   156 /**
       
   157 Returns the maximum buffer size as specified by the constructing entity.
       
   158 
       
   159 @return the maximum buffer size. 
       
   160 */
       
   161 TInt CImageFrame::CBody::MaxBufferSize() const
       
   162 	{
       
   163 	return iMaxBufferSize;
       
   164 	}
       
   165 		
       
   166 /**
       
   167 Static factory function used to create a CImageFrame::CBody object.
       
   168 
       
   169 @param aHandle
       
   170        a reference to the owning CImageFrame object.
       
   171 
       
   172 @param aBuffer
       
   173        a reference to the TDesc8 object the CImageFrame::CBody wraps around
       
   174 
       
   175 @param aMaxBufferSize
       
   176 	   the maximum buffer size. 
       
   177 
       
   178 @return a pointer to a valid CImageFrame::CBody object.
       
   179 
       
   180 @leave  KErrArgument
       
   181 @leave  KErrNoMemory or other system wide error codes. 
       
   182 */
       
   183 CImageFrame::CBody* CImageFrame::CBody::NewL(CImageFrame& aHandle, 
       
   184  											 const TDes8& aBuffer,
       
   185  											 TInt aMaxBufferSize)
       
   186 	{
       
   187 	CImageFrame::CBody* self =  new(ELeave) CImageFrame::CBody(aHandle, aBuffer); 
       
   188 	CleanupStack::PushL(self);
       
   189 	self->SetMaxSizeL(aMaxBufferSize);
       
   190 	self->SetDefaultFormatL();
       
   191 	CleanupStack::Pop();
       
   192 	return self;	
       
   193 	}
       
   194 
       
   195 /**
       
   196 Static factory function used to create a CImageFrame::CBody object.
       
   197 
       
   198 @param aHandle
       
   199        a reference to the owning CImageFrame object.
       
   200 
       
   201 @param aBuffer
       
   202        a reference to the TDesc8 object the CImageFrame::CBody wraps around.
       
   203 
       
   204 @param aMaxBufferSize
       
   205 	   the maximum buffer size. 
       
   206 
       
   207 @param aFrameSize
       
   208        a reference to the TSize object to initialise the CImageFrame::CBody object.      
       
   209 
       
   210 @param aFrameFormat
       
   211        a reference to the TFrameFormatBase to initialise the CImageFrame::CBody object.    
       
   212 
       
   213 @param aFrameLayout
       
   214        a reference to the TFrameLayoutBase to initialise the CImageFrame::CBody object.
       
   215 
       
   216 @return a pointer to a valid CImageFrame::CBody object.       
       
   217               
       
   218 @leave  KErrArgument
       
   219 @leave  KErrNoMemory or other system wide error code.
       
   220 */						  
       
   221 CImageFrame::CBody* CImageFrame::CBody::NewL(CImageFrame& aHandle, 
       
   222 										 	 const TDes8& aBuffer, TInt aMaxBufferSize,
       
   223 						   					 const TSize& aFrameSize, 
       
   224 										 	 const TFrameFormatBase& aFrameFormat,
       
   225 											 const TFrameLayoutBase& aFrameLayout)
       
   226 	{
       
   227 	CImageFrame::CBody* self =  new(ELeave) CImageFrame::CBody(aHandle, aBuffer); 
       
   228 	CleanupStack::PushL(self);
       
   229 	self->SetMaxSizeL(aMaxBufferSize);
       
   230 	self->StoreAddParamL(aFrameSize, aFrameFormat, aFrameLayout);
       
   231 	CleanupStack::Pop();
       
   232 	return self;
       
   233 	}
       
   234 
       
   235 /**
       
   236 Static factory function used to create a CImageFrameRChunk object.
       
   237 
       
   238 @param aHandle
       
   239        a reference to the owning CImageFrame object.
       
   240 
       
   241 @param aBuffer
       
   242        a reference to the RChunk object the CImageFrameRChunk wraps around.
       
   243 
       
   244 @param aMaxBufferSize
       
   245 	   the maximum buffer size.       
       
   246 
       
   247 @param aDataOffset
       
   248        The offset at which the data for this frame starts.       
       
   249 
       
   250 @return a pointer to a valid CImageFrame::CBody object.
       
   251 
       
   252 @leave  KErrArgument
       
   253 @leave  KErrNoMemory or other system wide error code.
       
   254 */
       
   255 CImageFrame::CBody* CImageFrame::CBody::NewL(CImageFrame& aHandle, 
       
   256 											const RChunk* aBuffer, 
       
   257 											TInt aMaxBufferSize, 
       
   258 											TInt aDataOffset)
       
   259 	{
       
   260 	CImageFrame::CBody* self = new(ELeave) CImageFrame::CBody(aHandle); 
       
   261 	CleanupStack::PushL(self);
       
   262 	self->StoreChunkL(aBuffer, aMaxBufferSize, aDataOffset);
       
   263 	self->SetDefaultFormatL();
       
   264 	CleanupStack::Pop();
       
   265 	return self;	
       
   266 	}
       
   267 
       
   268 /**
       
   269 Static factory function used to create a CImageFrameRChunk object.
       
   270 
       
   271 @param aHandle
       
   272        a reference to the owning CImageFrame object.
       
   273 
       
   274 @param aBuffer
       
   275        a reference to the RChunk object the CImageFrameRChunk wraps around.
       
   276 
       
   277 @param aMaxBufferSize
       
   278 	   the maximum buffer size.            
       
   279 
       
   280 @param aDataOffset
       
   281        The offset at which the data for this frame starts. 
       
   282 
       
   283 @param aFrameSize
       
   284        a reference to the TSize object to initialise the CImageFrameRChunk object.
       
   285 
       
   286 @param aFrameFormat
       
   287        a reference to the TFrameFormatBase to initialise the CImageFrameRChunk object. 
       
   288 
       
   289 @param aFrameLayout
       
   290        a reference to the TFrameLayoutBase to initialise the CImageFrameRChunk object.      
       
   291 
       
   292 @return a pointer to a valid CImageFrame::CBody object.
       
   293 
       
   294 @leave  KErrArgument
       
   295 @leave  KErrNoMemory or other system wide error code.
       
   296 */
       
   297 CImageFrame::CBody* CImageFrame::CBody::NewL(CImageFrame& aHandle,const RChunk* aBuffer, 
       
   298 											TInt aMaxBufferSize,
       
   299 											TInt aDataOffset, 
       
   300 											const TSize& aFrameSize,
       
   301 											const TFrameFormatBase& aFrameFormat,																	    	
       
   302 											const TFrameLayoutBase& aFrameLayout)
       
   303 	{
       
   304 	CImageFrame::CBody* self = new(ELeave) CImageFrame::CBody(aHandle); 
       
   305 	CleanupStack::PushL(self);
       
   306 	self->StoreChunkL(aBuffer, aMaxBufferSize, aDataOffset);
       
   307 	self->StoreAddParamL(aFrameSize, aFrameFormat, aFrameLayout);
       
   308 	CleanupStack::Pop();
       
   309 	return self;
       
   310 	}
       
   311 
       
   312 /**
       
   313 CImageFrame::CBody constructor.
       
   314 
       
   315 @param aHandle
       
   316        a reference to the owning CImageFrame object.      
       
   317 */			
       
   318 CImageFrame::CBody::CBody(CImageFrame& aHandle) : 
       
   319 						iHandle(aHandle),
       
   320 	  					iBufferPtr(0,0),
       
   321 	  					iIsChunk(ETrue)							
       
   322 	{
       
   323 	}
       
   324 	
       
   325 /**
       
   326 CImageFrame::CBody constructor.
       
   327 
       
   328 @param aHandle
       
   329        a reference to the owning CImageFrame object.
       
   330 
       
   331 @param aBuffer
       
   332        a reference to the TDes8 object the CImageFrame::Body object contains.      
       
   333 */	
       
   334 CImageFrame::CBody::CBody(CImageFrame& aHandle, const TDes8& aBuffer) : 
       
   335 												iHandle(aHandle),			   
       
   336 												iBufferPtr((TUint8*)(aBuffer.Ptr()), aBuffer.Size(), aBuffer.MaxLength()),
       
   337 												iIsChunk(EFalse)
       
   338 												
       
   339 	{
       
   340 	}
       
   341 
       
   342 /**
       
   343 Stores the maximum size of the buffer
       
   344 
       
   345 @param aMaxBufferSize
       
   346        buffer maximum size.
       
   347 
       
   348 @leave KErrArgument.      
       
   349 */	
       
   350 void CImageFrame::CBody::SetMaxSizeL(TInt aMaxBufferSize)
       
   351 	{
       
   352 	if (aMaxBufferSize <= 0)
       
   353 		{
       
   354 		User::Leave(KErrArgument);
       
   355 		}
       
   356 	iMaxBufferSize = aMaxBufferSize;
       
   357 	}
       
   358 
       
   359 /** 
       
   360 Function used to store the chunk relevant information.
       
   361 
       
   362 @param aBuffer
       
   363 	   a pointer to a valid RChunk object.
       
   364 
       
   365 @param aMaxBufferSize
       
   366 		buffer maximum size.
       
   367 
       
   368 @param aDataOffset
       
   369 	   The offset of the data in the CImageFrame::CBody object from the start of the chunk. 
       
   370 
       
   371 @leave KErrArgument
       
   372 */
       
   373 void CImageFrame::CBody::StoreChunkL(const RChunk* aBuffer, TInt aMaxBufferSize, TInt aDataOffset)
       
   374 	{
       
   375 	if (aBuffer == NULL)
       
   376 		{
       
   377 		User::Leave(KErrArgument);
       
   378 		}
       
   379 		
       
   380 	if (aDataOffset < 0)
       
   381 		{
       
   382 		User::Leave(KErrArgument);
       
   383 		}
       
   384 			
       
   385 	SetMaxSizeL(aMaxBufferSize);	
       
   386 	iDataOffset = aDataOffset;
       
   387 	iDataChunk = (RChunk*)aBuffer;
       
   388 	iBufferPtr.Set((iDataChunk->Base() + iDataOffset), iDataChunk->Size(), iDataChunk->MaxSize());
       
   389 	}
       
   390 	
       
   391 /**
       
   392 Initialise CImageFrame::CBody object.
       
   393 
       
   394 @param aSize
       
   395 	   a reference to a TSize object containing image size in pixels. 
       
   396 
       
   397 @param aFormat
       
   398 	   a reference to a TFrameFormatBase object containing image format information. 	
       
   399 
       
   400 @param aLayout
       
   401 	   a reference to FrameLayoutBase object containing image layout information.
       
   402 
       
   403 @leave KErrNoMemory
       
   404 */	
       
   405 void CImageFrame::CBody::StoreAddParamL( const TSize& aSize, 
       
   406 					 				     const TFrameFormatBase& aFormat,								   
       
   407 									     const TFrameLayoutBase& aLayout)
       
   408 	{
       
   409 	iFrameSize = aSize;
       
   410 	if (iFormat!=NULL)
       
   411 		{
       
   412 		delete iFormat;
       
   413 		iFormat = NULL;
       
   414 		}
       
   415 	iFormat = (TFrameFormatBase*)aFormat.DuplicateL();
       
   416 	
       
   417 	if (iLayout!=NULL)
       
   418 		{
       
   419 		delete iLayout;
       
   420 		iLayout = NULL;
       
   421 		}
       
   422 	iLayout = (TFrameLayoutBase*)aLayout.DuplicateL();
       
   423 	}
       
   424 
       
   425 /**
       
   426 Sets default Frame Format and Frame Layout for this version of Image Frame
       
   427 
       
   428 @leave KErrNoMemory
       
   429 */	
       
   430 void CImageFrame::CBody::SetDefaultFormatL()
       
   431 	{
       
   432 	iFormat = new (ELeave) TFrameFormat(KNullUid);
       
   433 	iLayout = new (ELeave) TFrameLayout(0);
       
   434 	}
       
   435 	
       
   436 /*
       
   437 Used for padding the BWINS def file.
       
   438 */
       
   439 #ifdef __WINS__
       
   440 EXPORT_C void Reserved1()
       
   441 	{
       
   442 	}
       
   443 #endif // __WINS__