1
0
mirror of https://github.com/cdcseacave/TinyEXIF.git synced 2026-07-21 19:23:01 +04:00

Add support for big-endian CPUs (#14)

This commit is contained in:
Marco
2025-01-01 07:09:30 -03:00
committed by GitHub
parent ccd676f1b9
commit 7d7a36dae4
+4 -2
View File
@@ -943,12 +943,14 @@ int EXIFInfo::parseFromEXIFSegment(const uint8_t* buf, unsigned len) {
// 8 bytes // 8 bytes
if (offs + 8 > len) if (offs + 8 > len)
return PARSE_CORRUPT_DATA; return PARSE_CORRUPT_DATA;
const uint32_t _ONE32 = 1;
const bool IS_LITTLE_ENDIAN = reinterpret_cast<uint8_t const*>(&_ONE32)[0] == 1;
bool alignIntel; bool alignIntel;
if (buf[offs] == 'I' && buf[offs+1] == 'I') if (buf[offs] == 'I' && buf[offs+1] == 'I')
alignIntel = true; // 1: Intel byte alignment alignIntel = IS_LITTLE_ENDIAN; // 1: Intel byte alignment
else else
if (buf[offs] == 'M' && buf[offs+1] == 'M') if (buf[offs] == 'M' && buf[offs+1] == 'M')
alignIntel = false; // 0: Motorola byte alignment alignIntel = !IS_LITTLE_ENDIAN; // 0: Motorola byte alignment
else else
return PARSE_UNKNOWN_BYTEALIGN; return PARSE_UNKNOWN_BYTEALIGN;
EntryParser parser(buf, len, offs, alignIntel); EntryParser parser(buf, len, offs, alignIntel);