Skip to content

Commit

Permalink
Convert IfdId and SectionId to enum classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse committed Jul 11, 2022
1 parent 62043c1 commit b7152ec
Show file tree
Hide file tree
Showing 29 changed files with 4,988 additions and 4,614 deletions.
2 changes: 1 addition & 1 deletion include/exiv2/exif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class EXIV2API Exifdatum : public Metadatum {
[[nodiscard]] std::string tagLabel() const override;
[[nodiscard]] uint16_t tag() const override;
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
[[nodiscard]] int ifdId() const;
[[nodiscard]] IfdId ifdId() const;
//! Return the name of the IFD
[[nodiscard]] const char* ifdName() const;
//! Return the index (unique id of this key within the original IFD)
Expand Down
46 changes: 25 additions & 21 deletions include/exiv2/tags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,8 @@ using TagListFct = const TagInfo* (*)();
// *****************************************************************************
// class definitions

//! The details of an Exif group. Groups include IFDs and binary arrays.
struct EXIV2API GroupInfo {
struct GroupName;
bool operator==(int ifdId) const; //!< Comparison operator for IFD id
bool operator==(const GroupName& groupName) const; //!< Comparison operator for group name
int ifdId_; //!< IFD id
const char* ifdName_; //!< IFD name
const char* groupName_; //!< Group name, unique for each group.
TagListFct tagList_; //!< Tag list
};

//! Search key to find a GroupInfo by its group name.
struct EXIV2API GroupInfo::GroupName {
explicit GroupName(std::string groupName);
std::string g_; //!< Group name
};

//! Type to specify the IFD to which a metadata belongs
enum IfdId {
enum class IfdId : uint32_t {
ifdIdNotSet,
ifd0Id,
ifd1Id,
Expand Down Expand Up @@ -192,11 +175,32 @@ enum IfdId {
ignoreId = lastId
};

inline std::ostream& operator<<(std::ostream& os, IfdId id) {
return os << static_cast<int>(id);
}

//! The details of an Exif group. Groups include IFDs and binary arrays.
struct EXIV2API GroupInfo {
struct GroupName;
bool operator==(IfdId ifdId) const; //!< Comparison operator for IFD id
bool operator==(const GroupName& groupName) const; //!< Comparison operator for group name
IfdId ifdId_; //!< IFD id
const char* ifdName_; //!< IFD name
const char* groupName_; //!< Group name, unique for each group.
TagListFct tagList_; //!< Tag list
};

//! Search key to find a GroupInfo by its group name.
struct EXIV2API GroupInfo::GroupName {
explicit GroupName(std::string groupName);
std::string g_; //!< Group name
};

/*!
@brief Section identifiers to logically group tags. A section consists
of nothing more than a name, based on the Exif standard.
*/
enum SectionId {
enum class SectionId {
sectionIdNotSet,
imgStruct, // 4.6.4 A
recOffset, // 4.6.4 B
Expand Down Expand Up @@ -330,8 +334,8 @@ class EXIV2API ExifKey : public Key {
[[nodiscard]] std::string key() const override;
[[nodiscard]] const char* familyName() const override;
[[nodiscard]] std::string groupName() const override;
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
[[nodiscard]] int ifdId() const;
//! Return the IFD id. (Do not use, this is meant for library internal use.)
[[nodiscard]] IfdId ifdId() const;
[[nodiscard]] std::string tagName() const override;
[[nodiscard]] uint16_t tag() const override;
[[nodiscard]] std::string tagLabel() const override;
Expand Down
1,254 changes: 662 additions & 592 deletions src/canonmn_int.cpp

Large diffs are not rendered by default.

223 changes: 116 additions & 107 deletions src/casiomn_int.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cr2header_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DataBuf Cr2Header::write() const {

bool Cr2Header::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* /*pPrimaryGroups*/) const {
// CR2 image tags are all IFD2 and IFD3 tags
if (group == ifd2Id || group == ifd3Id)
if (group == IfdId::ifd2Id || group == IfdId::ifd3Id)
return true;
// ...and any (IFD0) tag that is in the TIFF image tags list
return isTiffImageTag(tag, group);
Expand Down
2 changes: 1 addition & 1 deletion src/cr2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteO

// Delete IFDs which do not occur in TIFF images
static constexpr auto filteredIfds = std::array{
panaRawId,
IfdId::panaRawId,
};
for (auto&& filteredIfd : filteredIfds) {
#ifdef EXIV2_DEBUG_MESSAGES
Expand Down
76 changes: 38 additions & 38 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,31 @@ namespace Exiv2::Internal {
const CrwMapping CrwMap::crwMapping_[] = {
// CrwTag CrwDir Size ExifTag IfdId decodeFct encodeFct
// ------ ------ ---- ------- ----- --------- ---------
CrwMapping(0x0805, 0x300a, 0, 0, canonId, decode0x0805, encode0x0805),
CrwMapping(0x080a, 0x2807, 0, 0, canonId, decode0x080a, encode0x080a),
CrwMapping(0x080b, 0x3004, 0, 0x0007, canonId, decodeBasic, encodeBasic),
CrwMapping(0x0810, 0x2807, 0, 0x0009, canonId, decodeBasic, encodeBasic),
CrwMapping(0x0815, 0x2804, 0, 0x0006, canonId, decodeBasic, encodeBasic),
CrwMapping(0x1029, 0x300b, 0, 0x0002, canonId, decodeBasic, encodeBasic),
CrwMapping(0x102a, 0x300b, 0, 0x0004, canonId, decodeArray, encodeArray),
CrwMapping(0x102d, 0x300b, 0, 0x0001, canonId, decodeArray, encodeArray),
CrwMapping(0x1033, 0x300b, 0, 0x000f, canonId, decodeArray, encodeArray),
CrwMapping(0x1038, 0x300b, 0, 0x0012, canonId, decodeArray, encodeArray),
CrwMapping(0x10a9, 0x300b, 0, 0x00a9, canonId, decodeBasic, encodeBasic),
CrwMapping(0x0805, 0x300a, 0, 0, IfdId::canonId, decode0x0805, encode0x0805),
CrwMapping(0x080a, 0x2807, 0, 0, IfdId::canonId, decode0x080a, encode0x080a),
CrwMapping(0x080b, 0x3004, 0, 0x0007, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x0810, 0x2807, 0, 0x0009, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x0815, 0x2804, 0, 0x0006, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x1029, 0x300b, 0, 0x0002, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x102a, 0x300b, 0, 0x0004, IfdId::canonId, decodeArray, encodeArray),
CrwMapping(0x102d, 0x300b, 0, 0x0001, IfdId::canonId, decodeArray, encodeArray),
CrwMapping(0x1033, 0x300b, 0, 0x000f, IfdId::canonId, decodeArray, encodeArray),
CrwMapping(0x1038, 0x300b, 0, 0x0012, IfdId::canonId, decodeArray, encodeArray),
CrwMapping(0x10a9, 0x300b, 0, 0x00a9, IfdId::canonId, decodeBasic, encodeBasic),
// Mapped to Exif.Photo.ColorSpace instead (see below)
// CrwMapping(0x10b4, 0x300b, 0, 0x00b4, canonId, decodeBasic, encodeBasic),
CrwMapping(0x10b4, 0x300b, 0, 0xa001, exifId, decodeBasic, encodeBasic),
CrwMapping(0x10b5, 0x300b, 0, 0x00b5, canonId, decodeBasic, encodeBasic),
CrwMapping(0x10c0, 0x300b, 0, 0x00c0, canonId, decodeBasic, encodeBasic),
CrwMapping(0x10c1, 0x300b, 0, 0x00c1, canonId, decodeBasic, encodeBasic),
CrwMapping(0x1807, 0x3002, 0, 0x9206, exifId, decodeBasic, encodeBasic),
CrwMapping(0x180b, 0x3004, 0, 0x000c, canonId, decodeBasic, encodeBasic),
CrwMapping(0x180e, 0x300a, 0, 0x9003, exifId, decode0x180e, encode0x180e),
CrwMapping(0x1810, 0x300a, 0, 0xa002, exifId, decode0x1810, encode0x1810),
CrwMapping(0x1817, 0x300a, 4, 0x0008, canonId, decodeBasic, encodeBasic),
// CrwMapping(0x1818, 0x3002, 0, 0x9204, exifId, decodeBasic, encodeBasic),
CrwMapping(0x183b, 0x300b, 0, 0x0015, canonId, decodeBasic, encodeBasic),
CrwMapping(0x2008, 0x0000, 0, 0, ifd1Id, decode0x2008, encode0x2008),
// CrwMapping(0x10b4, 0x300b, 0, 0x00b4, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x10b4, 0x300b, 0, 0xa001, IfdId::exifId, decodeBasic, encodeBasic),
CrwMapping(0x10b5, 0x300b, 0, 0x00b5, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x10c0, 0x300b, 0, 0x00c0, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x10c1, 0x300b, 0, 0x00c1, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x1807, 0x3002, 0, 0x9206, IfdId::exifId, decodeBasic, encodeBasic),
CrwMapping(0x180b, 0x3004, 0, 0x000c, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x180e, 0x300a, 0, 0x9003, IfdId::exifId, decode0x180e, encode0x180e),
CrwMapping(0x1810, 0x300a, 0, 0xa002, IfdId::exifId, decode0x1810, encode0x1810),
CrwMapping(0x1817, 0x300a, 4, 0x0008, IfdId::canonId, decodeBasic, encodeBasic),
// CrwMapping(0x1818, 0x3002, 0, 0x9204, IfdId::exifId, decodeBasic, encodeBasic),
CrwMapping(0x183b, 0x300b, 0, 0x0015, IfdId::canonId, decodeBasic, encodeBasic),
CrwMapping(0x2008, 0x0000, 0, 0, IfdId::ifd1Id, decode0x2008, encode0x2008),
}; // CrwMap::crwMapping_[]

/*
Expand Down Expand Up @@ -698,19 +698,19 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
int64_t aperture = 0;
int64_t shutterSpeed = 0;

IfdId ifdId = ifdIdNotSet;
IfdId ifdId = IfdId::ifdIdNotSet;
switch (pCrwMapping->tag_) {
case 0x0001:
ifdId = canonCsId;
ifdId = IfdId::canonCsId;
break;
case 0x0004:
ifdId = canonSiId;
ifdId = IfdId::canonSiId;
break;
case 0x000f:
ifdId = canonCfId;
ifdId = IfdId::canonCfId;
break;
case 0x0012:
ifdId = canonPiId;
ifdId = IfdId::canonPiId;
break;
}

Expand All @@ -725,18 +725,18 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
uint16_t n = 1;
ExifKey key(c, groupName);
UShortValue value;
if (ifdId == canonCsId && c == 23 && component_size >= 52)
if (ifdId == IfdId::canonCsId && c == 23 && component_size >= 52)
n = 3;
value.read(ciffComponent.pData() + c * 2, n * 2, byteOrder);
image.exifData().add(key, &value);
if (ifdId == canonSiId && c == 21)
if (ifdId == IfdId::canonSiId && c == 21)
aperture = value.toInt64();
if (ifdId == canonSiId && c == 22)
if (ifdId == IfdId::canonSiId && c == 22)
shutterSpeed = value.toInt64();
c += n;
}

if (ifdId == canonSiId) {
if (ifdId == IfdId::canonSiId) {
// Exif.Photo.FNumber
float f = fnumber(canonEv(aperture));
auto [r, s] = floatToRationalCast(f);
Expand Down Expand Up @@ -912,19 +912,19 @@ void CrwMap::encode0x080a(const Image& image, const CrwMapping* pCrwMapping, Cif
}

void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) {
IfdId ifdId = ifdIdNotSet;
IfdId ifdId = IfdId::ifdIdNotSet;
switch (pCrwMapping->tag_) {
case 0x0001:
ifdId = canonCsId;
ifdId = IfdId::canonCsId;
break;
case 0x0004:
ifdId = canonSiId;
ifdId = IfdId::canonSiId;
break;
case 0x000f:
ifdId = canonCfId;
ifdId = IfdId::canonCfId;
break;
case 0x0012:
ifdId = canonPiId;
ifdId = IfdId::canonPiId;
break;
}
DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder());
Expand Down
11 changes: 6 additions & 5 deletions src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ uint16_t Exifdatum::tag() const {
return key_ ? key_->tag() : 0xffff;
}

int Exifdatum::ifdId() const {
return key_ ? key_->ifdId() : ifdIdNotSet;
IfdId Exifdatum::ifdId() const {
return key_ ? key_->ifdId() : IfdId::ifdIdNotSet;
}

const char* Exifdatum::ifdName() const {
Expand Down Expand Up @@ -430,7 +430,7 @@ void ExifThumb::setJpegThumbnail(const byte* buf, size_t size) {
}

void ExifThumb::erase() {
eraseIfd(exifData_, ifd1Id);
eraseIfd(exifData_, IfdId::ifd1Id);
}

Exifdatum& ExifData::operator[](const std::string& key) {
Expand Down Expand Up @@ -544,8 +544,9 @@ WriteMethod ExifParser::encode(Blob& blob, const byte* pData, size_t size, ByteO

// Delete IFDs which do not occur in JPEGs
static constexpr auto filteredIfds = std::array{
subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id, subImage6Id, subImage7Id,
subImage8Id, subImage9Id, subThumb1Id, panaRawId, ifd2Id, ifd3Id,
IfdId::subImage1Id, IfdId::subImage2Id, IfdId::subImage3Id, IfdId::subImage4Id, IfdId::subImage5Id,
IfdId::subImage6Id, IfdId::subImage7Id, IfdId::subImage8Id, IfdId::subImage9Id, IfdId::subThumb1Id,
IfdId::panaRawId, IfdId::ifd2Id, IfdId::ifd3Id,
};
for (auto&& filteredIfd : filteredIfds) {
#ifdef EXIV2_DEBUG_MESSAGES
Expand Down
Loading

0 comments on commit b7152ec

Please sign in to comment.