EngSrc/IEImageDecoder.cpp
changeset 3 93fff7023be8
equal deleted inserted replaced
2:e1e28b0273b0 3:93fff7023be8
       
     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: Juha Kauppinen, Mika Hokkanen
       
    13 * 
       
    14 * Description: Photo Browser
       
    15 *
       
    16 */
       
    17 
       
    18 // Include files
       
    19 #include "IEImageDecoder.h"
       
    20 
       
    21 
       
    22 // ========================== MEMBER FUNCTIONS ============================= //
       
    23 
       
    24 CIEImageDecoder* CIEImageDecoder::NewL(RFs& aFileServer, MDecodingObserver& aObserver)
       
    25 {
       
    26 	CIEImageDecoder* self = new (ELeave) CIEImageDecoder(aFileServer, aObserver);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop();
       
    30 	return self;
       
    31 }
       
    32 
       
    33 CIEImageDecoder::~CIEImageDecoder()
       
    34 {
       
    35 	if(iImageDecoder)
       
    36 	{
       
    37 		delete iImageDecoder;
       
    38 		iImageDecoder = NULL;
       
    39 	}
       
    40 	
       
    41 	if(iExtImageDecoder)
       
    42 	{
       
    43 		delete iExtImageDecoder;
       
    44 		iExtImageDecoder = NULL;
       
    45 	}
       
    46 	
       
    47 	if(iVisualFrame)
       
    48 	{
       
    49 		delete iVisualFrame;
       
    50 		iVisualFrame = NULL;
       
    51 	}
       
    52 }
       
    53 
       
    54 //EPriorityIdle, EPriorityLow, EPriorityStandard, EPriorityUserInput, EPriorityHigh
       
    55 CIEImageDecoder::CIEImageDecoder(RFs& aFileServer, MDecodingObserver& aObserver)
       
    56 : CActive(EPriorityStandard), iFileServer(aFileServer), iObserver(aObserver), iSrcPtr(NULL, 0, 0)
       
    57 {	
       
    58 }
       
    59 
       
    60 void CIEImageDecoder::ConstructL()
       
    61 {
       
    62 	CActiveScheduler::Add(this);
       
    63 	
       
    64 	iDecoderBusy = EFalse;
       
    65 	iDecode2Yuv = EFalse;
       
    66 	iDecode2Bitmap = EFalse;
       
    67 	
       
    68 	iNumOfBitmaps = 0;
       
    69 }
       
    70 
       
    71 void CIEImageDecoder::RunL()
       
    72 {
       
    73 	TPtr8 ptr = iVisualFrame->DataPtrL();
       
    74 	TInt dataSize = ptr.Size(); 
       
    75 	TUint8* bufU = (TUint8*) ptr.Ptr();
       
    76 
       
    77 	if(iDecode2Yuv)
       
    78 	{
       
    79 		iDecode2Yuv = EFalse;
       
    80 		//iObserver.YuvImageReadyL(iStatus.Int());
       
    81 	}
       
    82 		
       
    83 	if(iDecode2Bitmap)
       
    84 	{
       
    85 		iDecode2Bitmap = EFalse;
       
    86 		iObserver.BitmapReadyL(iStatus.Int());
       
    87 	}		
       
    88 	
       
    89 	iDecoderBusy = EFalse;	
       
    90 }
       
    91 
       
    92 void CIEImageDecoder::DoCancel()
       
    93 {
       
    94 	
       
    95 }
       
    96 
       
    97 void CIEImageDecoder::GetImageSizeL(const TFileName aFileName, TSize& aSize)
       
    98 {
       
    99 	if(iImageDecoder)
       
   100 	{
       
   101 		delete iImageDecoder;
       
   102 		iImageDecoder = NULL;
       
   103 	}
       
   104 	
       
   105 	iImageDecoder = CImageDecoder::FileNewL(iFileServer, aFileName);
       
   106 	TFrameInfo frameInfo = iImageDecoder->FrameInfo();
       
   107 	
       
   108 	aSize.iWidth = frameInfo.iOverallSizeInPixels.iWidth;
       
   109 	aSize.iHeight = frameInfo.iOverallSizeInPixels.iHeight;
       
   110 	
       
   111 	delete iImageDecoder;
       
   112 	iImageDecoder = NULL;	
       
   113 }
       
   114 
       
   115 void CIEImageDecoder::ConvertJpeg2YuvL(const TDesC& aSourceFile, 
       
   116 								HBufC8& aBuffer, 
       
   117 								const TImageForamt /*aImageFormat*/)
       
   118 {
       
   119 	TInt fileSize = 0;
       
   120 	TInt blocks = 0;
       
   121 	
       
   122 	iDecoderBusy = ETrue;
       
   123 	iDecode2Yuv = ETrue;
       
   124 	
       
   125 	if(iExtImageDecoder)
       
   126 	{
       
   127 		delete iExtImageDecoder;
       
   128 		iExtImageDecoder = NULL;
       
   129 	}
       
   130 	
       
   131 	iExtImageDecoder = CExtJpegDecoder::FileNewL(iFileServer, aSourceFile);
       
   132 	
       
   133 	TFrameInfo frameInfo = iExtImageDecoder->FrameInfo();
       
   134 	
       
   135 	TInt width = frameInfo.iOverallSizeInPixels.iWidth;
       
   136 	TInt height = frameInfo.iOverallSizeInPixels.iHeight;
       
   137 
       
   138 	/*if(width%2 != 0)
       
   139 	    width++;
       
   140     if(height%2 != 0)
       
   141         height++;*/
       
   142 	        
       
   143 	TPtr8 bufPtr = aBuffer.Des();
       
   144 	
       
   145 	iBufU = (TUint8*)bufPtr.Ptr();
       
   146 	
       
   147 	if(iVisualFrame)
       
   148 	{
       
   149 		delete iVisualFrame;
       
   150 		iVisualFrame = NULL;
       
   151 	}
       
   152 	
       
   153 	iVisualFrame = CVisualFrame::NewL(bufPtr, 
       
   154 											TSize(width, height), 
       
   155 											CVisualFrame::EFormatYUV420Planar);
       
   156 	
       
   157 	
       
   158 	iExtImageDecoder->ConvertL(&iStatus, iVisualFrame, blocks);
       
   159 	
       
   160 	if(!IsActive())
       
   161 		SetActive();
       
   162 }
       
   163 
       
   164 
       
   165 void CIEImageDecoder::ConvertJpeg2BitmapL(CFbsBitmap& aDestBitmap, TDesC8& aSourceData)
       
   166 {
       
   167 	TInt frameNumber = 0;
       
   168 	
       
   169 	iDecoderBusy = ETrue;
       
   170 	iDecode2Bitmap = ETrue;
       
   171 	
       
   172 	TInt dataSize = aSourceData.Size();
       
   173 	
       
   174 	iSrcPtr.Set((TUint8*)aSourceData.Ptr(), aSourceData.Size(), aSourceData.Size());
       
   175 	
       
   176 	if(iImageDecoder)
       
   177 	{
       
   178 		delete iImageDecoder;
       
   179 		iImageDecoder = NULL;
       
   180 	}
       
   181 	
       
   182 	iImageDecoder = CImageDecoder::DataNewL(iFileServer, iSrcPtr);
       
   183 	
       
   184 	iImageDecoder->Convert(&iStatus, aDestBitmap, frameNumber);
       
   185 	
       
   186 	iNumOfBitmaps++;
       
   187 	
       
   188 	if(!IsActive())
       
   189 		SetActive();
       
   190 }
       
   191 
       
   192 
       
   193 TPtr8 CIEImageDecoder::GetVisualFrame()
       
   194 {
       
   195 	return iVisualFrame->DataPtrL();	 
       
   196 }
       
   197 
       
   198 void CIEImageDecoder::CancelDecoding()
       
   199 {
       
   200 	if(iDecoderBusy)
       
   201 	{
       
   202 		if(iImageDecoder)
       
   203 			iImageDecoder->Cancel();
       
   204 	
       
   205 		if(iExtImageDecoder)
       
   206 			iExtImageDecoder->Cancel();
       
   207 	}
       
   208 		
       
   209 	if(IsActive())
       
   210 		Cancel();	
       
   211 }
       
   212 
       
   213 
       
   214 // EOF