activityfw/tsutils/inc/tsgraphicfilescalinghandler.h
changeset 116 305818acdca4
parent 112 dbfb5e38438b
child 119 50e220be30d1
equal deleted inserted replaced
112:dbfb5e38438b 116:305818acdca4
     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 #ifndef __E32SVR_H__
       
    21 #define __E32SVR_H__
       
    22 #endif
       
    23 
       
    24 
       
    25 #ifndef SYMBIAN_ENABLE_PUBLIC_PLATFORM_HEADER_SPLIT
       
    26 #define SYMBIAN_ENABLE_PUBLIC_PLATFORM_HEADER_SPLIT
       
    27 #endif
       
    28 
       
    29 #include <bitmaptransforms.h>
       
    30 
       
    31 class CImageDecoder;
       
    32 class CFbsBitmap;
       
    33 
       
    34 /**
       
    35  * Interface to observer contain
       
    36  * ImageReadyCallBack function return error code and scaled/resized bitmap.
       
    37  */
       
    38 class MImageReadyCallBack
       
    39 {
       
    40 public:
       
    41     virtual void ImageReadyCallBack(TInt error, const CFbsBitmap *bitmap) = 0;
       
    42 };
       
    43 
       
    44 /**
       
    45  * Class to scaling graphic file/s.
       
    46  */
       
    47 class CTsGraphicFileScalingHandler : public CActive
       
    48 {
       
    49 public:
       
    50     /**
       
    51      * Kind of graphic file scaling.
       
    52      * EIgnoreAspectRatio          - the file is scaled to size, aspect ratio isn't preserving.
       
    53      * EKeepAspectRatio            - the file is scaled to a rectangle as large as possible inside size
       
    54      *                               preserving the aspect ratio.
       
    55      * EKeepAspectRatioByExpanding - the file is scaled to a rectangle as small as possible outside size
       
    56      *                               preserving the aspect ratio.
       
    57      */
       
    58     enum TKindOfScaling
       
    59     {
       
    60        EIgnoreAspectRatio = 0,
       
    61        EKeepAspectRatio = 1,
       
    62        EKeepAspectRatioByExpanding = 2,
       
    63     };
       
    64 
       
    65 private:
       
    66     /**
       
    67      * Active object current operation.
       
    68      */
       
    69     enum TCurrentOperation{
       
    70         ENone = 0,
       
    71         EConvertBitmapFromFile = 1,
       
    72         EScale = 2
       
    73     };
       
    74 
       
    75 public:
       
    76     /**
       
    77     * Destructor.
       
    78     */
       
    79     IMPORT_C ~CTsGraphicFileScalingHandler();
       
    80 
       
    81     /**
       
    82      * All constructors initialise active object asynchronous operation
       
    83      * by calling ConstructL function.
       
    84      * 1st group - decoding and scaling.
       
    85      * 2nd group - scaling.
       
    86      */
       
    87 
       
    88     /**
       
    89      * 1st group.
       
    90      * Exported from dll constructors for activation graphic file scaling.
       
    91      * aNotify        - reference to observer implementation.
       
    92      * aFs            - reference to file server session.
       
    93      * aFileName      - path to graphic file.
       
    94      * aMimeType      - mime type of graphic file.
       
    95      * aNewSize       - new size of output graphic file.
       
    96      * aKindOfScaling - kind of graphic file scaling described above.
       
    97      */
       
    98     IMPORT_C static CTsGraphicFileScalingHandler* NewL(MImageReadyCallBack &aNotify,
       
    99         RFs &aFs,
       
   100         const TDesC &aFileName,
       
   101         const TDesC8& aMimeType,
       
   102         const TSize &aNewSize,
       
   103         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio);
       
   104     IMPORT_C static CTsGraphicFileScalingHandler* NewLC(MImageReadyCallBack &aNotify,
       
   105         RFs &aFs,
       
   106         const TDesC &aFileName,
       
   107         const TDesC8& aMimeType,
       
   108         const TSize &aNewSize,
       
   109         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio);
       
   110 
       
   111     /**
       
   112      * 2nd group.
       
   113      * Exported from dll constructors for activation graphic file scaling.
       
   114      * aNotify         - reference to observer implementation.
       
   115      * aImputFbsBitmap - reference to pattern CFbsBitmap.
       
   116      * aNewSize        - new size of output graphic file.
       
   117      * aKindOfScaling  - kind of graphic file scaling described above.
       
   118      */
       
   119     IMPORT_C static CTsGraphicFileScalingHandler* NewL(MImageReadyCallBack &aNotify,
       
   120         const CFbsBitmap &aImputFbsBitmap,
       
   121         const TSize &aNewSize,
       
   122         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio);
       
   123      IMPORT_C static CTsGraphicFileScalingHandler* NewLC(MImageReadyCallBack &aNotify,
       
   124         const CFbsBitmap &aImputFbsBitmap,
       
   125         const TSize &aNewSize,
       
   126         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio);
       
   127 
       
   128 protected:
       
   129      /**
       
   130       * Cancels the wait for completion of an outstanding request.
       
   131       */
       
   132     void DoCancel();
       
   133     /**
       
   134      * Handles an active object’s request completion event.
       
   135      */
       
   136     void RunL();
       
   137     /**
       
   138      * Handles a leave occurring in the request completion event handler RunL().
       
   139      */
       
   140     TInt RunError(TInt);
       
   141 
       
   142 private:
       
   143     /**
       
   144      * Functions construct active objest instance and made asynchronous operation/s.
       
   145      * Parameters - the same meaning as in appropriate NewL/NewLC functions.
       
   146      */
       
   147     void ConstructL(RFs &aFs, const TDesC &aFileName, const TDesC8& aMimeType);
       
   148     void ConstructL(const CFbsBitmap &aImputFbsBitmap);
       
   149     /**
       
   150      * Private constructor.
       
   151      * Parameters - the same meaning as in appropriate NewL/NewLC functions.
       
   152      */
       
   153     CTsGraphicFileScalingHandler(MImageReadyCallBack &aNotify,
       
   154         const TSize &aNewSize,
       
   155         TKindOfScaling aKindOfScaling = CTsGraphicFileScalingHandler::EIgnoreAspectRatio);
       
   156     /**
       
   157      * Action to made before decoding graphic file operation.
       
   158      * Parameters - the same meaning as in appropriate NewL/NewLC functions.
       
   159      */
       
   160     void DecodingOperationL(RFs &aFs, const TDesC &aFileName, const TDesC8& aMimeType);
       
   161     /**
       
   162      * Action to made before scaling graphic file operation.
       
   163      */
       
   164     void ScalingOperationL();
       
   165     /**
       
   166      * Algorithm to determine output bitmap (returned in ImageReadyCallBack) size
       
   167      * after scaling operation.
       
   168      */
       
   169     TSize NewSizeToScalingOperation();
       
   170     /**
       
   171      * Fix for TDisplayMode == EColor16MAP not supported by scaling operation!
       
   172      * ! ! ! ADD OTHER NOT SUPPORTED DISPLAY MODES ! ! !
       
   173      */
       
   174     void FixForDisplayModeNotSupportedByScalingOperation();
       
   175 
       
   176 private:
       
   177     /**
       
   178      * Reference to observer implementation - return error code and output bitmap.
       
   179      */
       
   180     MImageReadyCallBack &mNotify;
       
   181     /**
       
   182      * Pointer to decoder used by decoding graphic file algorithm.
       
   183      */
       
   184     CImageDecoder *mImageDecoder;
       
   185     /**
       
   186      * Pointer to input bitmap - before decoding/scaling operation/s.
       
   187      */
       
   188     CFbsBitmap *mInputBitmap;
       
   189     /**
       
   190      * Pointer to output bitmap - returned in mNotify object.
       
   191      */
       
   192     CFbsBitmap *mOutputBitmap;
       
   193     /**
       
   194      * Pointer to CBitmapScaler calss used by scaling graphic file algorithm.
       
   195      */
       
   196     CBitmapScaler *mBitmapScaler;
       
   197     /**
       
   198      * New size of output graphic file.
       
   199      */
       
   200     TSize mNewSize;
       
   201     /**
       
   202      * Kind of graphic file scaling described above.
       
   203      */
       
   204     TBool mKindOfScaling;
       
   205     /**
       
   206      * Active object current operation.
       
   207      */
       
   208     TCurrentOperation mCurrentOperation;
       
   209 };
       
   210 
       
   211 #endif // TSGRAPHICFILESCALINGHANDLER_H