Skip to content

Commit 3ef783e

Browse files
Convert IfdId and SectionId to enum classes.
1 parent 62043c1 commit 3ef783e

28 files changed

+4987
-4613
lines changed

include/exiv2/exif.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class EXIV2API Exifdatum : public Metadatum {
142142
[[nodiscard]] std::string tagLabel() const override;
143143
[[nodiscard]] uint16_t tag() const override;
144144
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
145-
[[nodiscard]] int ifdId() const;
145+
[[nodiscard]] IfdId ifdId() const;
146146
//! Return the name of the IFD
147147
[[nodiscard]] const char* ifdName() const;
148148
//! Return the index (unique id of this key within the original IFD)

include/exiv2/tags.hpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,8 @@ using TagListFct = const TagInfo* (*)();
3030
// *****************************************************************************
3131
// class definitions
3232

33-
//! The details of an Exif group. Groups include IFDs and binary arrays.
34-
struct EXIV2API GroupInfo {
35-
struct GroupName;
36-
bool operator==(int ifdId) const; //!< Comparison operator for IFD id
37-
bool operator==(const GroupName& groupName) const; //!< Comparison operator for group name
38-
int ifdId_; //!< IFD id
39-
const char* ifdName_; //!< IFD name
40-
const char* groupName_; //!< Group name, unique for each group.
41-
TagListFct tagList_; //!< Tag list
42-
};
43-
44-
//! Search key to find a GroupInfo by its group name.
45-
struct EXIV2API GroupInfo::GroupName {
46-
explicit GroupName(std::string groupName);
47-
std::string g_; //!< Group name
48-
};
49-
5033
//! Type to specify the IFD to which a metadata belongs
51-
enum IfdId {
34+
enum class IfdId : uint32_t {
5235
ifdIdNotSet,
5336
ifd0Id,
5437
ifd1Id,
@@ -192,11 +175,32 @@ enum IfdId {
192175
ignoreId = lastId
193176
};
194177

178+
inline std::ostream& operator<<(std::ostream& os, IfdId id) {
179+
return os << static_cast<int>(id);
180+
}
181+
182+
//! The details of an Exif group. Groups include IFDs and binary arrays.
183+
struct EXIV2API GroupInfo {
184+
struct GroupName;
185+
bool operator==(IfdId ifdId) const; //!< Comparison operator for IFD id
186+
bool operator==(const GroupName& groupName) const; //!< Comparison operator for group name
187+
IfdId ifdId_; //!< IFD id
188+
const char* ifdName_; //!< IFD name
189+
const char* groupName_; //!< Group name, unique for each group.
190+
TagListFct tagList_; //!< Tag list
191+
};
192+
193+
//! Search key to find a GroupInfo by its group name.
194+
struct EXIV2API GroupInfo::GroupName {
195+
explicit GroupName(std::string groupName);
196+
std::string g_; //!< Group name
197+
};
198+
195199
/*!
196200
@brief Section identifiers to logically group tags. A section consists
197201
of nothing more than a name, based on the Exif standard.
198202
*/
199-
enum SectionId {
203+
enum class SectionId {
200204
sectionIdNotSet,
201205
imgStruct, // 4.6.4 A
202206
recOffset, // 4.6.4 B
@@ -330,8 +334,8 @@ class EXIV2API ExifKey : public Key {
330334
[[nodiscard]] std::string key() const override;
331335
[[nodiscard]] const char* familyName() const override;
332336
[[nodiscard]] std::string groupName() const override;
333-
//! Return the IFD id as an integer. (Do not use, this is meant for library internal use.)
334-
[[nodiscard]] int ifdId() const;
337+
//! Return the IFD id. (Do not use, this is meant for library internal use.)
338+
[[nodiscard]] IfdId ifdId() const;
335339
[[nodiscard]] std::string tagName() const override;
336340
[[nodiscard]] uint16_t tag() const override;
337341
[[nodiscard]] std::string tagLabel() const override;

src/canonmn_int.cpp

Lines changed: 662 additions & 592 deletions
Large diffs are not rendered by default.

src/casiomn_int.cpp

Lines changed: 116 additions & 107 deletions
Large diffs are not rendered by default.

src/cr2header_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ DataBuf Cr2Header::write() const {
5252

5353
bool Cr2Header::isImageTag(uint16_t tag, IfdId group, const PrimaryGroups* /*pPrimaryGroups*/) const {
5454
// CR2 image tags are all IFD2 and IFD3 tags
55-
if (group == ifd2Id || group == ifd3Id)
55+
if (group == IfdId::ifd2Id || group == IfdId::ifd3Id)
5656
return true;
5757
// ...and any (IFD0) tag that is in the TIFF image tags list
5858
return isTiffImageTag(tag, group);

src/cr2image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ WriteMethod Cr2Parser::encode(BasicIo& io, const byte* pData, size_t size, ByteO
112112

113113
// Delete IFDs which do not occur in TIFF images
114114
static constexpr auto filteredIfds = std::array{
115-
panaRawId,
115+
IfdId::panaRawId,
116116
};
117117
for (auto&& filteredIfd : filteredIfds) {
118118
#ifdef EXIV2_DEBUG_MESSAGES

src/crwimage_int.cpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,31 @@ namespace Exiv2::Internal {
7878
const CrwMapping CrwMap::crwMapping_[] = {
7979
// CrwTag CrwDir Size ExifTag IfdId decodeFct encodeFct
8080
// ------ ------ ---- ------- ----- --------- ---------
81-
CrwMapping(0x0805, 0x300a, 0, 0, canonId, decode0x0805, encode0x0805),
82-
CrwMapping(0x080a, 0x2807, 0, 0, canonId, decode0x080a, encode0x080a),
83-
CrwMapping(0x080b, 0x3004, 0, 0x0007, canonId, decodeBasic, encodeBasic),
84-
CrwMapping(0x0810, 0x2807, 0, 0x0009, canonId, decodeBasic, encodeBasic),
85-
CrwMapping(0x0815, 0x2804, 0, 0x0006, canonId, decodeBasic, encodeBasic),
86-
CrwMapping(0x1029, 0x300b, 0, 0x0002, canonId, decodeBasic, encodeBasic),
87-
CrwMapping(0x102a, 0x300b, 0, 0x0004, canonId, decodeArray, encodeArray),
88-
CrwMapping(0x102d, 0x300b, 0, 0x0001, canonId, decodeArray, encodeArray),
89-
CrwMapping(0x1033, 0x300b, 0, 0x000f, canonId, decodeArray, encodeArray),
90-
CrwMapping(0x1038, 0x300b, 0, 0x0012, canonId, decodeArray, encodeArray),
91-
CrwMapping(0x10a9, 0x300b, 0, 0x00a9, canonId, decodeBasic, encodeBasic),
81+
CrwMapping(0x0805, 0x300a, 0, 0, IfdId::canonId, decode0x0805, encode0x0805),
82+
CrwMapping(0x080a, 0x2807, 0, 0, IfdId::canonId, decode0x080a, encode0x080a),
83+
CrwMapping(0x080b, 0x3004, 0, 0x0007, IfdId::canonId, decodeBasic, encodeBasic),
84+
CrwMapping(0x0810, 0x2807, 0, 0x0009, IfdId::canonId, decodeBasic, encodeBasic),
85+
CrwMapping(0x0815, 0x2804, 0, 0x0006, IfdId::canonId, decodeBasic, encodeBasic),
86+
CrwMapping(0x1029, 0x300b, 0, 0x0002, IfdId::canonId, decodeBasic, encodeBasic),
87+
CrwMapping(0x102a, 0x300b, 0, 0x0004, IfdId::canonId, decodeArray, encodeArray),
88+
CrwMapping(0x102d, 0x300b, 0, 0x0001, IfdId::canonId, decodeArray, encodeArray),
89+
CrwMapping(0x1033, 0x300b, 0, 0x000f, IfdId::canonId, decodeArray, encodeArray),
90+
CrwMapping(0x1038, 0x300b, 0, 0x0012, IfdId::canonId, decodeArray, encodeArray),
91+
CrwMapping(0x10a9, 0x300b, 0, 0x00a9, IfdId::canonId, decodeBasic, encodeBasic),
9292
// Mapped to Exif.Photo.ColorSpace instead (see below)
93-
// CrwMapping(0x10b4, 0x300b, 0, 0x00b4, canonId, decodeBasic, encodeBasic),
94-
CrwMapping(0x10b4, 0x300b, 0, 0xa001, exifId, decodeBasic, encodeBasic),
95-
CrwMapping(0x10b5, 0x300b, 0, 0x00b5, canonId, decodeBasic, encodeBasic),
96-
CrwMapping(0x10c0, 0x300b, 0, 0x00c0, canonId, decodeBasic, encodeBasic),
97-
CrwMapping(0x10c1, 0x300b, 0, 0x00c1, canonId, decodeBasic, encodeBasic),
98-
CrwMapping(0x1807, 0x3002, 0, 0x9206, exifId, decodeBasic, encodeBasic),
99-
CrwMapping(0x180b, 0x3004, 0, 0x000c, canonId, decodeBasic, encodeBasic),
100-
CrwMapping(0x180e, 0x300a, 0, 0x9003, exifId, decode0x180e, encode0x180e),
101-
CrwMapping(0x1810, 0x300a, 0, 0xa002, exifId, decode0x1810, encode0x1810),
102-
CrwMapping(0x1817, 0x300a, 4, 0x0008, canonId, decodeBasic, encodeBasic),
103-
// CrwMapping(0x1818, 0x3002, 0, 0x9204, exifId, decodeBasic, encodeBasic),
104-
CrwMapping(0x183b, 0x300b, 0, 0x0015, canonId, decodeBasic, encodeBasic),
105-
CrwMapping(0x2008, 0x0000, 0, 0, ifd1Id, decode0x2008, encode0x2008),
93+
// CrwMapping(0x10b4, 0x300b, 0, 0x00b4, IfdId::canonId, decodeBasic, encodeBasic),
94+
CrwMapping(0x10b4, 0x300b, 0, 0xa001, IfdId::exifId, decodeBasic, encodeBasic),
95+
CrwMapping(0x10b5, 0x300b, 0, 0x00b5, IfdId::canonId, decodeBasic, encodeBasic),
96+
CrwMapping(0x10c0, 0x300b, 0, 0x00c0, IfdId::canonId, decodeBasic, encodeBasic),
97+
CrwMapping(0x10c1, 0x300b, 0, 0x00c1, IfdId::canonId, decodeBasic, encodeBasic),
98+
CrwMapping(0x1807, 0x3002, 0, 0x9206, IfdId::exifId, decodeBasic, encodeBasic),
99+
CrwMapping(0x180b, 0x3004, 0, 0x000c, IfdId::canonId, decodeBasic, encodeBasic),
100+
CrwMapping(0x180e, 0x300a, 0, 0x9003, IfdId::exifId, decode0x180e, encode0x180e),
101+
CrwMapping(0x1810, 0x300a, 0, 0xa002, IfdId::exifId, decode0x1810, encode0x1810),
102+
CrwMapping(0x1817, 0x300a, 4, 0x0008, IfdId::canonId, decodeBasic, encodeBasic),
103+
// CrwMapping(0x1818, 0x3002, 0, 0x9204, IfdId::exifId, decodeBasic, encodeBasic),
104+
CrwMapping(0x183b, 0x300b, 0, 0x0015, IfdId::canonId, decodeBasic, encodeBasic),
105+
CrwMapping(0x2008, 0x0000, 0, 0, IfdId::ifd1Id, decode0x2008, encode0x2008),
106106
}; // CrwMap::crwMapping_[]
107107

108108
/*
@@ -698,19 +698,19 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
698698
int64_t aperture = 0;
699699
int64_t shutterSpeed = 0;
700700

701-
IfdId ifdId = ifdIdNotSet;
701+
IfdId ifdId = IfdId::ifdIdNotSet;
702702
switch (pCrwMapping->tag_) {
703703
case 0x0001:
704-
ifdId = canonCsId;
704+
ifdId = IfdId::canonCsId;
705705
break;
706706
case 0x0004:
707-
ifdId = canonSiId;
707+
ifdId = IfdId::canonSiId;
708708
break;
709709
case 0x000f:
710-
ifdId = canonCfId;
710+
ifdId = IfdId::canonCfId;
711711
break;
712712
case 0x0012:
713-
ifdId = canonPiId;
713+
ifdId = IfdId::canonPiId;
714714
break;
715715
}
716716

@@ -725,18 +725,18 @@ void CrwMap::decodeArray(const CiffComponent& ciffComponent, const CrwMapping* p
725725
uint16_t n = 1;
726726
ExifKey key(c, groupName);
727727
UShortValue value;
728-
if (ifdId == canonCsId && c == 23 && component_size >= 52)
728+
if (ifdId == IfdId::canonCsId && c == 23 && component_size >= 52)
729729
n = 3;
730730
value.read(ciffComponent.pData() + c * 2, n * 2, byteOrder);
731731
image.exifData().add(key, &value);
732-
if (ifdId == canonSiId && c == 21)
732+
if (ifdId == IfdId::canonSiId && c == 21)
733733
aperture = value.toInt64();
734-
if (ifdId == canonSiId && c == 22)
734+
if (ifdId == IfdId::canonSiId && c == 22)
735735
shutterSpeed = value.toInt64();
736736
c += n;
737737
}
738738

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

914914
void CrwMap::encodeArray(const Image& image, const CrwMapping* pCrwMapping, CiffHeader* pHead) {
915-
IfdId ifdId = ifdIdNotSet;
915+
IfdId ifdId = IfdId::ifdIdNotSet;
916916
switch (pCrwMapping->tag_) {
917917
case 0x0001:
918-
ifdId = canonCsId;
918+
ifdId = IfdId::canonCsId;
919919
break;
920920
case 0x0004:
921-
ifdId = canonSiId;
921+
ifdId = IfdId::canonSiId;
922922
break;
923923
case 0x000f:
924-
ifdId = canonCfId;
924+
ifdId = IfdId::canonCfId;
925925
break;
926926
case 0x0012:
927-
ifdId = canonPiId;
927+
ifdId = IfdId::canonPiId;
928928
break;
929929
}
930930
DataBuf buf = packIfdId(image.exifData(), ifdId, pHead->byteOrder());

src/exif.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ uint16_t Exifdatum::tag() const {
296296
return key_ ? key_->tag() : 0xffff;
297297
}
298298

299-
int Exifdatum::ifdId() const {
300-
return key_ ? key_->ifdId() : ifdIdNotSet;
299+
IfdId Exifdatum::ifdId() const {
300+
return key_ ? key_->ifdId() : IfdId::ifdIdNotSet;
301301
}
302302

303303
const char* Exifdatum::ifdName() const {
@@ -430,7 +430,7 @@ void ExifThumb::setJpegThumbnail(const byte* buf, size_t size) {
430430
}
431431

432432
void ExifThumb::erase() {
433-
eraseIfd(exifData_, ifd1Id);
433+
eraseIfd(exifData_, IfdId::ifd1Id);
434434
}
435435

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

545545
// Delete IFDs which do not occur in JPEGs
546546
static constexpr auto filteredIfds = std::array{
547-
subImage1Id, subImage2Id, subImage3Id, subImage4Id, subImage5Id, subImage6Id, subImage7Id,
548-
subImage8Id, subImage9Id, subThumb1Id, panaRawId, ifd2Id, ifd3Id,
547+
IfdId::subImage1Id, IfdId::subImage2Id, IfdId::subImage3Id, IfdId::subImage4Id, IfdId::subImage5Id,
548+
IfdId::subImage6Id, IfdId::subImage7Id, IfdId::subImage8Id, IfdId::subImage9Id, IfdId::subThumb1Id,
549+
IfdId::panaRawId, IfdId::ifd2Id, IfdId::ifd3Id,
549550
};
550551
for (auto&& filteredIfd : filteredIfds) {
551552
#ifdef EXIV2_DEBUG_MESSAGES

0 commit comments

Comments
 (0)