|
1 /* |
|
2 * Copyright (c) 2004-2007 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: Static factory class for creating file instances. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <IHLImageFactory.h> |
|
21 |
|
22 #include "CIHLFileImage.h" |
|
23 #include "CIHLFileImageExtJpg.h" |
|
24 #include <IclExtJpegApi.h> |
|
25 |
|
26 // Private namespace for constants and functions |
|
27 namespace |
|
28 { |
|
29 // First image index |
|
30 const TInt KIHLFirstImage = 0; |
|
31 const TInt KIHLNullOptions = 0; |
|
32 |
|
33 const TInt KMimeTypeStringLength = 255; |
|
34 _LIT( KJpgType, "image/jpeg" ); |
|
35 |
|
36 |
|
37 // Helper functions |
|
38 // ----------------------------------------------------------------------------- |
|
39 // OpenExtendedFileImageL |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CIHLFileImageExtJpg* OpenExtendedFileImageL( RFs& aFs, const TDesC& aFilename, |
|
43 TInt aImageIndex, const TUint32 aOptions ) |
|
44 { |
|
45 CIHLFileImageExtJpg* fileImageExtJpg = NULL; |
|
46 TRAPD( err, fileImageExtJpg = CIHLFileImageExtJpg::NewL( aFs, aFilename, |
|
47 aImageIndex, aOptions ) ); |
|
48 if( !err ) |
|
49 { |
|
50 // Hw or Sw extended decoder found; check for cropping capability |
|
51 CleanupStack::PushL( fileImageExtJpg ); |
|
52 if( !( fileImageExtJpg->CapabilitiesL() & CExtJpegDecoder::ECapCropping ) ) |
|
53 { |
|
54 //Decoder does not support cropping, use the old implementation |
|
55 CleanupStack::PopAndDestroy( fileImageExtJpg ); |
|
56 fileImageExtJpg = NULL; |
|
57 } |
|
58 else |
|
59 { |
|
60 CleanupStack::Pop( fileImageExtJpg ); |
|
61 } |
|
62 } |
|
63 |
|
64 return fileImageExtJpg; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // MimeTypeIsJpgL |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 TBool MimeTypeIsJpgL( RFile& aFile ) |
|
72 { |
|
73 using namespace ContentAccess; |
|
74 |
|
75 TBuf<KMimeTypeStringLength> mime; |
|
76 CContent* content = CContent::NewL( aFile ); |
|
77 CleanupStack::PushL( content ); |
|
78 CData* data = content->OpenContentL( EPeek ); |
|
79 CleanupStack::PushL( data ); |
|
80 User::LeaveIfError( data->GetStringAttribute( EMimeType, mime ) ); |
|
81 CleanupStack::PopAndDestroy( 2 ); //data, content |
|
82 if( mime.Compare( KJpgType ) == 0 ) return ETrue; |
|
83 return EFalse; |
|
84 } |
|
85 } |
|
86 |
|
87 // ============================ STATIC FUNCTIONS =============================== |
|
88 // ----------------------------------------------------------------------------- |
|
89 // IHLImageFactory::OpenFileImageL |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFs& aFs, const TDesC& aFilename ) |
|
93 { |
|
94 RFile fileHandle; |
|
95 TInt err( fileHandle.Open( aFs, aFilename, EFileShareReadersOnly ) ); |
|
96 if( err ) |
|
97 { |
|
98 User::LeaveIfError( fileHandle.Open( aFs, aFilename, EFileShareAny ) ); |
|
99 } |
|
100 CleanupClosePushL( fileHandle ); |
|
101 |
|
102 if ( MimeTypeIsJpgL( fileHandle ) ) |
|
103 { |
|
104 CIHLFileImageExtJpg* fileImageExtJpg = OpenExtendedFileImageL( aFs, |
|
105 aFilename, |
|
106 KIHLFirstImage, |
|
107 KIHLNullOptions ); |
|
108 if ( fileImageExtJpg ) |
|
109 { |
|
110 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
111 return fileImageExtJpg; |
|
112 } |
|
113 } |
|
114 |
|
115 CIHLFileImage* fileImage = CIHLFileImage::NewL( fileHandle, KIHLFirstImage, KIHLNullOptions ); |
|
116 |
|
117 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
118 |
|
119 return fileImage; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // IHLImageFactory::OpenFileImageL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFs& aFs, const TDesC& aFilename, |
|
127 TInt aImageIndex ) |
|
128 { |
|
129 RFile fileHandle; |
|
130 TInt err( fileHandle.Open( aFs, aFilename, EFileShareReadersOnly ) ); |
|
131 if( err ) |
|
132 { |
|
133 User::LeaveIfError( fileHandle.Open( aFs, aFilename, EFileShareAny ) ); |
|
134 } |
|
135 CleanupClosePushL( fileHandle ); |
|
136 |
|
137 if ( MimeTypeIsJpgL( fileHandle ) ) |
|
138 { |
|
139 CIHLFileImageExtJpg* fileImageExtJpg = OpenExtendedFileImageL( aFs, |
|
140 aFilename, |
|
141 aImageIndex, |
|
142 KIHLNullOptions ); |
|
143 if ( fileImageExtJpg ) |
|
144 { |
|
145 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
146 return fileImageExtJpg; |
|
147 } |
|
148 } |
|
149 |
|
150 CIHLFileImage* fileImage = CIHLFileImage::NewL( fileHandle, aImageIndex, KIHLNullOptions ); |
|
151 |
|
152 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
153 |
|
154 return fileImage; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // IHLImageFactory::OpenFileImageL |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFs& aFs, const TDesC& aFilename, |
|
162 TInt aImageIndex, const TUint32 aOptions ) |
|
163 { |
|
164 RFile fileHandle; |
|
165 TInt err( fileHandle.Open( aFs, aFilename, EFileShareReadersOnly ) ); |
|
166 if( err ) |
|
167 { |
|
168 User::LeaveIfError( fileHandle.Open( aFs, aFilename, EFileShareAny ) ); |
|
169 } |
|
170 CleanupClosePushL( fileHandle ); |
|
171 |
|
172 if ( MimeTypeIsJpgL( fileHandle ) ) |
|
173 { |
|
174 CIHLFileImageExtJpg* fileImageExtJpg = OpenExtendedFileImageL( aFs, |
|
175 aFilename, |
|
176 aImageIndex, |
|
177 aOptions ); |
|
178 if ( fileImageExtJpg ) |
|
179 { |
|
180 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
181 return fileImageExtJpg; |
|
182 } |
|
183 } |
|
184 |
|
185 CIHLFileImage* fileImage = CIHLFileImage::NewL( fileHandle, aImageIndex, aOptions ); |
|
186 |
|
187 CleanupStack::PopAndDestroy(); // fileHandle.Close() |
|
188 |
|
189 return fileImage; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // IHLImageFactory::OpenFileImageL |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFile& aFile ) |
|
197 { |
|
198 return CIHLFileImage::NewL( aFile, KIHLFirstImage, KIHLNullOptions ); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // IHLImageFactory::OpenFileImageL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFile& aFile, TInt aImageIndex ) |
|
206 { |
|
207 return CIHLFileImage::NewL( aFile, aImageIndex, KIHLNullOptions ); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // IHLImageFactory::OpenFileImageL |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 EXPORT_C MIHLFileImage* IHLImageFactory::OpenFileImageL( RFile& aFile, TInt aImageIndex, |
|
215 const TUint32 aOptions ) |
|
216 { |
|
217 return CIHLFileImage::NewL( aFile, aImageIndex, aOptions ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // IHLImageFactory::OpenBufferedFileImageL |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C MIHLFileImage* IHLImageFactory::OpenBufferedFileImageL( RFs& aFs, const TDesC8& aDataBuf ) |
|
225 { |
|
226 return CIHLFileImage::NewL( aFs, aDataBuf, KIHLFirstImage, KIHLNullOptions ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // IHLImageFactory::OpenBufferedFileImageL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C MIHLFileImage* IHLImageFactory::OpenBufferedFileImageL( RFs& aFs, |
|
234 const TDesC8& aDataBuf, TInt aImageIndex ) |
|
235 { |
|
236 return CIHLFileImage::NewL( aFs, aDataBuf, aImageIndex, KIHLNullOptions ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // IHLImageFactory::OpenBufferedFileImageL |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 EXPORT_C MIHLFileImage* IHLImageFactory::OpenBufferedFileImageL( RFs& aFs, |
|
244 const TDesC8& aDataBuf, TInt aImageIndex, const TUint32 aOptions ) |
|
245 { |
|
246 return CIHLFileImage::NewL( aFs, aDataBuf, aImageIndex, aOptions ); |
|
247 } |
|
248 |
|
249 // End of File |