46
46
#define TAG_MAKER_NOTE 0x927C // Maker note
48
48
// CANON cameras have some funny bespoke fields that need further processing...
49
#define TAG_CANON_CAMERA_STATE_1 0x0001
50
#define TAG_CANON_CAMERA_STATE_2 0x0002
51
#define TAG_CANON_CAMERA_STATE_4 0x0004
49
#define TAG_CANON_CAMERA_STATE_0x01 0x0001 // tags under tag 0x001 (CameraSettings)
50
#define TAG_CANON_CAMERA_STATE_0x02 0x0002 // tags under tag 0x002 (FocalLength)
51
#define TAG_CANON_CAMERA_STATE_0x04 0x0004 // tags under tag 0x004 (ShotInfo)
52
#define TAG_CANON_CAMERA_STATE_0x12 0x0012 // tags under tag 0x012 (AFInfo)
53
#define TAG_CANON_CAMERA_STATE_0xA0 0x00A0 // tags under tag 0x0A0 (ProcessingInfo)
54
#define TAG_CANON_CAMERA_STATE_0xE0 0x00E0 // tags under tag 0x0E0 (SensorInfo)
54
57
// =====================================================================
172
175
FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, "Make", &tagMake);
173
176
const char *Maker = (char*)FreeImage_GetTagValue(tagMake);
175
if((strncmp("OLYMP", pval, 5) == 0) || (strncmp("EPSON", pval, 5) == 0) || (strncmp("AGFA", pval, 4) == 0)) {
178
if((strncmp("OLYMP\x00\x01", pval, 7) == 0) || (strncmp("OLYMP\x00\x02", pval, 7) == 0) || (strncmp("EPSON", pval, 5) == 0) || (strncmp("AGFA", pval, 4) == 0)) {
179
// Olympus Type 1 Makernote
177
180
// Epson and Agfa use Olympus maker note standard,
178
181
// see: http://www.ozhiker.com/electronics/pjmt/jpeg_info/
179
*md_model = TagLib::EXIF_MAKERNOTE_OLYMPUS;
182
*md_model = TagLib::EXIF_MAKERNOTE_OLYMPUSTYPE1;
180
183
*subdirOffset = 8;
185
else if(strncmp("OLYMPUS\x00\x49\x49\x03\x00", pval, 12) == 0) {
186
// Olympus Type 2 Makernote
187
// !!! NOT YET SUPPORTED !!!
189
*md_model = TagLib::UNKNOWN;
182
191
else if(strncmp("Nikon", pval, 5) == 0) {
183
192
/* There are two scenarios here:
222
231
} else if ((strncmp("FUJIFILM", pval, 8) == 0) || (Maker && (FreeImage_strnicmp("Fujifilm", Maker, 8) == 0))) {
223
232
// Fujifile Makernote
233
// Fujifilm's Makernote always use Intel order altough the Exif section maybe in Intel order or in Motorola order.
234
// If msb_order == TRUE, the Makernote won't be read:
235
// the value of ifdStart will be 0x0c000000 instead of 0x0000000c and the MakerNote section will be discarded later
236
// in jpeg_read_exif_dir because the IFD is too high
224
237
*md_model = TagLib::EXIF_MAKERNOTE_FUJIFILM;
225
238
DWORD ifdStart = (DWORD) ReadUint32(msb_order, pval + 8);
226
239
*subdirOffset = ifdStart;
270
283
WORD tag_id = FreeImage_GetTagID(tag);
272
if((tag_id == TAG_CANON_CAMERA_STATE_1) || (tag_id == TAG_CANON_CAMERA_STATE_2) || (tag_id == TAG_CANON_CAMERA_STATE_4)) {
273
// this single tag has multiple values within
275
int subTagTypeBase = 0;
278
case TAG_CANON_CAMERA_STATE_1:
279
subTagTypeBase = 0xC100;
282
case TAG_CANON_CAMERA_STATE_2:
283
subTagTypeBase = 0xC200;
286
case TAG_CANON_CAMERA_STATE_4:
287
subTagTypeBase = 0xC400;
292
WORD *pvalue = (WORD*)FreeImage_GetTagValue(tag);
294
// we intentionally skip the first array member
295
for (DWORD i = startIndex; i < FreeImage_GetTagCount(tag); i++) {
297
FITAG *canonTag = FreeImage_CreateTag();
298
if(!canonTag) return;
300
tag_id = (WORD)(subTagTypeBase + i);
302
FreeImage_SetTagID(canonTag, tag_id);
303
FreeImage_SetTagType(canonTag, FIDT_SHORT);
304
FreeImage_SetTagCount(canonTag, 1);
305
FreeImage_SetTagLength(canonTag, 2);
306
FreeImage_SetTagValue(canonTag, &pvalue[i]);
285
int subTagTypeBase = 0;
288
case TAG_CANON_CAMERA_STATE_0x01:
289
subTagTypeBase = 0xC100;
292
case TAG_CANON_CAMERA_STATE_0x02:
293
subTagTypeBase = 0xC200;
296
case TAG_CANON_CAMERA_STATE_0x04:
297
subTagTypeBase = 0xC400;
300
case TAG_CANON_CAMERA_STATE_0x12:
301
subTagTypeBase = 0xC120;
304
case TAG_CANON_CAMERA_STATE_0xA0:
305
subTagTypeBase = 0xCA00;
308
case TAG_CANON_CAMERA_STATE_0xE0:
309
subTagTypeBase = 0xCE00;
315
// process as a normal tag
308
317
// get the tag key and description
309
318
const char *key = s.getTagFieldName(TagLib::EXIF_MAKERNOTE_CANON, tag_id, defaultKey);
310
FreeImage_SetTagKey(canonTag, key);
319
FreeImage_SetTagKey(tag, key);
311
320
const char *description = s.getTagDescription(TagLib::EXIF_MAKERNOTE_CANON, tag_id);
312
FreeImage_SetTagDescription(canonTag, description);
321
FreeImage_SetTagDescription(tag, description);
316
FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, canonTag);
325
FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, tag);
320
FreeImage_DeleteTag(canonTag);
324
// process as a normal tag
334
WORD *pvalue = (WORD*)FreeImage_GetTagValue(tag);
337
FITAG *canonTag = FreeImage_CreateTag();
338
if(!canonTag) return FALSE;
340
// we intentionally skip the first array member (if needed)
341
for (DWORD i = startIndex; i < FreeImage_GetTagCount(tag); i++) {
343
tag_id = (WORD)(subTagTypeBase + i);
345
FreeImage_SetTagID(canonTag, tag_id);
346
FreeImage_SetTagType(canonTag, FIDT_SHORT);
347
FreeImage_SetTagCount(canonTag, 1);
348
FreeImage_SetTagLength(canonTag, 2);
349
FreeImage_SetTagValue(canonTag, &pvalue[i]);
326
351
// get the tag key and description
327
352
const char *key = s.getTagFieldName(TagLib::EXIF_MAKERNOTE_CANON, tag_id, defaultKey);
328
FreeImage_SetTagKey(tag, key);
353
FreeImage_SetTagKey(canonTag, key);
329
354
const char *description = s.getTagDescription(TagLib::EXIF_MAKERNOTE_CANON, tag_id);
330
FreeImage_SetTagDescription(tag, description);
355
FreeImage_SetTagDescription(canonTag, description);
334
FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, tag);
359
FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, canonTag);
364
FreeImage_DeleteTag(canonTag);
537
567
// 4 bytes or less and value is in the dir entry itself
542
570
// if its bigger than 4 bytes, the directory entry contains an offset
543
offset_value = ReadUint32(msb_order, pde + 8);
544
if((size_t) (offset_value + FreeImage_GetTagLength(tag)) > length) {
571
// first check if offset exceeds buffer, at this stage FreeImage_GetTagLength may return invalid data
572
DWORD offset_value = ReadUint32(msb_order, pde + 8);
573
if(offset_value > length) {
574
// a problem occured : delete the tag (not free'd after)
575
FreeImage_DeleteTag(tag);
576
// jump to next entry
579
// now check if offset + tag length exceeds buffer
580
if(offset_value > length - FreeImage_GetTagLength(tag)) {
545
581
// a problem occured : delete the tag (not free'd after)
546
582
FreeImage_DeleteTag(tag);
547
583
// jump to next entry