File indexing completed on 2025-01-18 09:30:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
0012 #define BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
0013
0014 #include <boost/throw_exception.hpp>
0015
0016 #include <boost/compute/command_queue.hpp>
0017 #include <boost/compute/exception/opencl_error.hpp>
0018 #include <boost/compute/image/image2d.hpp>
0019 #include <boost/compute/image/image_format.hpp>
0020 #include <boost/compute/utility/dim.hpp>
0021
0022 #include <QImage>
0023
0024 namespace boost {
0025 namespace compute {
0026
0027 inline image_format qt_qimage_format_to_image_format(const QImage::Format &format)
0028 {
0029 if(format == QImage::Format_RGB32){
0030 return image_format(image_format::bgra, image_format::unorm_int8);
0031 }
0032
0033 BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
0034 }
0035
0036 inline QImage::Format qt_image_format_to_qimage_format(const image_format &format)
0037 {
0038 if(format == image_format(image_format::bgra, image_format::unorm_int8)){
0039 return QImage::Format_RGB32;
0040 }
0041
0042 return QImage::Format_Invalid;
0043 }
0044
0045 inline image_format qt_qimage_get_format(const QImage &image)
0046 {
0047 return qt_qimage_format_to_image_format(image.format());
0048 }
0049
0050 inline void qt_copy_qimage_to_image2d(const QImage &qimage,
0051 image2d &image,
0052 command_queue &queue)
0053 {
0054 queue.enqueue_write_image(image, image.origin(), image.size(), qimage.constBits());
0055 }
0056
0057 inline void qt_copy_image2d_to_qimage(const image2d &image,
0058 QImage &qimage,
0059 command_queue &queue)
0060 {
0061 queue.enqueue_read_image(
0062 image, dim(0, 0), dim(qimage.width(), qimage.height()), qimage.bits()
0063 );
0064 }
0065
0066 }
0067 }
0068
0069 #endif