Merge pull request #2158 from neheb/1

array and constexpr conversions
main
Luis Díaz Más 3 years ago committed by GitHub
commit 5a47d251f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -297,7 +297,7 @@ class EXIV2API IptcParser {
private:
// Constant data
static const byte marker_; // Dataset marker
static constexpr byte marker_ = 0x1C; // Dataset marker
}; // class IptcParser

@ -24,11 +24,11 @@ namespace Exiv2 {
*/
struct EXIV2API Photoshop {
// Todo: Public for now
static constexpr std::array<const char*, 4> irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
inline static const char* ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
inline static const char* bimId_ = "8BIM"; //!< %Photoshop IRB marker (deprecated)
inline static const uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
inline static const uint16_t preview_ = 0x040c; //!< %Photoshop preview marker
static constexpr std::array irbId_{"8BIM", "AgHg", "DCSR", "PHUT"}; //!< %Photoshop IRB markers
static constexpr auto ps3Id_ = "Photoshop 3.0\0"; //!< %Photoshop marker
static constexpr auto bimId_ = "8BIM"; //!< %Photoshop IRB marker (deprecated)
static constexpr uint16_t iptc_ = 0x0404; //!< %Photoshop IPTC marker
static constexpr uint16_t preview_ = 0x040c; //!< %Photoshop preview marker
/*!
@brief Checks an IRB
@ -313,7 +313,7 @@ class EXIV2API JpegImage : public JpegBase {
private:
// Constant data
static const byte soi_; // SOI marker
static constexpr byte soi_ = 0xd8; // SOI marker
static const byte blank_[]; // Minimal Jpeg image
}; // class JpegImage

@ -69,22 +69,23 @@ class EXIV2API WebPImage : public Image {
void debugPrintHex(byte* data, long size);
void decodeChunks(long filesize);
void inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_alpha, bool has_icc, int width, int height);
static const byte WEBP_PAD_ODD;
static const int WEBP_TAG_SIZE;
static const int WEBP_VP8X_ICC_BIT;
static const int WEBP_VP8X_ALPHA_BIT;
static const int WEBP_VP8X_EXIF_BIT;
static const int WEBP_VP8X_XMP_BIT;
static const char* const WEBP_CHUNK_HEADER_VP8X;
static const char* const WEBP_CHUNK_HEADER_VP8L;
static const char* const WEBP_CHUNK_HEADER_VP8;
static const char* const WEBP_CHUNK_HEADER_ANMF;
static const char* const WEBP_CHUNK_HEADER_ANIM;
static const char* const WEBP_CHUNK_HEADER_ICCP;
static const char* const WEBP_CHUNK_HEADER_EXIF;
static const char* const WEBP_CHUNK_HEADER_XMP;
/* Misc. */
static constexpr byte WEBP_PAD_ODD = 0;
static constexpr int WEBP_TAG_SIZE = 0x4;
/* VP8X feature flags */
static constexpr int WEBP_VP8X_ICC_BIT = 0x20;
static constexpr int WEBP_VP8X_ALPHA_BIT = 0x10;
static constexpr int WEBP_VP8X_EXIF_BIT = 0x8;
static constexpr int WEBP_VP8X_XMP_BIT = 0x4;
/* Chunk header names */
static constexpr auto WEBP_CHUNK_HEADER_VP8X = "VP8X";
static constexpr auto WEBP_CHUNK_HEADER_VP8L = "VP8L";
static constexpr auto WEBP_CHUNK_HEADER_VP8 = "VP8 ";
static constexpr auto WEBP_CHUNK_HEADER_ANMF = "ANMF";
static constexpr auto WEBP_CHUNK_HEADER_ANIM = "ANIM";
static constexpr auto WEBP_CHUNK_HEADER_ICCP = "ICCP";
static constexpr auto WEBP_CHUNK_HEADER_EXIF = "EXIF";
static constexpr auto WEBP_CHUNK_HEADER_XMP = "XMP ";
}; // Class WebPImage
// *****************************************************************************

@ -2568,16 +2568,16 @@ std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& value, co
bool unmatched = true;
// we loop over all our lenses to print out all matching lenses
// if we have multiple possibilities, they are concatenated by "*OR*"
for (auto const& lens : canonCsLensType) {
if (lens.val_ != lensType) {
for (auto&& [val, label] : canonCsLensType) {
if (val != lensType) {
continue;
}
std::cmatch base_match;
if (!std::regex_search(lens.label_, base_match, lens_regex)) {
if (!std::regex_search(label, base_match, lens_regex)) {
// this should never happen, as it would indicate the lens is specified incorrectly
// in the CanonCsLensType array
throw Error(ErrorCode::kerErrorMessage, std::string("Lens regex didn't match for: ") + std::string(lens.label_));
throw Error(ErrorCode::kerErrorMessage, std::string("Lens regex didn't match for: ") + std::string(label));
}
auto tc = base_match[5].length() > 0 ? std::stof(base_match[5].str()) : 1.f;
@ -2595,11 +2595,11 @@ std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& value, co
if (unmatched) {
unmatched = false;
os << lens.label_;
os << label;
continue;
}
os << " *OR* " << lens.label_;
os << " *OR* " << label;
}
// if the entire for loop left us with unmatched==false

@ -40,9 +40,9 @@ constexpr RotationMap::OmList RotationMap::omList_[] = {
uint16_t RotationMap::orientation(int32_t degrees) {
uint16_t o = 1;
for (auto&& om : omList_) {
if (om.degrees == degrees) {
o = om.orientation;
for (auto&& [deg, orient] : omList_) {
if (deg == degrees) {
o = orient;
break;
}
}
@ -51,9 +51,9 @@ uint16_t RotationMap::orientation(int32_t degrees) {
int32_t RotationMap::degrees(uint16_t orientation) {
int32_t d = 0;
for (auto&& om : omList_) {
if (om.orientation == orientation) {
d = om.degrees;
for (auto&& [deg, orient] : omList_) {
if (orient == orientation) {
d = deg;
break;
}
}

@ -65,41 +65,41 @@ struct Registry {
};
/// \todo Use std::unordered_map for implementing the registry. Avoid to use ImageType::none
constexpr Registry registry[] = {
constexpr auto registry = std::array{
// image type creation fct type check Exif mode IPTC mode XMP mode Comment mode
//--------------- --------------- ---------- ----------- ----------- ----------- ------------
{ImageType::jpeg, newJpegInstance, isJpegType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
{ImageType::exv, newExvInstance, isExvType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
{ImageType::cr2, newCr2Instance, isCr2Type, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amNone, amReadWrite},
{ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amRead, amNone},
{ImageType::tiff, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::webp, newWebPInstance, isWebPType, amReadWrite, amNone, amReadWrite, amNone},
{ImageType::dng, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::nef, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::pef, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::arw, newTiffInstance, isTiffType, amRead, amRead, amRead, amNone},
{ImageType::rw2, newRw2Instance, isRw2Type, amRead, amRead, amRead, amNone},
{ImageType::sr2, newTiffInstance, isTiffType, amRead, amRead, amRead, amNone},
{ImageType::srw, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::orf, newOrfInstance, isOrfType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::jpeg, newJpegInstance, isJpegType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
Registry{ImageType::exv, newExvInstance, isExvType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
Registry{ImageType::cr2, newCr2Instance, isCr2Type, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amNone, amReadWrite},
Registry{ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amRead, amNone},
Registry{ImageType::tiff, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::webp, newWebPInstance, isWebPType, amReadWrite, amNone, amReadWrite, amNone},
Registry{ImageType::dng, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::nef, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::pef, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::arw, newTiffInstance, isTiffType, amRead, amRead, amRead, amNone},
Registry{ImageType::rw2, newRw2Instance, isRw2Type, amRead, amRead, amRead, amNone},
Registry{ImageType::sr2, newTiffInstance, isTiffType, amRead, amRead, amRead, amNone},
Registry{ImageType::srw, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::orf, newOrfInstance, isOrfType, amReadWrite, amReadWrite, amReadWrite, amNone},
#ifdef EXV_HAVE_LIBZ
{ImageType::png, newPngInstance, isPngType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
Registry{ImageType::png, newPngInstance, isPngType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
#endif // EXV_HAVE_LIBZ
{ImageType::pgf, newPgfInstance, isPgfType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
{ImageType::raf, newRafInstance, isRafType, amRead, amRead, amRead, amNone},
{ImageType::eps, newEpsInstance, isEpsType, amNone, amNone, amReadWrite, amNone},
{ImageType::xmp, newXmpInstance, isXmpType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::gif, newGifInstance, isGifType, amNone, amNone, amNone, amNone},
{ImageType::psd, newPsdInstance, isPsdType, amReadWrite, amReadWrite, amReadWrite, amNone},
{ImageType::tga, newTgaInstance, isTgaType, amNone, amNone, amNone, amNone},
{ImageType::bmp, newBmpInstance, isBmpType, amNone, amNone, amNone, amNone},
{ImageType::jp2, newJp2Instance, isJp2Type, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::pgf, newPgfInstance, isPgfType, amReadWrite, amReadWrite, amReadWrite, amReadWrite},
Registry{ImageType::raf, newRafInstance, isRafType, amRead, amRead, amRead, amNone},
Registry{ImageType::eps, newEpsInstance, isEpsType, amNone, amNone, amReadWrite, amNone},
Registry{ImageType::xmp, newXmpInstance, isXmpType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::gif, newGifInstance, isGifType, amNone, amNone, amNone, amNone},
Registry{ImageType::psd, newPsdInstance, isPsdType, amReadWrite, amReadWrite, amReadWrite, amNone},
Registry{ImageType::tga, newTgaInstance, isTgaType, amNone, amNone, amNone, amNone},
Registry{ImageType::bmp, newBmpInstance, isBmpType, amNone, amNone, amNone, amNone},
Registry{ImageType::jp2, newJp2Instance, isJp2Type, amReadWrite, amReadWrite, amReadWrite, amNone},
#ifdef EXV_ENABLE_BMFF
{ImageType::bmff, newBmffInstance, isBmffType, amRead, amRead, amRead, amNone},
Registry{ImageType::bmff, newBmffInstance, isBmffType, amRead, amRead, amRead, amNone},
#endif // EXV_ENABLE_BMFF
// End of list marker
{ImageType::none, nullptr, nullptr, amNone, amNone, amNone, amNone},
Registry{ImageType::none, nullptr, nullptr, amNone, amNone, amNone, amNone},
};
std::string pathOfFileUrl(const std::string& url) {
@ -706,8 +706,8 @@ const std::string& Image::tagName(uint16_t tag) {
}
AccessMode ImageFactory::checkMode(ImageType type, MetadataId metadataId) {
const Registry* r = find(registry, type);
if (!r)
auto r = std::find(registry.begin(), registry.end(), type);
if (r == registry.end())
throw Error(ErrorCode::kerUnsupportedImageType, static_cast<int>(type));
AccessMode am = amNone;
switch (metadataId) {
@ -734,10 +734,9 @@ AccessMode ImageFactory::checkMode(ImageType type, MetadataId metadataId) {
}
bool ImageFactory::checkType(ImageType type, BasicIo& io, bool advance) {
const Registry* r = find(registry, type);
if (r) {
auto r = std::find(registry.begin(), registry.end(), type);
if (r != registry.end())
return r->isThisType_(io, advance);
}
return false;
}
@ -836,12 +835,11 @@ Image::UniquePtr ImageFactory::create(ImageType type) {
Image::UniquePtr ImageFactory::create(ImageType type, BasicIo::UniquePtr io) {
// BasicIo instance does not need to be open
const Registry* r = find(registry, type);
if (!r || type == ImageType::none) {
if (type == ImageType::none)
return {};
auto r = std::find(registry.begin(), registry.end(), type);
if (r == registry.end())
return {};
}
return r->newInstance_(std::move(io), true);
}

@ -359,8 +359,6 @@ const char* IptcData::detectCharset() const {
return nullptr;
}
const byte IptcParser::marker_ = 0x1C; // Dataset marker
int IptcParser::decode(IptcData& iptcData, const byte* pData, size_t size) {
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "IptcParser::decode, size = " << size << "\n";

@ -1103,7 +1103,6 @@ void JpegBase::doWriteMetadata(BasicIo& outIo) {
} // JpegBase::doWriteMetadata
const byte JpegImage::soi_ = 0xd8;
const byte JpegImage::blank_[] = {
0xFF, 0xD8, 0xFF, 0xDB, 0x00, 0x84, 0x00, 0x10, 0x0B, 0x0B, 0x0B, 0x0C, 0x0B, 0x10, 0x0C, 0x0C, 0x10, 0x17,
0x0F, 0x0D, 0x0F, 0x17, 0x1B, 0x14, 0x10, 0x10, 0x14, 0x1B, 0x1F, 0x17, 0x17, 0x17, 0x17, 0x17, 0x1F, 0x1E,

@ -808,51 +808,42 @@ struct NikonArrayIdx {
#define NA ((uint32_t)-1)
//! Nikon binary array version lookup table
constexpr NikonArrayIdx nikonArrayIdx[] = {
constexpr auto nikonArrayIdx = std::array{
// NikonSi
{0x0091, "0208", 0, 0, 4}, // D80
{0x0091, "0209", 0, 1, 4}, // D40
{0x0091, "0210", 5291, 2, 4}, // D300
{0x0091, "0210", 5303, 3, 4}, // D300, firmware version 1.10
{0x0091, "02", 0, 4, 4}, // Other v2.* (encrypted)
{0x0091, "01", 0, 5, NA}, // Other v1.* (not encrypted)
NikonArrayIdx{0x0091, "0208", 0, 0, 4}, // D80
NikonArrayIdx{0x0091, "0209", 0, 1, 4}, // D40
NikonArrayIdx{0x0091, "0210", 5291, 2, 4}, // D300
NikonArrayIdx{0x0091, "0210", 5303, 3, 4}, // D300, firmware version 1.10
NikonArrayIdx{0x0091, "02", 0, 4, 4}, // Other v2.* (encrypted)
NikonArrayIdx{0x0091, "01", 0, 5, NA}, // Other v1.* (not encrypted)
// NikonCb
{0x0097, "0100", 0, 0, NA},
{0x0097, "0102", 0, 1, NA},
{0x0097, "0103", 0, 4, NA},
{0x0097, "0205", 0, 2, 4},
{0x0097, "0209", 0, 5, 284},
{0x0097, "0212", 0, 5, 284},
{0x0097, "0214", 0, 5, 284},
{0x0097, "02", 0, 3, 284},
NikonArrayIdx{0x0097, "0100", 0, 0, NA}, NikonArrayIdx{0x0097, "0102", 0, 1, NA},
NikonArrayIdx{0x0097, "0103", 0, 4, NA}, NikonArrayIdx{0x0097, "0205", 0, 2, 4},
NikonArrayIdx{0x0097, "0209", 0, 5, 284}, NikonArrayIdx{0x0097, "0212", 0, 5, 284},
NikonArrayIdx{0x0097, "0214", 0, 5, 284}, NikonArrayIdx{0x0097, "02", 0, 3, 284},
// NikonLd
{0x0098, "0100", 0, 0, NA},
{0x0098, "0101", 0, 1, NA},
{0x0098, "0201", 0, 1, 4},
{0x0098, "0202", 0, 1, 4},
{0x0098, "0203", 0, 1, 4},
{0x0098, "0204", 0, 2, 4},
{0x0098, "0800", 0, 3, 4}, // for e.g. Z6/7
{0x0098, "0801", 0, 3, 4}, // for e.g. Z6/7
NikonArrayIdx{0x0098, "0100", 0, 0, NA}, NikonArrayIdx{0x0098, "0101", 0, 1, NA},
NikonArrayIdx{0x0098, "0201", 0, 1, 4}, NikonArrayIdx{0x0098, "0202", 0, 1, 4},
NikonArrayIdx{0x0098, "0203", 0, 1, 4}, NikonArrayIdx{0x0098, "0204", 0, 2, 4},
NikonArrayIdx{0x0098, "0800", 0, 3, 4}, // for e.g. Z6/7
NikonArrayIdx{0x0098, "0801", 0, 3, 4}, // for e.g. Z6/7
// NikonFl
{0x00a8, "0100", 0, 0, NA},
{0x00a8, "0101", 0, 0, NA},
{0x00a8, "0102", 0, 1, NA},
{0x00a8, "0103", 0, 2, NA},
{0x00a8, "0104", 0, 2, NA},
{0x00a8, "0105", 0, 2, NA},
{0x00a8, "0107", 0, 3, NA},
{0x00a8, "0108", 0, 3, NA},
NikonArrayIdx{0x00a8, "0100", 0, 0, NA}, NikonArrayIdx{0x00a8, "0101", 0, 0, NA},
NikonArrayIdx{0x00a8, "0102", 0, 1, NA}, NikonArrayIdx{0x00a8, "0103", 0, 2, NA},
NikonArrayIdx{0x00a8, "0104", 0, 2, NA}, NikonArrayIdx{0x00a8, "0105", 0, 2, NA},
NikonArrayIdx{0x00a8, "0107", 0, 3, NA}, NikonArrayIdx{0x00a8, "0108", 0, 3, NA},
// NikonAf
{0x00b7, "0100", 30, 0, NA}, // These sizes have been found in tiff headers of MN
{0x00b7, "0101", 84, 1, NA}, // tag 0xb7 in sample image metadata for each version
NikonArrayIdx{0x00b7, "0100", 30, 0, NA}, // These sizes have been found in tiff headers of MN
NikonArrayIdx{0x00b7, "0101", 84, 1, NA}, // tag 0xb7 in sample image metadata for each version
};
int nikonSelector(uint16_t tag, const byte* pData, size_t size, TiffComponent* const /*pRoot*/) {
if (size < 4)
return -1;
const NikonArrayIdx* aix = find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
return aix ? aix->idx_ : -1;
for (auto&& aix : nikonArrayIdx)
if (aix == NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size))
return aix.idx_;
return -1;
}
DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent* const pRoot) {
@ -860,8 +851,9 @@ DataBuf nikonCrypt(uint16_t tag, const byte* pData, size_t size, TiffComponent*
if (size < 4)
return buf;
const NikonArrayIdx* nci = find(nikonArrayIdx, NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
if (!nci || nci->start_ == NA || size <= nci->start_)
auto nci = std::find(nikonArrayIdx.begin(), nikonArrayIdx.end(),
NikonArrayIdx::Key(tag, reinterpret_cast<const char*>(pData), size));
if (nci == nikonArrayIdx.end() || nci->start_ == NA || size <= nci->start_)
return buf;
// Find Exif.Nikon3.ShutterCount
@ -912,7 +904,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) {

@ -1625,19 +1625,11 @@ static std::ostream& resolveLens0xffff(std::ostream& os, const Value& value, con
return EXV_PRINT_TAG(minoltaSonyLensID)(os, value, metadata);
}
struct LensIdFct {
uint32_t id_; //!< Lens id
PrintFct fct_; //!< Pretty-print function
//! Comparison operator for find template
bool operator==(uint32_t id) const {
return id_ == id;
}
};
using LensIdFct = std::pair<uint32_t, PrintFct>;
//! List of lens ids which require special treatment from printMinoltaSonyLensID
const LensIdFct lensIdFct[] = {
{0x001c, resolveLens0x1c}, {0x0029, resolveLens0x29}, {0x0034, resolveLens0x34},
{0x0080, resolveLens0x80}, {0x00ff, resolveLens0xff}, {0xffff, resolveLens0xffff},
constexpr auto lensIdFct = std::array{
LensIdFct(0x001c, resolveLens0x1c), LensIdFct(0x0029, resolveLens0x29), LensIdFct(0x0034, resolveLens0x34),
LensIdFct(0x0080, resolveLens0x80), LensIdFct(0x00ff, resolveLens0xff), LensIdFct(0xffff, resolveLens0xffff),
// { 0x00ff, resolveLensTypeUsingExiftool }, // was used for debugging
};
// #1145 end - respect lenses with shared LensID
@ -1657,12 +1649,9 @@ std::ostream& printMinoltaSonyLensID(std::ostream& os, const Value& value, const
// #1145 - respect lenses with shared LensID
uint32_t index = value.toUint32();
const LensIdFct* lif = find(lensIdFct, index);
if (lif && metadata) {
if (lif->fct_)
return lif->fct_(os, value, metadata);
}
for (auto&& [idx, fct] : lensIdFct)
if (metadata && idx == index && fct)
return fct(os, value, metadata);
return EXV_PRINT_TAG(minoltaSonyLensID)(os, value, metadata);
}

@ -36,7 +36,7 @@ constexpr TagDetails nikonActiveDLighting[] = {
};
//! Focus area for Nikon cameras.
constexpr const char* nikonFocusarea[] = {
constexpr auto nikonFocusarea = std::array{
N_("Single area"), N_("Dynamic area"), N_("Dynamic area, closest subject"),
N_("Group dynamic"), N_("Single area (wide)"), N_("Dynamic area (wide)"),
};
@ -45,7 +45,7 @@ constexpr const char* nikonFocusarea[] = {
// module. Note that relative size and position will vary depending on if
// "wide" or not
//! Focus points for Nikon cameras, used for Nikon 1 and Nikon 3 makernotes.
constexpr const char* nikonFocuspoints[] = {
constexpr auto nikonFocuspoints = std::array{
N_("Center"), N_("Top"), N_("Bottom"), N_("Left"), N_("Right"), N_("Upper-left"),
N_("Upper-right"), N_("Lower-left"), N_("Lower-right"), N_("Left-most"), N_("Right-most"),
};
@ -227,7 +227,7 @@ std::ostream& Nikon1MakerNote::print0x0086(std::ostream& os, const Value& value,
std::ostream& Nikon1MakerNote::print0x0088(std::ostream& os, const Value& value, const ExifData*) {
if (value.count() >= 1) {
const uint32_t focusArea = value.toUint32(0);
if (focusArea >= std::size(nikonFocusarea)) {
if (focusArea >= nikonFocusarea.size()) {
os << "Invalid value";
} else {
os << nikonFocusarea[focusArea];
@ -248,7 +248,7 @@ std::ostream& Nikon1MakerNote::print0x0088(std::ostream& os, const Value& value,
break;
default:
os << value;
if (focusPoint < sizeof(nikonFocuspoints) / sizeof(nikonFocuspoints[0]))
if (focusPoint < nikonFocuspoints.size())
os << " " << _("guess") << " " << nikonFocuspoints[focusPoint];
break;
}
@ -1416,7 +1416,6 @@ std::ostream& Nikon3MakerNote::print0x0088(std::ostream& os, const Value& value,
const uint32_t focuspoint = value.toUint32(1);
const uint32_t focusused = (value.toUint32(2) << 8) + value.toUint32(3);
// TODO: enum {standard, wide} combination = standard;
const size_t focuspoints = sizeof(nikonFocuspoints) / sizeof(nikonFocuspoints[0]);
if (focusmetering == 0 && focuspoint == 0 && focusused == 0) {
// Special case, in Manual focus and with Nikon compacts
@ -1457,7 +1456,7 @@ std::ostream& Nikon3MakerNote::print0x0088(std::ostream& os, const Value& value,
os << sep << ' ';
// What focuspoint did the user select?
if (focuspoint < focuspoints) {
if (focuspoint < nikonFocuspoints.size()) {
os << nikonFocuspoints[focuspoint];
// TODO: os << position[focuspoint][combination]
} else
@ -1473,7 +1472,7 @@ std::ostream& Nikon3MakerNote::print0x0088(std::ostream& os, const Value& value,
// selected point was not the actually used one
// (Roger Larsson: my interpretation, verify)
os << sep;
for (size_t fpid = 0; fpid < focuspoints; fpid++)
for (size_t fpid = 0; fpid < nikonFocuspoints.size(); fpid++)
if (focusused & 1 << fpid)
os << ' ' << nikonFocuspoints[fpid];
}
@ -3242,32 +3241,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<uint16_t, const char*, const char*>;
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<uint16_t>(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;
}

@ -9,6 +9,8 @@
#include "types.hpp"
#include "value.hpp"
#include <array>
// *****************************************************************************
// class member definitions
namespace Exiv2::Internal {
@ -1237,11 +1239,12 @@ struct LensIdFct {
};
//! List of lens ids which require special treatment using resolveLensType
const LensIdFct lensIdFct[] = {
{0x0317, resolveLensType}, {0x0319, resolveLens0x319}, {0x031b, resolveLensType}, {0x031c, resolveLensType},
{0x031d, resolveLensType}, {0x031f, resolveLensType}, {0x0329, resolveLensType}, {0x032c, resolveLens0x32c},
{0x032e, resolveLensType}, {0x0334, resolveLensType}, {0x03ff, resolveLens0x3ff}, {0x041a, resolveLensType},
{0x042d, resolveLensType}, {0x08ff, resolveLens0x8ff},
constexpr auto lensIdFct = std::array{
LensIdFct{0x0317, resolveLensType}, LensIdFct{0x0319, resolveLens0x319}, LensIdFct{0x031b, resolveLensType},
LensIdFct{0x031c, resolveLensType}, LensIdFct{0x031d, resolveLensType}, LensIdFct{0x031f, resolveLensType},
LensIdFct{0x0329, resolveLensType}, LensIdFct{0x032c, resolveLens0x32c}, LensIdFct{0x032e, resolveLensType},
LensIdFct{0x0334, resolveLensType}, LensIdFct{0x03ff, resolveLens0x3ff}, LensIdFct{0x041a, resolveLensType},
LensIdFct{0x042d, resolveLensType}, LensIdFct{0x08ff, resolveLens0x8ff},
};
//! A lens id and a pretty-print function for special treatment of the id.
@ -1256,17 +1259,13 @@ std::ostream& printLensType(std::ostream& os, const Value& value, const ExifData
const auto index = value.toUint32(0) * 256 + value.toUint32(1);
// std::cout << std::endl << "printLensType value =" << value.toLong() << " index = " << index << std::endl;
const LensIdFct* lif = find(lensIdFct, index);
if (!lif) {
auto lif = std::find(lensIdFct.begin(), lensIdFct.end(), index);
if (lif == lensIdFct.end())
return EXV_PRINT_COMBITAG_MULTI(pentaxLensType, 2, 1, 2)(os, value, metadata);
}
if (metadata && lif->fct_) {
if (metadata && lif->fct_)
return lif->fct_(os, value, metadata);
}
if (value.typeId() != unsignedShort || value.count() == 0)
return os << "(" << value << ")";
return os << value;
}

@ -43,20 +43,12 @@ TiffImage::TiffImage(BasicIo::UniquePtr io, bool /*create*/) :
} // TiffImage::TiffImage
//! Structure for TIFF compression to MIME type mappings
struct MimeTypeList {
//! Comparison operator for compression
bool operator==(int compression) const {
return compression_ == compression;
}
int compression_; //!< TIFF compression
const char* mimeType_; //!< MIME type
};
using MimeTypeList = std::pair<int, const char*>;
//! List of TIFF compression to MIME type mappings
constexpr auto mimeTypeList = std::array{
MimeTypeList{32770, "image/x-samsung-srw"},
MimeTypeList{34713, "image/x-nikon-nef"},
MimeTypeList{65535, "image/x-pentax-pef"},
MimeTypeList(32770, "image/x-samsung-srw"),
MimeTypeList(34713, "image/x-nikon-nef"),
MimeTypeList(65535, "image/x-pentax-pef"),
};
std::string TiffImage::mimeType() const {
@ -67,9 +59,10 @@ std::string TiffImage::mimeType() const {
std::string key = "Exif." + primaryGroup() + ".Compression";
auto md = exifData_.findKey(ExifKey(key));
if (md != exifData_.end() && md->count() > 0) {
auto i = std::find(mimeTypeList.begin(), mimeTypeList.end(), static_cast<int>(md->toInt64()));
if (i != mimeTypeList.end())
mimeType_ = std::string(i->mimeType_);
for (auto&& [comp, type] : mimeTypeList)
if (comp == static_cast<int>(md->toInt64())) {
mimeType_ = type;
}
}
return mimeType_;
}

@ -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<uint16_t, uint16_t, bool>;
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++);
}

@ -78,30 +78,6 @@ std::string WebPImage::mimeType() const {
return "image/webp";
}
/* =========================================== */
/* Misc. */
constexpr byte WebPImage::WEBP_PAD_ODD = 0;
constexpr int WebPImage::WEBP_TAG_SIZE = 0x4;
/* VP8X feature flags */
constexpr int WebPImage::WEBP_VP8X_ICC_BIT = 0x20;
constexpr int WebPImage::WEBP_VP8X_ALPHA_BIT = 0x10;
constexpr int WebPImage::WEBP_VP8X_EXIF_BIT = 0x8;
constexpr int WebPImage::WEBP_VP8X_XMP_BIT = 0x4;
/* Chunk header names */
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_VP8X = "VP8X";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_VP8L = "VP8L";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_VP8 = "VP8 ";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_ANMF = "ANMF";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_ANIM = "ANIM";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_ICCP = "ICCP";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_EXIF = "EXIF";
constexpr const char* WebPImage::WEBP_CHUNK_HEADER_XMP = "XMP ";
/* =========================================== */
void WebPImage::setIptcData(const IptcData& /*iptcData*/) {
// not supported
// just quietly ignore the request

Loading…
Cancel
Save