From b29a985f541e5b91a083f8359cc8313d7ab9e6b3 Mon Sep 17 00:00:00 2001 From: James Holderness Date: Mon, 3 Feb 2025 22:46:26 +0000 Subject: [PATCH] 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 --- .github/actions/spelling/expect/expect.txt | 1 + src/renderer/gdi/state.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 1a896e0ced..e78cb97139 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -215,6 +215,7 @@ codepages codepath coinit colorizing +COLORONCOLOR COLORREFs colorschemes colorspec diff --git a/src/renderer/gdi/state.cpp b/src/renderer/gdi/state.cpp index 7563a68b7d..d8f98ef50f 100644 --- a/src/renderer/gdi/state.cpp +++ b/src/renderer/gdi/state.cpp @@ -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) {