|
1 /* |
|
2 * Copyright (c) 2003, 2004 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: An internal service class including some utility functions. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "ExifCommon.h" |
|
21 |
|
22 // ============================ MEMBER FUNCTIONS =============================== |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // TExifCommon::SetUint32 |
|
26 // Puts the given 32-bit unsigned integer to the 4-byte location, whose start |
|
27 // point is specified with the given 8-bit unsigned integer pointer. |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 TInt TExifCommon::SetUint32( TUint8* aPtr, TUint32 aUint32 ) |
|
31 { |
|
32 if ( !aPtr ) |
|
33 { |
|
34 return KErrGeneral; |
|
35 } |
|
36 *( aPtr + 3 ) = STATIC_CAST( TUint8, ( aUint32 >> 24 ) & KOneByteMask ); |
|
37 *( aPtr + 2 ) = STATIC_CAST( TUint8, ( aUint32 >> 16 ) & KOneByteMask ); |
|
38 *( aPtr + 1 ) = STATIC_CAST( TUint8, ( aUint32 >> 8 ) & KOneByteMask ); |
|
39 *aPtr = STATIC_CAST( TUint8, aUint32 & KOneByteMask ); |
|
40 return KErrNone; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // TExifCommon::SetUint16 |
|
45 // Puts the given 16-bit unsigned integer to the 2-byte location, whose start |
|
46 // point is specified with the given 8-bit unsigned integer pointer. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 TInt TExifCommon::SetUint16( TUint8* aPtr, TUint16 aUint16 ) |
|
50 { |
|
51 if ( !aPtr ) |
|
52 { |
|
53 return KErrGeneral; |
|
54 } |
|
55 *( aPtr + 1 ) = STATIC_CAST( TUint8, ( aUint16 >> 8 ) & KOneByteMask ); |
|
56 *aPtr = STATIC_CAST( TUint8, aUint16 & KOneByteMask ); |
|
57 return KErrNone; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // TExifCommon::Uint32 |
|
62 // Returns a 32-bit unsigned integer from the location, whose start point is |
|
63 // specified with the given 8-bit unsigned integer pointer. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 TUint32 TExifCommon::Uint32L( TUint8* aPtr ) |
|
67 { |
|
68 if ( !aPtr ) |
|
69 { |
|
70 User::Leave( KErrGeneral ); |
|
71 } |
|
72 TUint32 ret = 0; |
|
73 ret = *( aPtr + 3 ); |
|
74 ret = ( ret << 8 ) + *( aPtr + 2 ); |
|
75 ret = ( ret << 8 ) + *( aPtr + 1 ); |
|
76 ret = ( ret << 8 ) + *aPtr; |
|
77 return ret; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // TExifCommon::Int32 |
|
82 // Returns a 32-bit integer from the location, whose start point is specified |
|
83 // with the given 8-bit integer pointer. |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 TInt32 TExifCommon::Int32L( TUint8* aPtr ) |
|
87 { |
|
88 if ( !aPtr ) |
|
89 { |
|
90 User::Leave( KErrGeneral ); |
|
91 } |
|
92 TUint32 ret = 0; |
|
93 ret = *( aPtr + 3 ); |
|
94 ret = ( ret << 8 ) + *( aPtr + 2 ); |
|
95 ret = ( ret << 8 ) + *( aPtr + 1 ); |
|
96 ret = ( ret << 8 ) + *aPtr; |
|
97 return STATIC_CAST( TInt32, ret ); |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // TExifCommon::Uint16 |
|
102 // Returns a 16-bit unsigned integer from the location, whose start point is |
|
103 // specified with the given 8-bit unsigned integer pointer. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 TUint16 TExifCommon::Uint16L( TUint8* aPtr ) |
|
107 { |
|
108 if ( !aPtr ) |
|
109 { |
|
110 User::Leave( KErrGeneral ); |
|
111 } |
|
112 TUint16 ret = 0; |
|
113 ret = *( aPtr + 1 ); |
|
114 ret = STATIC_CAST( TUint16, ( ret << 8 ) + *aPtr ); |
|
115 return ret; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // TExifCommon::IsValidTagId |
|
120 // Checks if the given 16-bit unsigned integer is one of the defined tag IDs. |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 TBool TExifCommon::IsValidTagId( TUint16 aTagId ) |
|
124 { |
|
125 TInt i = 0; |
|
126 for ( i = 0; i < KNoIfd0Tags; ++i ) |
|
127 { |
|
128 if ( aTagId == ifd0Tags[i].iId ) |
|
129 { |
|
130 return ETrue; |
|
131 } |
|
132 } |
|
133 for ( i = 0; i < KNoIfdExifTags; ++i ) |
|
134 { |
|
135 if ( aTagId == ifdExifTags[i].iId ) |
|
136 { |
|
137 return ETrue; |
|
138 } |
|
139 } |
|
140 for ( i = 0; i < KNoIfd1Tags; ++i ) |
|
141 { |
|
142 if ( aTagId == ifd1Tags[i].iId ) |
|
143 { |
|
144 return ETrue; |
|
145 } |
|
146 } |
|
147 for ( i = 0; i < KNoIfdGpsTags; ++i ) |
|
148 { |
|
149 if ( aTagId == ifdGpsTags[i].iId ) |
|
150 { |
|
151 return ETrue; |
|
152 } |
|
153 } |
|
154 for ( i = 0; i < KNoIfdIntOpTags; ++i ) |
|
155 { |
|
156 if ( aTagId == ifdIntOpTags[i].iId ) |
|
157 { |
|
158 return ETrue; |
|
159 } |
|
160 } |
|
161 LOGTEXT2( _L( "ExifLib: TExifCommon::IsValidTagId() returning EFalse: aTagId=0x%x" ), aTagId ); |
|
162 return EFalse; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // TExifCommon::LocateJpegMarkerPtr |
|
167 // Locates the pointer to the first specified Jpeg Marker from the begining |
|
168 // inside the given interval. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TUint8* TExifCommon::LocateJpegMarkerPtr( |
|
172 TUint16 aMarker, |
|
173 TUint8* aStartPtr, |
|
174 TUint8* aEndPtr) |
|
175 { |
|
176 if ( ( !aStartPtr ) || ( !aEndPtr ) || ( !aMarker ) ) |
|
177 { |
|
178 return NULL; |
|
179 } |
|
180 |
|
181 TUint16 revMarker = |
|
182 STATIC_CAST( TUint16, ( aMarker << 8 ) + ( aMarker >> 8 ) ); |
|
183 --aStartPtr; |
|
184 TUint16 atHand = 0; |
|
185 TInt error = KErrNone; |
|
186 do |
|
187 { |
|
188 if ( aStartPtr >= aEndPtr ) |
|
189 { |
|
190 return NULL; |
|
191 } |
|
192 if ( *( ++aStartPtr ) == KMarkerStart ) |
|
193 { |
|
194 TRAP( error, atHand = TExifCommon::Uint16L( aStartPtr ) ); |
|
195 } |
|
196 } |
|
197 while ( (atHand != revMarker ) && ( error == KErrNone) ); |
|
198 if ( error ) |
|
199 { |
|
200 return NULL; |
|
201 } |
|
202 return aStartPtr; |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // TExifCommon::LocateJpegMarkerPtrFromEnd |
|
207 // Locates the pointer to the first specified Jpeg Marker from the end |
|
208 // inside the given interval. |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 TUint8* TExifCommon::LocateJpegMarkerPtrFromEnd( |
|
212 TUint16 aMarker, |
|
213 TUint8* aStartPtr, |
|
214 TUint8* aEndPtr) |
|
215 { |
|
216 if ( ( !aStartPtr ) || ( !aEndPtr ) || ( !aMarker ) ) |
|
217 { |
|
218 return NULL; |
|
219 } |
|
220 |
|
221 TUint16 revMarker = |
|
222 STATIC_CAST( TUint16, ( aMarker << 8 ) + ( aMarker >> 8 ) ); |
|
223 --aEndPtr; |
|
224 TUint16 atHand = 0; |
|
225 TInt error = KErrNone; |
|
226 do |
|
227 { |
|
228 if ( aEndPtr <= aStartPtr ) |
|
229 { |
|
230 return NULL; |
|
231 } |
|
232 if ( *( --aEndPtr ) == KMarkerStart ) |
|
233 { |
|
234 TRAP( error, atHand = TExifCommon::Uint16L( aEndPtr ) ); |
|
235 } |
|
236 } |
|
237 while ( (atHand != revMarker ) && ( error == KErrNone) ); |
|
238 if ( error ) |
|
239 { |
|
240 return NULL; |
|
241 } |
|
242 return aEndPtr; |
|
243 } |