Project

General

Profile

Bug #565 ยป fix565-0.17.1.patch

Redmine Admin, 23 Jul 2008 04:48

View differences:

../0.17.1-bug565/src/ifd.cpp 2008-07-23 19:36:00.000000000 +0800
566 566
        const iterator e = entries_.end();
567 567
        iterator i;
568 568
        for (i = b; i != e; ++i) {
569
            if (i->size() > 4) {
570
                totalDataSize += i->size();
569
            long sz = i->size();
570
            if (sz > 4) {
571
                sz += sz & 1;                   // Align size to word boundary
572
                totalDataSize += sz;
571 573
            }
572 574
        }
573 575
        for (i = b; i != e; ++i) {
......
575 577
            us2Data(buf + o + 2, i->type(), byteOrder);
576 578
            ul2Data(buf + o + 4, i->count(), byteOrder);
577 579
            if (i->sizeDataArea() > 0) {
578
                long dataAreaOffset = offset_+size()+totalDataSize+dataAreaSize;
579
                i->setDataAreaOffsets(dataAreaOffset, byteOrder);
580
                dataAreaSize += i->sizeDataArea();
580
                long dao = offset_ + size() + totalDataSize + dataAreaSize;
581
                dao += dao & 1;       // Align data area offset to word boundary
582
                i->setDataAreaOffsets(dao, byteOrder);
583
                long das = i->sizeDataArea();
584
                das += das & 1;         // Align data area size to word boundary
585
                dataAreaSize += das; 
581 586
            }
582 587
            if (i->size() > 4) {
583 588
                // Set the offset of the entry, data immediately follows the IFD
584
                i->setOffset(size() + dataSize);
589
                long of = size() + dataSize;
590
                of += of & 1;                   // Align offset to word boundary
591
                i->setOffset(of);
585 592
                l2Data(buf + o + 8, offset_ + i->offset(), byteOrder);
586
                dataSize += i->size();
593
                long ds = i->size();
594
                ds += ds & 1;                // Align data size to word boundary
595
                dataSize += ds;
587 596
            }
588 597
            else {
589 598
                // Copy data into the offset field
......
606 615

  
607 616
        // Add the data of all IFD entries to the data buffer
608 617
        for (i = b; i != e; ++i) {
609
            if (i->size() > 4) {
610
                std::memcpy(buf + o, i->data(), i->size());
611
                o += i->size();
618
            long sz = i->size();
619
            if (sz > 4) {
620
                std::memcpy(buf + o, i->data(), sz);
621
                if ((sz & 1) == 1) {
622
                    // Align data to word boundary
623
                    std::memset(buf + o + sz, 0x0, 1);
624
                    sz += 1;
625
                }
626
                o += sz;
612 627
            }
613 628
        }
614 629

  
615 630
        // Add all data areas to the data buffer
616 631
        for (i = b; i != e; ++i) {
617
            if (i->sizeDataArea() > 0) {
618
                std::memcpy(buf + o, i->dataArea(), i->sizeDataArea());
619
                o += i->sizeDataArea();
632
            long sz = i->sizeDataArea();
633
            if (sz > 0) {
634
                std::memcpy(buf + o, i->dataArea(), sz);
635
                if ((sz & 1) == 1) {
636
                    // Align data area to word boundary
637
                    std::memset(buf + o + sz, 0x0, 1);
638
                    sz += 1;
639
                }
640
                o += sz;
620 641
            }
621 642
        }
622 643

  
......
701 722
        long dataSize = 0;
702 723
        const_iterator end = this->end();
703 724
        for (const_iterator i = begin(); i != end; ++i) {
704
            if (i->size() > 4) dataSize += i->size();
705
            dataSize += i->sizeDataArea();
725
            long sz = i->size();
726
            if (sz > 4) {
727
                sz += sz & 1;                // Align data size to word boundary
728
                dataSize += sz;
729
            }
730
            sz = i->sizeDataArea();
731
            sz += sz & 1;               // Align data area size to word boundary
732
            dataSize += sz;
706 733
        }
707 734
        return dataSize;
708 735
    }
    (1-1/1)