imagehandlinglib/Src/CIHLFileImage.h
changeset 0 2014ca87e772
equal deleted inserted replaced
-1:000000000000 0:2014ca87e772
       
     1 /*
       
     2 * Copyright (c) 2004 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:
       
    13 *
       
    14 * Description:  Implementation of ImageFile class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CIHLFILEIMAGE_H
       
    20 #define CIHLFILEIMAGE_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <MIHLFileImage.h>
       
    24 #include <e32base.h>
       
    25 #include <imageconversion.h> // TFrameInfo
       
    26 #include <gdi.h> // TDisplayMode
       
    27 #include <TIHLInterfaceType.h>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class MIHLBitmap;
       
    31 class CIHLBitmap;
       
    32 class CImageDecoder;
       
    33 class TRequestStatus;
       
    34 
       
    35 // CLASS DECLARATION
       
    36 /**
       
    37 *  CIHLImage
       
    38 *
       
    39 *  Implementation of file based image class.
       
    40 *  @lib IHL.lib
       
    41 *  @since 3.0
       
    42 */
       
    43 NONSHARABLE_CLASS( CIHLFileImage ) : public CActive, public MIHLFileImage
       
    44     {
       
    45     public:  // Constructors and destructor
       
    46 
       
    47         /**
       
    48         * Two-phased constructor.
       
    49         */
       
    50         static CIHLFileImage* NewL( RFile& aFile, TInt aImageIndex, const TUint32 aOptions );
       
    51         static CIHLFileImage* NewL( RFs& aFs, const TDesC8& aDataBuf,
       
    52                                     TInt aImageIndex, const TUint32 aOptions );
       
    53 
       
    54         /*
       
    55         * Virtual destructor.
       
    56         */
       
    57         virtual ~CIHLFileImage();
       
    58 
       
    59 	public: // From base class MIHLImage
       
    60 
       
    61         /*
       
    62         * From MIHLImage, see base class header.
       
    63         */
       
    64 		TIHLInterfaceType Type() const;
       
    65 
       
    66 	public: // From base class MIHLFileImage
       
    67 
       
    68         /*
       
    69         * From MIHLFileImage, see base class header.
       
    70         */
       
    71 		const TUid& ImageType() const;
       
    72 
       
    73         /*
       
    74         * From MIHLFileImage, see base class header.
       
    75         */
       
    76 		const TUid& ImageSubType() const;
       
    77 
       
    78         /*
       
    79         * From MIHLFileImage, see base class header.
       
    80         */
       
    81 		TInt ImageIndex() const;
       
    82 
       
    83         /*
       
    84         * From MIHLFileImage, see base class header.
       
    85         */
       
    86 		TInt ImageCount() const;
       
    87 
       
    88         /*
       
    89         * From MIHLFileImage, see base class header.
       
    90         */
       
    91 		TSize Size() const;
       
    92 
       
    93         /*
       
    94         * From MIHLFileImage, see base class header.
       
    95         */
       
    96 		TDisplayMode DisplayMode() const;
       
    97 
       
    98         /*
       
    99         * From MIHLFileImage, see base class header.
       
   100         */
       
   101 		TDisplayMode MaskDisplayMode() const;
       
   102 
       
   103         /*
       
   104         * From MIHLFileImage, see base class header.
       
   105         */
       
   106 		TRgb BackgroundColor() const;
       
   107 
       
   108         /*
       
   109         * From MIHLFileImage, see base class header.
       
   110         */
       
   111 		const RArray<TSize>& CustomLoadSizeArray() const;
       
   112 
       
   113         /*
       
   114         * From MIHLFileImage, see base class header.
       
   115         */
       
   116 		TBool IsFullyScaleable() const;
       
   117 
       
   118         /*
       
   119         * From MIHLFileImage, see base class header.
       
   120         */
       
   121 		TBool IsAnimation() const;
       
   122 
       
   123         /*
       
   124         * From MIHLFileImage, see base class header.
       
   125         */
       
   126 		TInt AnimationFrameCount() const;
       
   127 
       
   128         /*
       
   129         * From MIHLFileImage, see base class header.
       
   130         */
       
   131 		TTimeIntervalMicroSeconds32 AnimationFrameDelay( TInt aAnimationFrameIndex ) const;
       
   132 
       
   133         /*
       
   134         * From MIHLFileImage, see base class header.
       
   135         */
       
   136 		TInt Load( TRequestStatus& aStatus, MIHLBitmap& aDestination, TInt aFrameIndex = 0 ); 
       
   137 		
       
   138         /*
       
   139         * From MIHLFileImage, see base class header.
       
   140         */
       
   141 		TInt LoadAnimation( TRequestStatus& aStatus, MIHLBitmap& aDestination,
       
   142                             TInt aAnimationFrameIndex );
       
   143 
       
   144         /*
       
   145         * From MIHLFileImage, see base class header.
       
   146         */
       
   147 		TBool IsBusy() const;
       
   148 
       
   149         /*
       
   150         * From MIHLFileImage, see base class header.
       
   151         */
       
   152 		void CancelLoad();
       
   153 
       
   154         /*
       
   155         * From MIHLFileImage, see base class header.
       
   156         */
       
   157 		void SetFilter( MIHLFilter* aFilter );
       
   158 
       
   159 	private: // From base class CActive
       
   160 
       
   161         /*
       
   162         * From CActive, see base class header.
       
   163         */
       
   164 		void DoCancel();
       
   165 
       
   166         /*
       
   167         * From CActive, see base class header.
       
   168         */
       
   169 		void RunL();
       
   170 
       
   171         /*
       
   172         * From CActive, see base class header.
       
   173         */
       
   174 		TInt RunError( TInt aError );
       
   175 
       
   176 	public: // Internal interface
       
   177 
       
   178         /**
       
   179         * Return reference to used CImageDecoder instance.
       
   180 		* For internal use.
       
   181         * @since 3.0
       
   182 		* @return Reference to used CImageDecoder instance.
       
   183 		*/
       
   184 		const CImageDecoder& Decoder() const;
       
   185 
       
   186 	private: // Private methods
       
   187 
       
   188         /*
       
   189         * Request load and start ActiveScheduler.
       
   190         * Called from Load() and LoadAnimation() methods.
       
   191         */
       
   192 		TInt LoadRequest( TRequestStatus& aStatus, MIHLBitmap& aDestination, TInt aFrameIndex );
       
   193 
       
   194         /*
       
   195         * Start loading from file. Checks if image is still or animation.
       
   196         * Called by ActiveSheduler when state is EStartLoad.
       
   197         */
       
   198 		void StartLoadL();
       
   199 
       
   200         /*
       
   201         * Start loading normal frame. Called by StartLoadL() method.
       
   202         */
       
   203 		void StartLoadNormalFrame( TInt aFrameIndex );
       
   204 
       
   205         /*
       
   206         * Start loading sub frame. Called by StartLoadL() method.
       
   207         */
       
   208 		void StartLoadSubFrameL( TInt aFrameIndex, TBool aAnimation );
       
   209 
       
   210         /*
       
   211         * Loading complete. Build possible animation and notify client.
       
   212         * Called by ActiveSheduler when state is ECompleteLoad.
       
   213         */
       
   214 		void CompleteLoadL();
       
   215 
       
   216         /*
       
   217         * Build sub frame. Called by CompleteLoadL() method.
       
   218         */
       
   219 		void BuildSubFrameL();
       
   220 
       
   221         /*
       
   222         * Fill whole bitmap using given color.
       
   223         * Used by BuildAnimationFrameL().
       
   224         */
       
   225 		void FillL( CFbsBitmap& aBitmap, const TRgb& aColor );
       
   226 
       
   227         /*
       
   228         * Fill bitmap rect using given color.
       
   229         * Used by BuildAnimationFrameL().
       
   230         */
       
   231 		void FillRectL( CFbsBitmap& aBitmap, const TRect& aRect, const TRgb& aColor );
       
   232 
       
   233         /*
       
   234         * Error cleanup. Called if error occurs during load.
       
   235         */
       
   236 		void ErrorCleanup();
       
   237 
       
   238         /*
       
   239         * Complete dummy request. This causes RunL() method to be called.
       
   240         * Needed by state machine.
       
   241         */
       
   242 		void SelfComplete();
       
   243 
       
   244         /*
       
   245         * Complete client load request.
       
   246         * This causes client RunL() method to be called.
       
   247         */
       
   248 		void RequestComplete( TInt aReason );
       
   249 
       
   250         /*
       
   251         * Calculate scaled size.
       
   252         * Original size is divided by scale factor and result is rounded up
       
   253         * to next integer.
       
   254         */
       
   255 		TSize ScaledLoadSize( const TSize& aOriginalSize, TInt aScaleFactor );
       
   256 
       
   257         /*
       
   258         * Calculate scaled frame position.
       
   259         * Original position is divided by scale factor and result is rounded up
       
   260         * to next integer.
       
   261         */
       
   262         TPoint ScaledFramePosition( const TPoint& aOriginalPos, TInt aScaleFactor );
       
   263 
       
   264 	private: // Private constructors
       
   265 
       
   266         CIHLFileImage( TInt aImageIndex );
       
   267         void ConstructL( RFile& aFile, const TUint32 aOptions );
       
   268         void ConstructL( RFs& aFs, const TDesC8& aDataBuf, const TUint32 aOptions );
       
   269         void ConstructCommonL();
       
   270 
       
   271 	private: // Private data types
       
   272 
       
   273 		enum TImageState
       
   274 			{
       
   275 			EInactive,
       
   276 			EStartLoad,
       
   277 			ECompleteLoad,
       
   278 			};
       
   279 
       
   280 	private: // Data
       
   281 
       
   282 		// Ref: Image status & state
       
   283 		TRequestStatus* iImageStatus;
       
   284 		TImageState iImageState;
       
   285 
       
   286 		// Own: Image decoder
       
   287 		CImageDecoder* iDecoder;
       
   288 
       
   289 		// Image information
       
   290 		TUid iImageType;
       
   291 		TUid iImageSubType;
       
   292 		TInt iImageIndex;
       
   293 		TInt iImageCount;
       
   294 		RArray<TSize> iLoadSizeArray;
       
   295 		TBool iFullyScaleable;
       
   296 		TFrameInfo iFrameInfo;
       
   297 		TBool iGif;
       
   298 		TBool iAnimation;
       
   299 		TInt iAnimationFrameCount;
       
   300 
       
   301 		// Ref: Destination bitmap
       
   302 		CIHLBitmap* iDestination;
       
   303 		TInt iFrameIndex;
       
   304 
       
   305 		// Own: Temporary animation bitmap
       
   306 		CIHLBitmap* iSubFrameBitmap;
       
   307 		TInt iSubFrameIndex;
       
   308 		CIHLBitmap* iPrevAnimationFrame;
       
   309         TInt iSubFrameScaleFactor;
       
   310     };
       
   311 
       
   312 #endif   // CIHLFILEIMAGE_H
       
   313 
       
   314 // End of File