javaextensions/pim/cntadapter/inc.s60/cpimimagescaler.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Downscales images when necessary
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPIMIMAGESCALER_H
       
    20 #define CPIMIMAGESCALER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <imageconversion.h>
       
    25 #include <bitmaptransforms.h>
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KThumbHeight = 96;
       
    29 const TInt KThumbWidth = 80;
       
    30 const TInt KMaxJpegSize = 23296; // 80*96*3+256
       
    31 
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35  *  Scales bitmaps when necessary.
       
    36  *  The purpose of this class is to resize given bitmaps to thumbnail size
       
    37  * (80x96). If the given image is already smaller than 80x96, it is not scaled.
       
    38  *
       
    39  */
       
    40 NONSHARABLE_CLASS(CPIMImageScaler): public CActive
       
    41 {
       
    42 public: // type definitions
       
    43     enum TState
       
    44     {
       
    45         EReady,
       
    46         EOpening,
       
    47         EScaling,
       
    48         EEncoding,
       
    49         ECompleted,
       
    50         // Error state
       
    51         EError
       
    52     };
       
    53 
       
    54 public: // Constructors and destructor
       
    55 
       
    56     /**
       
    57      * Two-phased constructor.
       
    58      */
       
    59     static CPIMImageScaler* NewL();
       
    60 
       
    61     /**
       
    62      * Destructor.
       
    63      */
       
    64     virtual ~CPIMImageScaler();
       
    65 
       
    66 public: // New functions
       
    67 
       
    68     /**
       
    69      * Scales the bitmap to thumbnail size (80x96) if necessary.
       
    70      * The image is not scaled, if it already is smaller than necessary.
       
    71      *
       
    72      * @param aSrcImage Source image.
       
    73      * @return thumbnail sized full color JPEG as a descriptor. Caller takes
       
    74      * the ownership.
       
    75      */
       
    76     HBufC8* ScaleL(TDesC8& aSrcImage);
       
    77 
       
    78 public: // CActive
       
    79     void RunL();
       
    80     void DoCancel();
       
    81 
       
    82 private:
       
    83 
       
    84     /**
       
    85      * C++ default constructor.
       
    86      */
       
    87     CPIMImageScaler();
       
    88 
       
    89     /**
       
    90      * Second phase constructor
       
    91      */
       
    92     void ConstructL();
       
    93 
       
    94     /**
       
    95      * Completes the operation
       
    96      * @param aError Error status or KErrNone if no error
       
    97      */
       
    98     void Complete(TInt aError);
       
    99 
       
   100     /**
       
   101      * Checks the given size. If the size is larger than required,
       
   102      * returns true
       
   103      */
       
   104     TBool CheckSize(TSize aSize);
       
   105 
       
   106     /**
       
   107      * Encodes the image
       
   108      */
       
   109     void Encode();
       
   110 
       
   111 private: // Data
       
   112 
       
   113     // Opens JPEG images from a descriptor, owned
       
   114     CImageDecoder* iImageReader;
       
   115 
       
   116     // Converts bitmap to a JPEG image, owned
       
   117     CImageEncoder* iImageWriter;
       
   118 
       
   119     // Scales bitmaps,owned
       
   120     CBitmapScaler* iBitmapScaler;
       
   121 
       
   122     // Holds the encoded image. Owned while processing the image
       
   123     // when the image is returned, this pointer is changed to NULL.
       
   124     HBufC8* iImage;
       
   125 
       
   126     // Holds the bitmap. Owned.
       
   127     CFbsBitmap* iBitmap;
       
   128 
       
   129     // Waits for the operation to complete. Owned.
       
   130     CActiveSchedulerWait* iWait;
       
   131 
       
   132     // Current state
       
   133     TState iState;
       
   134 
       
   135     // Error code, propagated upwards on error
       
   136     TInt iError;
       
   137 
       
   138     // Do we have a connection to Font and Bitmap Server
       
   139     TBool iFbsSessionConnected;
       
   140 
       
   141     RFs iFileServer;
       
   142 
       
   143 };
       
   144 
       
   145 #endif // CPIMIMAGESCALER_H
       
   146 // End of File