imaging/imagingfws/BitmapTransform/src/BitmapConverterBody.cpp
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 2001-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 // BitmapConvwerterBody.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "BitmapTransformsBody.h"
       
    19 #include "BitmapTransformsMain.h"
       
    20 #include <icl/imageprocessor.h>
       
    21 #include "ImageProcessorPriv.h"
       
    22 
       
    23 const TInt KPixelBufferSize = 128;
       
    24 const TInt KLinesPerCall = 10;
       
    25 
       
    26 /*
       
    27 *
       
    28 * CBody
       
    29 *
       
    30 */
       
    31 CBitmapConverter::CBody::CBody()
       
    32 : CActive(EPriorityLow), iPixelDes(0,0,0)
       
    33 	{
       
    34 	}
       
    35 
       
    36 /*
       
    37 *
       
    38 * RunL
       
    39 *
       
    40 */
       
    41 void CBitmapConverter::CBody::RunL()
       
    42 	{
       
    43 	DoConvert();
       
    44 	}
       
    45 
       
    46 /*
       
    47 *
       
    48 * DoCancel
       
    49 *
       
    50 */
       
    51 void CBitmapConverter::CBody::DoCancel()
       
    52 	{
       
    53 	RequestComplete(KErrCancel);
       
    54 	}
       
    55 
       
    56 /*
       
    57 *
       
    58 * ConstructL
       
    59 *
       
    60 */
       
    61 void CBitmapConverter::CBody::ConstructL()
       
    62 	{
       
    63 	CActiveScheduler::Add(this);
       
    64 	iImageProc = CErrorDiffuser::NewL();
       
    65 	iPixelBuffer = new (ELeave) TRgb[KPixelBufferSize];
       
    66 	TInt length = KPixelBufferSize * sizeof(TRgb);
       
    67 	TUint8* ptr = reinterpret_cast<TUint8*>(iPixelBuffer);
       
    68 	iPixelDes.Set( ptr, length, length );
       
    69 	}
       
    70 
       
    71 /*
       
    72 *
       
    73 * NewL Creates a CbitmapConverter
       
    74 *
       
    75 */
       
    76 CBitmapConverter::CBody* CBitmapConverter::CBody::NewL()
       
    77 	{
       
    78 	CBody* self = new (ELeave) CBody();
       
    79 	CleanupStack::PushL(self);
       
    80 	self->ConstructL();
       
    81 	CleanupStack::Pop(self);
       
    82 	return self;
       
    83 	}
       
    84 
       
    85 /*
       
    86 *
       
    87 * DoConvert Converts KLinesPerCall lines, then either queues a RunL
       
    88 * or, if the conversion has been completed, completes the client's message
       
    89 *
       
    90 */
       
    91 void CBitmapConverter::CBody::DoConvert()
       
    92 	{
       
    93 	TInt linesLeftThisCall = KLinesPerCall;
       
    94 	
       
    95 	while ((linesLeftThisCall-- > 0) && (iPos.iY < iSrcSize.iHeight))
       
    96 		{
       
    97 		iImageProc->SetPos(iPos);
       
    98 		for (iPos.iX = 0; iPos.iX < iSrcSize.iWidth; iPos.iX += KPixelBufferSize)
       
    99 			{
       
   100 			const TInt width = Min(KPixelBufferSize,iSrcSize.iWidth - iPos.iX);
       
   101 			iSrcBitmap->GetScanLine(iPixelDes,iPos,width,ERgb);
       
   102 			iImageProc->SetPixels(iPixelBuffer,width);
       
   103 			}
       
   104 		iPos.iY++;
       
   105 		}
       
   106 	
       
   107 	if (iPos.iY == iSrcSize.iHeight)
       
   108 		{
       
   109 		iImageProc->FlushPixels();
       
   110 		RequestComplete(KErrNone);
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		SelfComplete(KErrNone);
       
   115 		}
       
   116 	}
       
   117 
       
   118 /*
       
   119 *
       
   120 * SelfComplete
       
   121 * Queues a RunL
       
   122 *
       
   123 * @param aError
       
   124 *
       
   125 */
       
   126 void CBitmapConverter::CBody::SelfComplete(TInt aError)
       
   127 	{
       
   128 	TRequestStatus *status = &iStatus;
       
   129 	SetActive();
       
   130 	User::RequestComplete(status, aError);
       
   131 	}
       
   132 
       
   133 /*
       
   134 *
       
   135 * RequestComplete
       
   136 * Completes the client's message
       
   137 *
       
   138 * @param aReason
       
   139 *
       
   140 */
       
   141 void CBitmapConverter::CBody::RequestComplete(TInt aReason)
       
   142 	{
       
   143 	ASSERT(iCopyStatus);
       
   144 	TRequestStatus* status = iCopyStatus;
       
   145 	User::RequestComplete(status, aReason);
       
   146 	}
       
   147 
       
   148 /*
       
   149 *
       
   150 * ~CBody
       
   151 *
       
   152 */
       
   153 CBitmapConverter::CBody::~CBody()
       
   154 	{
       
   155 	Cancel();
       
   156 	delete [] iPixelBuffer;
       
   157 	delete iImageProc;
       
   158 	}
       
   159 
       
   160 /*
       
   161 *
       
   162 * Convert 
       
   163 * Converts one bitmap to another
       
   164 *
       
   165 * @param aStatus
       
   166 * @param aDstBitmap
       
   167 * @param aSrcBitmap
       
   168 * @pre aStatus != 0
       
   169 * @pre aDstBitmap handle != 0
       
   170 * @pre aSrcBitmap handle != 0
       
   171 * @pre aDstBitmap size != 0 on any dimension
       
   172 * @pre aSrcBitmap size != 0 on any dimension
       
   173 * @pre src bitmap size == destination bitmap size
       
   174 * Should this method be promoted to a public interface 
       
   175 * it is recommended to change some of the assertions
       
   176 * used in preconditions to User::Leave with an error code
       
   177 *
       
   178 */
       
   179 void CBitmapConverter::CBody::Convert(TRequestStatus* aStatus, CFbsBitmap& aDstBitmap,CFbsBitmap& aSrcBitmap)
       
   180 	{
       
   181 	//[preconditon aStatus != 0]
       
   182 	ASSERT( aStatus );
       
   183 	//[ precondition bitmaps have been created ]
       
   184 	ASSERT( aDstBitmap.Handle() != 0 );
       
   185 	ASSERT( aSrcBitmap.Handle() != 0 );
       
   186 
       
   187 	iCopyStatus = aStatus;
       
   188 	*iCopyStatus = KRequestPending;
       
   189 	if(aDstBitmap.ExtendedBitmapType()!=KNullUid || aSrcBitmap.ExtendedBitmapType()!=KNullUid)
       
   190         {
       
   191         RequestComplete(KErrNotSupported);
       
   192         return;
       
   193         }
       
   194 	
       
   195 	TSize srcSize;
       
   196 	      srcSize = aSrcBitmap.SizeInPixels();
       
   197 	TSize dstSize;
       
   198 	      dstSize = aDstBitmap.SizeInPixels();
       
   199 	//[ precondition no dimension is zero]
       
   200 	ASSERT( srcSize.iWidth != 0 );
       
   201 	ASSERT( srcSize.iHeight != 0 );
       
   202 	ASSERT( dstSize.iWidth != 0 );
       
   203 	ASSERT( dstSize.iHeight != 0 );
       
   204 	//[ precondition bitmaps are of the same dimension]
       
   205 	ASSERT( dstSize.iWidth == srcSize.iWidth );
       
   206 	ASSERT( dstSize.iHeight == srcSize.iHeight );
       
   207 	    
       
   208 	iSrcBitmap = &aSrcBitmap;
       
   209 	iSrcSize = aSrcBitmap.SizeInPixels();
       
   210 	iPos.SetXY(0,0);
       
   211 	TInt errCode = KErrNone;
       
   212 	TRAP( errCode, iImageProc->PrepareL(aDstBitmap,iSrcSize));
       
   213 	if( errCode != KErrNone )
       
   214 		{
       
   215 		RequestComplete(errCode);
       
   216 		return;
       
   217 		}
       
   218 	
       
   219 	SelfComplete(KErrNone);
       
   220 	}