image2d.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Image Copyright (c) 2008 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2011-04-05
  5. // Updated : 2011-04-05
  6. // Licence : This source is under MIT License
  7. // File : gli/core/image2d.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef GLI_CORE_IMAGE2D_INCLUDED
  10. #define GLI_CORE_IMAGE2D_INCLUDED
  11. // STD
  12. #include <vector>
  13. #include <cassert>
  14. #include <cmath>
  15. #include <cstring>
  16. // GLM
  17. #include <glm/glm.hpp>
  18. #include <glm/gtx/number_precision.hpp>
  19. #include <glm/gtx/raw_data.hpp>
  20. #include <glm/gtx/gradient_paint.hpp>
  21. #include <glm/gtx/component_wise.hpp>
  22. namespace gli
  23. {
  24. enum format
  25. {
  26. FORMAT_NULL,
  27. // Unsigned integer formats
  28. R8U,
  29. RG8U,
  30. RGB8U,
  31. RGBA8U,
  32. R16U,
  33. RG16U,
  34. RGB16U,
  35. RGBA16U,
  36. R32U,
  37. RG32U,
  38. RGB32U,
  39. RGBA32U,
  40. // Signed integer formats
  41. R8I,
  42. RG8I,
  43. RGB8I,
  44. RGBA8I,
  45. R16I,
  46. RG16I,
  47. RGB16I,
  48. RGBA16I,
  49. R32I,
  50. RG32I,
  51. RGB32I,
  52. RGBA32I,
  53. // Floating formats
  54. R16F,
  55. RG16F,
  56. RGB16F,
  57. RGBA16F,
  58. R32F,
  59. RG32F,
  60. RGB32F,
  61. RGBA32F,
  62. // Packed formats
  63. RGBE8,
  64. RGB9E5,
  65. RG11B10F,
  66. R5G6B5,
  67. RGBA4,
  68. RGB10A2,
  69. // Depth formats
  70. D16,
  71. D24X8,
  72. D24S8,
  73. D32F,
  74. D32FS8X24,
  75. // Compressed formats
  76. DXT1,
  77. DXT3,
  78. DXT5,
  79. ATI1N_UNORM,
  80. ATI1N_SNORM,
  81. ATI2N_UNORM,
  82. ATI2N_SNORM,
  83. BP_UF16,
  84. BP_SF16,
  85. BP,
  86. FORMAT_MAX
  87. };
  88. enum size_type
  89. {
  90. LINEAR_SIZE,
  91. BLOCK_SIZE,
  92. BIT_PER_PIXEL,
  93. COMPONENT
  94. };
  95. class image2D
  96. {
  97. public:
  98. typedef glm::uvec2 dimensions_type;
  99. typedef glm::vec2 texcoord_type;
  100. typedef glm::uint32 size_type;
  101. typedef glm::byte value_type;
  102. typedef gli::format format_type;
  103. typedef std::vector<value_type> data_type;
  104. public:
  105. image2D();
  106. image2D(
  107. image2D const & Image);
  108. explicit image2D(
  109. dimensions_type const & Dimensions,
  110. format_type const & Format);
  111. template <typename genType>
  112. explicit image2D(
  113. dimensions_type const & Dimensions,
  114. format_type const & Format,
  115. genType const & Value);
  116. explicit image2D(
  117. dimensions_type const & Dimensions,
  118. format_type const & Format,
  119. std::vector<value_type> const & Data);
  120. ~image2D();
  121. template <typename genType>
  122. void setPixel(
  123. dimensions_type const & TexelCoord,
  124. genType const & TexelData);
  125. size_type value_size() const;
  126. size_type capacity() const;
  127. dimensions_type dimensions() const;
  128. size_type components() const;
  129. format_type format() const;
  130. value_type * data();
  131. value_type const * const data() const;
  132. private:
  133. data_type Data;
  134. dimensions_type Dimensions;
  135. format_type Format;
  136. };
  137. }//namespace gli
  138. #include "image2d.inl"
  139. #endif//GLI_CORE_IMAGE2D_INCLUDED