Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement text contrast using greyscale dilation. #17511

Merged
merged 2 commits into from Jan 19, 2020

Conversation

@pchote
Copy link
Member

pchote commented Dec 27, 2019

Our current text contrast rendering cheats by drawing four copies of the text, offset in x/y. This looks ok when the offset is small relative to the pixel scale, but completely breaks on high DPI displays (e.g. using 150% UI scaling on a 200% DPI display):

This PR implements the feature properly, calculating contrast glyphs by applying a modified greyscale dilation operator. Wikipedia has a helpful animation demonstrating the process: https://en.wikipedia.org/wiki/Dilation_%28morphology%29#/media/File:Grayscale_Morphological_Dilation.gif. The implementation here uses a floating point structural element, which lets us blend out partially overlapping pixels instead of having harsh edges.

This produces the intended result (150% UI scaling on a 200% DPI display):

Now, this highlights that the default 2px contrast offset on LabelWidget is a bit ridiculous, so the second commit reduces this to 1px (150% UI scaling on a 200% DPI display):

which still looks reasonable on normal systems (100% UI scaling on a 100% DPI display):

Required for #10382.

// The output is a 2 * r + 1 square array giving the pixel intersection
// with a circle of radius (r + 0.5).
//
// Example output for r=1:

This comment has been minimized.

Copy link
@pchote

pchote Dec 27, 2019

Author Member

In case anybody wants to regenerate these:

Console.WriteLine("Example output for r={0}:", r);
for (var j = 0; j <= 2 * r; j++)
	Console.WriteLine(elem.Skip(j * stride).Take(stride).Select(x => x.ToString("F2")).JoinWith(" "));

Console.WriteLine();
@pchote

This comment has been minimized.

Copy link
Member Author

pchote commented Dec 27, 2019

I should look into what options FreeType provide for this - this would require less code and provide better performance.

@pchote pchote force-pushed the pchote:render-contrast branch from 3b7f227 to 241c5dc Dec 28, 2019
@pchote

This comment has been minimized.

Copy link
Member Author

pchote commented Jan 1, 2020

I haven't been able to get FT_Stroker to work, so the current approach is going to have to do.

@pchote pchote force-pushed the pchote:render-contrast branch from 241c5dc to c921c63 Jan 12, 2020
@pchote pchote force-pushed the pchote:render-contrast branch from c921c63 to 2c3980b Jan 12, 2020
@pchote

This comment has been minimized.

Copy link
Member Author

pchote commented Jan 12, 2020

Updated. This will now require an entry in https://github.com/OpenRA/OpenRAModSDK/wiki/Update-notes:-hotfix-release-to-next-release about adding the new metric options.

@Mailaender Mailaender merged commit f1325e1 into OpenRA:bleed Jan 19, 2020
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@pchote pchote deleted the pchote:render-contrast branch Jan 19, 2020
@Mailaender

This comment has been minimized.

Copy link
Member

Mailaender commented Jan 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.