You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2004—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The Pixel-related classes
  15. // -------------------------
  16. //
  17. #include <../legacy/lol/base/types.h>
  18. #include <lol/vector>
  19. namespace lol
  20. {
  21. /* The pixel formats we know about */
  22. enum class PixelFormat
  23. {
  24. /* XXX: make sure to update image.cpp and texture.cpp when this changes */
  25. Unknown,
  26. Y_8,
  27. RGB_8,
  28. RGBA_8,
  29. Y_F32,
  30. RGB_F32,
  31. RGBA_F32,
  32. };
  33. /* Associated storage types for each pixel format */
  34. template <PixelFormat T> struct PixelType { typedef void type; };
  35. template<> struct PixelType<PixelFormat::Y_8> { typedef uint8_t type; };
  36. template<> struct PixelType<PixelFormat::RGB_8> { typedef u8vec3 type; };
  37. template<> struct PixelType<PixelFormat::RGBA_8> { typedef u8vec4 type; };
  38. template<> struct PixelType<PixelFormat::Y_F32> { typedef float type; };
  39. template<> struct PixelType<PixelFormat::RGB_F32> { typedef vec3 type; };
  40. template<> struct PixelType<PixelFormat::RGBA_F32> { typedef vec4 type; };
  41. /* Number of bytes used by each pixel format */
  42. static inline uint8_t BytesPerPixel(PixelFormat format)
  43. {
  44. #if __GNUC__
  45. #pragma GCC diagnostic push
  46. #pragma GCC diagnostic error "-Wswitch"
  47. #endif
  48. switch (format)
  49. {
  50. case PixelFormat::Unknown:
  51. break;
  52. case PixelFormat::Y_8:
  53. return sizeof(PixelType<PixelFormat::Y_8>::type);
  54. case PixelFormat::RGB_8:
  55. return sizeof(PixelType<PixelFormat::RGB_8>::type);
  56. case PixelFormat::RGBA_8:
  57. return sizeof(PixelType<PixelFormat::RGBA_8>::type);
  58. case PixelFormat::Y_F32:
  59. return sizeof(PixelType<PixelFormat::Y_F32>::type);
  60. case PixelFormat::RGB_F32:
  61. return sizeof(PixelType<PixelFormat::RGB_F32>::type);
  62. case PixelFormat::RGBA_F32:
  63. return sizeof(PixelType<PixelFormat::RGBA_F32>::type);
  64. }
  65. return 0;
  66. #if __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif
  69. };
  70. } /* namespace lol */