| 65 | } // PgfImage::PgfImage |
| 66 | |
| 67 | void PgfImage::readMetadata() { |
| 68 | #ifdef EXIV2_DEBUG_MESSAGES |
| 69 | std::cerr << "Exiv2::PgfImage::readMetadata: Reading PGF file " << io_->path() << "\n"; |
| 70 | #endif |
| 71 | if (io_->open() != 0) { |
| 72 | throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); |
| 73 | } |
| 74 | IoCloser closer(*io_); |
| 75 | // Ensure that this is the correct image type |
| 76 | if (!isPgfType(*io_, true)) { |
| 77 | if (io_->error() || io_->eof()) |
| 78 | throw Error(ErrorCode::kerFailedToReadImageData); |
| 79 | throw Error(ErrorCode::kerNotAnImage, "PGF"); |
| 80 | } |
| 81 | clearMetadata(); |
| 82 | |
| 83 | readPgfMagicNumber(*io_); |
| 84 | |
| 85 | size_t headerSize = readPgfHeaderSize(*io_); |
| 86 | readPgfHeaderStructure(*io_, pixelWidth_, pixelHeight_); |
| 87 | |
| 88 | // And now, the most interesting, the user data byte array where metadata are stored as small image. |
| 89 | |
| 90 | Internal::enforce(headerSize <= std::numeric_limits<size_t>::max() - 8, ErrorCode::kerCorruptedMetadata); |
| 91 | size_t size = headerSize + 8 - io_->tell(); |
| 92 | |
| 93 | #ifdef EXIV2_DEBUG_MESSAGES |
| 94 | std::cout << "Exiv2::PgfImage::readMetadata: Found Image data (" << size << " bytes)\n"; |
| 95 | #endif |
| 96 | |
| 97 | if (size > io_->size()) |
| 98 | throw Error(ErrorCode::kerInputDataReadFailed); |
| 99 | if (size == 0) |
| 100 | return; |
| 101 | |
| 102 | DataBuf imgData(size); |
| 103 | const size_t bufRead = io_->read(imgData.data(), imgData.size()); |
| 104 | if (io_->error()) |
| 105 | throw Error(ErrorCode::kerFailedToReadImageData); |
| 106 | if (bufRead != imgData.size()) |
| 107 | throw Error(ErrorCode::kerInputDataReadFailed); |
| 108 | |
| 109 | auto image = Exiv2::ImageFactory::open(imgData.c_data(), imgData.size()); |
| 110 | image->readMetadata(); |
| 111 | exifData() = image->exifData(); |
| 112 | iptcData() = image->iptcData(); |
| 113 | xmpData() = image->xmpData(); |
| 114 | } |
| 115 | |
| 116 | void PgfImage::writeMetadata() { |
| 117 | if (io_->open() != 0) { |
nothing calls this directly
no test coverage detected