Exemple #1
0
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;
}
Exemple #2
0
        // 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")
    {
        mapnik::css_color_grammar<std::string::const_iterator> color_grammar;
        boost::spirit::qi::ascii::space_type space;
    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);
    CHECK(static_cast<int>(out.blue()) == 96);
    CHECK(static_cast<int>(out.alpha()) == 96);
    out = mapnik::get_pixel<mapnik::color>(im2_any, 0, 0);
    CHECK(static_cast<int>(out.red()) == 43);
    CHECK(static_cast<int>(out.green()) == 53);
    CHECK(static_cast<int>(out.blue()) == 96);