|
1 /* |
|
2 * Copyright (c) 2003-2006 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: Exif tag wrapper API implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ExifTagImpl.h" |
|
21 #include "ExifCommon.h" |
|
22 |
|
23 // ============================ CLASS TExifTagInfo ============================= |
|
24 // ============================ MEMBER FUNCTIONS =============================== |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // TExifTagInfo::TExifTagInfo |
|
28 // C++ default constructor can NOT contain any code, that |
|
29 // might leave. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C TExifTagInfo::TExifTagInfo( |
|
33 TUint16 aTagId, |
|
34 CExifTag::TExifTagDataType aDataType, |
|
35 TUint32 aDataCount ): |
|
36 iId( aTagId ), |
|
37 iDataType( aDataType ), |
|
38 iDataCount( aDataCount ) |
|
39 { |
|
40 } |
|
41 |
|
42 |
|
43 // ============================ CLASS CExifTag ================================= |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // Destructor |
|
47 CExifTag::~CExifTag() |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 // ============================ CLASS CExifTagImpl ============================= |
|
53 // ============================ MEMBER FUNCTIONS =============================== |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CExifTagImpl::CExifTagImpl |
|
57 // C++ default constructor can NOT contain any code, that |
|
58 // might leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CExifTagImpl::CExifTagImpl( TExifTagInfo aTagInfo ): iTagInfo( aTagInfo ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CExifTagImpl::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CExifTagImpl::ConstructL( HBufC8* aDataBuffer, TBool aCheckValidity ) |
|
71 { |
|
72 LOGTEXT2( _L( "ExifLib: CExifTagImpl::ConstructL entering aCheckValidity=%d" ), aCheckValidity); |
|
73 if ( !aDataBuffer ) |
|
74 { |
|
75 LOGTEXT( _L( "ExifLib: CExifTagImpl::ConstructL leaving KErrGeneral" ) ); |
|
76 User::Leave( KErrGeneral ); |
|
77 } |
|
78 if ( aCheckValidity && !TExifCommon::IsValidTagId( iTagInfo.iId ) ) |
|
79 { |
|
80 LOGTEXT( _L( "ExifLib: CExifTagImpl::ConstructL leaving KErrNotSupported" ) ); |
|
81 User::Leave( KErrNotSupported ); |
|
82 } |
|
83 |
|
84 TInt wordLength = 1; |
|
85 if ( iTagInfo.iDataType == ETagShort ) |
|
86 { |
|
87 wordLength = 2; |
|
88 } |
|
89 else if ( ( iTagInfo.iDataType == ETagLong ) || |
|
90 ( iTagInfo.iDataType == ETagSlong ) ) |
|
91 { |
|
92 wordLength = 4; |
|
93 } |
|
94 else if ( ( iTagInfo.iDataType == ETagRational ) || |
|
95 ( iTagInfo.iDataType == ETagSrational ) ) |
|
96 { |
|
97 wordLength = 8; |
|
98 } |
|
99 else |
|
100 { |
|
101 // In practice, it never arrives here. |
|
102 } |
|
103 LOGTEXT2( _L( "ExifLib: CExifTagImpl::ConstructL wordLength=%d" ), wordLength ); |
|
104 |
|
105 if ( aDataBuffer->Length() != |
|
106 STATIC_CAST( TInt, wordLength * iTagInfo.iDataCount ) ) |
|
107 { |
|
108 LOGTEXT3( _L( "ExifLib: CExifTagImpl::ConstructL leaving KErrArgument aDataBuffer->Length()=%d, iTagInfo.iDataCount=%d" ), aDataBuffer->Length(), iTagInfo.iDataCount); |
|
109 User::Leave( KErrArgument ); |
|
110 } |
|
111 iData = aDataBuffer; |
|
112 LOGTEXT2( _L( "ExifLib: CExifTagImpl::ConstructL returning aDataBuffer->Length()=%d" ), aDataBuffer->Length() ); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CExifTagImpl::NewL |
|
117 // Two-phased constructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 CExifTagImpl* CExifTagImpl::NewL( |
|
121 TUint16 aTagId, |
|
122 CExifTag::TExifTagDataType aDataType, |
|
123 TUint32 aDataCount, |
|
124 HBufC8* aDataBuffer, |
|
125 TBool aCheckValidity ) |
|
126 { |
|
127 if ( !aDataBuffer->Length() ) |
|
128 { |
|
129 User::Leave( KErrArgument ); |
|
130 } |
|
131 |
|
132 CExifTagImpl* self = new( ELeave ) CExifTagImpl( TExifTagInfo( aTagId, |
|
133 aDataType, aDataCount ) ); |
|
134 CleanupStack::PushL( self ); |
|
135 self->ConstructL( aDataBuffer, aCheckValidity ); |
|
136 CleanupStack::Pop(); |
|
137 return self; |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CExifTagImpl::NewL |
|
142 // Two-phased constructor. |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 CExifTagImpl* CExifTagImpl::NewL( TExifTagInfo aTagInfo, HBufC8* aDataBuffer, TBool aCheckValidity ) |
|
146 { |
|
147 if ( !aDataBuffer ) |
|
148 { |
|
149 User::Leave( KErrGeneral ); |
|
150 } |
|
151 if ( !aDataBuffer->Length() ) |
|
152 { |
|
153 User::Leave( KErrArgument ); |
|
154 } |
|
155 |
|
156 CExifTagImpl* self = new( ELeave ) CExifTagImpl( aTagInfo ); |
|
157 CleanupStack::PushL( self ); |
|
158 self->ConstructL( aDataBuffer, aCheckValidity ); |
|
159 CleanupStack::Pop(); |
|
160 return self; |
|
161 } |
|
162 |
|
163 // Destructor |
|
164 CExifTagImpl::~CExifTagImpl() |
|
165 { |
|
166 if ( iData ) |
|
167 { |
|
168 delete iData; |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CExifTagImpl::DuplicateL |
|
174 // Duplicate constructor. Creates an exact copy instance of the tag. |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 CExifTag* CExifTagImpl::DuplicateL() const |
|
178 { |
|
179 HBufC8* buffer = iData->AllocL(); |
|
180 CleanupStack::PushL( buffer ); |
|
181 CExifTagImpl* tag = CExifTagImpl::NewL( iTagInfo.iId, iTagInfo.iDataType, |
|
182 iTagInfo.iDataCount, buffer, ETrue ); |
|
183 CleanupStack::Pop( buffer ); |
|
184 return tag; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CExifTagImpl::TagInfo |
|
189 // Returns the informative fields of a tag. |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 TExifTagInfo CExifTagImpl::TagInfo() const |
|
193 { |
|
194 return iTagInfo; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CExifTagImpl::Id |
|
199 // Returns the ID of the tag. |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TUint16 CExifTagImpl::Id() const |
|
203 { |
|
204 return iTagInfo.iId; |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CExifTagImpl::DataType |
|
209 // Returns the data type of the tag. |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 CExifTag::TExifTagDataType CExifTagImpl::DataType() const |
|
213 { |
|
214 return iTagInfo.iDataType; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CExifTagImpl::DataCount |
|
219 // Returns the data count of the tag. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TUint32 CExifTagImpl::DataCount() const |
|
223 { |
|
224 return iTagInfo.iDataCount; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CExifTagImpl::Data |
|
229 // Returns the data stored in the tag. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TPtrC8 CExifTagImpl::Data() const |
|
233 { |
|
234 return iData->Des(); |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CExifTagImpl::Size |
|
239 // Returns the total size of the tag in bytes |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 TUint CExifTagImpl::Size() const |
|
243 { |
|
244 // If the real tag data size is smaller than 4 bytes, then total tag size is |
|
245 // the default tag size (12). Otherwise, it is: |
|
246 // Default tag size + real tag data size (+ 1 if tag data size is odd). |
|
247 if ( iData->Length() < 5 ) |
|
248 { |
|
249 return 12; // The default tag size |
|
250 } |
|
251 else |
|
252 { |
|
253 if ( iData->Length() % 2 ) |
|
254 { |
|
255 return ( 12 + iData->Length() + 1 ); // Default tag size + ... |
|
256 } |
|
257 else |
|
258 { |
|
259 return ( 12 + iData->Length() ); // // Default tag size + ... |
|
260 } |
|
261 } |
|
262 } |
|
263 |