Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/boost/gil/extension/toolbox/metafunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
#include <boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp>
#include <boost/gil/extension/toolbox/metafunctions/is_similar.hpp>
#include <boost/gil/extension/toolbox/metafunctions/pixel_bit_size.hpp>
#include <boost/gil/extension/toolbox/metafunctions/shrink.hpp>

#endif
51 changes: 51 additions & 0 deletions include/boost/gil/extension/toolbox/metafunctions/shrink.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright Tom Brinkman 2008. 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)

#ifndef _shrink_hpp_
#define _shrink_hpp_
Comment thread
meshtag marked this conversation as resolved.
Outdated

#include <boost/gil.hpp>

namespace boost { namespace gil {

/// \brief Assigns a smaller subimage view of the view given as first parameter to the
/// destination/resultant view given as second parameter to the overloaded '()' operator.
/// The dimensions of the smaller view are specified by struct constructor parameters.
template <typename view_t>
Comment thread
meshtag marked this conversation as resolved.
Outdated
struct shrink
{
double left;
double top;
double right;
double bottom;

shrink(double left = 5, double top = 5, double right = 5, double bottom = 5)
: left(left)
, top(top)
, right(right)
, bottom(bottom)
{
}

void operator()(view_t& view, view_t& dstView)
{
if (left < 1.0)
left *= view.width();
if (right < 1.0)
right *= view.width();
if (top < 1.0)
top *= view.height();
if (bottom < 1.0)
bottom *= view.height();

double width = view.width() - left - right;
double height = view.height() - top - bottom;
Comment thread
meshtag marked this conversation as resolved.
Outdated
dstView = boost::gil::subimage_view(view, static_cast<std::ptrdiff_t>(left),
static_cast<std::ptrdiff_t>(top), static_cast<std::ptrdiff_t>(width),
static_cast<std::ptrdiff_t>(height));
}
}; // shrink
}} // namespace boost::gil

#endif
3 changes: 2 additions & 1 deletion test/extension/toolbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ foreach(_name
is_bit_aligned
is_homogeneous
pixel_bit_size
subchroma_image)
subchroma_image
shrink)
Comment thread
meshtag marked this conversation as resolved.
Outdated
set(_test t_ext_toolbox_${_name})
set(_target test_ext_toolbox_${_name})

Expand Down
1 change: 1 addition & 0 deletions test/extension/toolbox/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ run color_convert_lab.cpp ;
run color_convert_luminance.cpp ;
run color_convert_xyz.cpp ;
run indexed_image.cpp ;
run shrink.cpp ;

# TODO: Add subchroma_image.cpp after fixing run-time failure,
# for details see https://github.com/boostorg/gil/pull/164
Expand Down
31 changes: 31 additions & 0 deletions test/extension/toolbox/shrink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2021 Prathamesh Tagore <prathameshtagore@gmail.com>
//
// Use, modification and distribution are subject to 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)
//

// Reference for test case was taken from
// https://github.com/tuttleofx/TuttleOFX/blob/develop/libraries/boostHack/boost/gil/extension/toolbox/shrink.tests.cpp

#include <boost/gil/extension/toolbox/metafunctions.hpp>
#include <boost/core/lightweight_test.hpp>

namespace gil = boost::gil;

int main()
{
gil::rgb8_image_t original_img(20, 20), expected_img(12, 8);
gil::rgb8_view_t original_img_view = gil::view(original_img), obtained_img_view;

gil::fill_pixels(original_img_view, gil::rgb8_pixel_t(255, 255, 255));
gil::fill_pixels(gil::view(expected_img), gil::rgb8_pixel_t(255, 255, 255));

gil::shrink<gil::rgb8_view_t> shrink(0.20, 0.30, 0.20, 0.30);
shrink(original_img_view, obtained_img_view);

BOOST_TEST(gil::equal_pixels(obtained_img_view, gil::view(expected_img)));

return boost::report_errors();
}