Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port TuttleOFX extension : aligned #583

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Port TuttleOFX aligned extension
Add shrink

First checkpoint

test cases added

Add pattern

Updates

Updates

Port TuttleOFX extensions

Improve comments

Update copyright

Improve copyright header

Pass build

Add aligned extendion

Remove headers
  • Loading branch information
meshtag committed Mar 17, 2021

Verified

This commit was signed with the committer’s verified signature.
cz4rs Cezary Skrzyński
commit cf7d3ca3cd475e4b4300faeb1c9ff3f6473596cd
1 change: 1 addition & 0 deletions include/boost/gil/extension/toolbox/metafunctions.hpp
Original file line number Diff line number Diff line change
@@ -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/aligned.hpp>

#endif
67 changes: 67 additions & 0 deletions include/boost/gil/extension/toolbox/metafunctions/aligned.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 _aligned_hpp_
#define _aligned_hpp_

#include <boost/gil.hpp>

namespace boost { namespace gil {

/// \brief Aligns the smaller image view passed through struct constructor in a specific direction
/// inside the larger image view passed through the overloaded '()' operator. The direction of
/// alignment is specified thorugh the constructor parameters.
template <typename view_t>
struct aligned
{
// Following enum variables will be used for specifying alignment of view passed through
// constructor with respect to larger view passed through overloaded '()' operator.
enum
{
left = (0x1 << 0),
center = (0x1 << 1),
right = (0x1 << 2),
top = (0x1 << 3),
middle = (0x1 << 5),
bottom = (0x1 << 7),
};

view_t& v2;
int align;
aligned(view_t v2, int align = center | middle)
: v2(v2)
, align(align)
{
}

void operator()(view_t& view)
{
using namespace boost::gil;

int w = v2.width();
int h = v2.height();

// For ensuring that view passed through '()' operator has greater dimensions than view
// passed through the constructor.
if(h > view.height() || w > view.width())
return;

int x = 0;
if(align & center)
x = (view.width() - w) / 2;
else if(align & right)
x = view.width() - w;

int y = 0;
if(align & middle)
y = (view.height() - h) / 2;
else if(align & bottom)
y = view.height() - h;

view_t v3 = subimage_view(view, x, y, w, h);
boost::gil::copy_pixels(v2, v3);
}
};
} }
#endif
3 changes: 2 additions & 1 deletion test/extension/toolbox/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@ foreach(_name
is_bit_aligned
is_homogeneous
pixel_bit_size
subchroma_image)
subchroma_image
aligned)
set(_test t_ext_toolbox_${_name})
set(_target test_ext_toolbox_${_name})

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

# TODO: Add subchroma_image.cpp after fixing run-time failure,
# for details see https://github.com/boostorg/gil/pull/164
Loading