examples/ForumNokia/ImageConverter/inc/ImageConverterEngine.h

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #ifndef __IMAGECONVERTER_H__
00031 #define __IMAGECONVERTER_H__
00032 
00033 #include <e32std.h>
00034 #include <e32base.h>
00035 #include <f32file.h>
00036 #include <ImageConversion.h>
00037 #include <aknglobalnote.h>
00038 
00039 class CFbsBitmap;
00040 class CBitmapRotator;
00041 class CBitmapScaler;
00042 
00043 class MConverterController
00044     {
00045     public:
00046         virtual void NotifyCompletion( TInt aErr, const TDesC& aMsg ) = 0;
00047         virtual TBool IsAnimating() = 0;
00048     };
00049 
00050 // states for this engine
00051 enum TState 
00052     {
00053     EIdle = 0,
00054     EDecoding,
00055     EEncoding,
00056     ERotating,
00057     EScaling
00058     };
00059 
00060 class CImageConverterEngine : public CActive
00061     {
00062 
00063     public:
00064         // rotation directions
00065         enum TDirection 
00066             {
00067             EClockwise90 = 0,
00068             EAntiClockwise90 
00069             };
00070 
00071         public: // contructors/destructors
00072 
00073         /*
00074         * NewL
00075         *  
00076         * Create a CImageConverterEngine object and return a pointer to it.
00077         *
00078         * Params: 
00079         *       aController Pointer to a MConverterController interface.
00080         *      The engine uses NotifyCompletion callback from this interface
00081         *      to notify the controller about completions of coding or 
00082         *      encoding requests.
00083         *        
00084         * Returns:
00085         *       A pointer to the created engine
00086         *
00087         */  
00088         static CImageConverterEngine* NewL( MConverterController* aController );
00089     
00090         ~CImageConverterEngine();
00091         
00092     public: // interface methods
00093 
00094         /*
00095         * StartToDecodeL
00096         *  
00097         * Starts to decode an image from a file. When completed calls 
00098         * NotifyCompletion, from iController.
00099         *
00100         * Params: 
00101         *       aFileName Full path and filename of the image to be decoded.
00102         *        
00103         * Returns:
00104         *       Nothing
00105         */
00106         void StartToDecodeL( TFileName& aFileName );
00107 
00108         /*
00109         * StartToEncodeL
00110         *  
00111         * Starts to encode an image to a file. When completed calls 
00112         * NotifyCompletion, from iController.
00113         *
00114         * Params: 
00115         *       aFileName Full path and filename to the image to be encoded.
00116         *        
00117         * Returns:
00118         *       Nothing
00119         */
00120         void StartToEncodeL( TFileName& aFileName, 
00121             TUid aImageType, TUid aImageSubType );
00122 
00123         /*
00124         * GetImageInfoL
00125         *  
00126         * Gets frame 0 info strings. An image has to be decoded before 
00127         * call to this method, otherwise will return NULL.
00128         * 
00129         * Params: 
00130         *       None
00131         *        
00132         * Returns:
00133         *       CFrameInfoStrings* See Symbian OS documentation for 
00134         *       reference.
00135         */
00136         CFrameInfoStrings* GetImageInfoL();
00137 
00138         /*
00139         * GetEncoderImageTypesL
00140         *  
00141         * Gets descriptions of supported (encoding) image types. 
00142         *
00143         * Params: 
00144         *       aImageTypeArray Reference to an array to be filled.
00145         *       See Symbian OS documentation for reference.
00146         *
00147         * Returns:
00148         *       Nothing 
00149         */
00150         static void GetEncoderImageTypesL( 
00151             RImageTypeDescriptionArray& aImageTypeArray );
00152     
00153         /*
00154         * Rotate
00155         *  
00156         * Rotates the image to the given direction.
00157         *
00158         * Params: 
00159         *       aDirection The direction to rotate to.
00160         *
00161         * Returns:
00162         *       Nothing 
00163         */
00164         void Rotate( TDirection aDirection );
00165 
00166         /*
00167         * Scale
00168         *  
00169         * Scales the image to the given percentage of the current size.
00170         *
00171         * Params: 
00172         *       aPercent The new size relative to the current size 
00173         *       (e.g. 110 will increase the size by 10 %).
00174         *
00175         * Returns:
00176         *       Nothing 
00177         */
00178         TInt Scale( TInt aPercent );
00179     
00180         /*
00181         * GetBitmap
00182         *  
00183         * Returns a pointer to the decoded image.
00184         *
00185         * Params: 
00186         *       None
00187         *
00188         * Returns:
00189         *       A pointer to the encoded image  
00190         */
00191         CFbsBitmap* GetBitmap();
00192 
00193         void ShowProgress();
00194         void CancelProgress();
00195 
00196         TBool CanDownScaleMore();
00197         
00198         inline TState EngineState(){return iState;};
00199         
00200     protected: // implementation of CActive
00201         void DoCancel();
00202         void RunL();
00203         TInt RunError(TInt aError);
00204 
00205     private: // internal methods
00206         CImageConverterEngine( MConverterController* aController ); 
00207         void ConstructL();
00208         TBool FitToScreen();
00209         void DoFitToScreen();
00210 
00211 
00212     private: // internal data
00213         /*
00214         * Access to the decoded image,
00215         * images are also encoded from this bitmap.
00216         */
00217         CFbsBitmap*             iBitmap; // decoded image
00218         MConverterController*   iController; // ui controller
00219         RFs                     iFs; // for opening/saving images from/to files
00220         CImageDecoder*          iImageDecoder; // decoder from ICL API
00221         CImageEncoder*          iImageEncoder; // encoder from ICL API
00222         CBitmapRotator*         iRotator;
00223         CBitmapScaler*          iScaler;
00224         TState                  iState;
00225         CAknGlobalNote*         iGlobalNote;
00226         TInt                    iNoteId;
00227         TFileName               iFilename;
00228         TInt                    iScaleDownCounter;
00229     };
00230 
00231 #endif // #ifndef __IMAGECONVERTER_H__

Generated by  doxygen 1.6.2