Merge pull request #1781 from mapnik/subpixelhalo

Render halos < 1.0 with fast halo algorithm.
This commit is contained in:
Hermann Kraus 2013-04-24 16:23:39 -07:00
commit 24913c4759
4 changed files with 122 additions and 27 deletions

View file

@ -434,23 +434,48 @@ void render_halo(T & pixmap,
unsigned rgba,
int x1,
int y1,
int halo_radius,
double halo_radius,
double opacity,
composite_mode_e comp_op)
{
int width = bitmap->width;
int height = bitmap->rows;
int x, y;
for (x=0; x < width; x++)
if (halo_radius < 1.0)
{
for (y=0; y < height; y++)
for (x=0; x < width; x++)
{
int gray = bitmap->buffer[y*bitmap->width+x];
if (gray)
for (y=0; y < height; y++)
{
for (int n=-halo_radius; n <=halo_radius; ++n)
for (int m=-halo_radius; m <= halo_radius; ++m)
pixmap.composite_pixel(comp_op, x+x1+m, y+y1+n, rgba, gray, opacity);
int gray = bitmap->buffer[y*bitmap->width+x];
if (gray)
{
pixmap.composite_pixel(comp_op, x+x1-1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1, y+y1-1, rgba, gray*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1+1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1-1, y+y1, rgba, gray*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1, y+y1, rgba, gray, opacity);
pixmap.composite_pixel(comp_op, x+x1+1, y+y1, rgba, gray*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1-1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1, y+y1+1, rgba, gray*halo_radius, opacity);
pixmap.composite_pixel(comp_op, x+x1+1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
}
}
}
} else {
for (x=0; x < width; x++)
{
for (y=0; y < height; y++)
{
int gray = bitmap->buffer[y*bitmap->width+x];
if (gray)
{
for (int n=-halo_radius; n <=halo_radius; ++n)
for (int m=-halo_radius; m <= halo_radius; ++m)
pixmap.composite_pixel(comp_op, x+x1+m, y+y1+n, rgba, gray, opacity);
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -2,7 +2,29 @@
<Style name="labels">
<Rule>
<Filter>([id]=0)</Filter>
<Filter>([id]=0.1)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-rasterizer="fast"
halo-radius=".1"
>
'fast .1'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=0.3)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-rasterizer="fast"
halo-radius=".3"
>
'fast .3'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=0.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -13,7 +35,18 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=1)</Filter>
<Filter>([id]=0.7)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-rasterizer="fast"
halo-radius=".7"
>
'fast .7'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=1.0)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -24,7 +57,7 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=2)</Filter>
<Filter>([id]=1.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -35,7 +68,7 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=3)</Filter>
<Filter>([id]=2.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -57,7 +90,27 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=5)</Filter>
<Filter>([id]=100.1)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-radius=".1"
>
'full .1'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=100.3)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-radius=".3"
>
'full .3'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=100.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -67,7 +120,17 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=6)</Filter>
<Filter>([id]=100.7)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
halo-radius=".7"
>
'full .7'
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=101)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -77,7 +140,7 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=7)</Filter>
<Filter>([id]=101.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -87,7 +150,7 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=8)</Filter>
<Filter>([id]=102.5)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -97,7 +160,7 @@
</TextSymbolizer>
</Rule>
<Rule>
<Filter>([id]=9)</Filter>
<Filter>([id]=104)</Filter>
<TextSymbolizer
face-name="DejaVu Sans Book"
size="15"
@ -114,17 +177,24 @@
<Parameter name="type">csv</Parameter>
<Parameter name="inline">
id,x,y
0,1.5,1
1,1.5,2
2,1.5,3
3,1.5,4
4,1.5,4.5
0.1,1.5,4.5
0.3,1.5,4
0.5,1.5,3.5
0.7,1.5,3
1,1.5,2.5
1.5,1.5,2
2.5,1.5,1.5
4,1.5,1
100.1,3.5,4.5
100.3,3.5,4
100.5,3.5,3.5
100.7,3.5,3
101,3.5,2.5
101.5,3.5,2
102.5,3.5,1.5
104,3.5,1
5,3.5,1
6,3.5,2
7,3.5,3
8,3.5,4
9,3.5,4.5
</Parameter>
</Datasource>
</Layer>