From bad4712df8eb2299301568f19f64dcc36d04d1ef Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 18 Mar 2022 16:04:13 -0700 Subject: [PATCH] static constexpr conversions Signed-off-by: Rosen Penev --- include/exiv2/iptc.hpp | 2 +- include/exiv2/jpgimage.hpp | 12 ++++++------ include/exiv2/webpimage.hpp | 33 +++++++++++++++++---------------- src/iptc.cpp | 2 -- src/jpgimage.cpp | 1 - src/nikonmn_int.cpp | 13 ++++++------- src/webpimage.cpp | 24 ------------------------ 7 files changed, 30 insertions(+), 57 deletions(-) diff --git a/include/exiv2/iptc.hpp b/include/exiv2/iptc.hpp index c9a745ed..69f9e328 100644 --- a/include/exiv2/iptc.hpp +++ b/include/exiv2/iptc.hpp @@ -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 diff --git a/include/exiv2/jpgimage.hpp b/include/exiv2/jpgimage.hpp index def2a219..9c867d00 100644 --- a/include/exiv2/jpgimage.hpp +++ b/include/exiv2/jpgimage.hpp @@ -24,11 +24,11 @@ namespace Exiv2 { */ struct EXIV2API Photoshop { // Todo: Public for now - static constexpr std::array 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 diff --git a/include/exiv2/webpimage.hpp b/include/exiv2/webpimage.hpp index 6b84d939..29fbf189 100644 --- a/include/exiv2/webpimage.hpp +++ b/include/exiv2/webpimage.hpp @@ -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 // ***************************************************************************** diff --git a/src/iptc.cpp b/src/iptc.cpp index b11a7efe..75861799 100644 --- a/src/iptc.cpp +++ b/src/iptc.cpp @@ -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"; diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 4b016522..13e59471 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -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, diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index 9b898ea3..b6ee44cf 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -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]; } diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 0c4cb505..2018b5dc 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -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