Project

General

Profile

Patch #764 ยป exiv2-0.21.1_psdimage.patch

Michael Ulbrich, 04 Mar 2011 13:02

View differences:

psdimage.cpp 2011-03-04 21:24:02.000000000 +0100
400 400
            uint32_t resourceType = getULong(buf, bigEndian);
401 401

  
402 402
            if (resourceType != kPhotoshopResourceType) {
403
                break; // bad resource type
403
                throw Error(3, "Photoshop"); // bad resource type
404 404
            }
405 405
            uint16_t resourceId = getUShort(buf + 4, bigEndian);
406 406
            uint32_t resourceNameLength = buf[6];
......
416 416
            if (io_->read(buf, 4) != 4) throw Error(3, "Photoshop");
417 417

  
418 418
            uint32_t resourceSize = getULong(buf, bigEndian);
419
            uint32_t pResourceSize = (resourceSize + 1) & ~1;    // padded resource size
419 420
            uint32_t curOffset = io_->tell();
420 421

  
421 422
            // Write IPTC_NAA resource block
422 423
            if ((resourceId == kPhotoshopResourceID_IPTC_NAA  ||
423 424
                 resourceId >  kPhotoshopResourceID_IPTC_NAA) && iptcDone == false) {
424 425
                newResLength += writeIptcData(iptcData_, outIo);
425
                resourceSize = (resourceSize + 1) & ~1;    // adjust for padding
426 426
                iptcDone = true;
427 427
            }
428 428

  
......
430 430
            else if ((resourceId == kPhotoshopResourceID_ExifInfo  ||
431 431
                      resourceId >  kPhotoshopResourceID_ExifInfo) && exifDone == false) {
432 432
                newResLength += writeExifData(exifData_, outIo);
433
                resourceSize = (resourceSize + 1) & ~1;    // adjust for padding
434 433
                exifDone = true;
435 434
            }
436 435

  
......
438 437
            else if ((resourceId == kPhotoshopResourceID_XMPPacket  ||
439 438
                      resourceId >  kPhotoshopResourceID_XMPPacket) && xmpDone == false) {
440 439
                newResLength += writeXmpData(xmpData_, outIo);
441
                resourceSize = (resourceSize + 1) & ~1;    // adjust for padding
442 440
                xmpDone = true;
443 441
            }
444 442

  
......
467 465

  
468 466
                readTotal = 0;
469 467
                toRead = 0;
470
                resourceSize = (resourceSize + 1) & ~1;        // pad to even
471
                while (readTotal < resourceSize) {
472
                    toRead =   static_cast<long>(resourceSize - readTotal) < lbuf.size_
473
                             ? static_cast<long>(resourceSize - readTotal) : lbuf.size_;
468
                while (readTotal < pResourceSize) {
469
                    toRead =   static_cast<long>(pResourceSize - readTotal) < lbuf.size_
470
                             ? static_cast<long>(pResourceSize - readTotal) : lbuf.size_;
474 471
                    if (io_->read(lbuf.pData_, toRead) != toRead) {
475 472
                        throw Error(3, "Photoshop");
476 473
                    }
......
478 475
                    if (outIo.write(lbuf.pData_, toRead) != toRead) throw Error(21);
479 476
                }
480 477
                if (outIo.error()) throw Error(21);
481
                newResLength += resourceSize + adjResourceNameLen + 12;
478
                newResLength += pResourceSize + adjResourceNameLen + 12;
482 479
            }
483 480

  
484
            io_->seek(curOffset + resourceSize, BasicIo::beg);
485
            oldResLength -= (12 + adjResourceNameLen + resourceSize);
481
            io_->seek(curOffset + pResourceSize, BasicIo::beg);
482
            oldResLength -= (12 + adjResourceNameLen + pResourceSize);
486 483
        }
487 484

  
488 485
        // Append IPTC_NAA resource block, if not yet written
    (1-1/1)