fix darkroom bilineer interpolation

This commit is contained in:
bolero-MURAKAMI 2012-08-13 10:56:48 +09:00
parent aec77334ef
commit 744146ae38
6 changed files with 80 additions and 61 deletions

View file

@ -22,6 +22,9 @@ SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::version_type DARKROOM_LOAD_D
# include DARKROOM_DEF_LOAD_TEXTURE_FILE
# undef DARKROOM_LOADING_TEXTURE_VERSION
;
static_assert(DARKROOM_LOAD_DETAIL_IDENTIFIER(version) <= 0, "Unsupported darkroom tex version");
SPROUT_STATIC_CONSTEXPR sprout::darkroom::textures::info_type DARKROOM_LOAD_DETAIL_IDENTIFIER(info) = {
# define DARKROOM_LOADING_TEXTURE_INFO
# include DARKROOM_DEF_LOAD_TEXTURE_FILE

View file

@ -3,6 +3,7 @@
#include <sprout/config.hpp>
#include <sprout/darkroom/materials/material.hpp>
#include <sprout/darkroom/materials/interpolation.hpp>
#include <sprout/darkroom/materials/uniform.hpp>
#include <sprout/darkroom/materials/plaid.hpp>
#include <sprout/darkroom/materials/texture_map.hpp>

View file

@ -0,0 +1,53 @@
#ifndef SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP
#define SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP
#include <cstdint>
#include <sprout/config.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
namespace sprout {
namespace darkroom {
namespace materials {
//
// interpolation_type
//
struct interpolation_type {
public:
enum values {
nearest_neighbor,
bilinear,
bicubic
};
};
//
// bilinear_interpolate
//
template<typename Color, typename Unit>
inline SPROUT_CONSTEXPR Color bilinear_interpolate(
Color const& c00, Color const& c01, Color const& c10, Color const& c11,
Unit const& u, Unit const& v
)
{
return sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(c00, u),
sprout::darkroom::colors::mul(c01, 1 - u)
),
v
),
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(c10, u),
sprout::darkroom::colors::mul(c11, 1 - u)
),
1 - v
)
);
}
} // namespace materials
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP

View file

@ -6,7 +6,7 @@
#include <sprout/config.hpp>
#include <sprout/math/floor.hpp>
#include <sprout/utility/value_holder.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/materials/interpolation.hpp>
namespace sprout {
namespace darkroom {
@ -14,14 +14,7 @@ namespace sprout {
//
// texture_map_interpolation
//
struct texture_map_interpolation {
public:
enum values {
nearest_neighbor,
bilinear,
bicubic
};
};
typedef sprout::darkroom::materials::interpolation_type texture_map_interpolation;
//
// texture_map_placement
//
@ -41,29 +34,25 @@ namespace sprout {
typedef Texture texture_type;
typedef typename texture_type::value_type result_type;
typedef Scale unit_type;
typedef sprout::darkroom::materials::texture_map_interpolation texture_map_interpolation;
typedef sprout::darkroom::materials::interpolation_type interpolation_type;
typedef sprout::darkroom::materials::texture_map_placement texture_map_placement;
private:
static SPROUT_CONSTEXPR unit_type fmod(unit_type const& n, unit_type const& d) {
return n - std::intmax_t(n / d) * d;
}
private:
sprout::value_holder<texture_type const&> texture_;
unit_type scale_;
unit_type offset_u_;
unit_type offset_v_;
result_type default_color_;
texture_map_interpolation::values interpolation_value_;
interpolation_type::values interpolation_value_;
texture_map_placement::values placement_value_;
private:
SPROUT_CONSTEXPR bool is_nearest() const {
return interpolation_value_ == texture_map_interpolation::nearest_neighbor;
return interpolation_value_ == interpolation_type::nearest_neighbor;
}
SPROUT_CONSTEXPR bool is_bilinear() const {
return interpolation_value_ == texture_map_interpolation::bilinear;
return interpolation_value_ == interpolation_type::bilinear;
}
SPROUT_CONSTEXPR bool is_bicubic() const {
return interpolation_value_ == texture_map_interpolation::bicubic;
return interpolation_value_ == interpolation_type::bicubic;
}
SPROUT_CONSTEXPR bool is_tile() const {
return placement_value_ == texture_map_placement::tile;
@ -94,36 +83,21 @@ namespace sprout {
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_bilinear_1(
Unit const& x,
Unit const& xf,
Unit const& xc,
Unit const& y,
Unit const& yf,
Unit const& yc
Unit const& x, Unit const& x0,
Unit const& y, Unit const& y0
) const
{
return sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(get_color(xf, yf), 1 - (x - xf)),
sprout::darkroom::colors::mul(get_color(xc, yf), 1 - (xc - x))
),
1 - (y - yf)
),
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
sprout::darkroom::colors::mul(get_color(xf, yc), 1 - (x - xf)),
sprout::darkroom::colors::mul(get_color(xc, yc), 1 - (xc - x))
),
1 - (yc - y)
)
return sprout::darkroom::materials::bilinear_interpolate(
get_color(x0, y0), get_color(x0 + 1, y0),
get_color(x0, y0 + 1), get_color(x0 + 1, y0 + 1),
1 - (x - x0), 1 - (y - y0)
);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type calc_bilinear(Unit const& x, Unit const& y) const {
return calc_bilinear_1(
x, sprout::floor(x - 0.5), sprout::floor(x + 0.5),
y, sprout::floor(y - 0.5), sprout::floor(y + 0.5)
x, sprout::floor(x),
y, sprout::floor(y)
);
}
template<typename Unit>
@ -139,7 +113,7 @@ namespace sprout {
unit_type const& offset_u = 0,
unit_type const& offset_v = 0,
result_type const& default_color = result_type(),
texture_map_interpolation::values interpolation_value = texture_map_interpolation::nearest_neighbor,
interpolation_type::values interpolation_value = interpolation_type::nearest_neighbor,
texture_map_placement::values placement_value = texture_map_placement::tile
)
: texture_(texture)
@ -171,17 +145,13 @@ namespace sprout {
make_texture_map(
Texture const& texture,
Unit const& scale,
Unit const& offset_u
= 0
,
Unit const& offset_v
= 0
,
Unit const& offset_u = 0,
Unit const& offset_v = 0,
typename sprout::darkroom::materials::texture_map<Texture, Unit>::result_type const& default_color
= typename sprout::darkroom::materials::texture_map<Texture, Unit>::result_typ()
,
sprout::darkroom::materials::texture_map_interpolation::values interpolation_value
= sprout::darkroom::materials::texture_map_interpolation::nearest_neighbor
sprout::darkroom::materials::interpolation_type::values interpolation_value
= sprout::darkroom::materials::interpolation_type::nearest_neighbor
,
sprout::darkroom::materials::texture_map_placement::values placement_value
= sprout::darkroom::materials::texture_map_placement::tile

View file

@ -157,8 +157,7 @@ namespace sprout {
public:
template<typename CVRef, typename Tuple>
SPROUT_CONSTEXPR result_type operator()(CVRef& arg, Tuple&) const volatile {
// ???
//return arg.get();
//return arg.get(); // ???
return const_cast<typename std::remove_volatile<typename std::remove_reference<CVRef>::type>::type&>(arg).get();
}
};
@ -561,18 +560,12 @@ namespace sprout {
template<typename F, typename... BoundArgs>
inline SPROUT_CONSTEXPR typename sprout::detail::bind_helper<F, BoundArgs...>::type const
cbind(F&& f, BoundArgs&&... args) {
typedef sprout::detail::bind_helper<F, BoundArgs...> helper_type;
typedef typename helper_type::maybe_type maybe_type;
typedef typename helper_type::type result_type;
return result_type(maybe_type::do_wrap(sprout::forward<F>(f)), sprout::forward<BoundArgs>(args)...);
sprout::bind(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
}
template<typename R, typename F, typename... BoundArgs>
inline SPROUT_CONSTEXPR typename sprout::detail::bindres_helper<R, F, BoundArgs...>::type const
cbind(F&& f, BoundArgs&&... args) {
typedef sprout::detail::bindres_helper<R, F, BoundArgs...> helper_type;
typedef typename helper_type::maybe_type maybe_type;
typedef typename helper_type::type result_type;
return result_type(maybe_type::do_wrap(sprout::forward<F>(f)), sprout::forward<BoundArgs>(args)...);
sprout::bind<R>(sprout::forward<F>(f), sprout::forward<BoundArgs>(args)...);
}
} // namespace sprout

View file

@ -15,7 +15,6 @@ namespace sprout {
namespace detail {
template<std::size_t Index, typename Head, bool IsEmpty>
class head_base;
// ???
// EBO disabled
// template<std::size_t Index, typename Head>
// class head_base<Index, Head, true>