tests: add style_level_comp_op test
49
tests/data/good_maps/style_level_comp_op.xml
Normal 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>
|
|
@ -21,6 +21,10 @@ def debug_image(image,step=2):
|
||||||
red,green,blue,alpha = pixel2channels(pixel)
|
red,green,blue,alpha = pixel2channels(pixel)
|
||||||
print "rgba(%s,%s,%s,%s) at %s,%s" % (red,green,blue,alpha,x,y)
|
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
|
# note: it is impossible to know for all pixel colors
|
||||||
# we can only detect likely cases of non premultiplied colors
|
# we can only detect likely cases of non premultiplied colors
|
||||||
def validate_pixels_are_not_premultiplied(image):
|
def validate_pixels_are_not_premultiplied(image):
|
||||||
|
@ -145,6 +149,36 @@ def test_pre_multiply_status_of_map2():
|
||||||
mapnik.render(m,im)
|
mapnik.render(m,im)
|
||||||
eq_(validate_pixels_are_not_premultiplied(im),True)
|
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():
|
def test_style_level_opacity():
|
||||||
m = mapnik.Map(512,512)
|
m = mapnik.Map(512,512)
|
||||||
mapnik.load_map(m,'../data/good_maps/style_level_opacity_and_blur.xml')
|
mapnik.load_map(m,'../data/good_maps/style_level_opacity_and_blur.xml')
|
||||||
|
|
BIN
tests/python_tests/images/style-comp-op/clear.png
Normal file
After Width: | Height: | Size: 334 B |
BIN
tests/python_tests/images/style-comp-op/color.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/color_burn.png
Normal file
After Width: | Height: | Size: 15 KiB |
BIN
tests/python_tests/images/style-comp-op/color_dodge.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/contrast.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/darken.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/difference.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/dst.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
tests/python_tests/images/style-comp-op/dst_atop.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
tests/python_tests/images/style-comp-op/dst_in.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
tests/python_tests/images/style-comp-op/dst_out.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/dst_over.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
tests/python_tests/images/style-comp-op/exclusion.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/grain_extract.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
tests/python_tests/images/style-comp-op/grain_merge.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/hard_light.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/hue.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
tests/python_tests/images/style-comp-op/invert.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
tests/python_tests/images/style-comp-op/lighten.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
tests/python_tests/images/style-comp-op/minus.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/multiply.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/overlay.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/plus.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/saturation.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/screen.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/soft_light.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/src.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
tests/python_tests/images/style-comp-op/src_atop.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/src_in.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
tests/python_tests/images/style-comp-op/src_out.png
Normal file
After Width: | Height: | Size: 334 B |
BIN
tests/python_tests/images/style-comp-op/src_over.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/value.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
tests/python_tests/images/style-comp-op/xor.png
Normal file
After Width: | Height: | Size: 15 KiB |