Skip to content

Commit 1227cb0

Browse files
committed
Added the new set_alpha and multiply_alpha methods on image, also added tests for each
1 parent 1926698 commit 1227cb0

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
if create_paths:
8282
f_paths.write('mapniklibpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "plugins")\n')
8383
elif create_paths:
84-
f_paths.write("mapniklibpath = '"+lib_path+"/mapnik/plugins'\n")
84+
f_paths.write("mapniklibpath = '"+lib_path+"/mapnik'\n")
8585
f_paths.write('mapniklibpath = os.path.normpath(mapniklibpath)\n')
8686

8787
if create_paths:

src/mapnik_image.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ void set_alpha(image_any & im, float opacity)
287287
mapnik::set_alpha(im, opacity);
288288
}
289289

290+
void multiply_alpha(image_any & im, float opacity)
291+
{
292+
mapnik::multiply_alpha(im, opacity);
293+
}
294+
290295
bool premultiplied(image_any &im)
291296
{
292297
return im.get_premultiplied();
@@ -406,6 +411,7 @@ void export_image()
406411
.def("set_grayscale_to_alpha",&set_grayscale_to_alpha_c, "Set the grayscale values to the alpha channel of the Image")
407412
.def("set_color_to_alpha",&set_color_to_alpha, "Set a given color to the alpha channel of the Image")
408413
.def("set_alpha",&set_alpha, "Set the overall alpha channel of the Image")
414+
.def("multiply_alpha",&multiply_alpha, "Multiply the alpha channel of the Image")
409415
.def("composite",&composite,
410416
( arg("self"),
411417
arg("image"),

test/python_tests/compositing_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def test_rounding_and_color_expectations():
208208
# should have no effect
209209
im_file.premultiply()
210210
eq_(get_unique_colors(im_file),['rgba(0,0,0,0)', 'rgba(74,74,74,255)'])
211-
im_file.set_alpha(.5)
211+
im_file.multiply_alpha(.5)
212212
# should have effect now that image has transparency
213213
im_file.premultiply()
214214
eq_(get_unique_colors(im_file),['rgba(0,0,0,0)', 'rgba(37,37,37,127)'])

test/python_tests/image_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ def test_image_premultiply_values():
4949
eq_(c.b,255)
5050
eq_(c.a,128)
5151

52+
def test_set_alpha():
53+
im = mapnik.Image(4,4)
54+
im.fill(mapnik.Color(128,128,128,128))
55+
im.set_alpha(0.75);
56+
c = im.get_pixel(0,0,True)
57+
eq_(c.r,128)
58+
eq_(c.g,128)
59+
eq_(c.b,128)
60+
eq_(c.a,191)
61+
62+
def test_multiply_alpha():
63+
im = mapnik.Image(4,4)
64+
im.fill(mapnik.Color(128,128,128,128))
65+
im.multiply_alpha(0.75);
66+
c = im.get_pixel(0,0,True)
67+
eq_(c.r,128)
68+
eq_(c.g,128)
69+
eq_(c.b,128)
70+
eq_(c.a,96)
71+
5272
def test_background():
5373
im = mapnik.Image(256,256)
5474
eq_(im.premultiplied(), False)

test/python_tests/render_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_setting_alpha():
6767
im2 = mapnik.Image(w,h)
6868
c2 = mapnik.Color('rgba(255,255,255,1)')
6969
im2.fill(c2)
70-
im2.set_alpha(c1.a/255.0)
70+
im2.multiply_alpha(c1.a/255.0)
7171
eq_(im2.painted(),False)
7272
eq_(im2.is_solid(),True)
7373
eq_(len(im1.tostring('png32')), len(im2.tostring('png32')))

0 commit comments

Comments
 (0)