Changed the name of the set_alpha and multiply_alpha to be set_opacity and multiply_opacity
This commit is contained in:
parent
25c6576fdd
commit
b68d079255
4 changed files with 63 additions and 63 deletions
|
@ -136,17 +136,17 @@ MAPNIK_DECL bool is_solid (image_view_any const& image);
|
|||
template <typename T>
|
||||
MAPNIK_DECL bool is_solid (T const& image);
|
||||
|
||||
// SET ALPHA
|
||||
MAPNIK_DECL void set_alpha (image_any & image, float opacity);
|
||||
// SET OPACITY
|
||||
MAPNIK_DECL void set_opacity (image_any & image, float opacity);
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL void set_alpha (T & image, float opacity);
|
||||
MAPNIK_DECL void set_opacity (T & image, float opacity);
|
||||
|
||||
// MULTIPLY ALPHA
|
||||
MAPNIK_DECL void multiply_alpha (image_any & image, float opacity);
|
||||
// MULTIPLY OPACTIY
|
||||
MAPNIK_DECL void multiply_opacity (image_any & image, float multiplier);
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL void multiply_alpha (T & image, float opacity);
|
||||
MAPNIK_DECL void multiply_opacity (T & image, float multiplier);
|
||||
|
||||
// SET GRAYSCALE TO ALPHA
|
||||
MAPNIK_DECL void set_grayscale_to_alpha (image_any & image);
|
||||
|
|
|
@ -633,9 +633,9 @@ inline T clamp(T d, T min, T max)
|
|||
}
|
||||
|
||||
}
|
||||
struct visitor_set_alpha
|
||||
struct visitor_set_opacity
|
||||
{
|
||||
visitor_set_alpha(float opacity)
|
||||
visitor_set_opacity(float opacity)
|
||||
: opacity_(clamp(opacity, 0.0f, 1.0f)) {}
|
||||
|
||||
void operator() (image_rgba8 & data) const
|
||||
|
@ -663,7 +663,7 @@ struct visitor_set_alpha
|
|||
template <typename T>
|
||||
void operator() (T & data) const
|
||||
{
|
||||
throw std::runtime_error("Error: set_alpha with " + std::string(typeid(data).name()) + " is not supported");
|
||||
throw std::runtime_error("Error: set_opacity with " + std::string(typeid(data).name()) + " is not supported");
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -672,11 +672,11 @@ private:
|
|||
|
||||
} // end detail ns
|
||||
|
||||
MAPNIK_DECL void set_alpha(image_any & data, float opacity)
|
||||
MAPNIK_DECL void set_opacity(image_any & data, float opacity)
|
||||
{
|
||||
// Prior to calling the data must not be premultiplied
|
||||
bool remultiply = mapnik::demultiply_alpha(data);
|
||||
util::apply_visitor(detail::visitor_set_alpha(opacity), data);
|
||||
util::apply_visitor(detail::visitor_set_opacity(opacity), data);
|
||||
if (remultiply)
|
||||
{
|
||||
mapnik::premultiply_alpha(data);
|
||||
|
@ -684,11 +684,11 @@ MAPNIK_DECL void set_alpha(image_any & data, float opacity)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL void set_alpha(T & data, float opacity)
|
||||
MAPNIK_DECL void set_opacity(T & data, float opacity)
|
||||
{
|
||||
// Prior to calling the data must not be premultiplied
|
||||
bool remultiply = mapnik::demultiply_alpha(data);
|
||||
detail::visitor_set_alpha visit(opacity);
|
||||
detail::visitor_set_opacity visit(opacity);
|
||||
visit(data);
|
||||
if (remultiply)
|
||||
{
|
||||
|
@ -696,24 +696,24 @@ MAPNIK_DECL void set_alpha(T & data, float opacity)
|
|||
}
|
||||
}
|
||||
|
||||
template MAPNIK_DECL void set_alpha(image_rgba8 &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray8 &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray8s &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray16 &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray16s &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray32 &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray32s &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray32f &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray64 &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray64s &, float);
|
||||
template MAPNIK_DECL void set_alpha(image_gray64f &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_rgba8 &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray8 &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray8s &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray16 &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray16s &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray32 &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray32s &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray32f &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray64 &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray64s &, float);
|
||||
template MAPNIK_DECL void set_opacity(image_gray64f &, float);
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct visitor_multiply_alpha
|
||||
struct visitor_multiply_opacity
|
||||
{
|
||||
visitor_multiply_alpha(float opacity)
|
||||
: opacity_(opacity) {}
|
||||
visitor_multiply_opacity(float multiplier)
|
||||
: multiplier_(multiplier) {}
|
||||
|
||||
void operator() (image_rgba8 & data) const
|
||||
{
|
||||
|
@ -724,7 +724,7 @@ struct visitor_multiply_alpha
|
|||
for (std::size_t x = 0; x < data.width(); ++x)
|
||||
{
|
||||
pixel_type rgba = row_to[x];
|
||||
double new_a = static_cast<double>((rgba >> 24) & 0xff) * opacity_;
|
||||
double new_a = static_cast<double>((rgba >> 24) & 0xff) * multiplier_;
|
||||
pixel_type a = static_cast<uint8_t>(clamp(new_a, 0.0, 255.0));
|
||||
pixel_type r = rgba & 0xff;
|
||||
pixel_type g = (rgba >> 8 ) & 0xff;
|
||||
|
@ -737,21 +737,21 @@ struct visitor_multiply_alpha
|
|||
template <typename T>
|
||||
void operator() (T & data) const
|
||||
{
|
||||
throw std::runtime_error("Error: multiply_alpha with " + std::string(typeid(data).name()) + " is not supported");
|
||||
throw std::runtime_error("Error: multiply_opacity with " + std::string(typeid(data).name()) + " is not supported");
|
||||
}
|
||||
|
||||
private:
|
||||
float const opacity_;
|
||||
float const multiplier_;
|
||||
|
||||
};
|
||||
|
||||
} // end detail ns
|
||||
|
||||
MAPNIK_DECL void multiply_alpha(image_any & data, float opacity)
|
||||
MAPNIK_DECL void multiply_opacity(image_any & data, float multiplier)
|
||||
{
|
||||
// Prior to calling the data must not be premultiplied
|
||||
bool remultiply = mapnik::demultiply_alpha(data);
|
||||
util::apply_visitor(detail::visitor_multiply_alpha(opacity), data);
|
||||
util::apply_visitor(detail::visitor_multiply_opacity(multiplier), data);
|
||||
if (remultiply)
|
||||
{
|
||||
mapnik::premultiply_alpha(data);
|
||||
|
@ -759,11 +759,11 @@ MAPNIK_DECL void multiply_alpha(image_any & data, float opacity)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
MAPNIK_DECL void multiply_alpha(T & data, float opacity)
|
||||
MAPNIK_DECL void multiply_opacity(T & data, float multiplier)
|
||||
{
|
||||
// Prior to calling the data must not be premultiplied
|
||||
bool remultiply = mapnik::demultiply_alpha(data);
|
||||
detail::visitor_multiply_alpha visit(opacity);
|
||||
detail::visitor_multiply_opacity visit(multiplier);
|
||||
visit(data);
|
||||
if (remultiply)
|
||||
{
|
||||
|
@ -771,17 +771,17 @@ MAPNIK_DECL void multiply_alpha(T & data, float opacity)
|
|||
}
|
||||
}
|
||||
|
||||
template MAPNIK_DECL void multiply_alpha(image_rgba8 &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray8 &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray8s &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray16 &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray16s &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray32 &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray32s &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray32f &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray64 &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray64s &, float);
|
||||
template MAPNIK_DECL void multiply_alpha(image_gray64f &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_rgba8 &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray8 &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray8s &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray16 &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray16s &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray32 &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray32s &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray32f &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray64 &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray64s &, float);
|
||||
template MAPNIK_DECL void multiply_opacity(image_gray64f &, float);
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
|
||||
TEST_CASE("image multiply_alpha") {
|
||||
TEST_CASE("image multiply_opacity") {
|
||||
|
||||
SECTION("test rgba8") {
|
||||
|
||||
|
@ -22,10 +22,10 @@ SECTION("test rgba8") {
|
|||
mapnik::fill(im2, c2); // Because c1 is premultiplied it will make the image premultiplied
|
||||
mapnik::fill(im2_any, c2); // Because c1 is premultiplied it will make the image premultiplied
|
||||
|
||||
mapnik::multiply_alpha(im, 0.75);
|
||||
mapnik::multiply_alpha(im_any, 0.75);
|
||||
mapnik::multiply_alpha(im2, 0.75);
|
||||
mapnik::multiply_alpha(im2_any, 0.75);
|
||||
mapnik::multiply_opacity(im, 0.75);
|
||||
mapnik::multiply_opacity(im_any, 0.75);
|
||||
mapnik::multiply_opacity(im2, 0.75);
|
||||
mapnik::multiply_opacity(im2_any, 0.75);
|
||||
|
||||
mapnik::color out;
|
||||
// This should have only changed the alpha, as it was not premultipleid
|
||||
|
@ -65,7 +65,7 @@ SECTION("test rgba8 overflow") {
|
|||
CHECK(static_cast<int>(out.blue()) == 128);
|
||||
CHECK(static_cast<int>(out.alpha()) == 128);
|
||||
|
||||
mapnik::multiply_alpha(im, 2.5);
|
||||
mapnik::multiply_opacity(im, 2.5);
|
||||
|
||||
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||
CHECK(static_cast<int>(out.red()) == 128);
|
||||
|
@ -81,7 +81,7 @@ SECTION("test rgba8 underflow") {
|
|||
mapnik::color c(128,128,128,128); // This color is premultiplied
|
||||
mapnik::fill(im, c); // Because c1 is not premultiplied it will make the image not premultiplied
|
||||
|
||||
mapnik::multiply_alpha(im, -2.5);
|
||||
mapnik::multiply_opacity(im, -2.5);
|
||||
|
||||
mapnik::color out;
|
||||
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||
|
@ -97,8 +97,8 @@ SECTION("test gray8") {
|
|||
mapnik::image_gray8 im(4,4);
|
||||
mapnik::image_any im_any(mapnik::image_gray8(4,4));
|
||||
|
||||
CHECK_THROWS(mapnik::multiply_alpha(im, 0.25));
|
||||
CHECK_THROWS(mapnik::multiply_alpha(im_any, 0.25));
|
||||
CHECK_THROWS(mapnik::multiply_opacity(im, 0.25));
|
||||
CHECK_THROWS(mapnik::multiply_opacity(im_any, 0.25));
|
||||
|
||||
} // END SECTION
|
||||
} // END TEST_CASE
|
|
@ -5,7 +5,7 @@
|
|||
#include <mapnik/color.hpp>
|
||||
#include <mapnik/image_util.hpp>
|
||||
|
||||
TEST_CASE("image set_alpha") {
|
||||
TEST_CASE("image set_opacity") {
|
||||
|
||||
SECTION("test rgba8") {
|
||||
|
||||
|
@ -22,10 +22,10 @@ SECTION("test rgba8") {
|
|||
mapnik::fill(im2, c2); // Because c1 is premultiplied it will make the image premultiplied
|
||||
mapnik::fill(im2_any, c2); // Because c1 is premultiplied it will make the image premultiplied
|
||||
|
||||
mapnik::set_alpha(im, 0.25);
|
||||
mapnik::set_alpha(im_any, 0.25);
|
||||
mapnik::set_alpha(im2, 0.25);
|
||||
mapnik::set_alpha(im2_any, 0.25);
|
||||
mapnik::set_opacity(im, 0.25);
|
||||
mapnik::set_opacity(im_any, 0.25);
|
||||
mapnik::set_opacity(im2, 0.25);
|
||||
mapnik::set_opacity(im2_any, 0.25);
|
||||
|
||||
|
||||
mapnik::color out;
|
||||
|
@ -60,7 +60,7 @@ SECTION("test rgba8 overflow") {
|
|||
mapnik::color c(128,128,128,128); // This color is premultiplied
|
||||
mapnik::fill(im, c); // Because c1 is not premultiplied it will make the image not premultiplied
|
||||
|
||||
mapnik::set_alpha(im, 1.25);
|
||||
mapnik::set_opacity(im, 1.25);
|
||||
|
||||
mapnik::color out;
|
||||
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||
|
@ -77,7 +77,7 @@ SECTION("test rgba8 underflow") {
|
|||
mapnik::color c(128,128,128,128); // This color is premultiplied
|
||||
mapnik::fill(im, c); // Because c1 is not premultiplied it will make the image not premultiplied
|
||||
|
||||
mapnik::set_alpha(im, -1.25);
|
||||
mapnik::set_opacity(im, -1.25);
|
||||
|
||||
mapnik::color out;
|
||||
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||
|
@ -93,8 +93,8 @@ SECTION("test gray8") {
|
|||
mapnik::image_gray8 im(4,4);
|
||||
mapnik::image_any im_any(mapnik::image_gray8(4,4));
|
||||
|
||||
CHECK_THROWS(mapnik::set_alpha(im, 0.25));
|
||||
CHECK_THROWS(mapnik::set_alpha(im_any, 0.25));
|
||||
CHECK_THROWS(mapnik::set_opacity(im, 0.25));
|
||||
CHECK_THROWS(mapnik::set_opacity(im_any, 0.25));
|
||||
|
||||
} // END SECTION
|
||||
|
Loading…
Add table
Reference in a new issue