FourCC.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. namespace Gfx {
  9. struct [[gnu::packed]] FourCC {
  10. FourCC() = default;
  11. constexpr FourCC(char const name[4])
  12. {
  13. cc[0] = name[0];
  14. cc[1] = name[1];
  15. cc[2] = name[2];
  16. cc[3] = name[3];
  17. }
  18. static constexpr FourCC from_u32(u32 value)
  19. {
  20. FourCC result;
  21. result.cc[0] = static_cast<char>(value >> 24);
  22. result.cc[1] = static_cast<char>(value >> 16);
  23. result.cc[2] = static_cast<char>(value >> 8);
  24. result.cc[3] = static_cast<char>(value);
  25. return result;
  26. }
  27. bool operator==(FourCC const&) const = default;
  28. bool operator!=(FourCC const&) const = default;
  29. u32 to_u32() const
  30. {
  31. return (static_cast<u8>(cc[0]) << 24)
  32. | (static_cast<u8>(cc[1]) << 16)
  33. | (static_cast<u8>(cc[2]) << 8)
  34. | static_cast<u8>(cc[3]);
  35. }
  36. char cc[4];
  37. };
  38. }