• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 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_INTEROP_QT_QIMAGE_HPP
12 #define BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
13 
14 #include <boost/throw_exception.hpp>
15 
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/exception/opencl_error.hpp>
18 #include <boost/compute/image/image2d.hpp>
19 #include <boost/compute/image/image_format.hpp>
20 #include <boost/compute/utility/dim.hpp>
21 
22 #include <QImage>
23 
24 namespace boost {
25 namespace compute {
26 
qt_qimage_format_to_image_format(const QImage::Format & format)27 inline image_format qt_qimage_format_to_image_format(const QImage::Format &format)
28 {
29     if(format == QImage::Format_RGB32){
30         return image_format(image_format::bgra, image_format::unorm_int8);
31     }
32 
33     BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
34 }
35 
qt_image_format_to_qimage_format(const image_format & format)36 inline QImage::Format qt_image_format_to_qimage_format(const image_format &format)
37 {
38     if(format == image_format(image_format::bgra, image_format::unorm_int8)){
39         return QImage::Format_RGB32;
40     }
41 
42     return QImage::Format_Invalid;
43 }
44 
qt_qimage_get_format(const QImage & image)45 inline image_format qt_qimage_get_format(const QImage &image)
46 {
47     return qt_qimage_format_to_image_format(image.format());
48 }
49 
qt_copy_qimage_to_image2d(const QImage & qimage,image2d & image,command_queue & queue)50 inline void qt_copy_qimage_to_image2d(const QImage &qimage,
51                                       image2d &image,
52                                       command_queue &queue)
53 {
54     queue.enqueue_write_image(image, image.origin(), image.size(), qimage.constBits());
55 }
56 
qt_copy_image2d_to_qimage(const image2d & image,QImage & qimage,command_queue & queue)57 inline void qt_copy_image2d_to_qimage(const image2d &image,
58                                       QImage &qimage,
59                                       command_queue &queue)
60 {
61     queue.enqueue_read_image(
62         image, dim(0, 0), dim(qimage.width(), qimage.height()), qimage.bits()
63     );
64 }
65 
66 } // end compute namespace
67 } // end boost namespace
68 
69 #endif // BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
70