Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Render halos < 1.0 with fast halo algorithm #1781

Merged
merged 4 commits into from

2 participants

@herm
Collaborator

Implements a simple function to render halos using the fast algorithm even if the halo is smaller than one pixel.

@springmeyer
Owner

I like the look of this and it seems promising. But I think we need more before/after cases to look at with .1 -> .5 range halos using the fast vs full approach. There may be cases where the faster method cannot draw thin enough halos. However, your improvements look great in the one reference image.

@herm
Collaborator

The halos look quite well for thin sizes, too.

@springmeyer
Owner

k, please merge after updating docs. Thanks!

@herm herm merged commit 24913c4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2013
  1. @herm

    Render fast subpixel halos.

    herm authored
  2. @herm

    Update reference image.

    herm authored
Commits on Apr 3, 2013
  1. @herm

    More tests.

    herm authored
  2. @herm

    Updated reference images.

    herm authored
This page is out of date. Refresh to see the latest.
View
41 src/font_engine_freetype.cpp
@@ -405,23 +405,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);
+ }
}
}
}
View
BIN  tests/visual_tests/images/text-halo-rasterizer-600-400-1.0-agg-reference.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  tests/visual_tests/images/text-halo-rasterizer-600-400-2.0-agg-reference.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
108 tests/visual_tests/styles/text-halo-rasterizer.xml
@@ -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>
Something went wrong with that request. Please try again.