Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

Image.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef BZR_GRAPHICS_IMAGE_H
  19. #define BZR_GRAPHICS_IMAGE_H
  20. struct Palette;
  21. // enum PixelFormatID
  22. enum class PixelFormat : uint32_t
  23. {
  24. kUnknown = 0x0000, // used
  25. kR8G8B8 = 0x0014, // used
  26. kA8R8G8B8 = 0x0015, // used
  27. kX8R8G8B8 = 0x0016,
  28. kR5G6B5 = 0x0017, // used
  29. kX1R5G5B5 = 0x0018,
  30. kA1R5G5B5 = 0x0019,
  31. kA4R4G4B4 = 0x001a, // used
  32. kR3G3B2 = 0x001b,
  33. kA8 = 0x001c, // used
  34. kA8R3G3B2 = 0x001d,
  35. kX4R4G4B4 = 0x001e,
  36. kA2B10G10R10 = 0x001f,
  37. kA8B8G8R8 = 0x0020,
  38. kX8B8G8R8 = 0x0021,
  39. kA2R10G10B10 = 0x0023,
  40. kA8P8 = 0x0028,
  41. kP8 = 0x0029, // used
  42. kL8 = 0x0032,
  43. kA8L8 = 0x0033,
  44. kA4L4 = 0x0034,
  45. kV8U8 = 0x003c,
  46. kL6V5U5 = 0x003d,
  47. kX8L8V8U8 = 0x003e,
  48. kQ8W8V8U8 = 0x003f,
  49. kV16U16 = 0x0040,
  50. kA2W10V10U10 = 0x0043,
  51. kD16_Lockable = 0x0046,
  52. kD32 = 0x0047,
  53. kD15S1 = 0x0049,
  54. kD24S8 = 0x004b,
  55. kD24X8 = 0x004d,
  56. kD24X4S4 = 0x004f,
  57. kD16 = 0x0050,
  58. kVertexData = 0x0064,
  59. kIndex16 = 0x0065, // used
  60. kIndex32 = 0x0066,
  61. kCustom_R8G8B8A8 = 0x00f0,
  62. kCustom_A8B8G8R8 = 0x00f1,
  63. kCustom_B8G8R8 = 0x00f2,
  64. kCustomLscapeR8G8B8 = 0x00f3, // used
  65. kCustomLscapeAlpha = 0x00f4, // used
  66. kCustomRawJPEG = 0x01f4, // used
  67. kYUY2 = 0x32595559,
  68. kUYVY = 0x59565955,
  69. kG8R8_G8B8 = 0x42475247,
  70. kR8G8_B8G8 = 0x47424752,
  71. kDXT1 = 0x31545844, // used
  72. kDXT2 = 0x32545844,
  73. kDXT3 = 0x33545844, // used
  74. kDXT4 = 0x34545844,
  75. kDXT5 = 0x35545844 // used
  76. };
  77. int bitsPerPixel(PixelFormat format);
  78. bool isPaletted(PixelFormat format);
  79. bool isCompressed(PixelFormat format);
  80. bool hasAlpha(PixelFormat format);
  81. class Image
  82. {
  83. public:
  84. Image();
  85. void init(PixelFormat newFormat, int newWidth, int newHeight, const void* newData);
  86. void applyPalette(const Palette& palette);
  87. void scale(int newWidth, int newHeight);
  88. void fill(int value);
  89. void flipVertical();
  90. PixelFormat format() const;
  91. int width() const;
  92. int height() const;
  93. size_t size() const;
  94. const uint8_t* data() const;
  95. bool hasAlpha() const;
  96. private:
  97. template<class T>
  98. void applyPalette(const Palette& palette);
  99. void updateHasAlpha();
  100. PixelFormat format_;
  101. int width_;
  102. int height_;
  103. vector<uint8_t> data_;
  104. bool hasAlpha_;
  105. };
  106. #endif