1 //*@@@+++@@@@******************************************************************
2 //
3 // Copyright � Microsoft Corp.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // � Redistributions of source code must retain the above copyright notice,
10 //   this list of conditions and the following disclaimer.
11 // � Redistributions in binary form must reproduce the above copyright notice,
12 //   this list of conditions and the following disclaimer in the documentation
13 //   and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
26 //
27 //*@@@---@@@@******************************************************************
28 #pragma once
29 
30 #include <windowsmediaphoto.h>
31 #if !defined(WIN32) || defined(__MINGW32__)
32 #include <wmspecstring.h>
33 #endif
34 
35 #ifndef UNREFERENCED_PARAMETER
36 #define UNREFERENCED_PARAMETER(P) { (P) = (P); }
37 #endif // UNREFERENCED_PARAMETER
38 
39 //================================================================
40 // Container
41 //================================================================
42 
43 // Keep these in sort order so that we can easily confirm we are outputting tags in ascending order
44 #define WMP_tagNull 0
45 
46 #define WMP_tagDocumentName         0x010d  // Descriptive metadata tag
47 #define WMP_tagImageDescription     0x010e  // Descriptive metadata tag
48 #define WMP_tagCameraMake           0x010f  // Descriptive metadata tag
49 #define WMP_tagCameraModel          0x0110  // Descriptive metadata tag
50 #define WMP_tagPageName             0x011d  // Descriptive metadata tag
51 #define WMP_tagPageNumber           0x0129  // Descriptive metadata tag
52 #define WMP_tagSoftware             0x0131  // Descriptive metadata tag
53 #define WMP_tagDateTime             0x0132  // Descriptive metadata tag
54 #define WMP_tagArtist               0x013b  // Descriptive metadata tag
55 #define WMP_tagHostComputer         0x013c  // Descriptive metadata tag
56 
57 #define WMP_tagXMPMetadata 0x02bc
58 
59 #define WMP_tagRatingStars          0x4746  // Descriptive metadata tag
60 #define WMP_tagRatingValue          0x4749  // Descriptive metadata tag
61 #define WMP_tagCopyright            0x8298  // Descriptive metadata tag
62 
63 #define WMP_tagEXIFMetadata 0x8769
64 #define WMP_tagGPSInfoMetadata 0x8825
65 #define WMP_tagIPTCNAAMetadata 0x83bb
66 #define WMP_tagPhotoshopMetadata 0x8649
67 #define WMP_tagInteroperabilityIFD 0xa005
68 #define WMP_tagIccProfile 0x8773 // Need to use same tag as TIFF!!
69 
70 #define WMP_tagCaption              0x9c9b  // Descriptive metadata tag
71 
72 #define WMP_tagPixelFormat 0xbc01
73 #define WMP_tagTransformation 0xbc02
74 #define WMP_tagCompression 0xbc03
75 #define WMP_tagImageType 0xbc04
76 
77 #define WMP_tagImageWidth 0xbc80
78 #define WMP_tagImageHeight 0xbc81
79 
80 #define WMP_tagWidthResolution 0xbc82
81 #define WMP_tagHeightResolution 0xbc83
82 
83 #define WMP_tagImageOffset 0xbcc0
84 #define WMP_tagImageByteCount 0xbcc1
85 #define WMP_tagAlphaOffset 0xbcc2
86 #define WMP_tagAlphaByteCount 0xbcc3
87 #define WMP_tagImageDataDiscard 0xbcc4
88 #define WMP_tagAlphaDataDiscard 0xbcc5
89 
90 
91 #define WMP_typBYTE 1
92 #define WMP_typASCII 2
93 #define WMP_typSHORT 3
94 #define WMP_typLONG 4
95 #define WMP_typRATIONAL 5
96 #define WMP_typSBYTE 6
97 #define WMP_typUNDEFINED 7
98 #define WMP_typSSHORT 8
99 #define WMP_typSLONG 9
100 #define WMP_typSRATIONAL 10
101 #define WMP_typFLOAT 11
102 #define WMP_typDOUBLE 12
103 
104 
105 #define WMP_valCompression 0xbc
106 #define WMP_valWMPhotoID WMP_valCompression
107 
108 
109 #if defined(WIN32) && !defined(__MINGW32__)
110 #define __in_win    __in
111 #define __out_win   __out
112 #endif
113 
114 
115 //================================================================
116 
117 typedef enum
118 {
119     DPKVT_EMPTY = 0,
120     DPKVT_UI1 = 17,
121     DPKVT_UI2 = 18,
122     DPKVT_UI4 = 19,
123     DPKVT_LPSTR = 30,
124     DPKVT_LPWSTR = 31,
125     DPKVT_BYREF = 0x4000,
126 } DPKVARTYPE;
127 
128 typedef struct DPKPROPVARIANT
129 {
130     DPKVARTYPE  vt;
131     union
132     {
133         U8 bVal;        // DPKVT_UI1
134         U16 uiVal;      // DPKVT_UI2
135         U32 ulVal;      // DPKVT_UI4
136         char *pszVal;   // DPKVT_LPSTR
137         U16 *pwszVal;   // DPKVT_LPWSTR
138         U8 *pbVal;      // DPKVT_BYREF | DPKVT_UI1
139     } VT;
140 } DPKPROPVARIANT;
141 
142 typedef struct DESCRIPTIVEMETADATA
143 {
144     DPKPROPVARIANT  pvarImageDescription;   // WMP_tagImageDescription
145     DPKPROPVARIANT  pvarCameraMake;         // WMP_tagCameraMake
146     DPKPROPVARIANT  pvarCameraModel;        // WMP_tagCameraModel
147     DPKPROPVARIANT  pvarSoftware;           // WMP_tagSoftware
148     DPKPROPVARIANT  pvarDateTime;           // WMP_tagDateTime
149     DPKPROPVARIANT  pvarArtist;             // WMP_tagArtist
150     DPKPROPVARIANT  pvarCopyright;          // WMP_tagCopyright
151     DPKPROPVARIANT  pvarRatingStars;        // WMP_tagRatingStars
152     DPKPROPVARIANT  pvarRatingValue;        // WMP_tagRatingValue
153     DPKPROPVARIANT  pvarCaption;            // WMP_tagCaption
154     DPKPROPVARIANT  pvarDocumentName;       // WMP_tagDocumentName
155     DPKPROPVARIANT  pvarPageName;           // WMP_tagPageName
156     DPKPROPVARIANT  pvarPageNumber;         // WMP_tagPageNumber
157     DPKPROPVARIANT  pvarHostComputer;       // WMP_tagHostComputer
158 } DESCRIPTIVEMETADATA;
159 
160 typedef struct tagWmpDE
161 {
162     U16 uTag;
163     U16 uType;
164     U32 uCount;
165     U32 uValueOrOffset;
166 } WmpDE;
167 
168 typedef struct tagWmpDEMisc
169 {
170     U32 uImageOffset;
171     U32 uImageByteCount;
172     U32 uAlphaOffset;
173     U32 uAlphaByteCount;
174 
175     U32 uOffPixelFormat;
176     U32 uOffImageByteCount;
177     U32 uOffAlphaOffset;
178     U32 uOffAlphaByteCount;
179     U32 uColorProfileOffset;
180     U32 uColorProfileByteCount;
181     U32 uXMPMetadataOffset;
182     U32 uXMPMetadataByteCount;
183     U32 uEXIFMetadataOffset;
184     U32 uEXIFMetadataByteCount;
185     U32 uGPSInfoMetadataOffset;
186     U32 uGPSInfoMetadataByteCount;
187     U32 uIPTCNAAMetadataOffset;
188     U32 uIPTCNAAMetadataByteCount;
189     U32 uPhotoshopMetadataOffset;
190     U32 uPhotoshopMetadataByteCount;
191     U32 uDescMetadataOffset;
192     U32 uDescMetadataByteCount;
193 } WmpDEMisc;
194 
195 
196 //================================================================
197 EXTERN_C ERR GetUShort(
198     __in_ecount(1) struct WMPStream* pWS,
199     size_t offPos,
200     __out_ecount(1) U16* puValue
201 );
202 
203 EXTERN_C ERR PutUShort(
204     __in_ecount(1) struct WMPStream* pWS,
205     size_t offPos,
206     U16 uValue
207 );
208 
209 EXTERN_C ERR GetULong(
210     __in_ecount(1) struct WMPStream* pWS,
211     size_t offPos,
212     __out_ecount(1) U32* puValue
213 );
214 
215 EXTERN_C ERR PutULong(
216     __in_ecount(1) struct WMPStream* pWS,
217     size_t offPos,
218     U32 uValue
219 );
220 
221 EXTERN_C ERR WriteWmpDE(
222     __in_ecount(1) struct WMPStream* pWS,
223     size_t *pOffPos,
224     const __in_ecount(1) WmpDE* pDE,
225     const U8 *pbData,
226     U32 *pcbDataWrittenToOffset
227 );
228 
229 
230 EXTERN_C ERR ReadPropvar(__in_ecount(1) struct WMPStream* pWS,
231                          const __in_win U16 uType,
232                          const __in_win U32 uCount,
233                          const __in_win U32 uValue,
234                          __out_win DPKPROPVARIANT *pvar);
235 
236 
237 
238 // read and write little endian words/dwords from a buffer on both big and little endian cpu's
239 // with full buffer overflow checking
240 
241 #define WMP_INTEL_ENDIAN    ('I')
242 
243 EXTERN_C ERR getbfcpy(U8* pbdest, const U8* pb, size_t cb, size_t ofs, U32 n);
244 EXTERN_C ERR getbfw(const U8* pb, size_t cb, size_t ofs, U16* pw);
245 EXTERN_C ERR getbfdw(const U8* pb, size_t cb, size_t ofs, U32* pdw);
246 EXTERN_C ERR getbfwbig(const U8* pb, size_t cb, size_t ofs, U16* pw);
247 EXTERN_C ERR getbfdwbig(const U8* pb, size_t cb, size_t ofs, U32* pdw);
248 EXTERN_C ERR getbfwe(const U8* pb, size_t cb, size_t ofs, U16* pw, U8 endian);
249 EXTERN_C ERR getbfdwe(const U8* pb, size_t cb, size_t ofs, U32* pdw, U8 endian);
250 EXTERN_C ERR setbfcpy(U8* pb, size_t cb, size_t ofs, const U8* pbset, size_t cbset);
251 EXTERN_C ERR setbfw(U8* pb, size_t cb, size_t ofs, U16 dw);
252 EXTERN_C ERR setbfdw(U8* pb, size_t cb, size_t ofs, U32 dw);
253 EXTERN_C ERR setbfwbig(U8* pb, size_t cb, size_t ofs, U16 dw);
254 EXTERN_C ERR setbfdwbig(U8* pb, size_t cb, size_t ofs, U32 dw);
255 EXTERN_C ERR BufferCalcIFDSize(const U8* pb, size_t cb, U32 uIFDOfs, U8 endian, U32 *pcbifd);
256 EXTERN_C ERR StreamCalcIFDSize(struct WMPStream* pWS, U32 uIFDOfs, U32 *pcbifd);
257 EXTERN_C ERR BufferCopyIFD(const U8* pbsrc, U32 cbsrc, U32 ofssrc, U8 endian, U8* pbdest, U32 cbdest, U32* pofsdest);
258 EXTERN_C ERR StreamCopyIFD(struct WMPStream* pWS, U32 ofssrc, U8* pbdest, U32 cbdest, U32* pofsdest);
259