diff --git a/app/actions.cpp b/app/actions.cpp index 243d65cb..430a9bb4 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -236,7 +236,7 @@ int Print::printSummary() { auto image = Exiv2::ImageFactory::open(path_); image->readMetadata(); - Exiv2::ExifData& exifData = image->exifData(); + const Exiv2::ExifData& exifData = image->exifData(); align_ = 16; // Filename @@ -428,7 +428,7 @@ bool Print::grepTag(const std::string& key) { bool Print::keyTag(const std::string& key) { bool result = Params::instance().keys_.empty(); - for (auto&& k : Params::instance().keys_) { + for (const auto& k : Params::instance().keys_) { if (result) break; result = key == k; @@ -586,7 +586,7 @@ int Print::printPreviewList() { int cnt = 0; Exiv2::PreviewManager pm(*image); Exiv2::PreviewPropertiesList list = pm.getPreviewProperties(); - for (auto&& pos : list) { + for (const auto& pos : list) { if (manyFiles) { std::cout << std::setfill(' ') << std::left << std::setw(20) << path_ << " "; } @@ -735,7 +735,7 @@ int Erase::eraseThumbnail(Exiv2::Image* image) { } int Erase::eraseExifData(Exiv2::Image* image) { - if (Params::instance().verbose_ && image->exifData().count() > 0) { + if (Params::instance().verbose_ && !image->exifData().empty()) { std::cout << _("Erasing Exif data from the file") << std::endl; } image->clearExifData(); @@ -743,7 +743,7 @@ int Erase::eraseExifData(Exiv2::Image* image) { } int Erase::eraseIptcData(Exiv2::Image* image) { - if (Params::instance().verbose_ && image->iptcData().count() > 0) { + if (Params::instance().verbose_ && !image->iptcData().empty()) { std::cout << _("Erasing IPTC data from the file") << std::endl; } image->clearIptcData(); @@ -759,7 +759,7 @@ int Erase::eraseComment(Exiv2::Image* image) { } int Erase::eraseXmpData(Exiv2::Image* image) { - if (Params::instance().verbose_ && image->xmpData().count() > 0) { + if (Params::instance().verbose_ && !image->xmpData().empty()) { std::cout << _("Erasing XMP data from the file") << std::endl; } image->clearXmpData(); // Quick fix for bug #612 @@ -1141,10 +1141,10 @@ int Modify::applyCommands(Exiv2::Image* pImage) { } // loop through command table and apply each command - ModifyCmds& modifyCmds = Params::instance().modifyCmds_; + const ModifyCmds& modifyCmds = Params::instance().modifyCmds_; int rc = 0; int ret = 0; - for (auto&& cmd : modifyCmds) { + for (const auto& cmd : modifyCmds) { switch (cmd.cmdId_) { case CmdId::add: ret = addMetadatum(pImage, cmd); @@ -1649,7 +1649,7 @@ int str2Tm(const std::string& timeStr, struct tm* tm) { } // str2Tm std::string time2Str(time_t time) { - struct tm* tm = localtime(&time); + auto tm = localtime(&time); return tm2Str(tm); } // time2Str @@ -1732,7 +1732,7 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType std::cout << _("Writing Exif data from") << " " << source << " " << _("to") << " " << target << std::endl; } if (preserve) { - for (auto&& exif : sourceImage->exifData()) { + for (const auto& exif : sourceImage->exifData()) { targetImage->exifData()[exif.key()] = exif.value(); } } else { @@ -1744,7 +1744,7 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType std::cout << _("Writing IPTC data from") << " " << source << " " << _("to") << " " << target << std::endl; } if (preserve) { - for (auto&& iptc : sourceImage->iptcData()) { + for (const auto& iptc : sourceImage->iptcData()) { targetImage->iptcData()[iptc.key()] = iptc.value(); } } else { @@ -1767,7 +1767,7 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType os.close(); rc = 0; } else if (preserve) { - for (auto&& xmp : sourceImage->xmpData()) { + for (const auto& xmp : sourceImage->xmpData()) { targetImage->xmpData()[xmp.key()] = xmp.value(); } } else { diff --git a/app/exiv2.cpp b/app/exiv2.cpp index 12e1d434..063c5332 100644 --- a/app/exiv2.cpp +++ b/app/exiv2.cpp @@ -34,19 +34,19 @@ // ***************************************************************************** // local declarations namespace { -const Params::YodAdjust emptyYodAdjust_[] = { - {false, "-Y", 0}, - {false, "-O", 0}, - {false, "-D", 0}, +constexpr auto emptyYodAdjust_ = std::array{ + Params::YodAdjust{false, "-Y", 0}, + Params::YodAdjust{false, "-O", 0}, + Params::YodAdjust{false, "-D", 0}, }; //! List of all command identifiers and corresponding strings -const CmdIdAndString cmdIdAndString[] = { - {CmdId::add, "add"}, - {CmdId::set, "set"}, - {CmdId::del, "del"}, - {CmdId::reg, "reg"}, - {CmdId::invalid, "invalidCmd"}, // End of list marker +constexpr auto cmdIdAndString = std::array{ + CmdIdAndString{CmdId::add, "add"}, + CmdIdAndString{CmdId::set, "set"}, + CmdIdAndString{CmdId::del, "del"}, + CmdIdAndString{CmdId::reg, "reg"}, + CmdIdAndString{CmdId::invalid, "invalidCmd"}, // End of list marker }; // Return a command Id for a command string @@ -151,7 +151,7 @@ int main(int argc, char* const argv[]) { } else { int w = filesCount > 9 ? filesCount > 99 ? 3 : 2 : 1; int n = 1; - for (auto&& file : params.files_) { + for (const auto& file : params.files_) { // If extracting to stdout then ignore verbose if (params.verbose_ && !(params.action_ & Action::extract && params.target_ & Params::ctStdInOut)) { std::cout << _("File") << " " << std::setw(w) << std::right << n++ << "/" << filesCount << ": " << file @@ -1088,7 +1088,7 @@ bool parseTime(const std::string& ts, int64_t& time) { std::string hstr, mstr, sstr; auto cts = new char[ts.length() + 1]; strcpy(cts, ts.c_str()); - char* tmp = ::strtok(cts, ":"); + auto tmp = ::strtok(cts, ":"); if (tmp) hstr = tmp; tmp = ::strtok(nullptr, ":"); @@ -1430,11 +1430,8 @@ bool parseLine(ModifyCmd& modifyCmd, const std::string& line, int num) { } // parseLine CmdId commandId(const std::string& cmdString) { - int i = 0; - while (cmdIdAndString[i].first != CmdId::invalid && cmdIdAndString[i].second != cmdString) { - ++i; - } - return cmdIdAndString[i].first; + auto it = std::find_if(cmdIdAndString.begin(), cmdIdAndString.end(), [&](auto cs) { return cs.second == cmdString; }); + return it != cmdIdAndString.end() ? it->first : CmdId::invalid; } std::string parseEscapes(const std::string& input) { @@ -1446,7 +1443,7 @@ std::string parseEscapes(const std::string& input) { continue; } size_t escapeStart = i; - if (!(input.length() - 1 > i)) { + if (input.length() - 1 <= i) { result.push_back(ch); continue; } diff --git a/app/exiv2app.hpp b/app/exiv2app.hpp index 86896171..8107774d 100644 --- a/app/exiv2app.hpp +++ b/app/exiv2app.hpp @@ -63,7 +63,7 @@ struct ModifyCmd { //! Container for modification commands using ModifyCmds = std::vector; //! Structure to link command identifiers to strings -using CmdIdAndString = std::pair; +using CmdIdAndString = std::pair; /*! @brief Implements the command line handling for the program. @@ -209,21 +209,21 @@ class Params : public Util::Getopt { int action_{0}; CommonTarget target_; //!< What common target to process. - int64_t adjustment_{0}; //!< Adjustment in seconds. - YodAdjust yodAdjust_[3]; //!< Year, month and day adjustment info. - std::string format_; //!< Filename format (-r option arg). - bool formatSet_{false}; //!< Whether the format is set with -r - CmdFiles cmdFiles_; //!< Names of the modification command files - CmdLines cmdLines_; //!< Commands from the command line - ModifyCmds modifyCmds_; //!< Parsed modification commands - std::string jpegComment_; //!< Jpeg comment to set in the image - std::string directory_; //!< Location for files to extract/insert - std::string suffix_; //!< File extension of the file to insert - Files files_; //!< List of non-option arguments. - PreviewNumbers previewNumbers_; //!< List of preview numbers - std::vector greps_; //!< List of keys to 'grep' from the metadata - Keys keys_; //!< List of keys to match from the metadata - std::string charset_; //!< Charset to use for UNICODE Exif user comment + int64_t adjustment_{0}; //!< Adjustment in seconds. + std::array yodAdjust_; //!< Year, month and day adjustment info. + std::string format_; //!< Filename format (-r option arg). + bool formatSet_{false}; //!< Whether the format is set with -r + CmdFiles cmdFiles_; //!< Names of the modification command files + CmdLines cmdLines_; //!< Commands from the command line + ModifyCmds modifyCmds_; //!< Parsed modification commands + std::string jpegComment_; //!< Jpeg comment to set in the image + std::string directory_; //!< Location for files to extract/insert + std::string suffix_; //!< File extension of the file to insert + Files files_; //!< List of non-option arguments. + PreviewNumbers previewNumbers_; //!< List of preview numbers + std::vector greps_; //!< List of keys to 'grep' from the metadata + Keys keys_; //!< List of keys to match from the metadata + std::string charset_; //!< Charset to use for UNICODE Exif user comment Exiv2::DataBuf stdinBuf; //!< DataBuf with the binary bytes from stdin diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 1a7da741..f1704c84 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -67,7 +67,7 @@ class EXIV2API WebPImage : public Image { //! Finds the offset of header in data. Returns std::string::npos if the header isn't found. static size_t getHeaderOffset(const byte* data, size_t data_size, const byte* header, size_t header_size); - static bool equalsWebPTag(Exiv2::DataBuf& buf, const char* str); + static bool equalsWebPTag(const Exiv2::DataBuf& buf, const char* str); void debugPrintHex(byte* data, size_t size); void decodeChunks(uint32_t filesize); void inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_alpha, bool has_icc, uint32_t width, diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 8422d359..9801233f 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2581,7 +2581,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa ) { return os << "Canon EF-S 24mm f/2.8 STM"; } - } catch (std::exception&) { + } catch (const std::exception&) { }; return EXV_PRINT_TAG(canonCsLensType)(os, value, metadata); @@ -2652,7 +2652,7 @@ std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& value, co auto tc = base_match[5].length() > 0 ? std::stof(base_match[5].str()) : 1.f; - int flMax = static_cast(std::stof(base_match[2].str()) * tc); + auto flMax = static_cast(std::stof(base_match[2].str()) * tc); int flMin = base_match[1].length() > 0 ? static_cast(std::stof(base_match[1].str()) * tc) : flMax; auto aperMaxTele = std::stof(base_match[4].str()) * tc; diff --git a/src/casiomn_int.cpp b/src/casiomn_int.cpp index f182c3f5..7c3f993e 100644 --- a/src/casiomn_int.cpp +++ b/src/casiomn_int.cpp @@ -148,11 +148,10 @@ std::ostream& CasioMakerNote::print0x0015(std::ostream& os, const Value& value, if (numbers.size() >= 10) { // year long l = (numbers[0] - 48) * 10 + (numbers[1] - 48); - if (l < 70) { + if (l < 70) l += 2000; - } else { + else l += 1900; - }; os << l << ":"; // month, day, hour, minutes os << numbers[2] << numbers[3] << ":" << numbers[4] << numbers[5] << " " << numbers[6] << numbers[7] << ":" @@ -160,10 +159,9 @@ std::ostream& CasioMakerNote::print0x0015(std::ostream& os, const Value& value, // optional seconds if (numbers.size() == 12) { os << ":" << numbers[10] << numbers[11]; - }; - } else { + } + } else os << value; - }; return os; } @@ -393,18 +391,16 @@ std::ostream& Casio2MakerNote::print0x2001(std::ostream& os, const Value& value, if (numbers.size() >= 10) { // year long l = (numbers[0] - 48) * 10 + (numbers[1] - 48); - if (l < 70) { + if (l < 70) l += 2000; - } else { + else l += 1900; - }; os << l << ":"; // month, day, hour, minutes os << numbers[2] << numbers[3] << ":" << numbers[4] << numbers[5] << " " << numbers[6] << numbers[7] << ":" << numbers[8] << numbers[9]; - } else { + } else os << value; - }; return os; } @@ -414,7 +410,7 @@ std::ostream& Casio2MakerNote::print0x2022(std::ostream& os, const Value& value, os << N_("Inf"); os.flags(f); return os; - }; + } std::ostringstream oss; oss.copyfmt(os); os << std::fixed << std::setprecision(2) << value.toInt64() / 1000.0 << _(" m"); diff --git a/src/cr2image.cpp b/src/cr2image.cpp index d5bed61b..426e2a16 100644 --- a/src/cr2image.cpp +++ b/src/cr2image.cpp @@ -81,15 +81,13 @@ void Cr2Image::writeMetadata() { byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); - if (io_->open() == 0) { - // Ensure that this is the correct image type - if (isCr2Type(*io_, false)) { - pData = io_->mmap(true); - size = io_->size(); - Internal::Cr2Header cr2Header; - if (0 == cr2Header.read(pData, 16)) { - bo = cr2Header.byteOrder(); - } + // Ensure that this is the correct image type + if (io_->open() == 0 && isCr2Type(*io_, false)) { + pData = io_->mmap(true); + size = io_->size(); + Internal::Cr2Header cr2Header; + if (0 == cr2Header.read(pData, 16)) { + bo = cr2Header.byteOrder(); } } if (bo == invalidByteOrder) { diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 98dc859d..34f86c09 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -749,7 +749,7 @@ void CrwMap::decode0x180e(const CiffComponent& ciffComponent, const CrwMapping* ULongValue v; v.read(ciffComponent.pData(), 8, byteOrder); time_t t = v.value_.at(0); - struct tm* tm = std::localtime(&t); + auto tm = std::localtime(&t); if (tm) { const size_t m = 20; char s[m]; @@ -958,7 +958,7 @@ void CrwMap::encode0x1810(const Image& image, const CrwMapping* pCrwMapping, Cif const auto edO = exivData.findKey(kO); const auto edEnd = exivData.end(); - CiffComponent* cc = pHead->findComponent(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); + auto cc = pHead->findComponent(pCrwMapping->crwTagId_, pCrwMapping->crwDir_); if (edX != edEnd || edY != edEnd || edO != edEnd) { size_t size = 28; if (cc) { diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 380828da..5d20b702 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -104,17 +104,15 @@ void boxes_check(size_t b, size_t m) { } // namespace Jp2Image::Jp2Image(BasicIo::UniquePtr io, bool create) : Image(ImageType::jp2, mdExif | mdIptc | mdXmp, std::move(io)) { - if (create) { - if (io_->open() == 0) { + if (create && io_->open() == 0) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::Jp2Image:: Creating JPEG2000 image to memory" << std::endl; + std::cerr << "Exiv2::Jp2Image:: Creating JPEG2000 image to memory" << std::endl; #endif - IoCloser closer(*io_); - if (io_->write(Jp2Blank.data(), Jp2Blank.size()) != Jp2Blank.size()) { + IoCloser closer(*io_); + if (io_->write(Jp2Blank.data(), Jp2Blank.size()) != Jp2Blank.size()) { #ifdef EXIV2_DEBUG_MESSAGES - std::cerr << "Exiv2::Jp2Image:: Failed to create JPEG2000 image on memory" << std::endl; + std::cerr << "Exiv2::Jp2Image:: Failed to create JPEG2000 image on memory" << std::endl; #endif - } } } } @@ -756,7 +754,7 @@ void Jp2Image::doWriteMetadata(BasicIo& outIo) { // Write all updated metadata here, just after JP2Header. - if (exifData_.count() > 0) { + if (!exifData_.empty()) { // Update Exif data to a new UUID box Blob blob; @@ -782,7 +780,7 @@ void Jp2Image::doWriteMetadata(BasicIo& outIo) { } } - if (iptcData_.count() > 0) { + if (!iptcData_.empty()) { // Update Iptc data to a new UUID box DataBuf rawIptc = IptcParser::encode(iptcData_); diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 896cfb81..b4f6088e 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -682,13 +682,13 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { comPos = insertPos; ++search; } - if (exifData_.count() > 0) + if (!exifData_.empty()) ++search; - if (!writeXmpFromPacket() && xmpData_.count() > 0) + if (!writeXmpFromPacket() && !xmpData_.empty()) ++search; if (writeXmpFromPacket() && !xmpPacket_.empty()) ++search; - if (foundCompletePsData || iptcData_.count() > 0) + if (foundCompletePsData || !iptcData_.empty()) ++search; if (!comment_.empty()) ++search; @@ -707,7 +707,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { if (insertPos == count) { // Write Exif data first so that - if there is no app0 - we // create "Exif images" according to the Exif standard. - if (exifData_.count() > 0) { + if (!exifData_.empty()) { Blob blob; ByteOrder bo = byteOrder(); if (bo == invalidByteOrder) { @@ -808,7 +808,7 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) { --search; } - if (foundCompletePsData || iptcData_.count() > 0) { + if (foundCompletePsData || !iptcData_.empty()) { // Set the new IPTC IRB, keeps existing IRBs but removes the // IPTC block if there is no new IPTC data to write DataBuf newPsData = Photoshop::setIptcIrb(psBlob.data(), psBlob.size(), iptcData_); diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index 6c3c0ac8..af481f29 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -666,13 +666,10 @@ std::ostream& SonyMakerNote::printSony2FpFocusPosition2(std::ostream& os, const } } const auto val = value.toInt64(); - switch (val) { - case 255: - os << N_("Infinity"); - break; - default: - os << val; - } + if (val == 255) + os << N_("Infinity"); + else + os << val; } return os; } @@ -770,7 +767,7 @@ std::ostream& SonyMakerNote::printSonyMisc2bLensZoomPosition(std::ostream& os, c return os << N_("n/a"); } - os << std::round((value.toInt64() / 10.24)) << "%"; + os << std::round(value.toInt64() / 10.24) << "%"; return os; } diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 2e1e9db4..837f46f1 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1038,14 +1038,13 @@ uint32_t TiffImageEntry::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, size #endif DataBuf buf(strips_.size() * 4); uint32_t idx = 0; - for (auto&& strip : strips_) { + for (const auto& [_, off] : strips_) { idx += writeOffset(buf.data(idx), o2, tiffType(), byteOrder); // Align strip data to word boundary - const auto sz = Safe::add(strip.second, strip.second & 1); + const auto sz = Safe::add(off, off & 1); o2 = Safe::add(o2, sz); - if (!(group() > IfdId::mnId)) { // Todo: FIX THIS!! SHOULDN'T USE > + if (group() <= IfdId::mnId) imageIdx = Safe::add(imageIdx, static_cast(sz)); - } } ioWrapper.write(buf.c_data(), buf.size()); return static_cast(buf.size()); @@ -1129,7 +1128,7 @@ uint32_t TiffBinaryArray::doWrite(IoWrapper& ioWrapper, ByteOrder byteOrder, siz if (cfg()->cryptFct_) { // Select sonyTagEncipher CryptFct cryptFct = cfg()->cryptFct_; - if (cryptFct == sonyTagDecipher) { + if (cryptFct == &sonyTagDecipher) { cryptFct = sonyTagEncipher; } DataBuf buf = cryptFct(tag(), mio.mmap(), static_cast(mio.size()), pRoot_); @@ -1226,7 +1225,7 @@ uint32_t TiffComponent::writeImage(IoWrapper& ioWrapper, ByteOrder byteOrder) co uint32_t TiffDirectory::doWriteImage(IoWrapper& ioWrapper, ByteOrder byteOrder) const { uint32_t len = 0; TiffComponent* pSubIfd = nullptr; - for (auto&& component : components_) { + for (auto component : components_) { if (component->tag() == 0x014a) { // Hack: delay writing of sub-IFD image data to get the order correct #ifndef SUPPRESS_WARNINGS @@ -1469,8 +1468,8 @@ size_t TiffImageEntry::doSizeImage() const { return 0; auto len = pValue()->sizeDataArea(); if (len == 0) { - for (auto&& strip : strips_) { - len += strip.second; + for (const auto& [_, off] : strips_) { + len += off; } } return len; @@ -1478,9 +1477,11 @@ size_t TiffImageEntry::doSizeImage() const { static const TagInfo* findTagInfo(uint16_t tag, IfdId group) { const TagInfo* result = nullptr; - const TagInfo* tags = group == IfdId::exifId ? Internal::exifTagList() - : group == IfdId::gpsId ? Internal::gpsTagList() - : nullptr; + const TagInfo* tags = [=] { + if (group == IfdId::gpsId) + return group == IfdId::exifId ? Internal::exifTagList() : Internal::gpsTagList(); + return group == IfdId::exifId ? Internal::exifTagList() : nullptr; + }(); if (tags) { for (size_t idx = 0; !result && tags[idx].tag_ != 0xffff; ++idx) { if (tags[idx].tag_ == tag) { @@ -1503,10 +1504,9 @@ TypeId toTypeId(TiffType tiffType, uint16_t tag, IfdId group) { } // http://dev.exiv2.org/boards/3/topics/1337 change unsignedByte to signedByte // Exif.NikonAFT.AFFineTuneAdj || Exif.Pentax.Temperature - if (ti == Exiv2::unsignedByte) { - if ((tag == 0x0002 && group == IfdId::nikonAFTId) || (tag == 0x0047 && group == IfdId::pentaxId)) { - ti = Exiv2::signedByte; - } + if (ti == Exiv2::unsignedByte && + ((tag == 0x0002 && group == IfdId::nikonAFTId) || (tag == 0x0047 && group == IfdId::pentaxId))) { + ti = Exiv2::signedByte; } return ti; } diff --git a/src/tiffcomposite_int.hpp b/src/tiffcomposite_int.hpp index 377d31de..bae54d90 100644 --- a/src/tiffcomposite_int.hpp +++ b/src/tiffcomposite_int.hpp @@ -384,7 +384,6 @@ struct TiffMappingInfo::Key { class TiffEntryBase : public TiffComponent { friend class TiffReader; friend class TiffEncoder; - friend int selectNikonLd(TiffBinaryArray*, TiffComponent*); public: //! @name Creators @@ -1161,12 +1160,7 @@ class TiffIfdMakernote : public TiffComponent { the header is \c invalidByteOrder. */ [[nodiscard]] ByteOrder byteOrder() const; - /*! - @brief Return the byte order used for the image. - */ - [[nodiscard]] ByteOrder imageByteOrder() const { - return imageByteOrder_; - } + /*! @brief Return the base offset for use with the makernote IFD entries relative to the start of the TIFF header. diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp index 72ad9109..6aae676f 100644 --- a/src/tiffimage.cpp +++ b/src/tiffimage.cpp @@ -59,7 +59,7 @@ std::string TiffImage::mimeType() const { std::string key = "Exif." + primaryGroup() + ".Compression"; auto md = exifData_.findKey(ExifKey(key)); if (md != exifData_.end() && md->count() > 0) { - for (auto&& [comp, type] : mimeTypeList) + for (const auto& [comp, type] : mimeTypeList) if (comp == static_cast(md->toInt64())) { mimeType_ = type; } @@ -79,7 +79,7 @@ std::string TiffImage::primaryGroup() const { }; // Find the group of the primary image, default to "Image" primaryGroup_ = std::string("Image"); - for (auto&& i : keys) { + for (auto i : keys) { auto md = exifData_.findKey(ExifKey(i)); // Is it the primary image? if (md != exifData_.end() && md->count() > 0 && md->toInt64() == 0) { @@ -165,15 +165,13 @@ void TiffImage::writeMetadata() { byte* pData = nullptr; size_t size = 0; IoCloser closer(*io_); - if (io_->open() == 0) { - // Ensure that this is the correct image type - if (isTiffType(*io_, false)) { - pData = io_->mmap(true); - size = io_->size(); - TiffHeader tiffHeader; - if (0 == tiffHeader.read(pData, 8)) { - bo = tiffHeader.byteOrder(); - } + // Ensure that this is the correct image type + if (io_->open() == 0 && isTiffType(*io_, false)) { + pData = io_->mmap(true); + size = io_->size(); + TiffHeader tiffHeader; + if (0 == tiffHeader.read(pData, 8)) { + bo = tiffHeader.byteOrder(); } } if (bo == invalidByteOrder) { @@ -207,10 +205,8 @@ ByteOrder TiffParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xm // #1402 Fujifilm RAF. Change root when parsing embedded tiff Exiv2::ExifKey key("Exif.Image.Make"); - if (exifData.findKey(key) != exifData.end()) { - if (exifData.findKey(key)->toString() == "FUJIFILM") { - root = Tag::fuji; - } + if (exifData.findKey(key) != exifData.end() && exifData.findKey(key)->toString() == "FUJIFILM") { + root = Tag::fuji; } return TiffParserWorker::decode(exifData, iptcData, xmpData, pData, size, root, TiffMapping::findDecoder); @@ -225,7 +221,7 @@ WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, Byte static constexpr auto filteredIfds = std::array{ IfdId::panaRawId, }; - for (auto&& filteredIfd : filteredIfds) { + for (auto filteredIfd : filteredIfds) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Warning: Exif IFD " << filteredIfd << " not encoded\n"; #endif @@ -266,12 +262,10 @@ void TiffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption op if (io_->open() != 0) throw Error(ErrorCode::kerDataSourceOpenFailed, io_->path(), strError()); // Ensure that this is the correct image type - if (imageType() == ImageType::none) { - if (!isTiffType(*io_, false)) { - if (io_->error() || io_->eof()) - throw Error(ErrorCode::kerFailedToReadImageData); - throw Error(ErrorCode::kerNotAJpeg); - } + if (imageType() == ImageType::none && !isTiffType(*io_, false)) { + if (io_->error() || io_->eof()) + throw Error(ErrorCode::kerFailedToReadImageData); + throw Error(ErrorCode::kerNotAJpeg); } io_->seek(0, BasicIo::beg); diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp index 23f958a5..58abed0f 100644 --- a/src/tiffimage_int.cpp +++ b/src/tiffimage_int.cpp @@ -1934,7 +1934,7 @@ void TiffParserWorker::findPrimaryGroups(PrimaryGroups& primaryGroups, TiffCompo IfdId::subImage7Id, IfdId::subImage8Id, IfdId::subImage9Id, }; - for (auto&& imageGroup : imageGroups) { + for (auto imageGroup : imageGroups) { TiffFinder finder(0x00fe, imageGroup); pSourceDir->accept(finder); auto te = dynamic_cast(finder.result()); @@ -2164,10 +2164,10 @@ void OffsetWriter::setTarget(OffsetId id, uint32_t target) { } void OffsetWriter::writeOffsets(BasicIo& io) const { - for (auto&& it : offsetList_) { - io.seek(it.second.origin_, BasicIo::beg); + for (const auto& [_, off] : offsetList_) { + io.seek(off.origin_, BasicIo::beg); byte buf[4] = {0, 0, 0, 0}; - l2Data(buf, it.second.target_, it.second.byteOrder_); + l2Data(buf, off.target_, off.byteOrder_); io.write(buf, 4); } } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 044db7b6..5f4a096f 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -133,7 +133,7 @@ TiffCopier::TiffCopier(TiffComponent* pRoot, uint32_t root, const TiffHeaderBase pRoot_(pRoot), root_(root), pHeader_(pHeader), pPrimaryGroups_(pPrimaryGroups) { } -void TiffCopier::copyObject(TiffComponent* object) { +void TiffCopier::copyObject(const TiffComponent* object) { if (pHeader_->isImageTag(object->tag(), object->group(), pPrimaryGroups_)) { auto clone = object->clone(); // Assumption is that the corresponding TIFF entry doesn't exist @@ -282,8 +282,7 @@ void TiffDecoder::decodeXmp(const TiffEntryBase* object) { std::string::size_type idx = xmpPacket.find_first_of('<'); if (idx != std::string::npos && idx > 0) { #ifndef SUPPRESS_WARNINGS - EXV_WARNING << "Removing " << static_cast(idx) - << " characters from the beginning of the XMP packet\n"; + EXV_WARNING << "Removing " << idx << " characters from the beginning of the XMP packet\n"; #endif xmpPacket = xmpPacket.substr(idx); } @@ -392,13 +391,13 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) { }; // check we have enough data! uint16_t count = 0; - for (auto&& [tag, size, bSigned] : records) { + for (const auto& [tag, size, bSigned] : records) { count += size; if (count > ints.size()) return; } - for (auto&& [tag, size, bSigned] : records) { + for (const auto& [tag, size, bSigned] : records) { const TagInfo* pTags = ExifTags::tagList("Canon"); const TagInfo* pTag = findTag(pTags, tag); if (pTag) { @@ -591,7 +590,7 @@ void TiffEncoder::visitDirectory(TiffDirectory* /*object*/) { void TiffEncoder::visitDirectoryNext(TiffDirectory* object) { // Update type and count in IFD entries, in case they changed byte* p = object->start() + 2; - for (auto&& component : object->components_) { + for (auto component : object->components_) { p += updateDirEntry(p, byteOrder(), component); } } @@ -648,7 +647,7 @@ void TiffEncoder::visitIfdMakernote(TiffIfdMakernote* object) { static constexpr auto synthesizedTags = std::array{ "Exif.MakerNote.Offset", }; - for (auto&& synthesizedTag : synthesizedTags) { + for (auto synthesizedTag : synthesizedTags) { pos = exifData_.findKey(ExifKey(synthesizedTag)); if (pos != exifData_.end()) exifData_.erase(pos); @@ -682,7 +681,7 @@ void TiffEncoder::visitBinaryArrayEnd(TiffBinaryArray* object) { // Re-encrypt buffer if necessary CryptFct cryptFct = object->cfg()->cryptFct_; - if (cryptFct == sonyTagDecipher) { + if (cryptFct == &sonyTagDecipher) { cryptFct = sonyTagEncipher; } if (cryptFct) { @@ -1070,7 +1069,7 @@ int TiffReader::nextIdx(IfdId group) { void TiffReader::postProcess() { setMnState(); // All components to be post-processed must be from the Makernote postProc_ = true; - for (auto&& pos : postList_) { + for (auto pos : postList_) { pos->accept(*this); } postProc_ = false; @@ -1427,7 +1426,7 @@ void TiffReader::visitBinaryArray(TiffBinaryArray* object) { } // TiffReader::visitBinaryArray void TiffReader::visitBinaryElement(TiffBinaryElement* object) { - byte* pData = object->start(); + auto pData = object->start(); size_t size = object->TiffEntryBase::doSize(); ByteOrder bo = object->elByteOrder(); if (bo == invalidByteOrder) diff --git a/src/tiffvisitor_int.hpp b/src/tiffvisitor_int.hpp index 4b722e76..ec0fb9bb 100644 --- a/src/tiffvisitor_int.hpp +++ b/src/tiffvisitor_int.hpp @@ -234,7 +234,7 @@ class TiffCopier : public TiffVisitor { void visitBinaryElement(TiffBinaryElement* object) override; //! Check if \em object is an image tag and if so, copy it to the target tree. - void copyObject(TiffComponent* object); + void copyObject(const TiffComponent* object); //@} private: diff --git a/src/value.cpp b/src/value.cpp index d2d00f72..7d445753 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -712,7 +712,7 @@ std::ostream& LangAltValue::write(std::ostream& os) const { } // Write the others - for (auto&& [lang, s] : value_) { + for (const auto& [lang, s] : value_) { if (lang != x_default) { if (!first) os << ", "; diff --git a/src/version.cpp b/src/version.cpp index 9f7d0eff..6da53802 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -500,7 +500,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector& key Exiv2::Dictionary ns; Exiv2::XmpProperties::registeredNamespaces(ns); - for (auto&& [xmlns, uri] : ns) { + for (const auto& [xmlns, uri] : ns) { output(os, keys, name, xmlns + ":" + uri); } #endif diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 53387cce..03da237c 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -23,7 +23,7 @@ namespace { [[maybe_unused]] std::string binaryToHex(const uint8_t* data, size_t size) { std::stringstream hexOutput; - auto tl = static_cast(size / 16) * 16; + auto tl = size / 16 * 16; auto tl_offset = size - tl; for (size_t loop = 0; loop < size; loop++) { @@ -138,14 +138,14 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { byte size_buff[WEBP_TAG_SIZE]; Blob blob; - if (exifData_.count() > 0) { + if (!exifData_.empty()) { ExifParser::encode(blob, littleEndian, exifData_); if (!blob.empty()) { has_exif = true; } } - if (xmpData_.count() > 0 && !writeXmpFromPacket()) { + if (!xmpData_.empty() && !writeXmpFromPacket()) { XmpParser::encode(xmpPacket_, xmpData_, XmpParser::useCompactFormat | XmpParser::omitAllFormatting); } has_xmp = !xmpPacket_.empty(); @@ -326,10 +326,8 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { throw Error(ErrorCode::kerImageWriteFailed); if (outIo.write(payload.c_data(), payload.size()) != payload.size()) throw Error(ErrorCode::kerImageWriteFailed); - if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) - throw Error(ErrorCode::kerImageWriteFailed); - } + if (outIo.tell() % 2 && outIo.write(&WEBP_PAD_ODD, 1) != 1) + throw Error(ErrorCode::kerImageWriteFailed); if (has_icc) { if (outIo.write(reinterpret_cast(WEBP_CHUNK_HEADER_ICCP), WEBP_TAG_SIZE) != WEBP_TAG_SIZE) @@ -358,10 +356,8 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { } // Encoder required to pad odd sized data with a null byte - if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) - throw Error(ErrorCode::kerImageWriteFailed); - } + if (outIo.tell() % 2 && outIo.write(&WEBP_PAD_ODD, 1) != 1) + throw Error(ErrorCode::kerImageWriteFailed); } if (has_exif) { @@ -374,10 +370,8 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { if (outIo.write(blob.data(), blob.size()) != blob.size()) { throw Error(ErrorCode::kerImageWriteFailed); } - if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) - throw Error(ErrorCode::kerImageWriteFailed); - } + if (outIo.tell() % 2 && outIo.write(&WEBP_PAD_ODD, 1) != 1) + throw Error(ErrorCode::kerImageWriteFailed); } if (has_xmp) { @@ -389,10 +383,8 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) { if (outIo.write(reinterpret_cast(xmp.data()), xmp.size()) != xmp.size()) { throw Error(ErrorCode::kerImageWriteFailed); } - if (outIo.tell() % 2) { - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) - throw Error(ErrorCode::kerImageWriteFailed); - } + if (outIo.tell() % 2 && outIo.write(&WEBP_PAD_ODD, 1) != 1) + throw Error(ErrorCode::kerImageWriteFailed); } // Fix File Size Payload Data @@ -722,7 +714,7 @@ bool isWebPType(BasicIo& iIo, bool /*advance*/) { @param str char* Pointer to string @return Returns true if the buffer value is equal to string. */ -bool WebPImage::equalsWebPTag(Exiv2::DataBuf& buf, const char* str) { +bool WebPImage::equalsWebPTag(const Exiv2::DataBuf& buf, const char* str) { for (int i = 0; i < 4; i++) if (toupper(buf.read_uint8(i)) != str[i]) return false; @@ -784,10 +776,8 @@ void WebPImage::inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_ throw Error(ErrorCode::kerImageWriteFailed); if (iIo.write(iccProfile_.c_data(), iccProfile_.size()) != iccProfile_.size()) throw Error(ErrorCode::kerImageWriteFailed); - if (iIo.tell() % 2) { - if (iIo.write(&WEBP_PAD_ODD, 1) != 1) - throw Error(ErrorCode::kerImageWriteFailed); - } + if (iIo.tell() % 2 && iIo.write(&WEBP_PAD_ODD, 1) != 1) + throw Error(ErrorCode::kerImageWriteFailed); } } diff --git a/src/xmp.cpp b/src/xmp.cpp index 8a628774..b65b1186 100644 --- a/src/xmp.cpp +++ b/src/xmp.cpp @@ -503,7 +503,7 @@ void XmpData::eraseFamily(XmpData::iterator& pos) { } } // now erase the family! - for (auto&& k : keys) { + for (const auto& k : keys) { erase(findKey(Exiv2::XmpKey(k))); } } @@ -826,29 +826,29 @@ int XmpParser::encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t f return 2; } // Register custom namespaces with XMP-SDK - for (auto&& [xmp, uri] : XmpProperties::nsRegistry_) { + for (const auto& [xmp, uri] : XmpProperties::nsRegistry_) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Registering " << uri.prefix_ << " : " << xmp << "\n"; #endif registerNs(xmp, uri.prefix_); } SXMPMeta meta; - for (auto&& i : xmpData) { - const std::string ns = XmpProperties::ns(i.groupName()); + for (const auto& xmp : xmpData) { + const std::string ns = XmpProperties::ns(xmp.groupName()); XMP_OptionBits options = 0; - if (i.typeId() == langAlt) { + if (xmp.typeId() == langAlt) { // Encode Lang Alt property - const auto la = dynamic_cast(&i.value()); + const auto la = dynamic_cast(&xmp.value()); if (!la) - throw Error(ErrorCode::kerEncodeLangAltPropertyFailed, i.key()); + throw Error(ErrorCode::kerEncodeLangAltPropertyFailed, xmp.key()); int idx = 1; - for (auto&& [lang, specs] : la->value_) { + for (const auto& [lang, specs] : la->value_) { if (!specs.empty()) { // remove lang specs with no value - printNode(ns, i.tagName(), specs, 0); - meta.AppendArrayItem(ns.c_str(), i.tagName().c_str(), kXMP_PropArrayIsAlternate, specs.c_str()); - const std::string item = i.tagName() + "[" + toString(idx++) + "]"; + printNode(ns, xmp.tagName(), specs, 0); + meta.AppendArrayItem(ns.c_str(), xmp.tagName().c_str(), kXMP_PropArrayIsAlternate, specs.c_str()); + const std::string item = xmp.tagName() + "[" + toString(idx++) + "]"; meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", lang.c_str()); } } @@ -856,32 +856,32 @@ int XmpParser::encode(std::string& xmpPacket, const XmpData& xmpData, uint16_t f } // Todo: Xmpdatum should have an XmpValue, not a Value - const auto val = dynamic_cast(&i.value()); + const auto val = dynamic_cast(&xmp.value()); if (!val) - throw Error(ErrorCode::kerInvalidKeyXmpValue, i.key(), i.typeName()); + throw Error(ErrorCode::kerInvalidKeyXmpValue, xmp.key(), xmp.typeName()); options = xmpArrayOptionBits(val->xmpArrayType()) | xmpArrayOptionBits(val->xmpStruct()); - if (i.typeId() == xmpBag || i.typeId() == xmpSeq || i.typeId() == xmpAlt) { - printNode(ns, i.tagName(), "", options); - meta.SetProperty(ns.c_str(), i.tagName().c_str(), nullptr, options); - for (size_t idx = 0; idx < i.count(); ++idx) { - const std::string item = i.tagName() + "[" + toString(idx + 1) + "]"; - printNode(ns, item, i.toString(static_cast(idx)), 0); - meta.SetProperty(ns.c_str(), item.c_str(), i.toString(static_cast(idx)).c_str()); + if (xmp.typeId() == xmpBag || xmp.typeId() == xmpSeq || xmp.typeId() == xmpAlt) { + printNode(ns, xmp.tagName(), "", options); + meta.SetProperty(ns.c_str(), xmp.tagName().c_str(), nullptr, options); + for (size_t idx = 0; idx < xmp.count(); ++idx) { + const std::string item = xmp.tagName() + "[" + toString(idx + 1) + "]"; + printNode(ns, item, xmp.toString(static_cast(idx)), 0); + meta.SetProperty(ns.c_str(), item.c_str(), xmp.toString(static_cast(idx)).c_str()); } continue; } - if (i.typeId() == xmpText) { - if (i.count() == 0) { - printNode(ns, i.tagName(), "", options); - meta.SetProperty(ns.c_str(), i.tagName().c_str(), nullptr, options); + if (xmp.typeId() == xmpText) { + if (xmp.count() == 0) { + printNode(ns, xmp.tagName(), "", options); + meta.SetProperty(ns.c_str(), xmp.tagName().c_str(), nullptr, options); } else { - printNode(ns, i.tagName(), i.toString(0), options); - meta.SetProperty(ns.c_str(), i.tagName().c_str(), i.toString(0).c_str(), options); + printNode(ns, xmp.tagName(), xmp.toString(0), options); + meta.SetProperty(ns.c_str(), xmp.tagName().c_str(), xmp.toString(0).c_str(), options); } continue; } // Don't let any Xmpdatum go by unnoticed - throw Error(ErrorCode::kerUnhandledXmpdatum, i.tagName(), i.typeName()); + throw Error(ErrorCode::kerUnhandledXmpdatum, xmp.tagName(), xmp.typeName()); } std::string tmpPacket; meta.SerializeToBuffer(&tmpPacket, xmpFormatOptionBits(static_cast(formatFlags)), diff --git a/src/xmpsidecar.cpp b/src/xmpsidecar.cpp index 75881f98..64af61a8 100644 --- a/src/xmpsidecar.cpp +++ b/src/xmpsidecar.cpp @@ -21,11 +21,9 @@ constexpr auto xmlFooter = ""; // class member definitions namespace Exiv2 { XmpSidecar::XmpSidecar(BasicIo::UniquePtr io, bool create) : Image(ImageType::xmp, mdXmp, std::move(io)) { - if (create) { - if (io_->open() == 0) { - IoCloser closer(*io_); - io_->write(reinterpret_cast(xmlHeader), xmlHdrCnt); - } + if (create && io_->open() == 0) { + IoCloser closer(*io_); + io_->write(reinterpret_cast(xmlHeader), xmlHdrCnt); } } // XmpSidecar::XmpSidecar @@ -71,10 +69,10 @@ void XmpSidecar::readMetadata() { } // #1112 - store dates to deal with loss of TZ information during conversions - for (auto&& it : xmpData_) { - std::string key(it.key()); + for (const auto& xmp : xmpData_) { + std::string key(xmp.key()); if (key.find("Date") != std::string::npos) { - std::string value(it.value().toString()); + std::string value(xmp.value().toString()); dates_[key] = value; } } @@ -96,9 +94,9 @@ void XmpSidecar::writeMetadata() { if (!writeXmpFromPacket()) { // #589 copy XMP tags Exiv2::XmpData copy; - for (auto&& it : xmpData_) { - if (!matchi(it.key(), "exif") && !matchi(it.key(), "iptc")) { - copy[it.key()] = it.value(); + for (const auto& xmp : xmpData_) { + if (!matchi(xmp.key(), "exif") && !matchi(xmp.key(), "iptc")) { + copy[xmp.key()] = xmp.value(); } } @@ -107,7 +105,7 @@ void XmpSidecar::writeMetadata() { copyIptcToXmp(iptcData_, xmpData_); // #1112 - restore dates if they lost their TZ info - for (auto&& [sKey, value_orig] : dates_) { + for (const auto& [sKey, value_orig] : dates_) { Exiv2::XmpKey key(sKey); if (xmpData_.findKey(key) != xmpData_.end()) { std::string value_now(xmpData_[sKey].value().toString()); @@ -119,8 +117,8 @@ void XmpSidecar::writeMetadata() { } // #589 - restore tags which were modified by the convertors - for (auto&& it : copy) { - xmpData_[it.key()] = it.value(); + for (const auto& xmp : copy) { + xmpData_[xmp.key()] = xmp.value(); } if (XmpParser::encode(xmpPacket_, xmpData_, XmpParser::omitPacketWrapper | XmpParser::useCompactFormat) > 1) {