From a3be2f14ea51d5690d483c0a1dc680bd056a1c1f Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 23 Aug 2023 01:51:02 -0400 Subject: [PATCH 1/3] Compile PayingForward & ChannelPointHighlight colors as SKColors instead of using SKColor.Parse at runtime. --- TwitchDownloaderCore/ChatRenderer.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 9ffe12d4..e7122bd7 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -617,8 +617,11 @@ private SKBitmap CombineImages(List<(SKImageInfo info, SKBitmap bitmap)> section { if (highlightType is HighlightType.PayingForward or HighlightType.ChannelPointHighlight) { - var colorString = highlightType is HighlightType.PayingForward ? "#26262C" : "#80808C"; - using var paint = new SKPaint { Color = SKColor.Parse(colorString) }; + var accentColor = highlightType is HighlightType.PayingForward + ? new SKColor(0x26, 0x26, 0x2C, 0xFF) // #26262C (RRGGBB) + : new SKColor(0x80, 0x80, 0x8C, 0xFF); // #80808C (RRGGBB) + + using var paint = new SKPaint { Color = accentColor }; finalCanvas.DrawRect(renderOptions.SidePadding, 0, renderOptions.AccentStrokeWidth, finalBitmapInfo.Height, paint); } else if (highlightType is not HighlightType.None) From 58c44d5f3269d695d4303462a81dd6247460b4a9 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 23 Aug 2023 02:01:31 -0400 Subject: [PATCH 2/3] Do not draw subscribe/misc highlight background if the message background is not opaque enough. --- TwitchDownloaderCore/ChatRenderer.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index e7122bd7..9ffb7056 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -28,7 +28,6 @@ public sealed class ChatRenderer : IDisposable private const string PURPLE = "#7B2CF2"; private static readonly SKColor Purple = SKColor.Parse(PURPLE); - private static readonly SKColor HighlightBackground = SKColor.Parse("#1A6B6B6E"); private static readonly string[] DefaultUsernameColors = { "#FF0000", "#0000FF", "#00FF00", "#B22222", "#FF7F50", "#9ACD32", "#FF4500", "#2E8B57", "#DAA520", "#D2691E", "#5F9EA0", "#1E90FF", "#FF69B4", "#8A2BE2", "#00FF7F" }; private static readonly Regex RtlRegex = new("[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]", RegexOptions.Compiled); @@ -626,9 +625,17 @@ private SKBitmap CombineImages(List<(SKImageInfo info, SKBitmap bitmap)> section } else if (highlightType is not HighlightType.None) { - using var backgroundPaint = new SKPaint { Color = HighlightBackground }; + const int OPAQUE_THRESHOLD = 245; + if (renderOptions.BackgroundColor.Alpha >= OPAQUE_THRESHOLD || + (renderOptions.AlternateMessageBackgrounds && renderOptions.AlternateBackgroundColor.Alpha >= OPAQUE_THRESHOLD)) + { + // Draw the highlight background only if the message background is opaque enough + var backgroundColor = new SKColor(0x6B, 0x6B, 0x6E, 0x1A); // #1A6B6B6E (AARRGGBB) + using var backgroundPaint = new SKPaint { Color = backgroundColor }; + finalCanvas.DrawRect(renderOptions.SidePadding, 0, finalBitmapInfo.Width - renderOptions.SidePadding * 2, finalBitmapInfo.Height, backgroundPaint); + } + using var accentPaint = new SKPaint { Color = Purple }; - finalCanvas.DrawRect(renderOptions.SidePadding, 0, finalBitmapInfo.Width - renderOptions.SidePadding * 2, finalBitmapInfo.Height, backgroundPaint); finalCanvas.DrawRect(renderOptions.SidePadding, 0, renderOptions.AccentStrokeWidth, finalBitmapInfo.Height, accentPaint); } From 036a170d2bfa16d764a9a288357329d4bf175ae4 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 23 Aug 2023 02:13:02 -0400 Subject: [PATCH 3/3] Fix boolean logic --- TwitchDownloaderCore/ChatRenderer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 9ffb7056..adca1ed5 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -626,8 +626,8 @@ private SKBitmap CombineImages(List<(SKImageInfo info, SKBitmap bitmap)> section else if (highlightType is not HighlightType.None) { const int OPAQUE_THRESHOLD = 245; - if (renderOptions.BackgroundColor.Alpha >= OPAQUE_THRESHOLD || - (renderOptions.AlternateMessageBackgrounds && renderOptions.AlternateBackgroundColor.Alpha >= OPAQUE_THRESHOLD)) + if (!(renderOptions.BackgroundColor.Alpha < OPAQUE_THRESHOLD || + (renderOptions.AlternateMessageBackgrounds && renderOptions.AlternateBackgroundColor.Alpha < OPAQUE_THRESHOLD))) { // Draw the highlight background only if the message background is opaque enough var backgroundColor = new SKColor(0x6B, 0x6B, 0x6E, 0x1A); // #1A6B6B6E (AARRGGBB)