From 9cb1fcef5c9d2c8566d06ea2ec5e4531bd04d5a1 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 18 Mar 2022 15:54:42 -0700 Subject: [PATCH] std::array conversions Signed-off-by: Rosen Penev --- src/makernote_int.cpp | 2 +- src/nikonmn_int.cpp | 44 ++++++++++++++++------------------ src/tiffvisitor_int.cpp | 53 +++++++++++++++++++---------------------- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/src/makernote_int.cpp b/src/makernote_int.cpp index 6aaf5738..aaf0b4b5 100644 --- a/src/makernote_int.cpp +++ b/src/makernote_int.cpp @@ -912,7 +912,7 @@ int sony2010eSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, "NEX-6", "VG30E", "VG900", "DSC-RX100", "DSC-RX1", "DSC-RX1R", "DSC-HX300", "DSC-HX50V", "DSC-TX30", "DSC-WX60", "DSC-WX200", "DSC-WX300", }; - return std::find(models.begin(), models.end(), getExifModel(pRoot)) != std::end(models) ? 0 : -1; + return std::find(models.begin(), models.end(), getExifModel(pRoot)) != models.end() ? 0 : -1; } int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, size_t /*size*/, TiffComponent* const pRoot) { diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 2c06f1ee..9b898ea3 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -3242,32 +3242,30 @@ std::ostream& Nikon3MakerNote::printLensId4ZMount(std::ostream& os, const Value& } // from https://github.com/exiftool/exiftool/blob/12.12/lib/Image/ExifTool/Nikon.pm#L4646 - static const struct ZMntLens { - uint16_t lid; - const char *manuf, *lensname; - } zmountlens[] = { - {1, "Nikon", "Nikkor Z 24-70mm f/4 S"}, - {2, "Nikon", "Nikkor Z 14-30mm f/4 S"}, - {4, "Nikon", "Nikkor Z 35mm f/1.8 S"}, - {8, "Nikon", "Nikkor Z 58mm f/0.95 S Noct"}, // IB - {9, "Nikon", "Nikkor Z 50mm f/1.8 S"}, - {11, "Nikon", "Nikkor Z DX 16-50mm f/3.5-6.3 VR"}, - {12, "Nikon", "Nikkor Z DX 50-250mm f/4.5-6.3 VR"}, - {13, "Nikon", "Nikkor Z 24-70mm f/2.8 S"}, - {14, "Nikon", "Nikkor Z 85mm f/1.8 S"}, - {15, "Nikon", "Nikkor Z 24mm f/1.8 S"}, // IB - {16, "Nikon", "Nikkor Z 70-200mm f/2.8 VR S"}, // IB - {17, "Nikon", "Nikkor Z 20mm f/1.8 S"}, // IB - {18, "Nikon", "Nikkor Z 24-200mm f/4-6.3 VR"}, // IB - {21, "Nikon", "Nikkor Z 50mm f/1.2 S"}, // IB - {22, "Nikon", "Nikkor Z 24-50mm f/4-6.3"}, // IB - {23, "Nikon", "Nikkor Z 14-24mm f/2.8 S"}, // IB + using ZMntLens = std::tuple; + static constexpr auto zmountlens = std::array{ + ZMntLens(1, "Nikon", "Nikkor Z 24-70mm f/4 S"), + ZMntLens(2, "Nikon", "Nikkor Z 14-30mm f/4 S"), + ZMntLens(4, "Nikon", "Nikkor Z 35mm f/1.8 S"), + ZMntLens(8, "Nikon", "Nikkor Z 58mm f/0.95 S Noct"), // IB + ZMntLens(9, "Nikon", "Nikkor Z 50mm f/1.8 S"), + ZMntLens(11, "Nikon", "Nikkor Z DX 16-50mm f/3.5-6.3 VR"), + ZMntLens(12, "Nikon", "Nikkor Z DX 50-250mm f/4.5-6.3 VR"), + ZMntLens(13, "Nikon", "Nikkor Z 24-70mm f/2.8 S"), + ZMntLens(14, "Nikon", "Nikkor Z 85mm f/1.8 S"), + ZMntLens(15, "Nikon", "Nikkor Z 24mm f/1.8 S"), // IB + ZMntLens(16, "Nikon", "Nikkor Z 70-200mm f/2.8 VR S"), // IB + ZMntLens(17, "Nikon", "Nikkor Z 20mm f/1.8 S"), // IB + ZMntLens(18, "Nikon", "Nikkor Z 24-200mm f/4-6.3 VR"), // IB + ZMntLens(21, "Nikon", "Nikkor Z 50mm f/1.2 S"), // IB + ZMntLens(22, "Nikon", "Nikkor Z 24-50mm f/4-6.3"), // IB + ZMntLens(23, "Nikon", "Nikkor Z 14-24mm f/2.8 S"), // IB }; auto lid = static_cast(value.toInt64()); - auto it = std::find_if(std::begin(zmountlens), std::end(zmountlens), [=](const ZMntLens& z) { return z.lid == lid; }); - if (it != std::end(zmountlens)) - return os << it->manuf << " " << it->lensname; + for (auto&& [l, manuf, lensname] : zmountlens) + if (l == lid) + return os << manuf << " " << lensname; return os << lid; } diff --git a/src/tiffvisitor_int.cpp b/src/tiffvisitor_int.cpp index 4b097db7..ac41f133 100644 --- a/src/tiffvisitor_int.cpp +++ b/src/tiffvisitor_int.cpp @@ -372,46 +372,43 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) { const uint16_t nMasks = (nPoints + 15) / (sizeof(uint16_t) * 8); int nStart = 0; - static const struct { - uint16_t tag; - uint16_t size; - bool bSigned; - } records[] = { - {0x2600, 1, true}, // AFInfoSize - {0x2601, 1, true}, // AFAreaMode - {0x2602, 1, true}, // AFNumPoints - {0x2603, 1, true}, // AFValidPoints - {0x2604, 1, true}, // AFCanonImageWidth - {0x2605, 1, true}, // AFCanonImageHeight - {0x2606, 1, true}, // AFImageWidth" - {0x2607, 1, true}, // AFImageHeight - {0x2608, nPoints, true}, // AFAreaWidths - {0x2609, nPoints, true}, // AFAreaHeights - {0x260a, nPoints, true}, // AFXPositions - {0x260b, nPoints, true}, // AFYPositions - {0x260c, nMasks, false}, // AFPointsInFocus - {0x260d, nMasks, false}, // AFPointsSelected - {0x260e, nMasks, false}, // AFPointsUnusable + using record = std::tuple; + static const auto records = std::array{ + record(0x2600, 1, true), // AFInfoSize + record(0x2601, 1, true), // AFAreaMode + record(0x2602, 1, true), // AFNumPoints + record(0x2603, 1, true), // AFValidPoints + record(0x2604, 1, true), // AFCanonImageWidth + record(0x2605, 1, true), // AFCanonImageHeight + record(0x2606, 1, true), // AFImageWidth" + record(0x2607, 1, true), // AFImageHeight + record(0x2608, nPoints, true), // AFAreaWidths + record(0x2609, nPoints, true), // AFAreaHeights + record(0x260a, nPoints, true), // AFXPositions + record(0x260b, nPoints, true), // AFYPositions + record(0x260c, nMasks, false), // AFPointsInFocus + record(0x260d, nMasks, false), // AFPointsSelected + record(0x260e, nMasks, false), // AFPointsUnusable }; // check we have enough data! uint16_t count = 0; - for (auto&& record : records) { - count += record.size; + for (auto&& [tag, size, bSigned] : records) { + count += size; if (count > ints.size()) return; } - for (auto&& record : records) { + for (auto&& [tag, size, bSigned] : records) { const TagInfo* pTags = ExifTags::tagList("Canon"); - const TagInfo* pTag = findTag(pTags, record.tag); + const TagInfo* pTag = findTag(pTags, tag); if (pTag) { - auto v = Exiv2::Value::create(record.bSigned ? Exiv2::signedShort : Exiv2::unsignedShort); + auto v = Exiv2::Value::create(bSigned ? Exiv2::signedShort : Exiv2::unsignedShort); std::ostringstream s; - if (record.bSigned) { - for (uint16_t k = 0; k < record.size; k++) + if (bSigned) { + for (uint16_t k = 0; k < size; k++) s << " " << ints.at(nStart++); } else { - for (uint16_t k = 0; k < record.size; k++) + for (uint16_t k = 0; k < size; k++) s << " " << uint.at(nStart++); }