javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtimagedataloader.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 19 04becd199f91
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
    86 
    86 
    87 void CSwtImageDataLoader::ConstructL()
    87 void CSwtImageDataLoader::ConstructL()
    88 {
    88 {
    89     iImageDataArray = new(ELeave) CSwtImageDataArray(10);
    89     iImageDataArray = new(ELeave) CSwtImageDataArray(10);
    90     User::LeaveIfError(iFs.Connect());
    90     User::LeaveIfError(iFs.Connect());
       
    91     
       
    92     // In case there is no UI make sure there is an instance of FBS running
    91     User::LeaveIfError(RFbsSession::Connect(iFs));
    93     User::LeaveIfError(RFbsSession::Connect(iFs));
    92 }
    94 }
    93 
    95 
    94 void CSwtImageDataLoader::DecodeImageL(const TDesC& aFileName)
    96 void CSwtImageDataLoader::DecodeImageL(const TDesC& aFileName)
    95 {
    97 {
   164             iDecoder->Convert(&localStatus, *iBitmap, index);
   166             iDecoder->Convert(&localStatus, *iBitmap, index);
   165         }
   167         }
   166         else
   168         else
   167         {
   169         {
   168 
   170 
   169             iDecoder->Convert(&localStatus,*iBitmap, *iMask, index);
   171             iDecoder->Convert(&localStatus, *iBitmap, *iMask, index);
   170         }
   172         }
   171 
   173 
   172         // We are waiting on the TRequestStatus we passed to the asynchronous
   174         // We are waiting on the TRequestStatus we passed to the asynchronous
   173         // function "convert( ... )" so that we transform the call to an
   175         // function "convert( ... )" so that we transform the call to an
   174         // asyncrhonous method into a call to a synchronous one.
   176         // asyncrhonous method into a call to a synchronous one.
   179     }
   181     }
   180 
   182 
   181     FreeBitmaps();
   183     FreeBitmaps();
   182 }
   184 }
   183 
   185 
   184 void CSwtImageDataLoader::DecodeWholeImageFromBufferL(const TDesC8& aBuffer)
   186 void CSwtImageDataLoader::DecodeWholeImageFromBufferL(const TDesC8& aBuf)
   185 {
   187 {
   186     iWholeImageAtOnce = ETrue;
   188     iWholeImageAtOnce = ETrue;
   187 
   189 
   188     // In normal use of ImageDataLoader, it must be disposed by its creator after a call to this method ( so iDecoder should not be not NULL because of a previous call to this method )
   190     // In normal use of ImageDataLoader, it must be disposed by its creator after a call to this method ( so iDecoder should not be not NULL because of a previous call to this method )
   189     ASSERT(iDecoder == NULL);
   191     ASSERT(iDecoder == NULL);
   190     // In case ImageDataLoader is not used normally and we are not in debug, ASSERT is ignored, so deleting iDecoder is safer
   192     // In case ImageDataLoader is not used normally and we are not in debug, ASSERT is ignored, so deleting iDecoder is safer
   191     delete iDecoder;
   193     delete iDecoder;
   192     iDecoder = NULL;
   194     iDecoder = NULL;
   193     // Same applies to other data members of CSwtImageDataLoader
   195     // Same applies to other data members of CSwtImageDataLoader
   194 
   196 
   195     TRAPD(error,(iDecoder = CImageDecoder::DataNewL(iFs, aBuffer,CImageDecoder::EOptionAlwaysThread)));
   197     TRAPD(error,(iDecoder = CImageDecoder::DataNewL(iFs, aBuf, CImageDecoder::EOptionAlwaysThread)));
       
   198     
   196     LeaveIfErrorFromICLDecoderL(error);
   199     LeaveIfErrorFromICLDecoderL(error);
   197 
   200 
   198     TInt nbFrame = iDecoder->FrameCount();
   201     TInt nbFrame = iDecoder->FrameCount();
   199     for (TInt index = 0; index < nbFrame; ++index)
   202     for (TInt index = 0; index < nbFrame; ++index)
   200     {
   203     {
   202     }
   205     }
   203 
   206 
   204     FreeBitmaps();
   207     FreeBitmaps();
   205 
   208 
   206     LeaveIfErrorFromICLDecoderL(iResult);
   209     LeaveIfErrorFromICLDecoderL(iResult);
   207 }
       
   208 
       
   209 void CSwtImageDataLoader::DecodeImageFromBufferL(const TDesC8& aBuffer)
       
   210 {
       
   211     iNextFrameToDecode = 0;
       
   212 
       
   213     iBuffer = aBuffer.AllocL();
       
   214     iDesc.Set(iBuffer->Des());
       
   215 
       
   216     // In normal use of ImageDataLoader, it must be disposed by its creator after decoding an image ( so iDecoder should not be not NULL because of a previous call to this method )
       
   217     ASSERT(iDecoder == NULL);
       
   218     // In case ImageDataLoader is not used normally and we are not in debug, ASSERT is ignored, so deleting iDecoder is safer
       
   219     delete iDecoder;
       
   220     iDecoder = NULL;
       
   221     // Same applies to other data members of CSwtImageDataLoader
       
   222 
       
   223     TRAPD(error, (iDecoder = CImageDecoder::DataNewL(iFs, iDesc, CImageDecoder::EOptionAlwaysThread)));
       
   224     LeaveIfErrorFromICLDecoderL(error);
       
   225 
       
   226     // We are starting with a new frame ( the first one )
       
   227     iStartDecodingAnother = ETrue;
       
   228 
       
   229     // If frame to decode has not been detected by decoder and header is not complete, then more data is needed
       
   230     if ((iDecoder->FrameCount() <= iNextFrameToDecode) && (!iDecoder->IsImageHeaderProcessingComplete()))
       
   231         return; // need data
       
   232 
       
   233     // Start decoding frames from the buffer
       
   234     while (iStartDecodingAnother)
       
   235     {
       
   236         DecodeNextFrameL();
       
   237     };
       
   238 }
       
   239 
       
   240 TBool CSwtImageDataLoader::DecodeNextFrameL()
       
   241 {
       
   242     if (iNextFrameToDecode < iDecoder->FrameCount() && iStartDecodingAnother)
       
   243     {
       
   244         DecodeFrameL(iNextFrameToDecode);
       
   245         LeaveIfErrorFromICLDecoderL(iResult);
       
   246 
       
   247         return ETrue;
       
   248     }
       
   249 
       
   250     return EFalse;
       
   251 }
   210 }
   252 
   211 
   253 void CSwtImageDataLoader::DecodeFrameL(TInt aIndexOfFrame)
   212 void CSwtImageDataLoader::DecodeFrameL(TInt aIndexOfFrame)
   254 {
   213 {
   255     FreeBitmaps();
   214     FreeBitmaps();
   301     // ( the convert function returns and the returned status is KRequestPending ). So we use this one.
   260     // ( the convert function returns and the returned status is KRequestPending ). So we use this one.
   302     SetActive();
   261     SetActive();
   303     CActiveScheduler::Start();
   262     CActiveScheduler::Start();
   304 
   263 
   305     // Extracting Imagedata is performed in Runl;
   264     // Extracting Imagedata is performed in Runl;
   306 }
       
   307 
       
   308 void CSwtImageDataLoader::AppendDataL(const TDesC8& aBuffer)
       
   309 {
       
   310     // newBuffer is created and initialized with iBuffer content ( and iBuffer is deleted )
       
   311     HBufC8* newBuffer = iBuffer->ReAllocL(iBuffer->Length()+aBuffer.Length());
       
   312     // Set iBuffer to the new larger buffer ( for next time )
       
   313     iBuffer = newBuffer;
       
   314     // Refresh iDesc and append new data
       
   315     iDesc.Set(iBuffer->Des());
       
   316     iDesc.Append(aBuffer);
       
   317 
       
   318     // In normal use of ImageDataLoader, it must be disposed by its creator after decoding an image ( so iDecoder should not be not NULL because of a previous call to DecodeImageFromBufferL method )
       
   319     ASSERT(iDecoder);
       
   320     // In case ImageDataLoader is not used normally and we are not in debug, ASSERT is ignored, so deleting iDecoder is safer
       
   321     delete iDecoder;
       
   322     iDecoder = NULL;
       
   323     // Same applies to other data members of CSwtImageDataLoader
       
   324 
       
   325     TRAPD(error, (iDecoder = CImageDecoder::DataNewL(iFs, iDesc, CImageDecoder::EOptionAlwaysThread)));
       
   326     LeaveIfErrorFromICLDecoderL(error);
       
   327 
       
   328     // data have been appended. Now launching the correct action
       
   329     iStartDecodingAnother = ETrue;
       
   330 
       
   331     // If frame to decode has not been detected by decoder and header is not complete, then process newly read data
       
   332     if ((iDecoder->FrameCount() <= iNextFrameToDecode) && (!iDecoder->IsImageHeaderProcessingComplete()))
       
   333     {
       
   334         iDecoder->ContinueProcessingHeaderL();
       
   335         // If now processed data is enough to decode then do it
       
   336         if (!((iDecoder->FrameCount() <= iNextFrameToDecode) && (!iDecoder->IsImageHeaderProcessingComplete())))
       
   337         {
       
   338             while (DecodeNextFrameL()) {};
       
   339             return;
       
   340         }
       
   341         // If processed data is still not enough to decode then wait for next data
       
   342         else
       
   343         {
       
   344             return;
       
   345         }
       
   346     }
       
   347     // If frame to decode has been detected by decoder then decode frame
       
   348     else if (iDecoder->FrameCount() > iNextFrameToDecode)
       
   349     {
       
   350         while (DecodeNextFrameL()) {};
       
   351         return;
       
   352     }
       
   353     // If frame to decode has not been detected by decoder while header is complete, then don't process this unknown newly read data
       
   354     else
       
   355     {
       
   356         return;
       
   357     }
       
   358 }
   265 }
   359 
   266 
   360 void CSwtImageDataLoader::EncodeImageToFileL(MSwtImageData& aImageData, TInt aFormat, const TDesC& aDestination)
   267 void CSwtImageDataLoader::EncodeImageToFileL(MSwtImageData& aImageData, TInt aFormat, const TDesC& aDestination)
   361 {
   268 {
   362     CheckDestinationL(aDestination, iFs);
   269     CheckDestinationL(aDestination, iFs);
   710         ASSERT(EFalse);
   617         ASSERT(EFalse);
   711         return KNullDesC8;
   618         return KNullDesC8;
   712     }
   619     }
   713 }
   620 }
   714 
   621 
       
   622 
   715 //lint +esym( 613, CSwtImageDataLoader::iDecoder )
   623 //lint +esym( 613, CSwtImageDataLoader::iDecoder )
   716 //lint +esym( 613, CSwtImageDataLoader::iEncoder )
   624 //lint +esym( 613, CSwtImageDataLoader::iEncoder )