idlehomescreen/widgetmanager/inc/wmimageconverter.h
branchRCL_3
changeset 19 79311d856354
parent 11 ff572dfe6d86
equal deleted inserted replaced
18:d05a55b217df 19:79311d856354
    25 #include <f32file.h>
    25 #include <f32file.h>
    26 #include <AknIconUtils.h> // MAknIconFileProvider
    26 #include <AknIconUtils.h> // MAknIconFileProvider
    27 
    27 
    28 // Forward declarations
    28 // Forward declarations
    29 class CFbsBitmap;
    29 class CFbsBitmap;
    30 class CBitmapScaler;
       
    31 class CImageDecoder;
       
    32 class TAknsItemID;
    30 class TAknsItemID;
    33 class CWmUnitTest;
    31 class CWmUnitTest;
    34 class MSvgError;
    32 class MSvgError;
    35 
    33 
    36 // Class declaration
    34 // Class declaration
    37 /**
    35 /**
    38  *  MConverterObserver
       
    39  *  To notify when image is converted
       
    40  */
       
    41 NONSHARABLE_CLASS( MConverterObserver )
       
    42     {
       
    43     public:
       
    44         virtual void NotifyCompletion( TInt aError ) = 0;
       
    45     };
       
    46 
       
    47 // Class declaration
       
    48 /**
       
    49  * CWmImageConverter
    36  * CWmImageConverter
    50  * Image converter
    37  * Image converter
    51  */
    38  */
    52 NONSHARABLE_CLASS ( CWmImageConverter ) : public CActive,
    39 NONSHARABLE_CLASS ( CWmImageConverter ) : public MAknIconFileProvider
    53         public MAknIconFileProvider
       
    54     {
    40     {
    55     /** states for this converter */
       
    56     enum TState 
       
    57         {
       
    58         EIdle = 0,
       
    59         EDecoding,
       
    60         EScalingBitmap,
       
    61         EScalingMask,
       
    62         EFailed
       
    63         };
       
    64 
       
    65 public: //contructors/destructors
    41 public: //contructors/destructors
    66     /**
    42     /**
    67      * Two-phased constructor.
    43      * Two-phased constructor.
    68      * @param aObserver observer
    44      * @param aObserver observer
    69      */
    45      */
    70     static CWmImageConverter* NewL( MConverterObserver* aObserver );    
    46     static CWmImageConverter* NewL();    
    71     
    47     
    72     /** Destructor */
    48     /** Destructor */
    73     ~CWmImageConverter();
    49     ~CWmImageConverter();
    74         
    50         
    75 public: // interface methods
    51 public: // interface methods
    76     
    52     
    77     /**
    53     /**
    78      * Parses icon string and prepares logo image.
    54      * Parses icon string and prepares logo image.
    79      * 
    55      * 
    80      * @param aWidth wanted widht
    56      * @param aIconSize wanted size
    81      * @param aHeight wanted height
       
    82      * @param aIconStr str containing logo icon
    57      * @param aIconStr str containing logo icon
       
    58 	 * @param aBitmap bitmap to create. Empty if fails
       
    59 	 * @param aMask mask to create. Empty if fails
    83      * Supported values:
    60      * Supported values:
    84      * - skin(<major id> <minor id>):mif(<path> <bitmapid> <maskid>)
    61      * - skin(<major id> <minor id>):mif(<path> <bitmapid> <maskid>)
    85      * - mif(<path> <bitmapid> <maskid>)
    62      * - mif(<path> <bitmapid> <maskid>)
    86      * - uid(<application uid>)
    63      * - uid(<application uid>)
    87      * - <file name>.<png/svg>
    64      * - <file name>.<png/svg>
    88      * 
    65      * 
    89      * @return Error code 
    66      * @return Error code 
    90      */
    67      */
    91     TInt HandleIconString( TInt aWidth, TInt aHeight, const TDesC& aIconStr );
    68     TInt HandleIconString( 
    92 
    69             const TSize& aIconSize,
    93     /**
    70             const TDesC& aIconStr,
    94      * Returns converted bitmap. Caller takes ownership
    71             CFbsBitmap*& aBitmap,
       
    72             CFbsBitmap*& aMask  );
       
    73     
       
    74 	/**
       
    75      * Parses icon string and resizes given bitmaps if needed.
       
    76 	 * Errors are ignored and previos size image will be used.
    95      * 
    77      * 
    96      * @return CFbsBitmap
    78      * @param aIconSize wanted size
    97      */
    79      * @param aIconStr icon string to find out what to resize
    98     CFbsBitmap* Bitmap();
    80 	 * @param aBitmap bitmap to resize
       
    81 	 * @param aMask mask to resize
       
    82 	 */
       
    83     void UpdateImageSize( 
       
    84             const TSize& aSize,
       
    85             const TDesC& aIconStr, 
       
    86             CFbsBitmap& aBitmap, 
       
    87             CFbsBitmap& aMask );
    99     
    88     
   100     /**
       
   101      * Returns converted mask. Caller takes ownership
       
   102      * 
       
   103      * @return CFbsBitmap
       
   104      */
       
   105     CFbsBitmap* Mask();
       
   106 
       
   107     /**
       
   108      * sets the size for decoding
       
   109      * @param aSize the logo size
       
   110      */
       
   111     void SetLogoSize( const TSize& aSize );
       
   112 
       
   113     /** supported image conversion methods */
       
   114     enum TConversionMethod
       
   115         {
       
   116         EUnrecognized, // we could not recognise the icon string
       
   117         EUidIcon, // App.UID-coded icon
       
   118         ESvgIcon, // Icon from SVG-file
       
   119         ESkinIcon, // Icon from SKIN id
       
   120         EMifIcon, // Icon from MIF file, known graphic index
       
   121         ESkinAndMifIcon, // Icon from SKIN and MIF combination 
       
   122         EImageIcon, // Icon from image file (jpeg or png)
       
   123         };
       
   124 
       
   125     /**
       
   126      * The type of currently converted image.
       
   127      * This method can be used to check if correct conversion was used.
       
   128      * @return conversion method used for current image
       
   129      */
       
   130     TConversionMethod ConversionMethod();
       
   131 
       
   132     /**
       
   133      * Image convertion status
       
   134      * 
       
   135      * @return ETrue if processing image, false otherwise.
       
   136      */
       
   137     TBool IsProcessing();
       
   138 
       
   139 protected: // implementation of CActive
       
   140     /**
       
   141      * Implements cancellation of an outstanding request.
       
   142      * 
       
   143      * @see CActive::DoCancel
       
   144      */
       
   145     void DoCancel();
       
   146     
       
   147     /**
       
   148      * Handles an active object's request completion event.
       
   149      * 
       
   150      * @see CActive::RunL
       
   151      */
       
   152     void RunL();
       
   153     
       
   154     /**
       
   155      * RunError
       
   156      * 
       
   157      * @see CActive::RunError
       
   158      */
       
   159     TInt RunError(TInt aError);
       
   160         
       
   161 private:
    89 private:
   162     CWmImageConverter(); 
    90     CWmImageConverter(); 
   163     void ConstructL( MConverterObserver* aObserver );
    91     void ConstructL();
   164     void CheckSvgErrorL( MSvgError* aError );
       
   165     void HandleIconStringL( TInt aWidth, TInt aHeight, 
       
   166             const TDesC& aIconStr );
       
   167 
    92 
   168 private:
    93 private:
       
    94     void CheckSvgErrorL( MSvgError* aError );
       
    95     void HandleIconStringL( const TSize& aIconSize, const TDesC& aIconStr );
   169     
    96     
   170     TBool DoesScaleBitmapUseFallBack( CFbsBitmap* aSrcBitmap );
       
   171     void ScaleBitmapL( const TSize& aSize, 
       
   172                     CFbsBitmap* aTrgBitmap,
       
   173                     CFbsBitmap* aSrcBitmap );    
       
   174     void ScaleBitmap( TInt aWidth, TInt aHeight );
       
   175     void ScaleMask( TInt aWidth, TInt aHeight );
       
   176     void CreateIconFromUidL( const TUid& aUid );
    97     void CreateIconFromUidL( const TUid& aUid );
   177     void CreateIconFromSvgL( const TDesC& aFileName );
    98     void CreateIconFromSvgL( const TDesC& aFileName );
   178     void CreateIconFromOtherL( const TDesC& aFileName );
    99     void CreateIconFromOtherL( const TDesC& aFileName );
   179     void CreateSkinOrMifIconL( 
   100     void CreateSkinOrMifIconL( 
   180                     const TAknsItemID& aItemId, TInt aBitmapId, 
   101                     const TAknsItemID& aItemId, TInt aBitmapId, 
   188                         TInt& aBitmapId, TInt& aMaskId, TDes& aFileName );
   109                         TInt& aBitmapId, TInt& aMaskId, TDes& aFileName );
   189     TBool EndsWith( const TDesC& aString, const TDesC& aPattern );
   110     TBool EndsWith( const TDesC& aString, const TDesC& aPattern );
   190 
   111 
   191     // helpers
   112     // helpers
   192     TInt ParseNextUint( TLex& aLex, TUint& aValue );
   113     TInt ParseNextUint( TLex& aLex, TUint& aValue );
       
   114     void CopyBitmapL( CFbsBitmap& aTrgBitmap, CFbsBitmap& aSrcBitmap );
   193     
   115     
   194 private: // from MAknIconFileProvider
   116 private: // from MAknIconFileProvider
   195 
   117 
   196     /** Returns an open file handle to the icon file. */
   118     /** Returns an open file handle to the icon file. */
   197 	void RetrieveIconFileHandleL( RFile& aFile, const TIconFileType aType );
   119 	void RetrieveIconFileHandleL( RFile& aFile, const TIconFileType aType );
   199     /** Stops using this MAknIconFileProvider instance */
   121     /** Stops using this MAknIconFileProvider instance */
   200     void Finished();
   122     void Finished();
   201     
   123     
   202 private:
   124 private:
   203     /**
   125     /**
   204      * Converter observer (not owned)
       
   205      */
       
   206     MConverterObserver*     iObserver;
       
   207 
       
   208     /**
       
   209      * decoded image
   126      * decoded image
   210      */
   127      */
   211     CFbsBitmap*             iBitmap;
   128     CFbsBitmap*             iBitmap;
   212     
   129     
   213     /**
   130     /**
   214      * decoded image mask
   131      * decoded image mask
   215      */
   132      */
   216     CFbsBitmap*             iMask;
   133     CFbsBitmap*             iMask;
   217     
   134 
   218     /**
       
   219      * decoder from ICL API
       
   220      */
       
   221     CImageDecoder*          iImageDecoder;
       
   222     
       
   223     /**
       
   224      * bitmap scaler
       
   225      */
       
   226     CBitmapScaler*          iScaler;
       
   227     
       
   228     /**
       
   229      * internal state
       
   230      */
       
   231     TState                  iState;
       
   232     
       
   233     /**
   135     /**
   234      * File name to convert
   136      * File name to convert
   235      */
   137      */
   236     TFileName               iFilename;
   138     TFileName               iFilename;
   237     
   139     
   238     /**
   140     /**
   239      * size to convert
   141      * size to convert
   240      */
   142      */
   241     TSize                   iSize;
   143     TSize                   iSize;
   242     
   144 
   243     /**
       
   244      * is scaling needed
       
   245      */
       
   246     TBool                   iScaleNeeded;
       
   247     
       
   248     /**
   145     /**
   249      * File handle
   146      * File handle
   250      */
   147      */
   251     RFs                     iFs;
   148     RFs                     iFs;
   252 
       
   253     /**
       
   254      * Conversion method for current image
       
   255      */
       
   256     TConversionMethod       iConversionMethod;
       
   257 
       
   258     };
   149     };
   259 
   150 
   260 #endif // #ifndef WMIMAGECONVERTER_H
   151 #endif // #ifndef WMIMAGECONVERTER_H
   261 
   152 
   262 // end of file
   153 // end of file