imagehandlingutilities/thumbnailmanager/thumbnailserver/inc/thumbnailscaletask.h
changeset 54 48dd0f169f0d
parent 42 2e2a89493e2b
equal deleted inserted replaced
42:2e2a89493e2b 54:48dd0f169f0d
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Task for scaling thumbnails
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef THUMBNAILSCALETASK_H
       
    20 #define THUMBNAILSCALETASK_H
       
    21 
       
    22 #include "thumbnailtask.h"
       
    23 #include "thumbnailprovider.h"
       
    24 #include "thumbnailstore.h" // TThumbnailPersistentSize
       
    25 
       
    26 class CThumbnailServer;
       
    27 
       
    28 /**
       
    29  *  Task for scaling thumbnails.
       
    30  *
       
    31  *  @since S60 v5.0
       
    32  */
       
    33 class CThumbnailScaleTask: public CThumbnailTask
       
    34     {
       
    35 public:
       
    36 
       
    37     /**
       
    38      * Two-phased constructor
       
    39      *
       
    40      * @since S60 v5.0
       
    41      * @param aProcessor Processor object for running tasks.
       
    42      * @param aServer Server to use.
       
    43      * @param aFilename Filename of file from which the thumbnail is to be
       
    44      *                  created.
       
    45      * @param aBitmap Bitmap image. Scale task assumes ownership.
       
    46      * @param aOriginalSize Original size of the image.
       
    47      * @param aTargetSize Target size of thumbnail image.
       
    48      * @param aCrop Enable or disable cropping.
       
    49      * @param aDisplayMode Display mode.
       
    50      * @param aPriority Priority of the request.
       
    51      * @param aThumbnailSize Prededined size of thumbnail.
       
    52      * @return New CThumbnailScaleTask object.
       
    53      * @param aEXIF is origin EXIF.
       
    54      * @param aRequestId Request ID.
       
    55      */
       
    56     static CThumbnailScaleTask* NewL( CThumbnailTaskProcessor& aProcessor,
       
    57         CThumbnailServer& aServer, const TDesC& aFilename, CFbsBitmap* aBitmap,
       
    58         const TSize& aOriginalSize, const TSize& aTargetSize, TBool aCrop,
       
    59         TDisplayMode aDisplayMode, TInt aPriority, const TDesC& aTargetUri,
       
    60         const TThumbnailSize aThumbnailSize, const TInt64 aModified,
       
    61         const TBool aBitmapToPool, const TBool aEXIF, 
       
    62         const TThumbnailServerRequestId aRequestId, const TBool aImportVirtual);
       
    63 
       
    64     /**
       
    65      * Destructor
       
    66      *
       
    67      * @since S60 v5.0
       
    68      */
       
    69     virtual ~CThumbnailScaleTask();
       
    70 
       
    71     /**
       
    72      * StartL
       
    73      *
       
    74      * @since S60 v5.0
       
    75      */
       
    76     void StartL();
       
    77 
       
    78     /**
       
    79      * Handles an active object's request completion event.
       
    80      *
       
    81      * @since S60 v5.0
       
    82      */
       
    83     void RunL();
       
    84 
       
    85     /**
       
    86      * Implements cancellation of an outstanding request.
       
    87      *
       
    88      * @since S60 v5.0
       
    89      */
       
    90     void DoCancel();
       
    91 
       
    92     /**
       
    93      * Changes priority of the task.
       
    94      *
       
    95      * @since S60 v5.0
       
    96      */
       
    97     void ChangeTaskPriority( TInt aNewPriority );
       
    98 
       
    99     /**
       
   100      * Set whether the scaled image is to be stored or not.
       
   101      *
       
   102      * @since S60 v5.0
       
   103      * @param aDoStore Boolean value stating should the image be stored.
       
   104      */
       
   105     void SetDoStore( TBool aDoStore );
       
   106 
       
   107 private:
       
   108 
       
   109     /**
       
   110      * C++ default constructor
       
   111      *
       
   112      * @since S60 v5.0
       
   113      * @param aProcessor Processor object for running tasks.
       
   114      * @param aServer Server to use.
       
   115      * @param aFilename Filename of file from which the thumbnail is to be
       
   116      *                  created.
       
   117      * @param aBitmap Bitmap image. Scale task assumes ownership.
       
   118      * @param aOriginalSize Original size of the image.
       
   119      * @param aTargetSize Target size of thumbnail image.
       
   120      * @param aCrop Enable or disable cropping.
       
   121      * @param aDisplayMode Display mode.
       
   122      * @param aPriority Priority of the request.
       
   123      * @param aThumbnailSize Prededined size of thumbnail.
       
   124      * @return New CThumbnailScaleTask object.
       
   125      * @param aEXIF is origin EXIF.
       
   126      * @param aRequestId Request ID.
       
   127      */
       
   128     CThumbnailScaleTask( CThumbnailTaskProcessor& aProcessor, CThumbnailServer&
       
   129         aServer, const TDesC& aFilename, CFbsBitmap* aBitmap, const TSize&
       
   130         aOriginalSize, const TSize& aTargetSize, TBool aCrop, TDisplayMode
       
   131         aDisplayMode, TInt aPriority, const TDesC& aTargetUri,
       
   132         const TThumbnailSize aThumbnailSize, const TInt64 aModified,
       
   133         const TBool aBitmapToPool, const TBool aEXIF, 
       
   134         const TThumbnailServerRequestId aRequestId, const TBool aImportVirtual);
       
   135 
       
   136     /**
       
   137      * Symbian 2nd phase constructor can leave.
       
   138      *
       
   139      * @since S60 v5.0
       
   140      */
       
   141     void ConstructL();
       
   142 
       
   143     /**
       
   144      * Calculates target size to be used for the thumbnail when cropping is
       
   145      * disabled. The target size may be smaller than requested if aspect
       
   146      * ratios do not match. Updates iTargetSize.
       
   147      *
       
   148      * @since S60 v5.0
       
   149      */
       
   150     void CalculateTargetSize();
       
   151 
       
   152     /**
       
   153      * Calculates cropping rectangle to be used for the thumbnail when
       
   154      * cropping is enabled. Target size will always be the same as requested
       
   155      * size and the cropping rectangle defines which area of the image will
       
   156      * be visible. Updates iCropRectangle.
       
   157      *
       
   158      * @since S60 v5.0
       
   159      */
       
   160     void CalculateCropRectangle();
       
   161 
       
   162     /**
       
   163      * StoreAndCompleteL
       
   164      *
       
   165      * @since S60 v5.0
       
   166      */
       
   167     void StoreAndCompleteL();
       
   168 
       
   169 private:
       
   170     // Data
       
   171 
       
   172     /**
       
   173      * Server.
       
   174      */
       
   175     CThumbnailServer& iServer;
       
   176 
       
   177     /**
       
   178      * Resides in bitmap pool.
       
   179      * Not own. But we do are responsible for decreasing the reference count
       
   180      * if iBitmapInPool is set.
       
   181      */
       
   182     CFbsBitmap* iBitmap;
       
   183 
       
   184     /**
       
   185      * Temporary place to store the original bitmap. This is set to NULL
       
   186      * after the bitmap has been successfully added to the bitmap pool.
       
   187      * Own.
       
   188      */
       
   189     CFbsBitmap* iOwnBitmap;
       
   190 
       
   191     /**
       
   192      * Bitmap pool.
       
   193      */
       
   194     TBool iBitmapInPool;
       
   195 
       
   196     /**
       
   197      * Original size of media object.
       
   198      */
       
   199     TSize iOriginalSize;
       
   200 
       
   201     /**
       
   202      * Target size of scaled thubnail (not real of preview)
       
   203      */
       
   204     TSize iTargetSize;
       
   205     
       
   206     /**
       
   207      * Target size of the thumbnail.
       
   208      */
       
   209     TSize iTargetSizeTN;
       
   210 
       
   211     /**
       
   212      * Incidates if cropping is enabled.
       
   213      */
       
   214     TBool iCrop;
       
   215 
       
   216     /**
       
   217      * Defines the visible area of iBitmap which is to be included
       
   218      * in the thumbnail if cropping is enabled. Not used if cropping
       
   219      * is disabled.
       
   220      */
       
   221     TRect iCropRectangle;
       
   222 
       
   223     /**
       
   224      * Display mode.
       
   225      */
       
   226     TDisplayMode iDisplayMode;
       
   227 
       
   228     /**
       
   229      * Filename of the image to be used.
       
   230      */
       
   231     TFileName iFilename;
       
   232     
       
   233     /**
       
   234      * Uri of the target object
       
   235      */
       
   236     TFileName iTargetUri;
       
   237 
       
   238     /**
       
   239      * Scaled image.
       
   240      */
       
   241     CFbsBitmap* iScaledBitmap; // own
       
   242 
       
   243     /**
       
   244      * If set, scaled bitmap must be released from pool.
       
   245      */
       
   246     TInt iScaledBitmapHandle;
       
   247 
       
   248     /**
       
   249      * If set, thumbnail will be stored for later use.
       
   250      */
       
   251     TBool iDoStore;
       
   252 
       
   253     /**
       
   254      * Temporary buffer for client/server parameters
       
   255      */
       
   256     TThumbnailRequestParamsPckgBuf iParamsBuf;
       
   257 
       
   258      /**
       
   259      * Size of requested Thumbnail
       
   260      */
       
   261     TThumbnailSize iThumbnailSize;
       
   262     
       
   263 	 /**
       
   264      * timestamp
       
   265      */
       
   266     TInt64 iModified;
       
   267     
       
   268 	/**
       
   269      * Add bitmap to server's pool.
       
   270      */
       
   271     TBool iBitmapToPool;
       
   272  
       
   273 #ifdef _DEBUG
       
   274     TTime aStart, aStop;
       
   275 #endif
       
   276     
       
   277      /**
       
   278      * Is origin EXIF.
       
   279      */
       
   280     TBool iEXIF;
       
   281     
       
   282     // virtual uri
       
   283     TBool iVirtualUri;
       
   284 };
       
   285 
       
   286 #endif // THUMBNAILSCALETASK_H