imagehandlinglib/Src/CIHLImageViewer.h
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     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 Image Viewer class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CIHLIMAGEVIEWER_H
       
    20 #define CIHLIMAGEVIEWER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <MIHLImageViewer.h>
       
    24 #include <e32base.h>
       
    25 #include <hal.h>
       
    26 
       
    27 //FORWARD DECLARATIONS
       
    28 class MIHLFileImage;
       
    29 class MIHLBitmap;
       
    30 class MIHLViewerObserver;
       
    31 class CIHLBitmap;
       
    32 class CIHLBitmapProcessor;
       
    33 
       
    34 #define KMinimumInterval 10000
       
    35 
       
    36 // CLASS DECLARATION
       
    37 /**
       
    38 *  CIHLImageViewer
       
    39 *
       
    40 *  Image Viewer implementation class.
       
    41 *  @lib IHL.lib
       
    42 *  @since 3.0
       
    43 */
       
    44 NONSHARABLE_CLASS( CIHLImageViewer ) : public CTimer, public MIHLImageViewer
       
    45     {
       
    46     public:  // Constructors and destructor
       
    47 
       
    48         /**
       
    49         * Two-phased constructor.
       
    50         */
       
    51         static CIHLImageViewer* NewL( const TSize& aViewerSize,
       
    52 									  MIHLFileImage& aSource,
       
    53 									  MIHLBitmap& aDestination,
       
    54 									  MIHLViewerObserver& aObserver,
       
    55 									  const TUint32 aOptions );
       
    56 
       
    57         /*
       
    58         * Virtual destructor.
       
    59         */
       
    60         virtual ~CIHLImageViewer();
       
    61 
       
    62 	public: // From base class MIHLViewer
       
    63 
       
    64         /*
       
    65         * From MIHLViewer, see base class header.
       
    66         */
       
    67 		TIHLInterfaceType Type() const;
       
    68 
       
    69 	public: // From base class MIHLImageViewer
       
    70 
       
    71         /*
       
    72         * From MIHLImageViewer, see base class header.
       
    73         */
       
    74 		TBool IsAnimation() const;
       
    75 
       
    76         /*
       
    77         * From MIHLImageViewer, see base class header.
       
    78         */
       
    79 		void Play();
       
    80 
       
    81         /*
       
    82         * From MIHLImageViewer, see base class header.
       
    83         */
       
    84 		void Stop();
       
    85 
       
    86         /*
       
    87         * From MIHLImageViewer, see base class header.
       
    88         */
       
    89 		TBool IsPlaying() const;
       
    90 
       
    91         /*
       
    92         * From MIHLImageViewer, see base class header.
       
    93         */
       
    94 		TInt AnimationFrameCount() const;
       
    95 
       
    96         /*
       
    97         * From MIHLImageViewer, see base class header.
       
    98         */
       
    99 		TInt AnimationFrame() const;
       
   100 
       
   101         /*
       
   102         * From MIHLImageViewer, see base class header.
       
   103         */
       
   104 		TInt SetAnimationFrame( TInt aFrameIndex );
       
   105 
       
   106         /*
       
   107         * From MIHLImageViewer, see base class header.
       
   108         */
       
   109 		TInt SetViewerSize( const TSize& aViewerSize, TInt srcBitmapScaleFactor = 1 );
       
   110 
       
   111         /*
       
   112         * From MIHLImageViewer, see base class header.
       
   113         */
       
   114 		TSize ViewerSize() const;
       
   115 
       
   116         /*
       
   117         * From MIHLImageViewer, see base class header.
       
   118         */
       
   119 		TInt MoveSourceRect( TInt aDx, TInt aDy );
       
   120 
       
   121         /*
       
   122         * From MIHLImageViewer, see base class header.
       
   123         */
       
   124 		TInt SetSourceRectPosition( const TPoint& aPosition );
       
   125 
       
   126         /*
       
   127         * From MIHLImageViewer, see base class header.
       
   128         */
       
   129 		TRect SourceRect() const;
       
   130 
       
   131         /*
       
   132         * From MIHLImageViewer, see base class header.
       
   133         */
       
   134 		TSize SourceSize() const;
       
   135 
       
   136         /*
       
   137         * From MIHLImageViewer, see base class header.
       
   138         */
       
   139 		TInt SetZoomRatio( TReal aZoomRatio );
       
   140 
       
   141         /*
       
   142         * From MIHLImageViewer, see base class header.
       
   143         */
       
   144 		TReal ZoomRatio() const;
       
   145 
       
   146         /*
       
   147         * From MIHLImageViewer, see base class header.
       
   148         */
       
   149 		TReal ZoomToFitRatio() const;
       
   150 
       
   151         /*
       
   152         * From MIHLImageViewer, see base class header.
       
   153         */
       
   154 		TInt RotateClockwise();
       
   155 
       
   156         /*
       
   157         * From MIHLImageViewer, see base class header.
       
   158         */
       
   159 		TInt RotateCounterClockwise();
       
   160 
       
   161         /*
       
   162         * From MIHLImageViewer, see base class header.
       
   163         */
       
   164 		TInt SetRotationAngle( TInt aRotationAngle );
       
   165 
       
   166         /*
       
   167         * From MIHLImageViewer, see base class header.
       
   168         */
       
   169 		TInt RotationAngle() const;
       
   170 
       
   171         /*
       
   172         * From MIHLImageViewer, see base class header.
       
   173         */
       
   174 		TInt SetVerticalMirroring( TBool aValue );
       
   175 
       
   176         /*
       
   177         * From MIHLImageViewer, see base class header.
       
   178         */
       
   179 		TBool VerticalMirroring() const;
       
   180 
       
   181         /*
       
   182         * From MIHLImageViewer, see base class header.
       
   183         */
       
   184 		TInt SetHorizontalMirroring( TBool aValue );
       
   185 
       
   186         /*
       
   187         * From MIHLImageViewer, see base class header.
       
   188         */
       
   189 		TBool HorizontalMirroring() const;
       
   190 
       
   191         /*
       
   192         * From MIHLImageViewer, see base class header.
       
   193         */
       
   194 		void SetFilter( MIHLFilter* aFilter );
       
   195 
       
   196 	public: // From base class CTimer
       
   197 
       
   198         /*
       
   199         * From CTimer, see base class header.
       
   200         */
       
   201 		void DoCancel();
       
   202 
       
   203         /*
       
   204         * From CTimer, see base class header.
       
   205         */
       
   206 		void RunL();
       
   207 
       
   208         /*
       
   209         * From CTimer, see base class header.
       
   210         */
       
   211 		TInt RunError( TInt aError );
       
   212 
       
   213 	private: // Private methods
       
   214 
       
   215         /*
       
   216         * Start asynchronous processing with new settings.
       
   217         * This is needed always when settings are changed.
       
   218         */
       
   219 		TInt ApplySettings();
       
   220 
       
   221         /*
       
   222         * Start load process source bitmap.
       
   223         */
       
   224 		TInt AsyncLoad();
       
   225 
       
   226         /*
       
   227         * Check if process is needed.
       
   228         */
       
   229         TBool NeedAsyncProcess();
       
   230 
       
   231         /*
       
   232         * Start processing with new settings.
       
   233         */
       
   234 		TInt AsyncProcess();
       
   235 
       
   236         /*
       
   237         * No external processing.
       
   238         * Just duplicates source to destination.
       
   239         */
       
   240         TInt SyncProcess();
       
   241 
       
   242         /*
       
   243         * Finish processing and notify client.
       
   244         */
       
   245 		TInt Finish();
       
   246 
       
   247         /*
       
   248         * Update frame index when playing animation.
       
   249         */
       
   250 		void UpdateAnimationIndex();
       
   251 
       
   252         /*
       
   253         * Complete dummy request. This causes RunL() method to be called.
       
   254         * Needed by state machine.
       
   255         */
       
   256 		void SelfComplete();
       
   257 
       
   258         /*
       
   259         * Calculate minimum source bitmap size (using fixed loadsizes)
       
   260         * needed by processing and destination bitmap.
       
   261         */
       
   262 		TSize MinimumSourceLoadSize();
       
   263 
       
   264         /*
       
   265         * Calculate source bitmap rectangle needed by processor.
       
   266         * Rectangle is affected by rotating and mirroring settings etc.
       
   267         */
       
   268 		TRect CalculateProcessSourceRect( const TSize& aLoadSize );
       
   269 
       
   270         /*
       
   271         * Calculate destination bitmap rectangle needed by processor.
       
   272         * Rectangle is affected by rotating and mirroring settings etc.
       
   273         */
       
   274 		TRect CalculateProcessDestinationRect();
       
   275 
       
   276         /*
       
   277         * Calculate needed zoomratio for "fit-to-screen" zooming.
       
   278         */
       
   279 		void CalculateZoomToFitRatio();
       
   280 
       
   281         /*
       
   282         * Calculate source bitmap rectangle and destination bitmap size.
       
   283         * These values needs to be recalculated when rectangle setting is changed.
       
   284         */
       
   285 		void CalculateSourceRectAndDestinationSize( );
       
   286 		
       
   287 		/*
       
   288 		* Shedules next frame of animation in using aDelay CTimer::Hires().
       
   289 		* If this is not the first frame the shedule time is decreased by 
       
   290 		* previous frame draw time.
       
   291 		*/
       
   292 		void SheduleNextFrame(TTimeIntervalMicroSeconds32 aDelay);
       
   293 
       
   294         /*
       
   295         * Assert if source bitmap rectangle and destination bitmpa size are valid.
       
   296         * This method is called by CalculateSourceRectAndDestinationSize()
       
   297         */
       
   298 #ifdef _DEBUG
       
   299 		void AssertSourceRectAndDestinationSize();
       
   300 #endif
       
   301 
       
   302 	private: // Private constructors
       
   303 
       
   304         void ConstructL();
       
   305         CIHLImageViewer( const TSize& aViewerSize,
       
   306 						 MIHLFileImage& aSource,
       
   307 						 MIHLBitmap& aDestination,
       
   308 						 MIHLViewerObserver& aObserver,
       
   309 						 const TUint32 aOptions );
       
   310 
       
   311 	private: // Private data types
       
   312 
       
   313 		enum TViewerState
       
   314 			{
       
   315 			EInactive,
       
   316 			ELoad,
       
   317 			EProcess,
       
   318 			EAnimation,
       
   319 			};
       
   320 
       
   321 	private: // Data
       
   322 
       
   323 		// Viewer state
       
   324 		TViewerState iViewerState;
       
   325 
       
   326 		// Ref: Observers
       
   327 		MIHLViewerObserver& iObserver;
       
   328 
       
   329 		// Ref: Viewer source image
       
   330 		MIHLFileImage& iSource;
       
   331 		TSize iSourceSize;
       
   332 		TRect iSourceRect;
       
   333 
       
   334 		// Ref: Viewer destination bitmap
       
   335 		MIHLBitmap& iDestination;
       
   336 		TSize iDestinationSize;
       
   337 
       
   338 		// Viewing settings
       
   339 		const TUint32 iOptions;
       
   340 		TSize iViewerSize;
       
   341 		TReal iZoomRatio;
       
   342 		TReal iZoomToFitRatio;
       
   343 		TInt iRotationAngle;
       
   344 		TBool iVerticalMirroring;
       
   345 		TBool iHorizontalMirroring;
       
   346 
       
   347 		// Own: Bitmap caches
       
   348 		CIHLBitmap* iCacheSource;
       
   349 		CIHLBitmap* iCacheDestination;
       
   350 
       
   351 		// Own: Bitmap processor
       
   352 		CIHLBitmapProcessor* iProcessor;
       
   353 
       
   354 		// Animation info
       
   355 		TBool iIsPlaying;
       
   356 		TInt iAnimationIndex;
       
   357 
       
   358 		// src bitmap scale factor
       
   359 		TInt iSrcBitmapScaleFactor;
       
   360 		
       
   361 		// Animation time tweaking
       
   362 		TInt64 iAnimInitFastTime;			//clock ticks
       
   363 		TInt64 iAnimDrawStartFastTime;		//clock tics
       
   364 		TInt iAnimLastFrameDrawTime; 		//micro seconds
       
   365 		TInt iTickPeriod;					//clock tick period
       
   366 		TTimeIntervalMicroSeconds32 iAnimDelay;
       
   367 		
       
   368 		
       
   369 
       
   370     };
       
   371 
       
   372 #endif // CIHLIMAGEVIEWER_H
       
   373 
       
   374 // End of File