commonutilities/imagedecoderwrapper/src/glximagedecoder.cpp
changeset 42 5e1df1b52eb3
parent 23 74c9f037fd5d
child 50 a0f57508af73
equal deleted inserted replaced
41:ae07d189b490 42:5e1df1b52eb3
    19 #include "glximagedecoderwrapper.h"
    19 #include "glximagedecoderwrapper.h"
    20 
    20 
    21 #include <bitmaptransforms.h>
    21 #include <bitmaptransforms.h>
    22 #include <imageconversion.h>
    22 #include <imageconversion.h>
    23 #include <IclExtJpegApi.h>  // For CExtJpegDecoder
    23 #include <IclExtJpegApi.h>  // For CExtJpegDecoder
       
    24 #include <e32math.h>
    24 
    25 
    25 
    26 
    26 // ---------------------------------------------------------------------------
    27 // ---------------------------------------------------------------------------
    27 // Two-phased constructor.
    28 // Two-phased constructor.
    28 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    76 }
    77 }
    77 
    78 
    78 // ---------------------------------------------------------------------------
    79 // ---------------------------------------------------------------------------
    79 // DoDecodeImageL
    80 // DoDecodeImageL
    80 // ---------------------------------------------------------------------------	
    81 // ---------------------------------------------------------------------------	
    81 void CGlxImageDecoder::DecodeImageL(QString aSourceFileName)
    82 QSizeF CGlxImageDecoder::DecodeImageL(QString aSourceFileName)
    82 {
    83 {
    83 	//convert the argument to Symbian Format
    84 	//convert the argument to Symbian Format
    84 	TPtrC16 sourceFileName(reinterpret_cast<const TUint16*>(aSourceFileName.utf16()));
    85 	TPtrC16 sourceFileName(reinterpret_cast<const TUint16*>(aSourceFileName.utf16()));
    85 	if (iImageDecoder)
    86 	if (iImageDecoder)
    86         {
    87         {
    87 		iImageDecoder->Cancel();
    88 		iImageDecoder->Cancel();
    88         delete iImageDecoder;
    89         delete iImageDecoder;
    89         iImageDecoder = NULL;
    90         iImageDecoder = NULL;
    90         }
    91         }
    91 	/*TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL(
    92 	TRAPD( err, iImageDecoder = CExtJpegDecoder::FileNewL(
    92             CExtJpegDecoder::EHwImplementation, iFs, sourceFileName, CImageDecoder::EOptionNone ) );
    93             CExtJpegDecoder::EHwImplementation, iFs, sourceFileName, CImageDecoder::EOptionAutoRotate ) );
    93     if ( KErrNone != err )
    94     if ( KErrNone != err )
    94         {
    95         {
    95         TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL(
    96         TRAP(err,iImageDecoder = CExtJpegDecoder::FileNewL(
    96                 CExtJpegDecoder::ESwImplementation, iFs, sourceFileName, CImageDecoder::EOptionNone ) );
    97                 CExtJpegDecoder::ESwImplementation, iFs, sourceFileName, CImageDecoder::EOptionAutoRotate ) );
    97         if ( KErrNone != err )
    98         if ( KErrNone != err )
    98             {
    99             {
    99             // Not a JPEG - use standard decoder
   100             // Not a JPEG - use standard decoder
   100             iImageDecoder = CImageDecoder::FileNewL( iFs, sourceFileName, CImageDecoder::EOptionNone );
   101             iImageDecoder = CImageDecoder::FileNewL( iFs, sourceFileName, CImageDecoder::EOptionAutoRotate );
   101             }
   102             }
   102         }*/
   103         }
   103 	iImageDecoder = CImageDecoder::FileNewL( iFs, sourceFileName, CImageDecoder::EOptionNone );
       
   104 	TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
   104 	TSize imageSize = iImageDecoder->FrameInfo().iOverallSizeInPixels;
       
   105 	//limit size to 1MP
       
   106 	TSize decodeSize = imageSize;
       
   107 	TReal pixelsInImage = imageSize.iWidth*imageSize.iHeight;
       
   108 	if(pixelsInImage > KTargetSize)
       
   109 	{
       
   110 		TReal compressionFactor = 1;
       
   111 		TInt err = Math::Sqrt(compressionFactor, (KTargetSize/pixelsInImage) );
       
   112 		if(err != KErrNone) 
       
   113 		{
       
   114 			compressionFactor = .1;
       
   115 		}
       
   116 
       
   117 		decodeSize = TSize(imageSize.iWidth * compressionFactor, imageSize.iHeight * compressionFactor);
       
   118 	}
   105 	//clear the existing Bitmap
   119 	//clear the existing Bitmap
   106 	if(iBitmap)
   120 	if(iBitmap)
   107 	{
   121 	{
   108 		delete iBitmap;
   122 		delete iBitmap;
   109 		iBitmap = NULL;
   123 		iBitmap = NULL;
   110 	}
   124 	}
   111 	// create the destination bitmap and pass it on to the decoder
   125 	// create the destination bitmap and pass it on to the decoder
   112     if(!iBitmap)
   126     if(!iBitmap)
   113         {
   127         {
   114         iBitmap = new (ELeave) CFbsBitmap();
   128         iBitmap = new (ELeave) CFbsBitmap();
   115         iBitmap->Create( imageSize,EColor64K);
   129         iBitmap->Create( decodeSize,EColor64K);
   116         iImageDecoder->Convert( &iStatus, *iBitmap );
   130         iImageDecoder->Convert( &iStatus, *iBitmap );
   117 		SetActive();
   131 		SetActive();
   118 		}
   132 		}
       
   133 	return QSizeF(decodeSize.iWidth,decodeSize.iHeight) ;
   119 }
   134 }
   120 // ---------------------------------------------------------------------------
   135 // ---------------------------------------------------------------------------
   121 // RunL
   136 // RunL
   122 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   123 //
   138 //
   124 void CGlxImageDecoder::RunL()
   139 void CGlxImageDecoder::RunL()
   125     {
   140     {
   126     if( iStatus == KErrNone )
   141     if( iStatus == KErrNone )
   127         {   
   142         {   
   128         iDecoderWrapper->decodedImageAvailable();
   143         iDecoderWrapper->decodedImageAvailable();
   129         delete iImageDecoder;
       
   130         iImageDecoder = NULL;
       
   131 		iFs.Close();
       
   132         }	
   144         }	
       
   145      delete iImageDecoder;
       
   146      iImageDecoder = NULL;
       
   147      iFs.Close();
   133     }
   148     }
   134 
   149 
   135 // ---------------------------------------------------------------------------
   150 // ---------------------------------------------------------------------------
   136 // DoCancel
   151 // DoCancel
   137 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------