|
1 /* |
|
2 * Copyright (c) 2006-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: Implementation of base DLNA profile resolver class for image |
|
15 * files. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // system includes |
|
25 #include <imageconversion.h> |
|
26 #include <caf/caftypes.h> // ContentAccess |
|
27 #include <badesca.h> // CDesC16ArrayFlat |
|
28 |
|
29 // user includes |
|
30 #include "upnpimagesolverbase.h" |
|
31 |
|
32 _LIT( KComponentLogfile, "dlnaprofiler.txt"); |
|
33 #include "upnplog.h" |
|
34 |
|
35 // constants |
|
36 _LIT8( KImageJpeg, "image/jpeg" ); |
|
37 _LIT( KJpeg_sm, "JPEG_SM" ); |
|
38 _LIT( KJpeg_med, "JPEG_MED" ); |
|
39 _LIT( KJpeg_lrg, "JPEG_LRG" ); |
|
40 |
|
41 _LIT( KJpeg_tn, "JPEG_TN" ); |
|
42 _LIT( KJpeg_lrg_ico, "JPEG_LRG_ICO" ); |
|
43 _LIT( KJpeg_sm_ico, "JPEG_SM_ICO" ); |
|
44 |
|
45 _LIT8( KImagePng, "image/png" ); |
|
46 _LIT( KPngLrg, "PNG_LRG" ); |
|
47 |
|
48 |
|
49 const TInt KJpeg_smico_max_width = 48; |
|
50 const TInt KJpeg_smico_max_height = 48; |
|
51 const TInt KJpeg_lrgico_max_width = 120; |
|
52 const TInt KJpeg_lrgico_max_height = 120; |
|
53 const TInt KJpeg_sm_max_width = 640; |
|
54 const TInt KJpeg_sm_max_height = 480; |
|
55 const TInt KJpeg_med_max_width = 1024; |
|
56 const TInt KJpeg_med_max_height = 768; |
|
57 const TInt KJpeg_lrg_max_width = 4096; |
|
58 const TInt KJpeg_lrg_max_height = 4096; |
|
59 const TInt KPng_lrg_max_width = 4096; |
|
60 const TInt KPng_lrg_max_height = 4096; |
|
61 |
|
62 // ======== LOCAL FUNCTIONS ======== |
|
63 // NONE |
|
64 |
|
65 // ======== MEMBER FUNCTIONS ======== |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CUpnpImageSolverBase C++ constructor |
|
69 // -------------------------------------------------------------------------- |
|
70 // |
|
71 CUpnpImageSolverBase::CUpnpImageSolverBase() |
|
72 { |
|
73 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase constructor" ); |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CUpnpImageSolverBase::ConstructL |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 void CUpnpImageSolverBase::ConstructL() |
|
81 { |
|
82 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase::ConstructL" ); |
|
83 } |
|
84 |
|
85 |
|
86 // -------------------------------------------------------------------------- |
|
87 // CUpnpImageSolverBase::NewL |
|
88 // -------------------------------------------------------------------------- |
|
89 // |
|
90 CUpnpImageSolverBase* CUpnpImageSolverBase::NewL() |
|
91 { |
|
92 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase::NewL" ); |
|
93 CUpnpImageSolverBase* self = CUpnpImageSolverBase::NewLC(); |
|
94 CleanupStack::Pop( self ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // -------------------------------------------------------------------------- |
|
100 // CUpnpImageSolverBase::NewLC |
|
101 // -------------------------------------------------------------------------- |
|
102 // |
|
103 CUpnpImageSolverBase* CUpnpImageSolverBase::NewLC() |
|
104 { |
|
105 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase::NewLC" ); |
|
106 CUpnpImageSolverBase* self = new( ELeave ) CUpnpImageSolverBase; |
|
107 CleanupStack::PushL( self ); |
|
108 self->ConstructL(); |
|
109 return self; |
|
110 } |
|
111 |
|
112 |
|
113 // -------------------------------------------------------------------------- |
|
114 // CUpnpImageSolverBase destructor |
|
115 // -------------------------------------------------------------------------- |
|
116 // |
|
117 CUpnpImageSolverBase::~CUpnpImageSolverBase() |
|
118 { |
|
119 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase destructor" ); |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // From class MUpnpProfiler. |
|
124 // SupportedProfilesL returns DLNA profiles that are currently supported. |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CUpnpImageSolverBase::SupportedProfilesL( |
|
128 CDesC16ArrayFlat* aProfiles ) const |
|
129 { |
|
130 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase::\ |
|
131 SupportedProfilesL" ); |
|
132 TInt retval = KErrNone; |
|
133 |
|
134 if ( !aProfiles ) |
|
135 { |
|
136 // Invalid parameter |
|
137 retval = KErrArgument; |
|
138 } |
|
139 else |
|
140 { |
|
141 // append all new profiles recognized by this solver |
|
142 // do not allow duplicates |
|
143 TInt tempPos = KErrNotFound; |
|
144 |
|
145 if ( aProfiles->Find( KJpeg_sm(), tempPos, ECmpFolded ) ) |
|
146 { |
|
147 aProfiles->AppendL( KJpeg_sm() ); |
|
148 } |
|
149 if ( aProfiles->Find( KJpeg_med(), tempPos, ECmpFolded ) ) |
|
150 { |
|
151 aProfiles->AppendL( KJpeg_med() ); |
|
152 } |
|
153 if ( aProfiles->Find( KJpeg_lrg(), tempPos, ECmpFolded ) ) |
|
154 { |
|
155 aProfiles->AppendL( KJpeg_lrg() ); |
|
156 } |
|
157 if ( aProfiles->Find( KPngLrg(), tempPos, ECmpFolded ) ) |
|
158 { |
|
159 aProfiles->AppendL( KPngLrg() ); |
|
160 } |
|
161 if ( aProfiles->Find( KJpeg_tn(), tempPos, ECmpFolded ) ) |
|
162 { |
|
163 aProfiles->AppendL( KJpeg_tn() ); |
|
164 } |
|
165 if ( aProfiles->Find( KJpeg_lrg_ico(), tempPos, ECmpFolded ) ) |
|
166 { |
|
167 aProfiles->AppendL( KJpeg_lrg_ico() ); |
|
168 } |
|
169 if ( aProfiles->Find( KJpeg_sm_ico(), tempPos, ECmpFolded ) ) |
|
170 { |
|
171 aProfiles->AppendL( KJpeg_sm_ico() ); |
|
172 } |
|
173 |
|
174 |
|
175 } |
|
176 |
|
177 return retval; |
|
178 } |
|
179 |
|
180 // -------------------------------------------------------------------------- |
|
181 // From class MUpnpProfiler. |
|
182 // ProfileForFileL is for resolving a DLNA profile of a given file. Besides |
|
183 // of file name, also mime type of the file is passed as a parameter in order |
|
184 // to avoid re-opening the file. |
|
185 // -------------------------------------------------------------------------- |
|
186 // |
|
187 HBufC* CUpnpImageSolverBase::ProfileForFileL( const TDesC& /*aFilename*/, |
|
188 const TDesC8& aMimetype, |
|
189 RFile& aFile ) |
|
190 { |
|
191 __LOG( "[UPnPDlnaProfiler] CUpnpImageSolverBase::ProfileForFileL" ); |
|
192 HBufC* retval = NULL; |
|
193 |
|
194 |
|
195 CImageDecoder* imageDecoder = CImageDecoder::FileNewL( |
|
196 aFile, |
|
197 aMimetype, |
|
198 ContentAccess::EPeek ); |
|
199 |
|
200 CleanupStack::PushL( imageDecoder ); |
|
201 |
|
202 TSize imageResolution = imageDecoder->FrameInfo().iOverallSizeInPixels; |
|
203 |
|
204 if ( aMimetype.Compare( KImageJpeg() ) == 0 ) |
|
205 { |
|
206 // assuming here that thumbnails are not supported and that we do |
|
207 // not use device icons or at least we do not resolve DLNA profile |
|
208 // of device icons with this component. |
|
209 |
|
210 if ( imageResolution.iWidth <= KJpeg_smico_max_width && |
|
211 imageResolution.iHeight <= KJpeg_smico_max_height ) |
|
212 { |
|
213 retval = HBufC::NewL( KJpeg_sm_ico().Length() ); |
|
214 retval->Des().Append( KJpeg_sm_ico() ); |
|
215 } |
|
216 else if ( imageResolution.iWidth <= KJpeg_lrgico_max_width && |
|
217 imageResolution.iHeight <= KJpeg_lrgico_max_height ) |
|
218 { |
|
219 retval = HBufC::NewL( KJpeg_lrg_ico().Length() ); |
|
220 retval->Des().Append( KJpeg_lrg_ico() ); |
|
221 } |
|
222 else if ( imageResolution.iWidth <= KJpeg_sm_max_width && |
|
223 imageResolution.iHeight <= KJpeg_sm_max_height ) |
|
224 { |
|
225 retval = HBufC::NewL( KJpeg_sm().Length() ); |
|
226 retval->Des().Append( KJpeg_sm() ); |
|
227 } |
|
228 else if ( imageResolution.iWidth <= KJpeg_med_max_width && |
|
229 imageResolution.iHeight <= KJpeg_med_max_height ) |
|
230 { |
|
231 retval = HBufC::NewL( KJpeg_med().Length() ); |
|
232 retval->Des().Append( KJpeg_med() ); |
|
233 } |
|
234 else if ( imageResolution.iWidth <= KJpeg_lrg_max_width && |
|
235 imageResolution.iHeight <= KJpeg_lrg_max_height ) |
|
236 { |
|
237 retval = HBufC::NewL( KJpeg_lrg().Length() ); |
|
238 retval->Des().Append( KJpeg_lrg() ); |
|
239 } |
|
240 |
|
241 } |
|
242 else if ( aMimetype.Compare( KImagePng() ) == 0 ) |
|
243 { |
|
244 // assuming here that thumbnails are not supported and that we do |
|
245 // not use device icons or at least we do not resolve DLNA profile |
|
246 // of device icons with this component. This leads to profiling all |
|
247 // png-files as PNG_LRG in case their size is less than 4096x4096. |
|
248 if ( imageResolution.iWidth <= KPng_lrg_max_width && |
|
249 imageResolution.iHeight <= KPng_lrg_max_height ) |
|
250 { |
|
251 retval = HBufC::NewL( KPngLrg().Length() ); |
|
252 retval->Des().Append( KPngLrg() ); |
|
253 } |
|
254 } |
|
255 |
|
256 // clean up |
|
257 CleanupStack::PopAndDestroy( imageDecoder ); |
|
258 |
|
259 return retval; |
|
260 } |
|
261 |
|
262 // end of file |