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

Do not render sub/highlight backgrounds in transparent renders #799

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -617,15 +616,26 @@ 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)
{
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);
}

Expand Down