mirror of
https://github.com/boostorg/gil.git
synced 2026-02-18 14:12:10 +00:00
generate indexed_image_view from two views
This commit is contained in:
committed by
Stefan Seefeld
parent
86466ee82a
commit
9a7bfe8f71
@@ -209,6 +209,36 @@ private:
|
||||
std::size_t _num_colors;
|
||||
};
|
||||
|
||||
// build an indexed_image_view from two views
|
||||
template<typename Index_View, typename Palette_View>
|
||||
indexed_image_view
|
||||
<
|
||||
typename indexed_image_locator_type
|
||||
<
|
||||
typename Index_View::locator
|
||||
, typename Palette_View::locator
|
||||
>::type
|
||||
>
|
||||
view(Index_View iv, Palette_View pv)
|
||||
{
|
||||
typedef indexed_image_view<
|
||||
typename indexed_image_locator_type<
|
||||
typename Index_View::locator
|
||||
, typename Palette_View::locator
|
||||
>::type
|
||||
> view_t;
|
||||
|
||||
typedef indexed_image_deref_fn<
|
||||
typename Index_View::locator
|
||||
, typename Palette_View::locator
|
||||
> defer_fn_t;
|
||||
|
||||
return view_t(
|
||||
iv.dimensions()
|
||||
, pv.dimensions().x
|
||||
, view_t::locator(point_t(0, 0), point_t(1, 1), defer_fn_t(iv.xy_at(0, 0), pv.xy_at(0, 0)))
|
||||
);
|
||||
}
|
||||
|
||||
template< typename Index
|
||||
, typename Pixel
|
||||
|
||||
@@ -152,4 +152,49 @@ BOOST_AUTO_TEST_CASE( index_image_test )
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(index_image_view_test)
|
||||
{
|
||||
// generate some data
|
||||
int width = 640;
|
||||
int height = 480;
|
||||
int num_colors = 3;
|
||||
|
||||
// indices
|
||||
vector<uint8_t> indices(width * height, 2);
|
||||
|
||||
// colors
|
||||
vector<rgb8_pixel_t> palette(num_colors);
|
||||
palette[0] = rgb8_pixel_t(10, 20, 30);
|
||||
palette[1] = rgb8_pixel_t(40, 50, 60);
|
||||
palette[2] = rgb8_pixel_t(70, 80, 90);
|
||||
|
||||
// create image views from raw memory
|
||||
typedef gray8_image_t::view_t::locator indices_loc_t;
|
||||
typedef rgb8_image_t::view_t::locator palette_loc_t;
|
||||
|
||||
|
||||
auto indices_view = interleaved_view(width, height
|
||||
, (gray8_image_t::view_t::x_iterator) indices.data()
|
||||
, width // row size in bytes
|
||||
);
|
||||
|
||||
auto palette_view = interleaved_view(100, 1
|
||||
, (rgb8_image_t::view_t::x_iterator) palette.data()
|
||||
, num_colors * 3 // row size in bytes
|
||||
);
|
||||
|
||||
auto ii_view = view(indices_view, palette_view);
|
||||
|
||||
auto p = ii_view(point_t(0, 0));
|
||||
auto q = *ii_view.at(point_t(0, 0));
|
||||
|
||||
assert(get_color(p, red_t()) == 70);
|
||||
assert(get_color(p, green_t()) == 80);
|
||||
assert(get_color(p, blue_t()) == 90);
|
||||
|
||||
assert(get_color(q, red_t()) == 70);
|
||||
assert(get_color(q, green_t()) == 80);
|
||||
assert(get_color(q, blue_t()) == 90);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user