Sprout/sprout/darkroom/materials/interpolation.hpp

62 lines
1.7 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2014-01-08 07:48:12 +00:00
Copyright (c) 2011-2014 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
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)
=============================================================================*/
2012-08-13 01:56:48 +00:00
#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>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR Color
bilinear_interpolate(
2012-08-13 01:56:48 +00:00
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(
2012-08-13 14:55:30 +00:00
sprout::darkroom::colors::mul(c00, 1 - u),
sprout::darkroom::colors::mul(c01, u)
2012-08-13 01:56:48 +00:00
),
2012-08-13 14:55:30 +00:00
1 - v
2012-08-13 01:56:48 +00:00
),
sprout::darkroom::colors::mul(
sprout::darkroom::colors::add(
2012-08-13 14:55:30 +00:00
sprout::darkroom::colors::mul(c10, 1 - u),
sprout::darkroom::colors::mul(c11, u)
2012-08-13 01:56:48 +00:00
),
2012-08-13 14:55:30 +00:00
v
2012-08-13 01:56:48 +00:00
)
);
}
} // namespace materials
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_INTERPOLATION_HPP