From 744146ae38607ac52672bf3f8eee0f9a7e10cd8c Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 13 Aug 2012 10:56:48 +0900 Subject: [PATCH] fix darkroom bilineer interpolation --- sprout/darkroom/load/texture.hpp | 3 + sprout/darkroom/materials.hpp | 1 + sprout/darkroom/materials/interpolation.hpp | 53 ++++++++++++++++ sprout/darkroom/materials/texture_map.hpp | 70 ++++++--------------- sprout/functional/bind/bind.hpp | 13 +--- sprout/tuple/tuple/tuple.hpp | 1 - 6 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 sprout/darkroom/materials/interpolation.hpp diff --git a/sprout/darkroom/load/texture.hpp b/sprout/darkroom/load/texture.hpp index 83adf641..ddaf3c59 100644 --- a/sprout/darkroom/load/texture.hpp +++ b/sprout/darkroom/load/texture.hpp @@ -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 diff --git a/sprout/darkroom/materials.hpp b/sprout/darkroom/materials.hpp index fac1f936..55be84de 100644 --- a/sprout/darkroom/materials.hpp +++ b/sprout/darkroom/materials.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/sprout/darkroom/materials/interpolation.hpp b/sprout/darkroom/materials/interpolation.hpp new file mode 100644 index 00000000..386b8eaa --- /dev/null +++ b/sprout/darkroom/materials/interpolation.hpp @@ -0,0 +1,53 @@ +#ifndef SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP +#define SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP + +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace materials { + // + // interpolation_type + // + struct interpolation_type { + public: + enum values { + nearest_neighbor, + bilinear, + bicubic + }; + }; + + // + // bilinear_interpolate + // + template + 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 diff --git a/sprout/darkroom/materials/texture_map.hpp b/sprout/darkroom/materials/texture_map.hpp index 48a205a0..d1ffcb72 100644 --- a/sprout/darkroom/materials/texture_map.hpp +++ b/sprout/darkroom/materials/texture_map.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include 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_; 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 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 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 @@ -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::result_type const& default_color = typename sprout::darkroom::materials::texture_map::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 diff --git a/sprout/functional/bind/bind.hpp b/sprout/functional/bind/bind.hpp index 89436c26..44b9d888 100644 --- a/sprout/functional/bind/bind.hpp +++ b/sprout/functional/bind/bind.hpp @@ -157,8 +157,7 @@ namespace sprout { public: template SPROUT_CONSTEXPR result_type operator()(CVRef& arg, Tuple&) const volatile { - // ??? - //return arg.get(); + //return arg.get(); // ??? return const_cast::type>::type&>(arg).get(); } }; @@ -561,18 +560,12 @@ namespace sprout { template inline SPROUT_CONSTEXPR typename sprout::detail::bind_helper::type const cbind(F&& f, BoundArgs&&... args) { - typedef sprout::detail::bind_helper 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)), sprout::forward(args)...); + sprout::bind(sprout::forward(f), sprout::forward(args)...); } template inline SPROUT_CONSTEXPR typename sprout::detail::bindres_helper::type const cbind(F&& f, BoundArgs&&... args) { - typedef sprout::detail::bindres_helper 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)), sprout::forward(args)...); + sprout::bind(sprout::forward(f), sprout::forward(args)...); } } // namespace sprout diff --git a/sprout/tuple/tuple/tuple.hpp b/sprout/tuple/tuple/tuple.hpp index b6e38ff4..92f0e565 100644 --- a/sprout/tuple/tuple/tuple.hpp +++ b/sprout/tuple/tuple/tuple.hpp @@ -15,7 +15,6 @@ namespace sprout { namespace detail { template class head_base; - // ??? // EBO disabled // template // class head_base