|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #ifndef SWTIMAGEDATALOADER_H |
|
14 #define SWTIMAGEDATALOADER_H |
|
15 |
|
16 |
|
17 #include "eswtgraphics.h" |
|
18 |
|
19 |
|
20 class CImageDecoder; |
|
21 class CImageEncoder; |
|
22 class TFrameInfo; |
|
23 |
|
24 |
|
25 /** |
|
26 * CSwtImageDataLoader |
|
27 * Class used to encode and decode images (PNG, GIF, JPG). |
|
28 * @lib eswt |
|
29 */ |
|
30 NONSHARABLE_CLASS(CSwtImageDataLoader) |
|
31 : public CActive |
|
32 , public MSwtImageDataLoader |
|
33 { |
|
34 // Own methods |
|
35 public: |
|
36 |
|
37 /** |
|
38 * Two phase constructor. |
|
39 * Create the native object in charge of load and save image from/to a stream or a file. |
|
40 */ |
|
41 static CSwtImageDataLoader* NewL(); |
|
42 |
|
43 // From MSwtImageDataLoader |
|
44 public: |
|
45 void EncodeImageToFileL(MSwtImageData& aImageData, |
|
46 TInt aFormat, const TDesC& aDestination); |
|
47 HBufC8* EncodeImageToStreamL(MSwtImageData& aImageData, TInt aFormat); |
|
48 void DecodeImageL(const TDesC& aFileName); |
|
49 void DecodeWholeImageFromBufferL(const TDesC8& aBuffer); |
|
50 void DecodeImageFromBufferL(const TDesC8& aBuffer); |
|
51 void AppendDataL(const TDesC8& aBuffer); //loading |
|
52 CSwtImageDataArray* GetImageData(); |
|
53 void Dispose(); |
|
54 TInt GetLogicalScreenHeight(); |
|
55 TInt GetLogicalScreenWidth(); |
|
56 |
|
57 // Own methods |
|
58 private: |
|
59 TBool DecodeNextFrameL(); //starting |
|
60 void DecodeFrameL(TInt aIndexOfFrame); //starting |
|
61 |
|
62 protected: |
|
63 /** |
|
64 * Destructor. |
|
65 */ |
|
66 ~CSwtImageDataLoader(); |
|
67 |
|
68 private: |
|
69 CSwtImageDataLoader(); |
|
70 void ConstructL(); |
|
71 void SetImageDataL(MSwtImageData& aImageData); |
|
72 |
|
73 /** |
|
74 * Extract the ImageData from the members bitmap. |
|
75 */ |
|
76 void ExtractImagedataL(); |
|
77 |
|
78 /** |
|
79 * Build the mask bitmap if needed. |
|
80 */ |
|
81 void SetMaskL(const TFrameInfo& aInfo); |
|
82 |
|
83 /** |
|
84 * Ensure that the bitmap resources are freed before |
|
85 * reusing the decoder (for multi frame image). |
|
86 */ |
|
87 void FreeBitmaps(); |
|
88 |
|
89 /** |
|
90 * Free buffers. |
|
91 */ |
|
92 void FreeBuffers(); |
|
93 |
|
94 /** |
|
95 * Set the logical values for height or width equal to |
|
96 * the values of the greatest frame (for height or width). |
|
97 */ |
|
98 void CSwtImageDataLoader::SetLogicalScreenValues(const TFrameInfo& aInfo); |
|
99 |
|
100 /** |
|
101 * Set the x and y coordinates of the image in the current frame. |
|
102 */ |
|
103 void SetFrameInfosL(const TFrameInfo& aInfo); |
|
104 |
|
105 /** |
|
106 * Leaves if a leave happens. Transforms the leave's code into one expected by eSWT. |
|
107 * A leave code that is not handled in the function causes |
|
108 * the leave to be performed with the unchanged leave code. |
|
109 * @param aLeaveCode : the leave code to convert(if equal to KerrNone : do not leave) |
|
110 */ |
|
111 void LeaveIfErrorFromICLDecoderL(TInt aLeaveCode) const; |
|
112 |
|
113 |
|
114 /** |
|
115 * Leaves if a leave happens. Transforms the leave's code into one expected by eSWT. |
|
116 * A leave code that is not handled in the function causes |
|
117 * the leave to be performed with the unchanged leave code. |
|
118 * @param aLeaveCode : the leave code to convert(if equal to KerrNone : do not leave) |
|
119 */ |
|
120 void LeaveIfErrorFromICLEncoderL(TInt aLeaveCode) const; |
|
121 |
|
122 /** |
|
123 * Verify the file pointed by destination can be created and does not already exists. |
|
124 * @param aDestination : The file that is checked |
|
125 * @param aFs : a RFs object. |
|
126 */ |
|
127 void CheckDestinationL(const TDesC& aDestination, const RFs& aFs) const; |
|
128 |
|
129 const TDesC8& GetMimeType(TSwtImageType aFormat) const; |
|
130 |
|
131 // From CActive |
|
132 void RunL(); |
|
133 void DoCancel(); |
|
134 TInt RunError(TInt aError); |
|
135 |
|
136 private: |
|
137 CFbsBitmap* iMask; // The possible mask of the image |
|
138 CFbsBitmap* iBitmap; // The image bitmap (without its mask) |
|
139 MSwtImageData::TInfo iInfo; |
|
140 TSize iLogicalScreenValues; // LogicalScreenHeight and Width |
|
141 TPoint iImageCoordinates; // The coordinates of the frame within the screen in pixels. |
|
142 TInt iDelay; // The delay time of a gif |
|
143 TSwtGifDisposal iDisposal; // The disposal method of a gif image |
|
144 CImageDecoder* iDecoder; // Current decoder. Is a member to be persistent in order to be used asynchronously |
|
145 MSwtImageData* iImageData; // The imageData built when the conversion is finished |
|
146 CSwtImageDataArray* iImageDataArray; // The imageData array built step by step depending on how many images are stored in the image file/stream |
|
147 TInt iNextFrameToDecode; // The next frame we will decode |
|
148 HBufC8* iBuffer; // The data to decode when loading or the data encoded when saving |
|
149 TBool iStartDecodingAnother;// ETrue if a frame has just been decoded and ready to decode another frame. |
|
150 TPtr8 iDesc; // The descriptor furnished to the Convert function |
|
151 TInt iResult; // The code returned to the caller. |
|
152 TBool iWholeImageAtOnce; // ETrue when decoding whole image in one shot |
|
153 CImageEncoder* iEncoder; // Current encoder. Is a member to be persistent in order to be used asynchronously |
|
154 CActiveScheduler* iActiveScheduler; // Installed active scheduler. |
|
155 RFs iFs; // File server session. |
|
156 TBool iIsGif; |
|
157 TRequestStatus* iImageStatus; |
|
158 }; |
|
159 |
|
160 |
|
161 #endif // SWTIMAGEDATALOADER_H |