Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
0012 #define BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP
0013 
0014 #include <boost/compute/cl.hpp>
0015 
0016 namespace boost {
0017 namespace compute {
0018 
0019 /// \class image_format
0020 /// \brief A OpenCL image format
0021 ///
0022 /// For example, to create a format for a 8-bit RGBA image:
0023 /// \code
0024 /// boost::compute::image_format rgba8(CL_RGBA, CL_UNSIGNED_INT8);
0025 /// \endcode
0026 ///
0027 /// After being constructed, image_format objects are usually passed to the
0028 /// constructor of the various image classes (e.g. \ref image2d, \ref image3d)
0029 /// to create an image object on a compute device.
0030 ///
0031 /// Image formats supported by a context can be queried with the static
0032 /// get_supported_formats() in each image class. For example:
0033 /// \code
0034 /// std::vector<image_format> formats = image2d::get_supported_formats(ctx);
0035 /// \endcode
0036 ///
0037 /// \see image2d
0038 class image_format
0039 {
0040 public:
0041     enum channel_order {
0042         r = CL_R,
0043         a = CL_A,
0044         intensity = CL_INTENSITY,
0045         luminance = CL_LUMINANCE,
0046         rg = CL_RG,
0047         ra = CL_RA,
0048         rgb = CL_RGB,
0049         rgba = CL_RGBA,
0050         argb = CL_ARGB,
0051         bgra = CL_BGRA
0052     };
0053 
0054     enum channel_data_type {
0055         snorm_int8 = CL_SNORM_INT8,
0056         snorm_int16 = CL_SNORM_INT16,
0057         unorm_int8 = CL_UNORM_INT8,
0058         unorm_int16 = CL_UNORM_INT16,
0059         unorm_short_565 = CL_UNORM_SHORT_565,
0060         unorm_short_555 = CL_UNORM_SHORT_555,
0061         unorm_int_101010 = CL_UNORM_INT_101010,
0062         signed_int8 = CL_SIGNED_INT8,
0063         signed_int16 = CL_SIGNED_INT16,
0064         signed_int32 = CL_SIGNED_INT32,
0065         unsigned_int8 = CL_UNSIGNED_INT8,
0066         unsigned_int16 = CL_UNSIGNED_INT16,
0067         unsigned_int32 = CL_UNSIGNED_INT32,
0068         float16 = CL_HALF_FLOAT,
0069         float32 = CL_FLOAT
0070     };
0071 
0072     /// Creates a new image format object with \p order and \p type.
0073     explicit image_format(cl_channel_order order, cl_channel_type type)
0074     {
0075         m_format.image_channel_order = order;
0076         m_format.image_channel_data_type = type;
0077     }
0078 
0079     /// Creates a new image format object from \p format.
0080     explicit image_format(const cl_image_format &format)
0081     {
0082         m_format.image_channel_order = format.image_channel_order;
0083         m_format.image_channel_data_type = format.image_channel_data_type;
0084     }
0085 
0086     /// Creates a new image format object as a copy of \p other.
0087     image_format(const image_format &other)
0088         : m_format(other.m_format)
0089     {
0090     }
0091 
0092     /// Copies the format from \p other to \c *this.
0093     image_format& operator=(const image_format &other)
0094     {
0095         if(this != &other){
0096             m_format = other.m_format;
0097         }
0098 
0099         return *this;
0100     }
0101 
0102     /// Destroys the image format object.
0103     ~image_format()
0104     {
0105     }
0106 
0107     /// Returns a pointer to the \c cl_image_format object.
0108     const cl_image_format* get_format_ptr() const
0109     {
0110         return &m_format;
0111     }
0112 
0113     /// Returns \c true if \c *this is the same as \p other.
0114     bool operator==(const image_format &other) const
0115     {
0116         return m_format.image_channel_order ==
0117                    other.m_format.image_channel_order &&
0118                m_format.image_channel_data_type ==
0119                    other.m_format.image_channel_data_type;
0120     }
0121 
0122     /// Returns \c true if \c *this is not the same as \p other.
0123     bool operator!=(const image_format &other) const
0124     {
0125         return !(*this == other);
0126     }
0127 
0128 private:
0129     cl_image_format m_format;
0130 };
0131 
0132 } // end compute namespace
0133 } // end boost namespace
0134 
0135 #endif // BOOST_COMPUTE_IMAGE_IMAGE_FORMAT_HPP