utils/tsimageutils/inc/tsgraphicfilescalinghandler.h
changeset 124 e36b2f4799c0
parent 121 0b3699f6c654
equal deleted inserted replaced
121:0b3699f6c654 124:e36b2f4799c0
     1 /*
       
     2  * Copyright (c) 2009 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 :
       
    15  *
       
    16  */
       
    17 #ifndef TSGRAPHICFILESCALINGHANDLER_H
       
    18 #define TSGRAPHICFILESCALINGHANDLER_H
       
    19 
       
    20 #include <e32base.h>
       
    21 
       
    22 class RFs;
       
    23 class CImageDecoder;
       
    24 class CFbsBitmap;
       
    25 class CBitmapRotator;
       
    26 class CBitmapScaler;
       
    27 
       
    28 /**
       
    29  * Interface to observer contain
       
    30  * ImageReadyCallBack function return error code and scaled/resized bitmap.
       
    31  */
       
    32 class MImageReadyCallBack
       
    33     {
       
    34 public:
       
    35     virtual void ImageReadyCallBack( TInt aError, const CFbsBitmap* aBitmap ) = 0;
       
    36     };
       
    37 
       
    38 /**
       
    39  * Class to scaling graphic file/s.
       
    40  */
       
    41 class CTsGraphicFileScalingHandler : public CActive
       
    42     {
       
    43 public:
       
    44     /**
       
    45      * Kind of graphic file scaling.
       
    46      * EIgnoreAspectRatio          - the file is scaled to size, aspect ratio isn't preserving.
       
    47      * EKeepAspectRatio            - the file is scaled to a rectangle as large as possible inside size
       
    48      *                               preserving the aspect ratio.
       
    49      * EKeepAspectRatioByExpanding - the file is scaled to a rectangle as small as possible outside size
       
    50      *                               preserving the aspect ratio.
       
    51      */
       
    52     enum TKindOfScaling
       
    53         {
       
    54         EIgnoreAspectRatio = 0,
       
    55         EKeepAspectRatio = 1,
       
    56         EKeepAspectRatioByExpanding = 2,
       
    57         };
       
    58 
       
    59 private:
       
    60     /**
       
    61      * Active object current operation.
       
    62      */
       
    63     enum TCurrentOperation{
       
    64         ENone = 0,
       
    65         EConvertBitmapFromFile,
       
    66         ERotate,
       
    67         EScale
       
    68     };
       
    69 
       
    70 public:
       
    71     ~CTsGraphicFileScalingHandler();
       
    72 
       
    73     static CTsGraphicFileScalingHandler* NewL(MImageReadyCallBack &aNotify,
       
    74         RFs &aFs,
       
    75         const TDesC &aFileName,
       
    76         const TDesC8& aMimeType,
       
    77         const TSize &aNewSize,
       
    78         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio,
       
    79         TInt aRotation = 0);
       
    80     
       
    81     static CTsGraphicFileScalingHandler* NewLC(MImageReadyCallBack &aNotify,
       
    82         RFs &aFs,
       
    83         const TDesC &aFileName,
       
    84         const TDesC8& aMimeType,
       
    85         const TSize &aNewSize,
       
    86         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio,
       
    87         TInt aRotation = 0);
       
    88 
       
    89     
       
    90     static CTsGraphicFileScalingHandler* NewL(MImageReadyCallBack &aNotify,
       
    91         const CFbsBitmap &aInputFbsBitmap,
       
    92         const TSize &aNewSize,
       
    93         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio,
       
    94         TInt aRotation = 0);
       
    95      static CTsGraphicFileScalingHandler* NewLC(MImageReadyCallBack &aNotify,
       
    96         const CFbsBitmap &aInputFbsBitmap,
       
    97         const TSize &aNewSize,
       
    98         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio,
       
    99         TInt aRotation = 0);
       
   100 
       
   101 protected:
       
   102     void DoCancel();
       
   103     void RunL();
       
   104     TInt RunError(TInt);
       
   105 
       
   106 private:
       
   107     void ConstructL( RFs& aFs, const TDesC& aFileName, const TDesC8& aMimeType );
       
   108     void ConstructL( const CFbsBitmap& aInputFbsBitmap );
       
   109     CTsGraphicFileScalingHandler( MImageReadyCallBack& aNotify,
       
   110                                   const TSize& aNewSize,
       
   111         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio,
       
   112         TInt aRotation = 0);
       
   113     void DecodingOperationL( RFs& aFs, const TDesC& aFileName, const TDesC8& aMimeType );
       
   114 
       
   115     void ScalingOperationL();
       
   116 
       
   117     void RotationOperationL();
       
   118     
       
   119     TInt RotationMode()const;
       
   120     
       
   121     TBool IsSupportedRotationMode() const;
       
   122     
       
   123     TSize NewSizeToScalingOperation();
       
   124 
       
   125     void FixForDisplayModeNotSupportedByScalingOperation();
       
   126 
       
   127 private:
       
   128     /**
       
   129      * Reference to observer implementation - return error code and output bitmap.
       
   130      */
       
   131     MImageReadyCallBack& iNotify;
       
   132     /**
       
   133      * Pointer to decoder used by decoding graphic file algorithm.
       
   134      */
       
   135     CImageDecoder* iImageDecoder;
       
   136     /**
       
   137      * Pointer to input bitmap - before decoding/scaling operation/s.
       
   138      */
       
   139     CFbsBitmap* iInputBitmap;
       
   140     /**
       
   141      * Pointer to output bitmap - returned in mNotify object.
       
   142      */
       
   143     CFbsBitmap* iOutputBitmap;
       
   144     /**
       
   145      * Pointer to CBitmapScaler calss used by scaling graphic file algorithm.
       
   146      */
       
   147     CBitmapScaler* iBitmapScaler;
       
   148     
       
   149     CBitmapRotator* iBitmapRotator;
       
   150     /**
       
   151      * New size of output graphic file.
       
   152      */
       
   153     TSize iNewSize;
       
   154     /**
       
   155      * Kind of graphic file scaling described above.
       
   156      */
       
   157     TBool iKindOfScaling;
       
   158     
       
   159     const TInt iRotation;
       
   160     /**
       
   161      * Active object current operation.
       
   162      */
       
   163     TCurrentOperation iCurrentOperation;
       
   164     };
       
   165 
       
   166 #endif // TSGRAPHICFILESCALINGHANDLER_H