Skip to content

Commit

Permalink
Add color_spaces_are_compatible requirement as static_assert to thres…
Browse files Browse the repository at this point in the history
…hold (#329)

Since use of `gil_function_requires` check is optional, it can be
disabled by not defining `BOOST_GIL_USE_CONCEPT_CHECK`, we need
a mandatory form of the check.
Add compile-time test verifying the static assertion.
Closes #323
  • Loading branch information
mloskot committed Jul 10, 2019
1 parent 35a5bdc commit 0809f2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
14 changes: 6 additions & 8 deletions include/boost/gil/image_processing/threshold.hpp
Expand Up @@ -24,21 +24,20 @@ template
typename DstView,
typename Operator
>
void threshold_impl
(
SrcView const& src_view,
DstView const& dst_view,
Operator const& threshold_op
)
void threshold_impl(SrcView const& src_view, DstView const& dst_view, Operator const& threshold_op)
{
//template argument validation
gil_function_requires<ImageViewConcept<SrcView>>();
gil_function_requires<MutableImageViewConcept<DstView>>();
gil_function_requires<ColorSpacesCompatibleConcept
<
typename color_space_type<SrcView>::type,
typename color_space_type<DstView>::type>
>();
static_assert(color_spaces_are_compatible
<
typename color_space_type<SrcView>::type,
typename color_space_type<DstView>::type
>::value, "Source and destination views must have pixels with the same color space");

//iterate over the image chaecking each pixel value for the threshold
for (std::ptrdiff_t y = 0; y < src_view.height(); y++)
Expand Down Expand Up @@ -80,7 +79,6 @@ void threshold_binary
typedef typename channel_type<SrcView>::type source_channel_t;
typedef typename channel_type<DstView>::type result_channel_t;


if (direction == threshold_direction::regular)
{
detail::threshold_impl<source_channel_t, result_channel_t>(src_view, dst_view,
Expand Down
1 change: 1 addition & 0 deletions test/core/image_processing/Jamfile
Expand Up @@ -13,6 +13,7 @@ project
<include>..
;

compile-fail threshold_color_spaces_not_compatible_fail.cpp ;
run threshold_binary.cpp ;
run threshold_truncate.cpp ;
run lanczos_scaling.cpp ;
@@ -0,0 +1,25 @@
//
// Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
//
// 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
//
#include <boost/gil/image_processing/threshold.hpp>

namespace gil = boost::gil;

int main()
{
// Source and destination views must have pixels with the same (compatible) color space
{
gil::rgb8_image_t src;
gil::gray8_image_t dst;
gil::threshold_binary(const_view(src), view(dst), 0, 255);
}
{
gil::gray8_image_t src;
gil::rgb8_image_t dst;
gil::threshold_binary(const_view(src), view(dst), 0, 255);
}
}

0 comments on commit 0809f2d

Please sign in to comment.