diff --git a/src/datasets.cpp b/src/datasets.cpp index 3d257b2208..d910b1f077 100644 --- a/src/datasets.cpp +++ b/src/datasets.cpp @@ -579,14 +579,8 @@ void IptcKey::makeKey() { // free functions std::ostream& operator<<(std::ostream& os, const DataSet& dataSet) { - std::ios::fmtflags f(os.flags()); IptcKey iptcKey(dataSet.number_, dataSet.recordId_); - os << dataSet.name_ << ", " << std::dec << dataSet.number_ << ", " - << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << dataSet.number_ << ", " - << IptcDataSets::recordName(dataSet.recordId_) << ", " << std::boolalpha << dataSet.mandatory_ << ", " - << dataSet.repeatable_ << ", " << std::dec << dataSet.minbytes_ << ", " << dataSet.maxbytes_ << ", " - << iptcKey.key() << ", " << TypeInfo::typeName(IptcDataSets::dataSetType(dataSet.number_, dataSet.recordId_)) - << ", "; + // CSV encoded I am \"dead\" beat" => "I am ""dead"" beat" std::string escapedDesc; escapedDesc.push_back('"'); @@ -597,9 +591,12 @@ std::ostream& operator<<(std::ostream& os, const DataSet& dataSet) { escapedDesc.push_back(c); } escapedDesc.push_back('"'); - os << escapedDesc; - os.flags(f); - return os; + + return os << stringFormat( + "{}, {}, 0x{:04x}, {}, {}, {}, {}, {}, {}, {}, {}", dataSet.name_, dataSet.number_, dataSet.number_, + IptcDataSets::recordName(dataSet.recordId_), dataSet.mandatory_ ? "true" : "false", + dataSet.repeatable_ ? "true" : "false", dataSet.minbytes_, dataSet.maxbytes_, iptcKey.key(), + TypeInfo::typeName(IptcDataSets::dataSetType(dataSet.number_, dataSet.recordId_)), escapedDesc); } } // namespace Exiv2 diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index c8674e14ef..393af91eee 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -176,12 +176,9 @@ const TagInfo* Nikon1MakerNote::tagList() { } std::ostream& Nikon1MakerNote::print0x0002(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() > 1) { - os << value.toInt64(1); - } else { - os << "(" << value << ")"; - } - return os; + if (value.count() > 1) + return os << value.toInt64(1); + return os << "(" << value << ")"; } static std::string getKeyString(const std::string& key, const ExifData* metadata) { @@ -210,35 +207,29 @@ std::ostream& Nikon1MakerNote::printBarValue(std::ostream& os, const Value& valu std::ostream& Nikon1MakerNote::print0x0007(std::ostream& os, const Value& value, const ExifData*) { std::string focus = value.toString(); if (focus == "AF-C ") - os << _("Continuous autofocus"); - else if (focus == "AF-S ") - os << _("Single autofocus"); - else if (focus == "AF-A ") - os << _("Automatic"); - else - os << "(" << value << ")"; - return os; + return os << _("Continuous autofocus"); + if (focus == "AF-S ") + return os << _("Single autofocus"); + if (focus == "AF-A ") + return os << _("Automatic"); + return os << "(" << value << ")"; } std::ostream& Nikon1MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) { auto [r, s] = value.toRational(); - if (r == 0) { + if (r == 0) return os << _("Unknown"); - } - if (s != 0) { + if (s != 0) return os << stringFormat("{:.2f} m", static_cast(r) / s); - } return os << "(" << value << ")"; } std::ostream& Nikon1MakerNote::print0x0086(std::ostream& os, const Value& value, const ExifData*) { auto [r, s] = value.toRational(); - if (r == 0) { + if (r == 0) return os << _("Not used"); - } - if (s == 0) { + if (s == 0) return os << "(" << value << ")"; - } return os << stringFormat("{:.1f}x", static_cast(r) / s); } @@ -1022,7 +1013,7 @@ constexpr TagDetailsBitmask nikonFlashAdaptors[] = { {0x20, N_("Nikon Diffusion Dome")}, }; -static void printFlashCompensationValue(std::ostream& os, const unsigned char value, const bool manualScale) { +static std::ostream& printFlashCompensationValue(std::ostream& os, const unsigned char value, const bool manualScale) { std::ios::fmtflags f(os.flags()); std::ostringstream oss; oss.copyfmt(os); @@ -1044,7 +1035,7 @@ static void printFlashCompensationValue(std::ostream& os, const unsigned char va if (value > 48) { os << "(" << value << ")"; os.flags(f); - return; + return os; } const auto mod = value % 6; auto temp = (value < 6) ? 0 : (value - mod) / 6; @@ -1102,6 +1093,7 @@ static void printFlashCompensationValue(std::ostream& os, const unsigned char va } os.copyfmt(os); os.flags(f); + return os; } // Nikon3 Flash Info 1 Tag Info @@ -1801,12 +1793,9 @@ std::ostream& Nikon3MakerNote::printIiIso(std::ostream& os, const Value& value, } std::ostream& Nikon3MakerNote::print0x0002(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() > 1) { - os << value.toInt64(1); - } else { - os << "(" << value << ")"; - } - return os; + if (value.count() > 1) + return os << value.toInt64(1); + return os << "(" << value << ")"; } std::ostream& Nikon3MakerNote::printAf2AreaMode(std::ostream& os, const Value& value, const ExifData* metadata) { @@ -1826,14 +1815,12 @@ std::ostream& Nikon3MakerNote::printAf2AreaMode(std::ostream& os, const Value& v std::ostream& Nikon3MakerNote::print0x0007(std::ostream& os, const Value& value, const ExifData*) { std::string focus = value.toString(); if (focus == "AF-C ") - os << _("Continuous autofocus"); - else if (focus == "AF-S ") - os << _("Single autofocus"); - else if (focus == "AF-A ") - os << _("Automatic"); - else - os << "(" << value << ")"; - return os; + return os << _("Continuous autofocus"); + if (focus == "AF-S ") + return os << _("Single autofocus"); + if (focus == "AF-A ") + return os << _("Automatic"); + return os << "(" << value << ")"; } std::ostream& Nikon3MakerNote::print0x0083(std::ostream& os, const Value& value, const ExifData*) { @@ -1864,30 +1851,29 @@ std::ostream& Nikon3MakerNote::print0x0083(std::ostream& os, const Value& value, } std::ostream& Nikon3MakerNote::print0x0084(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 4 || value.toRational(0).second == 0 || value.toRational(1).second == 0) { - os << "(" << value << ")"; - return os; - } - const int64_t len1 = value.toInt64(0); - const int64_t len2 = value.toInt64(1); - - auto [r1, s1] = value.toRational(2); - auto [r2, s2] = value.toRational(3); - os << len1; - if (len2 != len1) { - os << "-" << len2; - } - os << "mm "; - std::ostringstream oss; - oss.copyfmt(os); - os << "F" << std::setprecision(2) << static_cast(r1) / s1; - if (r2 != r1) { - os << "-" << std::setprecision(2) << static_cast(r2) / s2; - } - os.copyfmt(oss); - os.flags(f); - return os; + if (value.count() != 4 || value.toRational(0).second == 0 || value.toRational(1).second == 0) + return os << "(" << value << ")"; + + auto focal = [&value] { + const int64_t len1 = value.toInt64(0); + const int64_t len2 = value.toInt64(1); + + if (len2 != len1) + return stringFormat("{}-{}mm ", len1, len2); + return stringFormat("{}mm ", len1); + }(); + + auto aperture = [&value] { + auto [r1, s1] = value.toRational(2); + auto [r2, s2] = value.toRational(3); + auto f1 = static_cast(r1) / s1; + + if (r2 != r1) + return stringFormat("F{:.2f}-{:.2f}", f1, static_cast(r2) / s2); + return stringFormat("F{:.2f}", f1); + }(); + + return os << focal << aperture; } std::ostream& Nikon3MakerNote::print0x0085(std::ostream& os, const Value& value, const ExifData*) { @@ -2031,19 +2017,15 @@ std::ostream& Nikon3MakerNote::print0x0089(std::ostream& os, const Value& value, } } } - if (d70) { - EXV_PRINT_TAG_BITMASK(nikonShootingModeD70)(os, value, nullptr); - } else { - EXV_PRINT_TAG_BITMASK(nikonShootingMode)(os, value, nullptr); - } - return os; + if (d70) + return EXV_PRINT_TAG_BITMASK(nikonShootingModeD70)(os, value, nullptr); + return EXV_PRINT_TAG_BITMASK(nikonShootingMode)(os, value, nullptr); } std::ostream& Nikon3MakerNote::print0x008b(std::ostream& os, const Value& value, const ExifData*) { // Decoded by Robert Rottmerhusen - if (value.size() != 4 || value.typeId() != undefined) { + if (value.size() != 4 || value.typeId() != undefined) return os << "(" << value << ")"; - } float a = value.toFloat(0); const auto b = value.toInt64(1); const auto c = value.toInt64(2); @@ -3390,32 +3372,29 @@ std::ostream& Nikon3MakerNote::printExitPupilPosition(std::ostream& os, const Va } std::ostream& Nikon3MakerNote::printFlashFocalLength(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + auto temp = value.toInt64(); if (temp == 0 || temp == 255) return os << _("n/a"); - return os << stringFormat("{:1} mm", temp); } std::ostream& Nikon3MakerNote::printRepeatingFlashRate(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedByte) { + if (value.count() != 1 || value.typeId() != unsignedByte) return os << "(" << value << ")"; - } + auto temp = value.toInt64(); if (temp == 0 || temp == 255) return os << _("n/a"); - return os << stringFormat("{:2} Hz", temp); } std::ostream& Nikon3MakerNote::printRepeatingFlashCount(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedByte) { + if (value.count() != 1 || value.typeId() != unsignedByte) return os << "(" << value << ")"; - } + auto temp = value.toInt64(); if (temp == 0 || temp == 255) return os << _("n/a"); @@ -3438,7 +3417,7 @@ std::ostream& Nikon3MakerNote::printExternalFlashData1Fl6(std::ostream& os, cons if (v0 & 0x01) { std::ostringstream ossTemp; - printTagBitmask(ossTemp, value, metadata); + EXV_PRINT_TAG_BITMASK(nikonFlashAdaptors)(ossTemp, value, metadata); std::string tempStr = ossTemp.str(); if (!tempStr.empty()) { os << ", " << tempStr; @@ -3464,7 +3443,7 @@ std::ostream& Nikon3MakerNote::printExternalFlashData2Fl6(std::ostream& os, cons if (v0 & 0x80) { os << ", "; - printTag(os, (value.toUint32() & 0x0F), metadata); + EXV_PRINT_TAG(nikonFlashControlMode)(os, (value.toUint32() & 0x0F), metadata); } os.copyfmt(oss); os.flags(f); @@ -3489,7 +3468,7 @@ std::ostream& Nikon3MakerNote::printExternalFlashData1Fl7(std::ostream& os, cons os << (v0 & 0x80 ? _("External flash zoom override") : _("No external flash zoom override")); std::ostringstream ossTemp; - printTagBitmask(ossTemp, value, metadata); + EXV_PRINT_TAG_BITMASK(nikonFlashAdaptors)(ossTemp, value, metadata); std::string tempStr = ossTemp.str(); if (!tempStr.empty()) { os << ", " << tempStr; @@ -3501,92 +3480,45 @@ std::ostream& Nikon3MakerNote::printExternalFlashData1Fl7(std::ostream& os, cons } std::ostream& Nikon3MakerNote::printExternalFlashData2(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - printTag(os, (value.toUint32() & 0x0F), metadata); - - os.flags(f); - return os; + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + return EXV_PRINT_TAG(nikonFlashControlMode)(os, (value.toUint32() & 0x0F), metadata); } std::ostream& Nikon3MakerNote::printFlashMasterDataFl6(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl6.ExternalFlashData1")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x0F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x0F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashMasterDataFl7(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.ExternalFlashData2")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x0F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x0F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupAControlData(std::ostream& os, const Value& value, const ExifData* data) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - std::ostringstream oss; - oss.copyfmt(os); - - printTag(os, (value.toUint32() & 0x0F), data); - - os.copyfmt(oss); - os.flags(f); - return os; + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + return EXV_PRINT_TAG(nikonFlashControlMode)(os, (value.toUint32() & 0x0F), data); } std::ostream& Nikon3MakerNote::printFlashGroupBCControlData(std::ostream& os, const Value& value, @@ -3601,9 +3533,9 @@ std::ostream& Nikon3MakerNote::printFlashGroupBCControlData(std::ostream& os, co oss.copyfmt(os); const auto temp = value.toUint32(); - printTag(os, (temp >> 4), data); + EXV_PRINT_TAG(nikonFlashControlMode)(os, (temp >> 4), data); os << ", "; - printTag(os, (temp & 0x0f), data); + EXV_PRINT_TAG(nikonFlashControlMode)(os, (temp & 0x0f), data); os.copyfmt(oss); os.flags(f); @@ -3611,236 +3543,124 @@ std::ostream& Nikon3MakerNote::printFlashGroupBCControlData(std::ostream& os, co } std::ostream& Nikon3MakerNote::printFlashGroupADataFl6(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl6.FlashGroupAControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x0F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x0F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupADataFl7(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupAControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x0F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x0F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupBDataFl6(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl6.FlashGroupBCControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) >> 4; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) >> 4) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupBDataFl7(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupBCControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) >> 4; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) >> 4) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupCDataFl6(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl6.FlashGroupBCControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x000F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x000F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printFlashGroupCDataFl7(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - os.flags(f); - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Check if using an automated or manual mode auto pos = metadata->findKey(ExifKey("Exif.NikonFl7.FlashGroupBCControlData")); - if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - const auto mode = pos->toUint32(0) & 0x000F; - if (mode == 0) { - os << _("n/a"); - os.flags(f); - return os; - } - - printFlashCompensationValue(os, static_cast(value.toUint32(0)), flashModeUsesManualScale(mode)); + if (pos == metadata->end() || pos->count() != 1 || pos->typeId() != unsignedByte) + return os << "(" << value << ")"; - os.flags(f); - return os; + if (auto mode = pos->toUint32(0) & 0x000F) + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), + flashModeUsesManualScale(mode)); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printExternalFlashData3(std::ostream& os, const Value& value, const ExifData* data) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - printTag(os, (value.toUint32(0) & 0x04), data); - - os.flags(f); - return os; + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + return EXV_PRINT_TAG(nikonFlashExposureComp)(os, (value.toUint32(0) & 0x04), data); } std::ostream& Nikon3MakerNote::printCameraExposureCompensation(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - printFlashCompensationValue(os, static_cast(value.toUint32(0)), false); - os.flags(f); - return os; + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + return printFlashCompensationValue(os, static_cast(value.toUint32(0)), false); } std::ostream& Nikon3MakerNote::printExternalFlashData4(std::ostream& os, const Value& value, const ExifData* metadata) { - std::ios::fmtflags f(os.flags()); - if (value.count() != 1 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - os.flags(f); - return os; - } - - printTag(os, value.toUint32(0), metadata); - - os.flags(f); - return os; + if (value.count() != 1 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; + return EXV_PRINT_TAG(nikonFlashIlluminationPat)(os, value.toUint32(0), metadata); } std::ostream& Nikon3MakerNote::printFlashZoomHeadPosition(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedByte) { + if (value.count() != 1 || value.typeId() != unsignedByte) return os << "(" << value << ")"; - } - - auto v0 = value.toUint32(0); - if (v0 == 0) { - return os << _("n/a"); - } - - return os << stringFormat("{} mm", v0); + if (auto v0 = value.toUint32(0)) + return os << stringFormat("{} mm", v0); + return os << _("n/a"); } std::ostream& Nikon3MakerNote::printTimeZone(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != signedShort) { + if (value.count() != 1 || value.typeId() != signedShort) return os << "(" << value << ")"; - } char sign = value.toInt64() < 0 ? '-' : '+'; long h = static_cast(std::fabs(value.toFloat() / 60.0F)) % 24; long min = static_cast(std::fabs(value.toFloat() - (h * 60))) % 60; @@ -3848,37 +3668,23 @@ std::ostream& Nikon3MakerNote::printTimeZone(std::ostream& os, const Value& valu } std::ostream& Nikon3MakerNote::printPictureControl(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedByte) { + if (value.count() != 1 || value.typeId() != unsignedByte) return os << "(" << value << ")"; - } const auto pcval = value.toInt64() - 0x80; - std::ostringstream oss; - oss.copyfmt(os); - switch (pcval) { - case 0: - os << _("Normal"); - break; - case 127: - os << _("n/a"); - break; - case -127: - os << _("User"); - break; - case -128: - os << _("Auto"); - break; - default: - os << pcval; - break; - } - os.copyfmt(oss); - return os; + if (pcval == 0) + return os << _("Normal"); + if (pcval == 127) + return os << _("n/a"); + if (pcval == -127) + return os << _("User"); + if (pcval == -128) + return os << _("Auto"); + return os << pcval; } std::ostream& Nikon3MakerNote::print0x009a(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 2 || value.typeId() != unsignedRational) { + if (value.count() != 2 || value.typeId() != unsignedRational) return os << value; - } float f1 = value.toFloat(0); float f2 = value.toFloat(1); return os << f1 << " x " << f2 << " um"; @@ -3913,34 +3719,28 @@ std::ostream& Nikon3MakerNote::print0x009e(std::ostream& os, const Value& value, } std::ostream& Nikon3MakerNote::printApertureLd4(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedShort) { + if (value.count() != 1 || value.typeId() != unsignedShort) return os << "(" << value << ")"; - } auto temp = value.toInt64(); if (temp == 0) return os << _("n/a"); - return os << stringFormat("F{:.1f}", std::exp2((temp / 384.0) - 1.0)); } std::ostream& Nikon3MakerNote::printFocalLd4(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedShort) { + if (value.count() != 1 || value.typeId() != unsignedShort) return os << "(" << value << ")"; - } auto temp = value.toInt64(); if (temp == 0) return os << _("n/a"); - return os << stringFormat("{} mm", temp); } std::ostream& Nikon3MakerNote::printFocusDistanceLd4(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedShort) { + if (value.count() != 1 || value.typeId() != unsignedShort) return os << "(" << value << ")"; - } auto temp = value.toInt64(); if (temp == 0) return os << _("n/a"); - return os << stringFormat("{:.2f} m", std::pow(10.0, (temp / (256.0 * 40.0)) - 2.0)); } diff --git a/src/olympusmn_int.cpp b/src/olympusmn_int.cpp index e03f262684..0456a4706f 100644 --- a/src/olympusmn_int.cpp +++ b/src/olympusmn_int.cpp @@ -1582,18 +1582,15 @@ std::ostream& OlympusMakerNote::printCs0x0301(std::ostream& os, const Value& val //! OlympusCs ArtFilter, tag 0x0529, OlympusCs MagicFilter, tag 0x052c std::ostream& OlympusMakerNote::print0x0529(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 4 || value.typeId() != unsignedShort) { + if (value.count() != 4 || value.typeId() != unsignedShort) return os << "(" << value << ")"; - } const auto v0 = value.toInt64(0); - - printTag(os, v0, metadata); + EXV_PRINT_TAG(artFilters)(os, v0, metadata); if (v0 == 39) { // The "Partial color" option also has a color choice const auto v3 = value.toInt64(3); - os << " (" << _("position") << " " << (v3 + 1) << ")"; - return os; + return os << " (" << _("position") << " " << (v3 + 1) << ")"; } return os; diff --git a/src/sonymn_int.cpp b/src/sonymn_int.cpp index 570aed2aad..e7059cdb55 100644 --- a/src/sonymn_int.cpp +++ b/src/sonymn_int.cpp @@ -897,45 +897,37 @@ static auto getFocusMode2(const ExifData* metadata, uint32_t& val) { } std::ostream& SonyMakerNote::printWhiteBalanceFineTune(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedLong) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedLong) + return os << "(" << value << ")"; + // Sony writes the tag as an unsignedLong but treat it as a signedLong. Source: // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L681 - os << static_cast(value.toUint32(0)); - return os; + return os << static_cast(value.toUint32(0)); } std::ostream& SonyMakerNote::printMultiBurstMode(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != undefined) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != undefined) + return os << "(" << value << ")"; + // Some cameras do not set the type to undefined. Source: // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L763 - printMinoltaSonyBoolValue(os, value, metadata); - return os; + return printMinoltaSonyBoolValue(os, value, metadata); } std::ostream& SonyMakerNote::printMultiBurstSize(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedShort) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedShort) + return os << "(" << value << ")"; + // Some cameras do not set the type to unsignedShort. Source: // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L771 - os << value.toUint32(0); - return os; + return os << value.toUint32(0); } std::ostream& SonyMakerNote::printAutoHDRStd(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != unsignedLong) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedLong) + return os << "(" << value << ")"; // Sony writes the tag as an unsignedLong but treat it as 2 unsignedShort values. Source: // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L887 @@ -949,10 +941,9 @@ std::ostream& SonyMakerNote::printAutoHDRStd(std::ostream& os, const Value& valu } std::ostream& SonyMakerNote::printWBShiftABGM(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 2 || value.typeId() != signedLong) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 2 || value.typeId() != signedLong) + return os << "(" << value << ")"; + // Examples of Output: // 1. "A/B: 0, G/M: 0" // 2. "A/B: 1B, G/M: 2M" @@ -970,226 +961,171 @@ std::ostream& SonyMakerNote::printWBShiftABGM(std::ostream& os, const Value& val } os << ", G/M: "; - if (v1 == 0) { - os << 0; - } else if (v1 < 0) { - os << "G" << -v1; - } else { - os << "M" << v1; - } - return os; + if (v1 == 0) + return os << 0; + + if (v1 < 0) + return os << "G" << -v1; + + return os << "M" << v1; } std::ostream& SonyMakerNote::printFocusMode2(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1123 std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; + const auto v0 = value.toUint32(0); constexpr std::array models{"DSC-RX10M4", "DSC-RX100M6", "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2"}; if (!model.starts_with("DSC-") || - std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyFocusMode2)(os, v0, metadata); - return os; - } - - os << _("n/a"); + std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) + return EXV_PRINT_TAG(sonyFocusMode2)(os, v0, metadata); - return os; + return os << _("n/a"); } std::ostream& SonyMakerNote::printAFAreaModeSetting(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1139 std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; + const auto v0 = value.toUint32(0); - constexpr std::array models1{"SLT-", "HV"}; - if (std::any_of(models1.begin(), models1.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyAFAreaModeSettingSet1)(os, v0, metadata); - return os; - } + for (auto m : {"SLT-", "HV"}) + if (model.starts_with(m)) + return EXV_PRINT_TAG(sonyAFAreaModeSettingSet1)(os, v0, metadata); - constexpr std::array models2{"NEX-", "ILCE-", "ILME-", "DSC-RX10M4", "DSC-RX100M6", - "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2"}; - if (std::any_of(models2.begin(), models2.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyAFAreaModeSettingSet2)(os, v0, metadata); - return os; - } + constexpr std::array models2{ + "NEX-", "ILCE-", "ILME-", "DSC-RX10M4", "DSC-RX100M6", "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2", + }; + if (std::any_of(models2.begin(), models2.end(), [&model](auto m) { return model.starts_with(m); })) + return EXV_PRINT_TAG(sonyAFAreaModeSettingSet2)(os, v0, metadata); - if (model.starts_with("ILCA-")) { - EXV_PRINT_TAG(sonyAFAreaModeSettingSet3)(os, v0, metadata); - return os; - } + if (model.starts_with("ILCA-")) + return EXV_PRINT_TAG(sonyAFAreaModeSettingSet3)(os, v0, metadata); - os << _("n/a"); - return os; + return os << _("n/a"); } std::ostream& SonyMakerNote::printFlexibleSpotPosition(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 2 || value.typeId() != unsignedShort || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 2 || value.typeId() != unsignedShort || !metadata) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1189 std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; - constexpr std::array models{"NEX-", "ILCE-", "ILME-", "DSC-RX10M4", "DSC-RX100M6", - "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2"}; - if (std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) { - os << value.toUint32(0) << ", " << value.toUint32(1); - return os; - } + constexpr std::array models{ + "NEX-", "ILCE-", "ILME-", "DSC-RX10M4", "DSC-RX100M6", "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2", + }; + if (std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) + return os << value.toUint32(0) << ", " << value.toUint32(1); - os << _("n/a"); - return os; + return os << _("n/a"); } std::ostream& SonyMakerNote::printAFPointSelected(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1203 std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; uint32_t aFAreaModeSetting = 0; const auto status = getAFAreaModeSetting(metadata, aFAreaModeSetting); - constexpr std::array models1{"SLT-", "HV-"}; - constexpr std::array models2{"ILCE-", "ILME-"}; - constexpr std::array models3{"ILCA-68", "ILCA-77M2"}; - constexpr std::array models4{"NEX-", "ILCE-", "ILME-"}; - - if (std::any_of(models1.begin(), models1.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyAFPointSelectedSet1)(os, value.toUint32(0), metadata); - return os; - } - if (std::any_of(models2.begin(), models2.end(), [&model](auto& m) { return model.starts_with(m); }) && status && - aFAreaModeSetting == 4) { - EXV_PRINT_TAG(sonyAFPointSelectedSet1)(os, value.toUint32(0), metadata); - return os; - } - if (std::any_of(models3.begin(), models3.end(), [&model](auto m) { return model.starts_with(m); }) && status && - aFAreaModeSetting != 8) { - EXV_PRINT_TAG(sonyAFPointSelectedSet2)(os, value, metadata); - return os; - } - if (model.starts_with("ILCA-99M2") && status && aFAreaModeSetting != 8) { - EXV_PRINT_TAG(sonyAFPointSelectedSet3)(os, value, metadata); - return os; - } - if (model.starts_with("ILCA-") && status && aFAreaModeSetting == 8) { - EXV_PRINT_TAG(sonyAFPointSelectedSet4)(os, value.toUint32(0), metadata); - return os; - } - if (std::any_of(models4.begin(), models4.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyAFPointSelectedSet5)(os, value.toUint32(0), metadata); - return os; - } - os << _("n/a"); - return os; + + for (auto m : {"SLT-", "HV-"}) + if (model.starts_with(m)) + return EXV_PRINT_TAG(sonyAFPointSelectedSet1)(os, value.toUint32(0), metadata); + + for (auto m : {"ILCE-", "ILME-"}) + if (model.starts_with(m) && status && aFAreaModeSetting == 4) + return EXV_PRINT_TAG(sonyAFPointSelectedSet1)(os, value.toUint32(0), metadata); + + for (auto m : {"ILCA-68", "ILCA-77M2"}) + if (model.starts_with(m) && status && aFAreaModeSetting != 8) + return EXV_PRINT_TAG(sonyAFPointSelectedSet2)(os, value, metadata); + + if (model.starts_with("ILCA-99M2") && status && aFAreaModeSetting != 8) + return EXV_PRINT_TAG(sonyAFPointSelectedSet3)(os, value, metadata); + + if (model.starts_with("ILCA-") && status && aFAreaModeSetting == 8) + return EXV_PRINT_TAG(sonyAFPointSelectedSet4)(os, value.toUint32(0), metadata); + + for (auto m : {"NEX-", "ILCE-", "ILME-"}) + if (model.starts_with(m)) + return EXV_PRINT_TAG(sonyAFPointSelectedSet5)(os, value.toUint32(0), metadata); + + return os << _("n/a"); } std::ostream& SonyMakerNote::printAFPointsUsed(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; constexpr std::array models1{"ILCA-", "DSC-"}; - constexpr std::array models2{"ILCA-68", "ILCA-77M2"}; + if (std::none_of(models1.begin(), models1.end(), [&model](auto m) { return model.starts_with(m); })) + return EXV_PRINT_TAG_BITLIST_ALL_LE(sonyAFPointsUsedSet1)(os, value, metadata); - if (std::none_of(models1.begin(), models1.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG_BITLIST_ALL_LE(sonyAFPointsUsedSet1)(os, value, metadata); - return os; - } - if (std::any_of(models2.begin(), models2.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG_BITLIST_ALL_LE(sonyAFPointsUsedSet2)(os, value, metadata); - return os; - } - os << _("n/a"); - return os; + for (auto m : {"ILCA-68", "ILCA-77M2"}) + if (model.starts_with(m)) + return EXV_PRINT_TAG_BITLIST_ALL_LE(sonyAFPointsUsedSet2)(os, value, metadata); + + return os << _("n/a"); } std::ostream& SonyMakerNote::printAFTracking(std::ostream& os, const Value& value, const ExifData* metadata) { - if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedByte || !metadata) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1353 std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; constexpr std::array models{"DSC-RX10M4", "DSC-RX100M6", "DSC-RX100M7", "DSC-RX100M5A", "DSC-HX99", "DSC-RX0M2"}; if (!model.starts_with("DSC-") || - std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) { - EXV_PRINT_TAG(sonyAFTracking)(os, value.toUint32(0), metadata); - return os; - } + std::any_of(models.begin(), models.end(), [&model](auto m) { return model.starts_with(m); })) + return EXV_PRINT_TAG(sonyAFTracking)(os, value.toUint32(0), metadata); - os << _("n/a"); - return os; + return os << _("n/a"); } std::ostream& SonyMakerNote::printFocalPlaneAFPointsUsed(std::ostream& os, const Value& value, const ExifData*) { - if (value.typeId() != unsignedByte) { - os << "(" << value << ")"; - return os; - } - if (value.toUint32(0) == 0) { - os << _("None"); - return os; - } - os << "(" << value << ")"; - return os; + if (value.typeId() != unsignedByte) + return os << "(" << value << ")"; + + if (value.toUint32(0) == 0) + return os << _("None"); + + return os << "(" << value << ")"; } std::ostream& SonyMakerNote::printWBShiftABGMPrecise(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 2 || value.typeId() != signedLong) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 2 || value.typeId() != signedLong) + return os << "(" << value << ")"; + std::ios::fmtflags f(os.flags()); const auto temp0 = static_cast(value.toInt64(0)) / 1000.0; @@ -1226,17 +1162,13 @@ std::ostream& SonyMakerNote::printExposureStandardAdjustment(std::ostream& os, c } std::ostream& SonyMakerNote::printPixelShiftInfo(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 6 || value.typeId() != undefined) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 6 || value.typeId() != undefined) + return os << "(" << value << ")"; // Tag format: // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1504 - if (value.toString() == "0 0 0 0 0 0") { - os << _("n/a"); - return os; - } + if (value.toString() == "0 0 0 0 0 0") + return os << _("n/a"); // Convert from little endian format auto groupID = (value.toUint32(3) << 24) + (value.toUint32(2) << 16) + (value.toUint32(1) << 8) + value.toUint32(0); @@ -1247,55 +1179,49 @@ std::ostream& SonyMakerNote::printPixelShiftInfo(std::ostream& os, const Value& } std::ostream& SonyMakerNote::printFocusFrameSize(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 6 || value.typeId() != undefined) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 6 || value.typeId() != undefined) + return os << "(" << value << ")"; // Tag is written as undefined type but is used as unsignedShort. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L1578 - if (value.toUint32(4) == 0 && value.toUint32(5) == 0) { - os << _("n/a"); - return os; - } + if (value.toUint32(4) == 0 && value.toUint32(5) == 0) + return os << _("n/a"); + // Convert from little endian format - os << ((value.toUint32(1) << 8) + value.toUint32(0)) << "x" << ((value.toUint32(3) << 8) + value.toUint32(2)); - return os; + return os << ((value.toUint32(1) << 8) + value.toUint32(0)) << "x" << ((value.toUint32(3) << 8) + value.toUint32(2)); } std::ostream& SonyMakerNote::printColorTemperature(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedLong) { - os << "(" << value << ")"; - return os; - } - if (auto v0 = value.toUint32(0); v0 == 0) - os << _("Auto"); - else if (v0 == 0xffffffff) - os << _("n/a"); - else - os << v0 << " K"; - return os; + if (value.count() != 1 || value.typeId() != unsignedLong) + return os << "(" << value << ")"; + + auto v0 = value.toUint32(0); + if (v0 == 0) + return os << _("Auto"); + + if (v0 == 0xffffffff) + return os << _("n/a"); + + return os << v0 << " K"; } std::ostream& SonyMakerNote::printColorCompensationFilter(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 1 || value.typeId() != unsignedLong) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 1 || value.typeId() != unsignedLong) + return os << "(" << value << ")"; + // Tag is written as an unsignedLong but used as a signedLong. See // https://github.com/exiftool/exiftool/blob/1e17485cbb372a502e5b9d052d01303db735e6fa/lib/Image/ExifTool/Sony.pm#L2093 int64_t temp = static_cast(value.toUint32(0)); os << "G/M: "; if (temp == 0) - os << "0"; - else if (temp < 0) - os << "G" << -temp; - else - os << "M" << temp; + return os << "0"; - return os; + if (temp < 0) + return os << "G" << -temp; + + return os << "M" << temp; } static void findLensSpecFlags(const Value& value, std::string& flagsStart, std::string& flagsEnd) { @@ -1338,10 +1264,8 @@ static void findLensSpecFlags(const Value& value, std::string& flagsStart, std:: } std::ostream& SonyMakerNote::printLensSpec(std::ostream& os, const Value& value, const ExifData*) { - if (value.count() != 8 || value.typeId() != unsignedByte) { - os << "(" << value << ")"; - return os; - } + if (value.count() != 8 || value.typeId() != unsignedByte) + return os << "(" << value << ")"; // Tag uses 8 bytes in the format: // 0 ? os << (8 * val) : os << N_("n/a"); } @@ -2312,10 +2186,8 @@ std::ostream& SonyMakerNote::printSonyMisc3cModelReleaseYear(std::ostream& os, c return os << "(" << value << ")"; std::string model; - if (!getModel(metadata, model)) { - os << "(" << value << ")"; - return os; - } + if (!getModel(metadata, model)) + return os << "(" << value << ")"; // Tag only valid for certain camera models. See // https://github.com/exiftool/exiftool/blob/7368629751669ba170511419b3d1e05bf0076d0e/lib/Image/ExifTool/Sony.pm#L8245 diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 021bca91d2..adf901d0a2 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -10,6 +10,7 @@ #include "canonmn_int.hpp" #include "casiomn_int.hpp" #include "fujimn_int.hpp" +#include "image_int.hpp" #include "minoltamn_int.hpp" #include "nikonmn_int.hpp" #include "olympusmn_int.hpp" @@ -2909,6 +2910,7 @@ std::ostream& print0x829a(std::ostream& os, const Value& value, const ExifData*) if (value.typeId() != unsignedRational) return os << "(" << value << ")"; + using Exiv2::operator<<; URational t = value.toRational(); if (t.first == 0 || t.second == 0) { os << "(" << t << ")"; @@ -2925,18 +2927,10 @@ std::ostream& print0x829a(std::ostream& os, const Value& value, const ExifData*) } std::ostream& print0x829d(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); Rational fnumber = value.toRational(); - if (fnumber.second != 0) { - std::ostringstream oss; - oss.copyfmt(os); - os << "F" << std::setprecision(2) << static_cast(fnumber.first) / fnumber.second; - os.copyfmt(oss); - } else { - os << "(" << value << ")"; - } - os.flags(f); - return os; + if (fnumber.second != 0) + return os << stringFormat("F{:.2g}", static_cast(fnumber.first) / fnumber.second); + return os << "(" << value << ")"; } //! ExposureProgram, tag 0x8822 @@ -3000,16 +2994,9 @@ std::ostream& print0x9201(std::ostream& os, const Value& value, const ExifData*) } std::ostream& print0x9202(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); - if (value.count() == 0 || value.toRational().second == 0) { + if (value.count() == 0 || value.toRational().second == 0) return os << "(" << value << ")"; - } - std::ostringstream oss; - oss.copyfmt(os); - os << "F" << std::setprecision(2) << fnumber(value.toFloat()); - os.copyfmt(oss); - os.flags(f); - return os; + return os << stringFormat("F{:.2g}", fnumber(value.toFloat())); } std::ostream& print0x9204(std::ostream& os, const Value& value, const ExifData*) { @@ -3033,22 +3020,14 @@ std::ostream& print0x9204(std::ostream& os, const Value& value, const ExifData*) } std::ostream& print0x9206(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); Rational distance = value.toRational(); - if (distance.first == 0) { - os << _("Unknown"); - } else if (static_cast(distance.first) == 0xffffffff) { - os << _("Infinity"); - } else if (distance.second != 0) { - std::ostringstream oss; - oss.copyfmt(os); - os << std::fixed << std::setprecision(2) << static_cast(distance.first) / distance.second << " m"; - os.copyfmt(oss); - } else { - os << "(" << value << ")"; - } - os.flags(f); - return os; + if (distance.first == 0) + return os << _("Unknown"); + if (static_cast(distance.first) == std::numeric_limits::max()) + return os << _("Infinity"); + if (distance.second != 0) + return os << stringFormat("{:.2f} m", static_cast(distance.first) / distance.second); + return os << "(" << value << ")"; } //! MeteringMode, tag 0x9207 @@ -3067,18 +3046,10 @@ std::ostream& print0x9208(std::ostream& os, const Value& value, const ExifData* } std::ostream& print0x920a(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); Rational length = value.toRational(); - if (length.second != 0) { - std::ostringstream oss; - oss.copyfmt(os); - os << std::fixed << std::setprecision(1) << static_cast(length.first) / length.second << " mm"; - os.copyfmt(oss); - } else { - os << "(" << value << ")"; - } - os.flags(f); - return os; + if (length.second != 0) + return os << stringFormat("{:.1f} mm", static_cast(length.first) / length.second); + return os << "(" << value << ")"; } //! ColorSpace, tag 0xa001 @@ -3159,26 +3130,16 @@ std::ostream& print0xa403(std::ostream& os, const Value& value, const ExifData* } std::ostream& print0xa404(std::ostream& os, const Value& value, const ExifData*) { - std::ios::fmtflags f(os.flags()); Rational zoom = value.toRational(); - if (zoom.second == 0) { - os << _("Digital zoom not used"); - } else { - std::ostringstream oss; - oss.copyfmt(os); - os << std::fixed << std::setprecision(1) << static_cast(zoom.first) / zoom.second; - os.copyfmt(oss); - } - os.flags(f); - return os; + if (zoom.second == 0) + return os << _("Digital zoom not used"); + return os << stringFormat("{:.1f}", static_cast(zoom.first) / zoom.second); } std::ostream& print0xa405(std::ostream& os, const Value& value, const ExifData*) { - if (auto length = value.toInt64(); length == 0) - os << _("Unknown"); - else - os << length << ".0 mm"; - return os; + if (auto length = value.toInt64(); length != 0) + return os << length << ".0 mm"; + return os << _("Unknown"); } //! SceneCaptureType, tag 0xa406