videditor/VideoEditorCommon/inc/VeiImageClipGenerator.h
changeset 0 951a5db380a0
equal deleted inserted replaced
-1:000000000000 0:951a5db380a0
       
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "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 * Ixonos Plc
       
    14 *
       
    15 * Description: 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __VEIIMAGECLIPGENERATOR_H__
       
    22 #define __VEIIMAGECLIPGENERATOR_H__
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <VedVideoClipGenerator.h>
       
    27 
       
    28 /*
       
    29  * UID of this generator. The Uids are only used to identify generators
       
    30  * in UI, the Engine does not use Uids for any purpose.
       
    31  */
       
    32 #define KUidImageClipGenerator TUid::Uid(0x00000001)
       
    33 
       
    34 
       
    35 // Forward declarations
       
    36 class CVeiImageClipFrameOperation;
       
    37 class CVeiImageClipDecodeOperation;
       
    38 class CFbsBitmap;
       
    39 class CImageDecoder;
       
    40 class CVeiImageClipGenerator;
       
    41 class CBitmapScaler;
       
    42 
       
    43 
       
    44 /**
       
    45  * Image clip generator observer.
       
    46  */
       
    47 class MVeiImageClipGeneratorObserver
       
    48 	{
       
    49 public:
       
    50 	/**
       
    51 	 * Callback method to notify that the image clip generator initialization
       
    52 	 * is complete.
       
    53 	 *
       
    54 	 * @param aGenerator  generator that caused the event
       
    55 	 * @param aError	  error code
       
    56 	 */
       
    57 	virtual void NotifyImageClipGeneratorInitializationComplete(
       
    58 		CVeiImageClipGenerator& aGenerator, TInt aError) = 0;
       
    59 	};
       
    60 
       
    61 
       
    62 /**
       
    63  * Image clip generator.
       
    64  */
       
    65 class CVeiImageClipGenerator : public CVedVideoClipGenerator
       
    66 	{
       
    67 public:
       
    68 
       
    69 	/* Constructors / destructors. */
       
    70 
       
    71 	/**
       
    72 	 * Factory method. Creates a new image clip generator.
       
    73 	 * 
       
    74 	 * @param aFilename		  filename for the image
       
    75 	 * @param aMaxResolution  maximum resolution that will be used
       
    76 	 * @param aDuration		  duration of the image frame
       
    77 	 * @param aBackgroundColor  background color
       
    78 	 * @param aMaxDisplayMode	display mode in which the bitmap is stored
       
    79 	 * @param aFs			  RFs session to use for loading the image
       
    80 	 * @param aObserver		  observer that will be notified when the
       
    81 	 *						  initialization is complete
       
    82 	 *
       
    83 	 * @return  constructed image clip generator
       
    84 	 */
       
    85 	IMPORT_C static CVeiImageClipGenerator* NewL(const TDesC& aFilename,
       
    86 												 const TSize& aMaxResolution, 
       
    87 												 const TTimeIntervalMicroSeconds& aDuration, 
       
    88 												 const TRgb& aBackgroundColor,
       
    89 												 TDisplayMode aMaxDisplayMode,
       
    90 												 RFs& aFs,
       
    91 												 MVeiImageClipGeneratorObserver& aObserver);
       
    92 		
       
    93 	/**
       
    94 	 * Factory method. Creates a new image clip generator and leaves it
       
    95 	 * in the cleanup stack.
       
    96 	 * 
       
    97 	 * @param aFilename		    filename for the image
       
    98 	 * @param aMaxResolution    maximum resolution that will be used
       
    99 	 * @param aDuration		    duration of the image frame
       
   100 	 * @param aBackgroundColor  background color
       
   101 	 * @param aMaxDisplayMode	display mode in which the bitmap is stored
       
   102 	 * @param aFs			    RFs session to use for loading the image
       
   103 	 * @param aObserver		    observer that will be notified when the
       
   104 	 *						    initialization is complete
       
   105 	 *
       
   106 	 * @return  constructed image clip generator
       
   107 	 */
       
   108 	IMPORT_C static CVeiImageClipGenerator* NewLC(const TDesC& aFilename,
       
   109 												  const TSize& aMaxResolution,
       
   110 												  const TTimeIntervalMicroSeconds& aDuration, 
       
   111 												  const TRgb& aBackgroundColor,
       
   112 												  TDisplayMode aMaxDisplayMode,
       
   113  												  RFs& aFs,
       
   114 												  MVeiImageClipGeneratorObserver& aObserver);
       
   115 
       
   116 	/**
       
   117 	 * Destructor.
       
   118 	 */
       
   119 	IMPORT_C virtual ~CVeiImageClipGenerator();
       
   120 
       
   121 
       
   122 	/* Property methods. */
       
   123 
       
   124 	IMPORT_C virtual TPtrC DescriptiveName() const;
       
   125 
       
   126 	IMPORT_C virtual TUid Uid() const;
       
   127 
       
   128     IMPORT_C virtual TTimeIntervalMicroSeconds Duration() const;
       
   129 
       
   130 
       
   131 	/* Video frame property methods. */
       
   132 
       
   133     IMPORT_C virtual TInt VideoFrameCount() const ;
       
   134 
       
   135 	IMPORT_C virtual TTimeIntervalMicroSeconds VideoFrameStartTime(TInt aIndex) const;
       
   136 
       
   137 	IMPORT_C virtual TTimeIntervalMicroSeconds VideoFrameEndTime(TInt aIndex) const;
       
   138 
       
   139 	IMPORT_C virtual TTimeIntervalMicroSeconds VideoFrameDuration(TInt aIndex) const;
       
   140 
       
   141 	IMPORT_C virtual TBool VideoFrameIsIntra(TInt aIndex) const;
       
   142 
       
   143 	IMPORT_C virtual TInt VideoFirstFrameComplexityFactor() const;
       
   144 
       
   145 	IMPORT_C virtual TInt VideoFrameDifferenceFactor(TInt aIndex) const;
       
   146 
       
   147     IMPORT_C virtual TInt GetVideoFrameIndex(TTimeIntervalMicroSeconds aTime) const;
       
   148 
       
   149 
       
   150 	/* Frame methods. */
       
   151 
       
   152 	IMPORT_C virtual void GetFrameL(MVedVideoClipGeneratorFrameObserver& aObserver,
       
   153                            TInt aIndex,
       
   154 		                   TSize* const aResolution,
       
   155 						   TDisplayMode aDisplayMode,
       
   156 						   TBool aEnhance,
       
   157 						   TInt aPriority);
       
   158     
       
   159 	IMPORT_C virtual void CancelFrame();
       
   160 
       
   161 
       
   162 	/* New methods. */
       
   163 
       
   164 	/**
       
   165 	 * Sets the duration.
       
   166 	 *
       
   167 	 * @param aDuration  duration
       
   168 	 */
       
   169 	IMPORT_C void SetDuration(const TTimeIntervalMicroSeconds& aDuration);
       
   170 
       
   171 	/**
       
   172 	 * Sets the background color.
       
   173 	 *
       
   174 	 * @param aBackgroundColor
       
   175 	 */
       
   176 	IMPORT_C void SetBackgroundColor(const TRgb& aBackgroundColor);
       
   177 
       
   178 	/**
       
   179 	 * Gets the background color.
       
   180 	 * 
       
   181 	 * @return  background color
       
   182 	 */
       
   183 	IMPORT_C const TRgb& BackgroundColor() const;
       
   184 
       
   185 	/**
       
   186 	 * Returns the image file name.
       
   187 	 *
       
   188 	 * @return  filename
       
   189 	 */
       
   190 	IMPORT_C TPtrC ImageFilename() const;
       
   191 
       
   192 private: // constructors
       
   193 	
       
   194 	/**
       
   195 	 * First-phase constructor.
       
   196 	 * 
       
   197 	 * @param aDuration        duration
       
   198 	 * @param aBackgroundColor background color 
       
   199 	 * @param aMaxResolution   maximum resolution
       
   200 	 */
       
   201 	CVeiImageClipGenerator(const TTimeIntervalMicroSeconds& aDuration, 
       
   202 						   const TRgb& aBackgroundColor,
       
   203 						   const TSize& aMaxResolution);
       
   204 
       
   205 	/**
       
   206 	 * Second-phase constructor.
       
   207 	 * 
       
   208 	 * @param aFilename       filename of the image
       
   209 	 * @param aObserver       observer
       
   210 	 * @param aMaxDisplyMode  display mode
       
   211 	 * @param aFs             RFs session
       
   212 	 */
       
   213 	void ConstructL(const TDesC& aFilename, 
       
   214 					MVeiImageClipGeneratorObserver& aObserver,
       
   215 					TDisplayMode aMaxDisplayMode, RFs& aFs);
       
   216 
       
   217 	
       
   218 private:
       
   219 	/**
       
   220 	 * Updates the first frame complexity factor.
       
   221 	 */
       
   222 	void UpdateFirstFrameComplexityFactorL();
       
   223 
       
   224 private:
       
   225     // Member variables
       
   226 
       
   227 	/** Flag for readiness indication. */
       
   228 	TBool iReady;
       
   229 
       
   230 	/** First frame complexity factor. */
       
   231 	TInt iFirstFrameComplexityFactor;
       
   232 
       
   233 	/** Resolution. */
       
   234 	TSize iMaxResolution;
       
   235 
       
   236 	/** Duration. */
       
   237 	TTimeIntervalMicroSeconds iDuration;
       
   238 
       
   239 	/** Background color. */
       
   240 	TRgb iBackgroundColor;
       
   241 
       
   242 	/** Image decode operation. */
       
   243 	CVeiImageClipDecodeOperation* iDecodeOperation;
       
   244 
       
   245 	/** Frame generating operation. */
       
   246 	CVeiImageClipFrameOperation* iFrameOperation;
       
   247 
       
   248 	/** Descriptive name. */
       
   249 	HBufC* iDescriptiveName;
       
   250 
       
   251 	/** Image filename */
       
   252 	HBufC* iFilename;
       
   253 	
       
   254 	/** Bitmap. */
       
   255 	CFbsBitmap* iBitmap;
       
   256 
       
   257 	/** Mask. */
       
   258 	CFbsBitmap* iMask;
       
   259 
       
   260 	/** Is the generator initializing? */
       
   261 	TBool iInitializing;
       
   262 
       
   263 	/** Frame count. */
       
   264 	TInt iFrameCount;
       
   265 
       
   266 	friend class CVeiImageClipDecodeOperation;
       
   267 	};
       
   268 
       
   269 
       
   270 /**
       
   271  * Image decode operation. Helper class for decoding the image and 
       
   272  * performing first-stage resizing.
       
   273  */
       
   274 class CVeiImageClipDecodeOperation : public CActive
       
   275 	{
       
   276 	public: 
       
   277 		/**
       
   278 		 * Factory constructor. 
       
   279 		 * 
       
   280 		 * @param aGenerator  generator that owns this operation
       
   281 		 * @param aFilename	  filename for the image
       
   282 		 * @param aObserver	  observer that will be notified when the
       
   283 		 *					  operation completes
       
   284 		 * @param aFs		  RFs session to use for loading the image
       
   285 		 * @param aPriority   priority of the active object
       
   286 		 *
       
   287 		 * @return  constructed image clip decode operation
       
   288 		 */
       
   289 		static CVeiImageClipDecodeOperation* NewL(CVeiImageClipGenerator& aGenerator,
       
   290 												  const TDesC& aFilename, 
       
   291 												  MVeiImageClipGeneratorObserver& aObserver,
       
   292 												  RFs& aFs,
       
   293 												  TInt aPriority = CActive::EPriorityStandard);
       
   294 		/**
       
   295 		 * Destructor.
       
   296 		 */
       
   297 		virtual ~CVeiImageClipDecodeOperation();
       
   298 
       
   299 		virtual void RunL();
       
   300 		virtual void DoCancel();
       
   301 		virtual TInt RunError(TInt aError);
       
   302 
       
   303 		/**
       
   304 		 * Starts the operation.
       
   305 		 * 
       
   306 		 * @param aMaxResolution  maximum resolution that will be used
       
   307 		 * @param aDisplayMode	  display mode
       
   308 		 */
       
   309 		void StartOperationL(const TSize& aMaxResolution, TDisplayMode aDisplayMode);
       
   310 
       
   311 	private: // methods
       
   312 
       
   313 		/**
       
   314 		 * First-phase constructor.
       
   315 		 *
       
   316 		 * @param aGenerator  generator that owns this operation
       
   317 		 * @param aObserver	  observer that will be notified when the
       
   318 		 *					  operation completes
       
   319 		 * @param aPriority   priority of the active object
       
   320 		 */
       
   321 		CVeiImageClipDecodeOperation(CVeiImageClipGenerator& aGenerator, 
       
   322 									 MVeiImageClipGeneratorObserver& aObserver,
       
   323 									 TInt aPriority);
       
   324 
       
   325 		/**
       
   326 		 * Second-phase constructor.
       
   327 		 *
       
   328  		 * @param aFilename	  filename for the image
       
   329 		 * @param aFs		  RFs session to use for loading the image
       
   330 		 */
       
   331 
       
   332 		void ConstructL(const TDesC& aFilename, RFs& aFs);
       
   333 
       
   334 	private: // members
       
   335 
       
   336 		/** Generator that owns this operation*/
       
   337 		CVeiImageClipGenerator& iGenerator;
       
   338 
       
   339 		/** Observer to be notified when the operation completes. */
       
   340 		MVeiImageClipGeneratorObserver& iObserver;
       
   341 
       
   342 		/** Decoder. */
       
   343 		CImageDecoder* iDecoder;
       
   344 
       
   345 		/** Bitmap. */
       
   346 		CFbsBitmap* iBitmap;
       
   347 
       
   348 		/** Mask. */
       
   349 		CFbsBitmap* iMask;
       
   350 	};
       
   351 
       
   352 
       
   353 /**
       
   354  * Image frame operation.
       
   355  */
       
   356 class CVeiImageClipFrameOperation : public CActive
       
   357 	{
       
   358 	public: 
       
   359 		/**
       
   360 		 * Factory constructor. 
       
   361 		 * 
       
   362 		 * @param aGenerator  generator that owns this operation
       
   363 		 *
       
   364 		 * @return  constructed image clip frame operation
       
   365 		 */
       
   366 		static CVeiImageClipFrameOperation* NewL(CVeiImageClipGenerator& aGenerator);
       
   367 
       
   368 		/**
       
   369 		 * Destructor. 
       
   370 		 */
       
   371 		virtual ~CVeiImageClipFrameOperation();
       
   372 
       
   373 		/**
       
   374 		 * Starts the operation.
       
   375 		 *
       
   376 		 * @param aObserver      observer to notify when the frame is complete
       
   377 		 * @param aIndex         index of the frame to generate
       
   378 		 * @param aEnhance       <code>ETrue</code> to produce better results
       
   379 		 *                       but slower, <code>EFalse</code> to be as fast
       
   380 		 *                       as possible.
       
   381 		 * @param aSourceBitmap  source bitmap
       
   382 		 * @param aDestBitmap    destination bitmap
       
   383 		 * @param aSourceMask    source mask
       
   384 		 * @param aPriority      priority for the active object
       
   385 		 *
       
   386 		 */
       
   387 		void StartOperationL(MVedVideoClipGeneratorFrameObserver* aObserver, 
       
   388 			TInt aIndex, TBool aEnhance, CFbsBitmap* aSourceBitmap, 
       
   389 			CFbsBitmap* aDestBitmap, CFbsBitmap* aSourceMask, TInt aPriority);
       
   390 
       
   391 		virtual void RunL();
       
   392 		virtual void DoCancel();
       
   393 		virtual TInt RunError(TInt aError);
       
   394 
       
   395 	private: // methods
       
   396 		/**
       
   397 		 * First-phase constructor.
       
   398 		 * 
       
   399 		 * @param aGenerator  generator that owns this operation
       
   400 		 */
       
   401 		CVeiImageClipFrameOperation(CVeiImageClipGenerator& aGenerator);
       
   402 
       
   403 		/**
       
   404 		 * Second-phase constructor.
       
   405 		 */
       
   406 		void ConstructL();
       
   407 
       
   408 	private: // members
       
   409 		/** Generator. */
       
   410 		CVeiImageClipGenerator& iGenerator;
       
   411 
       
   412 		/** Index of the frame being generated. */
       
   413 		TInt iIndex;
       
   414 
       
   415 		/** Whether to be fast or do quality work. */
       
   416 		TBool iEnhance;
       
   417 
       
   418 		/** Source bitmap. */
       
   419 		CFbsBitmap* iSourceBitmap;
       
   420 
       
   421 		/** Destination bitmap. */
       
   422 		CFbsBitmap* iDestBitmap;
       
   423 
       
   424 		/** Scaled bitmap. */
       
   425 		CFbsBitmap* iScaledBitmap;
       
   426 
       
   427 		/** Scaled mask. */
       
   428 		CFbsBitmap* iScaledMask;
       
   429 
       
   430 		/** Source mask. */
       
   431 		CFbsBitmap* iSourceMask;
       
   432 
       
   433 		/** Scaler. */
       
   434 		CBitmapScaler* iScaler;
       
   435 
       
   436 		/** Flag for no scaling. */
       
   437 		TBool iNoScaling;
       
   438 
       
   439 		/** Observer. */
       
   440 		MVedVideoClipGeneratorFrameObserver* iObserver;
       
   441 	};
       
   442 
       
   443 
       
   444 
       
   445 #endif // __VEIIMAGECLIPGENERATOR_H__
       
   446