//---------------------------------------------------------------------------// // Copyright (c) 2013 Kyle Lutz // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // // See http://kylelutz.github.com/compute for more information. //---------------------------------------------------------------------------// #define BOOST_TEST_MODULE TestImage2D #include #include #include #include #include #include #include "context_setup.hpp" namespace bc = boost::compute; BOOST_AUTO_TEST_CASE(image2d_get_supported_formats) { std::vector formats = bc::image2d::get_supported_formats(context, bc::image2d::read_only); BOOST_CHECK(!formats.empty()); } BOOST_AUTO_TEST_CASE(get_info) { bc::image2d image( context, bc::image2d::read_only, bc::image_format( bc::image_format::rgba, bc::image_format::unorm_int8 ), 48, 64 ); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_WIDTH), size_t(48)); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_HEIGHT), size_t(64)); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_DEPTH), size_t(0)); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_ROW_PITCH), size_t(48*4)); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_SLICE_PITCH), size_t(0)); BOOST_CHECK_EQUAL(image.get_info(CL_IMAGE_ELEMENT_SIZE), size_t(4)); BOOST_CHECK(bc::image_format( image.get_info(CL_IMAGE_FORMAT)) == bc::image_format( bc::image_format::rgba, bc::image_format::unorm_int8)); } BOOST_AUTO_TEST_CASE(count_with_pixel_iterator) { unsigned int data[] = { 0x00000000, 0x000000ff, 0xff0000ff, 0xffff00ff, 0x000000ff, 0xff0000ff, 0xff0000ff, 0x00ff00ff, 0x0000ffff }; bc::image2d image( context, bc::image2d::read_only | bc::image2d::use_host_ptr, bc::image_format( bc::image_format::rgba, bc::image_format::unorm_int8 ), 3, 3, 3 * 4, data ); BOOST_CHECK_EQUAL( bc::count(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(0, 0, 0, 0)), size_t(1)); BOOST_CHECK_EQUAL( bc::count(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(1, 0, 0, 0)), size_t(2)); BOOST_CHECK_EQUAL( bc::count(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(1, 0, 0, 1)), size_t(3)); BOOST_CHECK_EQUAL( bc::count(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(1, 1, 0, 0)), size_t(1)); BOOST_CHECK_EQUAL( bc::count(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(1, 0, 1, 1)), size_t(1)); } BOOST_AUTO_TEST_CASE(find_with_pixel_iterator) { unsigned int data[] = { 0x00000000, 0x000000ff, 0xff0000ff, 0xffff00ff, 0x000000ff, 0xff0000ff, 0xff0000ff, 0x00ff00ff, 0x0000ffff }; bc::image2d image( context, bc::image2d::read_only | bc::image2d::use_host_ptr, bc::image_format( bc::image_format::rgba, bc::image_format::unorm_int8 ), 3, 3, 3 * 4, data ); BOOST_CHECK_EQUAL( std::distance( bc::detail::make_pixel_input_iterator(image), bc::find(bc::detail::make_pixel_input_iterator(image, 0), bc::detail::make_pixel_input_iterator(image, image.get_pixel_count()), bc::float4_(1, 0, 1, 1)) ), ptrdiff_t(3)); } // check type_name() for image2d BOOST_AUTO_TEST_CASE(complex_type_name) { BOOST_CHECK( std::strcmp( boost::compute::type_name(), "image2d_t" ) == 0 ); } BOOST_AUTO_TEST_SUITE_END()