Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9245881 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Replace FOURCC macro with constexpr

And add an overload that takes a string argument, which means that.
FOURCC('m', 'o', 'o', 'v') can also be written as FOURCC("moov").

Test: build, boot, compare generated assembly.
Change-Id: I0850ad9c06e3fa3ad7ef2eedeb53c04c5cf289ca
parent 9ae88bd5
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -22,8 +22,20 @@

namespace android {

#define FOURCC(c1, c2, c3, c4) \
    ((c1) << 24 | (c2) << 16 | (c3) << 8 | (c4))
constexpr int FOURCC(unsigned char c1, unsigned char c2, unsigned char c3, unsigned char c4) {
    return ((c1) << 24 | (c2) << 16 | (c3) << 8 | (c4));
}

template <size_t N>
constexpr int32_t FOURCC(const char (&s) [N]) {
    static_assert(N == 5, "fourcc: wrong length");
    return
            (unsigned char) s[0] << 24 |
            (unsigned char) s[1] << 16 |
            (unsigned char) s[2] << 8 |
            (unsigned char) s[3] << 0;
}


uint16_t U16_AT(const uint8_t *ptr);
uint32_t U32_AT(const uint8_t *ptr);