tests: add style_level_comp_op test

This commit is contained in:
Mickey Rose 2012-10-16 14:32:57 +02:00
parent ccbfec8686
commit 2ee6c1e0e0
35 changed files with 83 additions and 0 deletions

View file

@ -0,0 +1,49 @@
<Map srs="+proj=lonlat +ellps=WGS84 +datum=WGS84 +no_defs +over"
background-color="lightsteelblue">
<Style name="land">
<Rule>
<PolygonSymbolizer fill="darkslategrey" geometry-transform="translate(+1,+1)" />
<PolygonSymbolizer fill="lightcyan" geometry-transform="translate(-1,-1)" />
<PolygonSymbolizer fill="forestgreen" />
</Rule>
</Style>
<Style name="markers" comp-op="src-over">
<Rule>
<MarkersSymbolizer fill="saddlebrown"
fill-opacity="0.5"
stroke-width="0"
width="45 - 5 * [SCALERANK]"
height="45 - 5 * [SCALERANK]"
allow-overlap="true"
ignore-placement="true"
/>
<MarkersSymbolizer fill="white"
fill-opacity="0.7"
stroke-width="0"
width="5"
height="5"
allow-overlap="true"
ignore-placement="true"
/>
</Rule>
</Style>
<Layer name="land">
<StyleName>land</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">../shp/new_zealand/ne_50m_land.shp</Parameter>
</Datasource>
</Layer>
<Layer name="cities">
<StyleName>markers</StyleName>
<Datasource>
<Parameter name="type">shape</Parameter>
<Parameter name="file">../shp/new_zealand/ne_50m_populated_places_simple.shp</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -21,6 +21,10 @@ def debug_image(image,step=2):
red,green,blue,alpha = pixel2channels(pixel)
print "rgba(%s,%s,%s,%s) at %s,%s" % (red,green,blue,alpha,x,y)
def replace_style(m, name, style):
m.remove_style(name)
m.append_style(name, style)
# note: it is impossible to know for all pixel colors
# we can only detect likely cases of non premultiplied colors
def validate_pixels_are_not_premultiplied(image):
@ -145,6 +149,36 @@ def test_pre_multiply_status_of_map2():
mapnik.render(m,im)
eq_(validate_pixels_are_not_premultiplied(im),True)
def test_style_level_comp_op():
m = mapnik.Map(256, 256)
mapnik.load_map(m, '../data/good_maps/style_level_comp_op.xml')
m.zoom_all()
successes = []
fails = []
for name in mapnik.CompositeOp.names:
# find_style returns a copy of the style object
style_markers = m.find_style("markers")
style_markers.comp_op = getattr(mapnik.CompositeOp, name)
# replace the original style with the modified one
replace_style(m, "markers", style_markers)
im = mapnik.Image(m.width, m.height)
mapnik.render(m, im)
actual = '/tmp/mapnik-style-comp-op-' + name + '.png'
expected = 'images/style-comp-op/' + name + '.png'
im.save(actual)
if not os.path.exists(expected):
print 'generating expected test image: %s' % expected
im.save(expected)
expected_im = mapnik.Image.open(expected)
# compare them
if im.tostring() == expected_im.tostring():
successes.append(name)
else:
fails.append('failed comparing actual (%s) and expected(%s)' % (actual,'tests/python_tests/'+ expected))
fail_im = side_by_side_image(expected_im, im)
fail_im.save('/tmp/mapnik-style-comp-op-' + name + '.fail.png')
eq_(len(fails), 0, '\n'+'\n'.join(fails))
def test_style_level_opacity():
m = mapnik.Map(512,512)
mapnik.load_map(m,'../data/good_maps/style_level_opacity_and_blur.xml')

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB