~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Source/Metadata/Exif.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#define TAG_MAKER_NOTE                  0x927C  // Maker note
47
47
 
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)
52
55
 
53
56
 
54
57
// =====================================================================
172
175
        FreeImage_GetMetadata(FIMD_EXIF_MAIN, dib, "Make", &tagMake);
173
176
        const char *Maker = (char*)FreeImage_GetTagValue(tagMake);
174
177
 
175
 
        if((strncmp("OLYMP", pval, 5) == 0) || (strncmp("EPSON", pval, 5) == 0) || (strncmp("AGFA", pval, 4) == 0)) {
176
 
                // Olympus Makernote
 
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;
181
184
        } 
 
185
        else if(strncmp("OLYMPUS\x00\x49\x49\x03\x00", pval, 12) == 0) {
 
186
                // Olympus Type 2 Makernote
 
187
                // !!! NOT YET SUPPORTED !!!
 
188
                *subdirOffset = 0;
 
189
                *md_model = TagLib::UNKNOWN;
 
190
        }
182
191
        else if(strncmp("Nikon", pval, 5) == 0) {
183
192
                /* There are two scenarios here:
184
193
                 * Type 1:
221
230
                }
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;
261
274
Process a Canon maker note tag. 
262
275
A single Canon tag may contain many other tags within.
263
276
*/
264
 
static void 
 
277
static BOOL 
265
278
processCanonMakerNoteTag(FIBITMAP *dib, FITAG *tag) {
266
279
        char defaultKey[16];
267
280
        DWORD startIndex = 0;
269
282
 
270
283
        WORD tag_id = FreeImage_GetTagID(tag);
271
284
 
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
274
 
 
275
 
                int subTagTypeBase = 0;
276
 
 
277
 
                switch(tag_id) {
278
 
                        case TAG_CANON_CAMERA_STATE_1:
279
 
                                subTagTypeBase = 0xC100;
280
 
                                startIndex = 1;
281
 
                                break;
282
 
                        case TAG_CANON_CAMERA_STATE_2:
283
 
                                subTagTypeBase = 0xC200;
284
 
                                startIndex = 0;
285
 
                                break;
286
 
                        case TAG_CANON_CAMERA_STATE_4:
287
 
                                subTagTypeBase = 0xC400;
288
 
                                startIndex = 2;
289
 
                                break;
290
 
                }
291
 
 
292
 
                WORD *pvalue = (WORD*)FreeImage_GetTagValue(tag);
293
 
 
294
 
        // we intentionally skip the first array member
295
 
        for (DWORD i = startIndex; i < FreeImage_GetTagCount(tag); i++) {
296
 
                        // create a tag
297
 
                        FITAG *canonTag = FreeImage_CreateTag();
298
 
                        if(!canonTag) return;
299
 
 
300
 
                        tag_id = (WORD)(subTagTypeBase + i);
301
 
 
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;
 
286
 
 
287
        switch(tag_id) {
 
288
                case TAG_CANON_CAMERA_STATE_0x01:
 
289
                        subTagTypeBase = 0xC100;
 
290
                        startIndex = 1;
 
291
                        break;
 
292
                case TAG_CANON_CAMERA_STATE_0x02:
 
293
                        subTagTypeBase = 0xC200;
 
294
                        startIndex = 0;
 
295
                        break;
 
296
                case TAG_CANON_CAMERA_STATE_0x04:
 
297
                        subTagTypeBase = 0xC400;
 
298
                        startIndex = 1;
 
299
                        break;
 
300
                case TAG_CANON_CAMERA_STATE_0x12:
 
301
                        subTagTypeBase = 0xC120;
 
302
                        startIndex = 0;
 
303
                        break;
 
304
                case TAG_CANON_CAMERA_STATE_0xA0:
 
305
                        subTagTypeBase = 0xCA00;
 
306
                        startIndex = 1;
 
307
                        break;
 
308
                case TAG_CANON_CAMERA_STATE_0xE0:
 
309
                        subTagTypeBase = 0xCE00;
 
310
                        startIndex = 1;
 
311
                        break;
 
312
 
 
313
                default:
 
314
                {
 
315
                        // process as a normal tag
307
316
 
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);
313
322
 
314
323
                        // store the tag
315
324
                        if(key) {
316
 
                                FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, canonTag);
 
325
                                FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, tag);
317
326
                        }
318
327
 
319
 
                        // delete the tag
320
 
                        FreeImage_DeleteTag(canonTag);
321
 
        }
 
328
                        return TRUE;
 
329
                }
 
330
                break;
 
331
 
322
332
        }
323
 
        else {
324
 
                // process as a normal tag
 
333
 
 
334
        WORD *pvalue = (WORD*)FreeImage_GetTagValue(tag);
 
335
 
 
336
        // create a tag
 
337
        FITAG *canonTag = FreeImage_CreateTag();
 
338
        if(!canonTag) return FALSE;
 
339
 
 
340
        // we intentionally skip the first array member (if needed)
 
341
    for (DWORD i = startIndex; i < FreeImage_GetTagCount(tag); i++) {
 
342
 
 
343
                tag_id = (WORD)(subTagTypeBase + i);
 
344
 
 
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]);
325
350
 
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);
331
356
 
332
357
                // store the tag
333
358
                if(key) {
334
 
                        FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, tag);
 
359
                        FreeImage_SetMetadata(FIMD_EXIF_MAKERNOTE, dib, key, canonTag);
335
360
                }
336
361
        }
 
362
 
 
363
        // delete the tag
 
364
        FreeImage_DeleteTag(canonTag);
 
365
 
 
366
        return TRUE;
337
367
}
338
368
 
339
369
/**
461
491
        @return 
462
492
*/
463
493
static BOOL 
464
 
jpeg_read_exif_dir(FIBITMAP *dib, const BYTE *tiffp, unsigned int offset, unsigned int length, BOOL msb_order) {
 
494
jpeg_read_exif_dir(FIBITMAP *dib, const BYTE *tiffp, unsigned long offset, unsigned int length, BOOL msb_order) {
465
495
        WORD de, nde;
466
496
 
467
497
        std::stack<WORD>                        destack;        // directory entries stack
495
525
                }
496
526
 
497
527
                // remember that we've visited this directory so that we don't visit it again later
498
 
                DWORD visited = (((DWORD)ifdp & 0xFFFF) << 16) | (DWORD)de;
 
528
                DWORD visited = (DWORD)( (((size_t)ifdp & 0xFFFF) << 16) | (size_t)de );
499
529
                if(visitedIFD.find(visited) != visitedIFD.end()) {
500
530
                        continue;
501
531
                } else {
537
567
                                // 4 bytes or less and value is in the dir entry itself
538
568
                                pval = pde + 8;
539
569
                        } else {
540
 
                                DWORD offset_value;
541
 
 
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
 
577
                                        continue;
 
578
                                }
 
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
634
670
        BYTE lsb_first[4] = { 0x49, 0x49, 0x2A, 0x00 };         // Intel order
635
671
        BYTE msb_first[4] = { 0x4D, 0x4D, 0x00, 0x2A };         // Motorola order
636
672
 
637
 
        size_t length = datalen;
 
673
        unsigned int length = datalen;
638
674
        BYTE *profile = (BYTE*)dataptr;
639
675
 
640
676
        // verify the identifying string
663
699
                }
664
700
 
665
701
                // this is the offset to the first IFD
666
 
                size_t first_offset = ReadUint32(bMotorolaOrder, profile + 4);
 
702
                unsigned long first_offset = ReadUint32(bMotorolaOrder, profile + 4);
667
703
 
668
704
                if (first_offset < 8 || first_offset > 16) {
669
705
                        // This is usually set to 8