image_format.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
  11. #define BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
  12. #include <boost/compute/cl.hpp>
  13. namespace boost {
  14. namespace compute {
  15. /// \class image_format
  16. /// \brief A OpenCL image format
  17. ///
  18. /// For example, to create a format for a 8-bit RGBA image:
  19. /// \code
  20. /// boost::compute::image_format rgba8(CL_RGBA, CL_UNSIGNED_INT8);
  21. /// \endcode
  22. ///
  23. /// After being constructed, image_format objects are usually passed to the
  24. /// constructor of the various image classes (e.g. \ref image2d, \ref image3d)
  25. /// to create an image object on a compute device.
  26. ///
  27. /// Image formats supported by a context can be queried with the static
  28. /// get_supported_formats() in each image class. For example:
  29. /// \code
  30. /// std::vector<image_format> formats = image2d::get_supported_formats(ctx);
  31. /// \endcode
  32. ///
  33. /// \see image2d
  34. class image_format
  35. {
  36. public:
  37. enum channel_order {
  38. r = CL_R,
  39. a = CL_A,
  40. intensity = CL_INTENSITY,
  41. luminance = CL_LUMINANCE,
  42. rg = CL_RG,
  43. ra = CL_RA,
  44. rgb = CL_RGB,
  45. rgba = CL_RGBA,
  46. argb = CL_ARGB,
  47. bgra = CL_BGRA
  48. };
  49. enum channel_data_type {
  50. snorm_int8 = CL_SNORM_INT8,
  51. snorm_int16 = CL_SNORM_INT16,
  52. unorm_int8 = CL_UNORM_INT8,
  53. unorm_int16 = CL_UNORM_INT16,
  54. unorm_short_565 = CL_UNORM_SHORT_565,
  55. unorm_short_555 = CL_UNORM_SHORT_555,
  56. unorm_int_101010 = CL_UNORM_INT_101010,
  57. signed_int8 = CL_SIGNED_INT8,
  58. signed_int16 = CL_SIGNED_INT16,
  59. signed_int32 = CL_SIGNED_INT32,
  60. unsigned_int8 = CL_UNSIGNED_INT8,
  61. unsigned_int16 = CL_UNSIGNED_INT16,
  62. unsigned_int32 = CL_UNSIGNED_INT32,
  63. float16 = CL_HALF_FLOAT,
  64. float32 = CL_FLOAT
  65. };
  66. /// Creates a new image format object with \p order and \p type.
  67. explicit image_format(cl_channel_order order, cl_channel_type type)
  68. {
  69. m_format.image_channel_order = order;
  70. m_format.image_channel_data_type = type;
  71. }
  72. /// Creates a new image format object from \p format.
  73. explicit image_format(const cl_image_format &format)
  74. {
  75. m_format.image_channel_order = format.image_channel_order;
  76. m_format.image_channel_data_type = format.image_channel_data_type;
  77. }
  78. /// Creates a new image format object as a copy of \p other.
  79. image_format(const image_format &other)
  80. : m_format(other.m_format)
  81. {
  82. }
  83. /// Copies the format from \p other to \c *this.
  84. image_format& operator=(const image_format &other)
  85. {
  86. if(this != &other){
  87. m_format = other.m_format;
  88. }
  89. return *this;
  90. }
  91. /// Destroys the image format object.
  92. ~image_format()
  93. {
  94. }
  95. /// Returns a pointer to the \c cl_image_format object.
  96. const cl_image_format* get_format_ptr() const
  97. {
  98. return &m_format;
  99. }
  100. /// Returns \c true if \c *this is the same as \p other.
  101. bool operator==(const image_format &other) const
  102. {
  103. return m_format.image_channel_order ==
  104. other.m_format.image_channel_order &&
  105. m_format.image_channel_data_type ==
  106. other.m_format.image_channel_data_type;
  107. }
  108. /// Returns \c true if \c *this is not the same as \p other.
  109. bool operator!=(const image_format &other) const
  110. {
  111. return !(*this == other);
  112. }
  113. private:
  114. cl_image_format m_format;
  115. };
  116. } // end compute namespace
  117. } // end boost namespace
  118. #endif // BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP