test_image1d.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #define BOOST_TEST_MODULE TestImage1D
  11. #include <boost/test/unit_test.hpp>
  12. #include <iostream>
  13. #include <boost/compute/image/image1d.hpp>
  14. #include <boost/compute/utility/dim.hpp>
  15. #include "quirks.hpp"
  16. #include "context_setup.hpp"
  17. namespace compute = boost::compute;
  18. BOOST_AUTO_TEST_CASE(image1d_get_supported_formats)
  19. {
  20. const std::vector<compute::image_format> formats =
  21. compute::image1d::get_supported_formats(context);
  22. }
  23. #ifdef BOOST_COMPUTE_CL_VERSION_1_2
  24. BOOST_AUTO_TEST_CASE(fill_image1d)
  25. {
  26. REQUIRES_OPENCL_VERSION(1, 2); // device OpenCL version check
  27. // single-channel unsigned char
  28. compute::image_format format(CL_R, CL_UNSIGNED_INT8);
  29. if(!compute::image1d::is_supported_format(format, context)){
  30. std::cerr << "skipping fill_image1d test, image format not supported" << std::endl;
  31. return;
  32. }
  33. compute::image1d img(context, 64, format);
  34. BOOST_CHECK_EQUAL(img.width(), size_t(64));
  35. BOOST_CHECK(img.size() == compute::dim(64));
  36. BOOST_CHECK(img.format() == format);
  37. // fill image with '128'
  38. compute::uint4_ fill_color(128, 0, 0, 0);
  39. queue.enqueue_fill_image(img, &fill_color, img.origin(), img.size());
  40. // read value of first pixel
  41. compute::uchar_ first_pixel = 0;
  42. queue.enqueue_read_image(img, compute::dim(0), compute::dim(1), &first_pixel);
  43. BOOST_CHECK_EQUAL(first_pixel, compute::uchar_(128));
  44. }
  45. #endif // BOOST_COMPUTE_CL_VERSION_1_2
  46. // check type_name() for image1d
  47. BOOST_AUTO_TEST_CASE(image1d_type_name)
  48. {
  49. BOOST_CHECK(
  50. std::strcmp(
  51. boost::compute::type_name<boost::compute::image1d>(), "image1d_t"
  52. ) == 0
  53. );
  54. }
  55. BOOST_AUTO_TEST_SUITE_END()