Skip to content

Commit c4e7503

Browse files
committed
use named enum
Signed-off-by: Rosen Penev <[email protected]>
1 parent dc7ddfc commit c4e7503

File tree

4 files changed

+227
-228
lines changed

4 files changed

+227
-228
lines changed

src/bmffimage.cpp

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,45 @@
2525
#include <iostream>
2626
#include <string>
2727

28-
enum {
29-
TAG_ftyp = 0x66747970U, //!< "ftyp" File type box */
30-
TAG_avci = 0x61766369U, //!< "avci" AVC */
31-
TAG_avcs = 0x61766373U, //!< "avcs" AVC */
32-
TAG_avif = 0x61766966U, //!< "avif" AVIF */
33-
TAG_avio = 0x6176696fU, //!< "avio" AVIF */
34-
TAG_avis = 0x61766973U, //!< "avis" AVIF */
35-
TAG_heic = 0x68656963U, //!< "heic" HEIC */
36-
TAG_heif = 0x68656966U, //!< "heif" HEIF */
37-
TAG_heim = 0x6865696dU, //!< "heim" HEIC */
38-
TAG_heis = 0x68656973U, //!< "heis" HEIC */
39-
TAG_heix = 0x68656978U, //!< "heix" HEIC */
40-
TAG_j2is = 0x6a326973U, //!< "j2is" HEJ2K */
41-
TAG_j2ki = 0x6a326b69U, //!< "j2ki" HEJ2K */
42-
TAG_mif1 = 0x6d696631U, //!< "mif1" HEIF */
43-
TAG_crx = 0x63727820U, //!< "crx " Canon CR3 */
44-
TAG_jxl = 0x6a786c20U, //!< "jxl " JPEG XL file type */
45-
TAG_moov = 0x6d6f6f76U, //!< "moov" Movie */
46-
TAG_meta = 0x6d657461U, //!< "meta" Metadata */
47-
TAG_mdat = 0x6d646174U, //!< "mdat" Media data */
48-
TAG_uuid = 0x75756964U, //!< "uuid" UUID */
49-
TAG_dinf = 0x64696e66U, //!< "dinf" Data information */
50-
TAG_iprp = 0x69707270U, //!< "iprp" Item properties */
51-
TAG_ipco = 0x6970636fU, //!< "ipco" Item property container */
52-
TAG_iinf = 0x69696e66U, //!< "iinf" Item info */
53-
TAG_iloc = 0x696c6f63U, //!< "iloc" Item location */
54-
TAG_ispe = 0x69737065U, //!< "ispe" Image spatial extents */
55-
TAG_infe = 0x696e6665U, //!< "infe" Item Info Extension */
56-
TAG_ipma = 0x69706d61U, //!< "ipma" Item Property Association */
57-
TAG_cmt1 = 0x434d5431U, //!< "CMT1" ifd0Id */
58-
TAG_cmt2 = 0x434D5432U, //!< "CMD2" exifID */
59-
TAG_cmt3 = 0x434D5433U, //!< "CMT3" canonID */
60-
TAG_cmt4 = 0x434D5434U, //!< "CMT4" gpsID */
61-
TAG_colr = 0x636f6c72U, //!< "colr" Colour information */
62-
TAG_exif = 0x45786966U, //!< "Exif" Used by JXL */
63-
TAG_xml = 0x786d6c20U, //!< "xml " Used by JXL */
64-
TAG_brob = 0x62726f62U, //!< "brob" Used by JXL (brotli box) */
65-
TAG_thmb = 0x54484d42U, //!< "THMB" Canon thumbnail */
66-
TAG_prvw = 0x50525657U, //!< "PRVW" Canon preview image */
28+
enum TAG {
29+
ftyp = 0x66747970U, //!< "ftyp" File type box */
30+
avci = 0x61766369U, //!< "avci" AVC */
31+
avcs = 0x61766373U, //!< "avcs" AVC */
32+
avif = 0x61766966U, //!< "avif" AVIF */
33+
avio = 0x6176696fU, //!< "avio" AVIF */
34+
avis = 0x61766973U, //!< "avis" AVIF */
35+
heic = 0x68656963U, //!< "heic" HEIC */
36+
heif = 0x68656966U, //!< "heif" HEIF */
37+
heim = 0x6865696dU, //!< "heim" HEIC */
38+
heis = 0x68656973U, //!< "heis" HEIC */
39+
heix = 0x68656978U, //!< "heix" HEIC */
40+
j2is = 0x6a326973U, //!< "j2is" HEJ2K */
41+
j2ki = 0x6a326b69U, //!< "j2ki" HEJ2K */
42+
mif1 = 0x6d696631U, //!< "mif1" HEIF */
43+
crx = 0x63727820U, //!< "crx " Canon CR3 */
44+
jxl = 0x6a786c20U, //!< "jxl " JPEG XL file type */
45+
moov = 0x6d6f6f76U, //!< "moov" Movie */
46+
meta = 0x6d657461U, //!< "meta" Metadata */
47+
mdat = 0x6d646174U, //!< "mdat" Media data */
48+
uuid = 0x75756964U, //!< "uuid" UUID */
49+
dinf = 0x64696e66U, //!< "dinf" Data information */
50+
iprp = 0x69707270U, //!< "iprp" Item properties */
51+
ipco = 0x6970636fU, //!< "ipco" Item property container */
52+
iinf = 0x69696e66U, //!< "iinf" Item info */
53+
iloc = 0x696c6f63U, //!< "iloc" Item location */
54+
ispe = 0x69737065U, //!< "ispe" Image spatial extents */
55+
infe = 0x696e6665U, //!< "infe" Item Info Extension */
56+
ipma = 0x69706d61U, //!< "ipma" Item Property Association */
57+
cmt1 = 0x434d5431U, //!< "CMT1" ifd0Id */
58+
cmt2 = 0x434D5432U, //!< "CMD2" exifID */
59+
cmt3 = 0x434D5433U, //!< "CMT3" canonID */
60+
cmt4 = 0x434D5434U, //!< "CMT4" gpsID */
61+
colr = 0x636f6c72U, //!< "colr" Colour information */
62+
exif = 0x45786966U, //!< "Exif" Used by JXL */
63+
xml = 0x786d6c20U, //!< "xml " Used by JXL */
64+
brob = 0x62726f62U, //!< "brob" Used by JXL (brotli box) */
65+
thmb = 0x54484d42U, //!< "THMB" Canon thumbnail */
66+
prvw = 0x50525657U, //!< "PRVW" Canon preview image */
6767
};
6868

6969
// *****************************************************************************
@@ -99,46 +99,46 @@ std::string BmffImage::toAscii(uint32_t n) {
9999
}
100100

101101
bool BmffImage::superBox(uint32_t box) {
102-
return box == TAG_moov || box == TAG_dinf || box == TAG_iprp || box == TAG_ipco || box == TAG_meta ||
103-
box == TAG_iinf || box == TAG_iloc;
102+
return box == TAG::moov || box == TAG::dinf || box == TAG::iprp || box == TAG::ipco || box == TAG::meta ||
103+
box == TAG::iinf || box == TAG::iloc;
104104
}
105105

106106
bool BmffImage::fullBox(uint32_t box) {
107-
return box == TAG_meta || box == TAG_iinf || box == TAG_iloc || box == TAG_thmb || box == TAG_prvw;
107+
return box == TAG::meta || box == TAG::iinf || box == TAG::iloc || box == TAG::thmb || box == TAG::prvw;
108108
}
109109

110110
static bool skipBox(uint32_t box) {
111111
// Allows boxHandler() to optimise the reading of files by identifying
112112
// box types that we're not interested in. Box types listed here must
113113
// not appear in the cases in switch (box_type) in boxHandler().
114-
return box == 0 || box == TAG_mdat; // mdat is where the main image lives and can be huge
114+
return box == 0 || box == TAG::mdat; // mdat is where the main image lives and can be huge
115115
}
116116

117117
std::string BmffImage::mimeType() const {
118118
switch (fileType_) {
119-
case TAG_avci:
119+
case TAG::avci:
120120
return "image/avci";
121-
case TAG_avcs:
121+
case TAG::avcs:
122122
return "image/avcs";
123-
case TAG_avif:
124-
case TAG_avio:
125-
case TAG_avis:
123+
case TAG::avif:
124+
case TAG::avio:
125+
case TAG::avis:
126126
return "image/avif";
127-
case TAG_heic:
128-
case TAG_heim:
129-
case TAG_heis:
130-
case TAG_heix:
127+
case TAG::heic:
128+
case TAG::heim:
129+
case TAG::heis:
130+
case TAG::heix:
131131
return "image/heic";
132-
case TAG_heif:
133-
case TAG_mif1:
132+
case TAG::heif:
133+
case TAG::mif1:
134134
return "image/heif";
135-
case TAG_j2is:
135+
case TAG::j2is:
136136
return "image/j2is";
137-
case TAG_j2ki:
137+
case TAG::j2ki:
138138
return "image/hej2k";
139-
case TAG_crx:
139+
case TAG::crx:
140140
return "image/x-canon-cr3";
141-
case TAG_jxl:
141+
case TAG::jxl:
142142
return "image/jxl"; // https://github.com/novomesk/qt-jpegxl-image-plugin/issues/1
143143
default:
144144
return "image/generic";
@@ -325,7 +325,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
325325

326326
switch (box_type) {
327327
// See notes in skipBox()
328-
case TAG_ftyp: {
328+
case TAG::ftyp: {
329329
Internal::enforce(data.size() >= 4, Exiv2::ErrorCode::kerCorruptedMetadata);
330330
fileType_ = data.read_uint32(0, endian_);
331331
if (bTrace) {
@@ -334,7 +334,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
334334
} break;
335335

336336
// 8.11.6.1
337-
case TAG_iinf: {
337+
case TAG::iinf: {
338338
if (bTrace) {
339339
out << '\n';
340340
bLF = false;
@@ -351,7 +351,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
351351
} break;
352352

353353
// 8.11.6.2
354-
case TAG_infe: { // .__._.__hvc1_ 2 0 0 1 0 1 0 0 104 118 99 49 0
354+
case TAG::infe: { // .__._.__hvc1_ 2 0 0 1 0 1 0 0 104 118 99 49 0
355355
Internal::enforce(data.size() - skip >= 8, Exiv2::ErrorCode::kerCorruptedMetadata);
356356
/* getULong (data.pData_+skip,endian_) ; */ skip += 4;
357357
uint16_t ID = data.read_uint16(skip, endian_);
@@ -375,10 +375,10 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
375375
}
376376
} break;
377377

378-
case TAG_moov:
379-
case TAG_iprp:
380-
case TAG_ipco:
381-
case TAG_meta: {
378+
case TAG::moov:
379+
case TAG::iprp:
380+
case TAG::ipco:
381+
case TAG::meta: {
382382
if (bTrace) {
383383
out << '\n';
384384
bLF = false;
@@ -388,7 +388,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
388388
io_->seek(boxHandler(out, option, box_end, depth + 1), BasicIo::beg);
389389
}
390390
// post-process meta box to recover Exif and XMP
391-
if (box_type == TAG_meta) {
391+
if (box_type == TAG::meta) {
392392
auto ilo = ilocs_.find(exifID_);
393393
if (ilo != ilocs_.end()) {
394394
const Iloc& iloc = ilo->second;
@@ -410,7 +410,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
410410
} break;
411411

412412
// 8.11.3.1
413-
case TAG_iloc: {
413+
case TAG::iloc: {
414414
Internal::enforce(data.size() - skip >= 2, Exiv2::ErrorCode::kerCorruptedMetadata);
415415
uint8_t u = data.read_uint8(skip++);
416416
uint16_t offsetSize = u >> 4;
@@ -461,7 +461,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
461461
}
462462
} break;
463463

464-
case TAG_ispe: {
464+
case TAG::ispe: {
465465
Internal::enforce(data.size() - skip >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
466466
skip += 4;
467467
uint32_t width = data.read_uint32(skip, endian_);
@@ -480,7 +480,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
480480
} break;
481481

482482
// 12.1.5.2
483-
case TAG_colr: {
483+
case TAG::colr: {
484484
if (data.size() >= (skip + 4 + 8)) { // .____.HLino..__mntrR 2 0 0 0 0 12 72 76 105 110 111 2 16 ...
485485
// https://www.ics.uci.edu/~dan/class/267/papers/jpeg2000.pdf
486486
uint8_t meth = data.read_uint8(skip + 0);
@@ -500,7 +500,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
500500
}
501501
} break;
502502

503-
case TAG_uuid: {
503+
case TAG::uuid: {
504504
DataBuf uuid(16);
505505
io_->read(uuid.data(), uuid.size());
506506
std::string name = uuidName(uuid);
@@ -522,25 +522,25 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
522522
}
523523
} break;
524524

525-
case TAG_cmt1:
525+
case TAG::cmt1:
526526
parseTiff(Internal::Tag::root, box_length);
527527
break;
528-
case TAG_cmt2:
528+
case TAG::cmt2:
529529
parseTiff(Internal::Tag::cmt2, box_length);
530530
break;
531-
case TAG_cmt3:
531+
case TAG::cmt3:
532532
parseTiff(Internal::Tag::cmt3, box_length);
533533
break;
534-
case TAG_cmt4:
534+
case TAG::cmt4:
535535
parseTiff(Internal::Tag::cmt4, box_length);
536536
break;
537-
case TAG_exif:
537+
case TAG::exif:
538538
parseTiff(Internal::Tag::root, buffer_size, io_->tell());
539539
break;
540-
case TAG_xml:
540+
case TAG::xml:
541541
parseXmp(buffer_size, io_->tell());
542542
break;
543-
case TAG_brob: {
543+
case TAG::brob: {
544544
Internal::enforce(data.size() >= 4, Exiv2::ErrorCode::kerCorruptedMetadata);
545545
uint32_t realType = data.read_uint32(0, endian_);
546546
if (bTrace) {
@@ -549,12 +549,12 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
549549
#ifdef EXV_HAVE_BROTLI
550550
DataBuf arr;
551551
brotliUncompress(data.c_data(4), data.size() - 4, arr);
552-
if (realType == TAG_exif) {
552+
if (realType == TAG::exif) {
553553
uint32_t offset = Safe::add(arr.read_uint32(0, endian_), 4u);
554554
Internal::enforce(Safe::add(offset, 4u) < arr.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
555555
Internal::TiffParserWorker::decode(exifData(), iptcData(), xmpData(), arr.c_data(offset), arr.size() - offset,
556556
Internal::Tag::root, Internal::TiffMapping::findDecoder);
557-
} else if (realType == TAG_xml) {
557+
} else if (realType == TAG::xml) {
558558
try {
559559
Exiv2::XmpParser::decode(xmpData(), std::string(arr.c_str(), arr.size()));
560560
} catch (...) {
@@ -563,7 +563,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
563563
}
564564
#endif
565565
} break;
566-
case TAG_thmb:
566+
case TAG::thmb:
567567
switch (version) {
568568
case 0: // JPEG
569569
parseCr3Preview(data, out, bTrace, version, skip, skip + 2, skip + 4, skip + 12);
@@ -575,7 +575,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
575575
break;
576576
}
577577
break;
578-
case TAG_prvw:
578+
case TAG::prvw:
579579
switch (version) {
580580
case 0: // JPEG
581581
case 1: // HDR

0 commit comments

Comments
 (0)