static jobject colorFromNative(JNIEnv *env, mapnik::color const& c) { jobject ret=env->AllocObject(CLASS_COLOR); env->SetIntField(ret, FIELD_COLOR_RED, c.red()); env->SetIntField(ret, FIELD_COLOR_GREEN, c.green()); env->SetIntField(ret, FIELD_COLOR_BLUE, c.blue()); env->SetIntField(ret, FIELD_COLOR_ALPHA, c.alpha()); return ret; }
void agg_renderer<T0,T1>::draw_geo_extent(box2d<double> const& extent, mapnik::color const& color) { box2d<double> box = common_.t_.forward(extent); double x0 = box.minx(); double x1 = box.maxx(); double y0 = box.miny(); double y1 = box.maxy(); unsigned rgba = color.rgba(); for (double x=x0; x<x1; x++) { pixmap_.setPixel(x, y0, rgba); pixmap_.setPixel(x, y1, rgba); } for (double y=y0; y<y1; y++) { pixmap_.setPixel(x0, y, rgba); pixmap_.setPixel(x1, y, rgba); } }
CHECK( conv(1.0) == 3 ); CHECK( conv(60.0) == 153 ); // should not overflow on invalid input CHECK( conv(100000.0) == 255 ); CHECK( conv(-100000.0) == 0 ); mapnik::alpha_conv_impl conv2; CHECK( conv2(0.5) == 128 ); CHECK( conv2(1.0) == 255 ); // should not overflow on invalid input CHECK( conv2(60.0) == 255 ); CHECK( conv2(100000.0) == 255 ); CHECK( conv2(-100000.0) == 0 ); mapnik::hsl_conv_impl conv3; mapnik::color c; conv3(c, 1.0, 1.0, 1.0); CHECK( c.alpha() == 255 ); CHECK( c.red() == 3 ); CHECK( c.green() == 3 ); CHECK( c.blue() == 3 ); // invalid conv3(c, -1, -1, -1); CHECK( c.alpha() == 255 ); // should not be touched by hsl converter CHECK( c.red() == 0 ); CHECK( c.green() == 0 ); CHECK( c.blue() == 0 ); } SECTION("hex colors") {
void set_pixel(mapnik::image_32 & im, unsigned x, unsigned y, mapnik::color const& c) { im.setPixel(x, y, c.rgba()); }
#include "catch.hpp" // mapnik #include <mapnik/image.hpp> #include <mapnik/color.hpp> #include <mapnik/image_view_any.hpp> #include <mapnik/image_util.hpp> TEST_CASE("image view") { SECTION("test rgba8") { mapnik::image_rgba8 im(4,4); mapnik::color c_red("red"); mapnik::color c_blue("blue"); mapnik::color c_green("green"); mapnik::color c_yellow("yellow"); mapnik::fill(im, c_red); // Upper Left 2x2 is blue mapnik::set_pixel(im, 0, 0, c_blue); mapnik::set_pixel(im, 0, 1, c_blue); mapnik::set_pixel(im, 1, 0, c_blue); mapnik::set_pixel(im, 1, 1, c_blue); // Upper Right 2x2 is green mapnik::set_pixel(im, 2, 0, c_green); mapnik::set_pixel(im, 2, 1, c_green); mapnik::set_pixel(im, 3, 0, c_green); mapnik::set_pixel(im, 3, 1, c_green); // Lower Left 2x2 is yellow mapnik::set_pixel(im, 0, 2, c_yellow);
mapnik::image_any im2_any(mapnik::image_rgba8(4,4,true,true)); // Fill the images with meaningfull values mapnik::color c1(57,70,128,128); // This color is not premultiplied mapnik::color c2(57,70,128,128, true); // This color is premultiplied mapnik::fill(im, c1); // Because c1 is not premultiplied it will make the image not premultiplied mapnik::fill(im_any, c1); // Because c1 is not premultiplied it will make the image not premultiplied 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::apply_opacity(im, 0.75); mapnik::apply_opacity(im_any, 0.75); mapnik::apply_opacity(im2, 0.75); mapnik::apply_opacity(im2_any, 0.75); mapnik::color out; // This should have only changed the alpha, as it was not premultipleid out = mapnik::get_pixel<mapnik::color>(im, 0, 0); CHECK(static_cast<int>(out.red()) == 57); CHECK(static_cast<int>(out.green()) == 70); CHECK(static_cast<int>(out.blue()) == 128); CHECK(static_cast<int>(out.alpha()) == 96); out = mapnik::get_pixel<mapnik::color>(im_any, 0, 0); CHECK(static_cast<int>(out.red()) == 57); CHECK(static_cast<int>(out.green()) == 70); CHECK(static_cast<int>(out.blue()) == 128); CHECK(static_cast<int>(out.alpha()) == 96); // This will be different because it is demultiplied then premultiplied again after setting alpha out = mapnik::get_pixel<mapnik::color>(im2, 0, 0); CHECK(static_cast<int>(out.red()) == 43); CHECK(static_cast<int>(out.green()) == 53);