Improve quality of GDI image scaling (#18495)

When Sixel images are rendered, they're automatically scaled to match
the 10x20 cell size of the original hardware terminals. If this requires
the image to be scaled down, the default GDI stretching mode can produce
ugly visual artefacts, particularly for color images. This PR changes
the stretching mode to `COLORONCOLOR`, which looks considerably better,
but without impacting performance.

The initial Sixel implementation was added in PR #17421.

## Validation Steps Performed

I've tested with a number of different images using a small font size to
trigger the downscaling, and I think the results are generally better,
although simple black on white images are still better with the default
mode (i.e. `BLACKONWHITE`), which is understandable.

I've also checked the performance with a variation of the [sixel-bench]
test, and confirmed that the new mode is no worse than the default.

[sixel-bench]: https://github.com/jerch/sixel-bench

(cherry picked from commit b243fb6189238b7549aea18cf54b58243c01ff6e)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgZ0dHA
Service-Version: 1.23
This commit is contained in:
James Holderness 2025-02-03 22:46:26 +00:00 committed by Dustin L. Howett
parent 684b91f5f1
commit b29a985f54
2 changed files with 4 additions and 0 deletions

View File

@ -215,6 +215,7 @@ codepages
codepath
coinit
colorizing
COLORONCOLOR
COLORREFs
colorschemes
colorspec

View File

@ -128,6 +128,9 @@ GdiEngine::~GdiEngine()
// We need the advanced graphics mode in order to set a transform.
SetGraphicsMode(hdcNewMemoryContext, GM_ADVANCED);
// We set the bitmap stretching mode to improve the Sixel image quality.
SetStretchBltMode(hdcNewMemoryContext, COLORONCOLOR);
// If we had an existing memory context stored, release it before proceeding.
if (nullptr != _hdcMemoryContext)
{