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