|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "gifscaler.h" |
|
17 #include "GifScalerMain.h" |
|
18 #include "GifScalerBody.h" |
|
19 |
|
20 /** |
|
21 The function NewL constructs a CGifScaler. |
|
22 This version constructs a scaler for scaling and color quantizing only. |
|
23 No mask data is required in this case) |
|
24 |
|
25 @param aSource |
|
26 The bitmap to be re-scaled. |
|
27 @param aOptions |
|
28 Scaling and color quantization options. |
|
29 |
|
30 @leave KErrArgument if the source bitmap or the options are invalid. |
|
31 @panic ENoSourceBitmap if the source bitmap has not been created. |
|
32 |
|
33 @return A pointer to a fully constructed CGifScaler |
|
34 */ |
|
35 |
|
36 EXPORT_C CGifScaler* CGifScaler::NewL(CFbsBitmap& aSource, TOptions aOptions) |
|
37 { |
|
38 CGifScaler* self = new(ELeave) CGifScaler(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(aSource, NULL, aOptions); |
|
41 |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 /** |
|
47 The function NewL constructs a CGifScaler. |
|
48 This version constructs a scaler for scaling and color quantizing an image with transparency. |
|
49 |
|
50 @param aSource |
|
51 The bitmap to be re-scaled. |
|
52 @param aSourceMask |
|
53 The mask bitmap that provides the transparency data. |
|
54 @param aOptions |
|
55 Scaling and color quantization options. |
|
56 |
|
57 @leave KErrArgument if the source bitmap, source mask bitmap, or the options are invalid. |
|
58 @panic ENoSourceBitmap if the source bitmap has not been created. |
|
59 @panic ENoSourceMaskBitmap if the source mask bitmap has not been created. |
|
60 |
|
61 @return A pointer to a fully constructed CGifScaler |
|
62 */ |
|
63 |
|
64 EXPORT_C CGifScaler* CGifScaler::NewL(CFbsBitmap& aSource, CFbsBitmap& aSourceMask, TOptions aOptions) |
|
65 { |
|
66 CGifScaler* self = new(ELeave) CGifScaler(); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(aSource, &aSourceMask, aOptions); |
|
69 |
|
70 CleanupStack::Pop(self); |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 /* |
|
76 Constructor for this class. |
|
77 |
|
78 @internalTechnology |
|
79 */ |
|
80 |
|
81 CGifScaler::CGifScaler() |
|
82 { |
|
83 } |
|
84 |
|
85 |
|
86 /** |
|
87 ConstructL |
|
88 Performs second phase of contruction |
|
89 |
|
90 @internalTechnology |
|
91 */ |
|
92 |
|
93 void CGifScaler::ConstructL(CFbsBitmap& aSource, CFbsBitmap* aSourceMask, TOptions aOptions) |
|
94 { |
|
95 iBody = CBody::NewL(aSource, aSourceMask, aOptions); |
|
96 } |
|
97 |
|
98 |
|
99 /** |
|
100 This is the destructor for the CGifScaler |
|
101 and is responsible for deallocating all resources |
|
102 allocated by the CGifScaler. |
|
103 */ |
|
104 |
|
105 EXPORT_C CGifScaler::~CGifScaler() |
|
106 { |
|
107 Cancel(); |
|
108 delete iBody; |
|
109 } |
|
110 |
|
111 /** |
|
112 Scale the source bitmap and mask to produce a single 8bpp bitmap and an output palette. |
|
113 If a mask was supplied during construction the last index in the palette will be used for transparency. |
|
114 |
|
115 The scaling factor is based on the relative sizes of the source |
|
116 and target bitmaps. The operation is asynchronous. When it is |
|
117 complete, successfully or otherwise, the TRequestStatus |
|
118 aStatus is set, passing the state of the operation. |
|
119 |
|
120 @param aStatus |
|
121 Request status to signal when scaling is complete. |
|
122 @param aDestination |
|
123 The destination bitmap. (EColor256) |
|
124 @param aPalette |
|
125 The output palette. |
|
126 @param aMaintainAspectRatio |
|
127 ETrue - the aspect ratio is retained; |
|
128 this is the default. The same scaling factor is |
|
129 applied in both the horizontal and vertical |
|
130 directions. This is the smaller of the horizontal |
|
131 scaling factor and the vertical scaling factor. |
|
132 EFalse - the aspect ratio need not be |
|
133 retained. |
|
134 */ |
|
135 |
|
136 EXPORT_C void CGifScaler::Scale(TRequestStatus* aStatus, CFbsBitmap& aDestination, CPalette& aPalette, TBool aMaintainAspectRatio) |
|
137 { |
|
138 ASSERT(iBody); |
|
139 iBody->Scale(aStatus, aDestination, aPalette, aMaintainAspectRatio); |
|
140 } |
|
141 |
|
142 /** |
|
143 Scale the source bitmap and mask to produce a single 8bpp bitmap and an output palette, |
|
144 specifying a transparency level to be used when determining whether destination pixels are transparent. |
|
145 If a mask was supplied during construction the last index in the palette will be used for transparency. |
|
146 |
|
147 The scaling factor is based on the relative sizes of the source |
|
148 and target bitmaps. The operation is asynchronous. When it is |
|
149 complete, successfully or otherwise, the TRequestStatus |
|
150 aStatus is set, passing the state of the operation. |
|
151 |
|
152 @param aStatus |
|
153 Request status to signal when scaling is complete. |
|
154 @param aDestination |
|
155 The destination bitmap. (EColor256) |
|
156 @param aPalette |
|
157 The output palette. |
|
158 @param aTransparencyThreshold |
|
159 The transparency level used to determine if destination pixels are transparent. |
|
160 @param aMaintainAspectRatio |
|
161 ETrue - the aspect ratio is retained; |
|
162 this is the default. The same scaling factor is |
|
163 applied in both the horizontal and vertical |
|
164 directions. This is the smaller of the horizontal |
|
165 scaling factor and the vertical scaling factor. |
|
166 EFalse - the aspect ratio need not be |
|
167 retained. |
|
168 */ |
|
169 |
|
170 EXPORT_C void CGifScaler::ThresholdScale(TRequestStatus* aStatus, CFbsBitmap& aDestination, CPalette& aPalette, TUint8 aTransparencyThreshold, TBool aMaintainAspectRatio) |
|
171 { |
|
172 ASSERT(iBody); |
|
173 iBody->Scale(aStatus, aDestination, aPalette, aTransparencyThreshold, aMaintainAspectRatio); |
|
174 } |
|
175 |
|
176 /** |
|
177 Cancel any outstanding activity. |
|
178 */ |
|
179 |
|
180 EXPORT_C void CGifScaler::Cancel() |
|
181 { |
|
182 if (iBody) |
|
183 iBody->Cancel(); |
|
184 } |