qimage.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
  11. #define BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP
  12. #include <boost/throw_exception.hpp>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/exception/opencl_error.hpp>
  15. #include <boost/compute/image/image2d.hpp>
  16. #include <boost/compute/image/image_format.hpp>
  17. #include <boost/compute/utility/dim.hpp>
  18. #include <QImage>
  19. namespace boost {
  20. namespace compute {
  21. inline image_format qt_qimage_format_to_image_format(const QImage::Format &format)
  22. {
  23. if(format == QImage::Format_RGB32){
  24. return image_format(image_format::bgra, image_format::unorm_int8);
  25. }
  26. BOOST_THROW_EXCEPTION(opencl_error(CL_IMAGE_FORMAT_NOT_SUPPORTED));
  27. }
  28. inline QImage::Format qt_image_format_to_qimage_format(const image_format &format)
  29. {
  30. if(format == image_format(image_format::bgra, image_format::unorm_int8)){
  31. return QImage::Format_RGB32;
  32. }
  33. return QImage::Format_Invalid;
  34. }
  35. inline image_format qt_qimage_get_format(const QImage &image)
  36. {
  37. return qt_qimage_format_to_image_format(image.format());
  38. }
  39. inline void qt_copy_qimage_to_image2d(const QImage &qimage,
  40. image2d &image,
  41. command_queue &queue)
  42. {
  43. queue.enqueue_write_image(image, image.origin(), image.size(), qimage.constBits());
  44. }
  45. inline void qt_copy_image2d_to_qimage(const image2d &image,
  46. QImage &qimage,
  47. command_queue &queue)
  48. {
  49. queue.enqueue_read_image(
  50. image, dim(0, 0), dim(qimage.width(), qimage.height()), qimage.bits()
  51. );
  52. }
  53. } // end compute namespace
  54. } // end boost namespace
  55. #endif // BOOST_COMPUTE_INTEROP_QT_QIMAGE_HPP