Skip to content

Commit

Permalink
Try and compensate for low contrast message colors
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Oct 27, 2019
1 parent ef3a3ea commit 111dfb6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
Point drawPos = new Point(default_x, 0);
System.Drawing.Color userColorSystemDrawing = System.Drawing.ColorTranslator.FromHtml(comment.message.user_color != null ? comment.message.user_color : defaultColors[rand.Next(0, defaultColors.Length)]);
SKColor userColor = new SKColor(userColorSystemDrawing.R, userColorSystemDrawing.G, userColorSystemDrawing.B);
userColor = GenerateUserColor(userColor, renderOptions.background_color);

List<SKBitmap> imageList = new List<SKBitmap>();
SKBitmap sectionImage = new SKBitmap((int)canvasSize.Width, (int)canvasSize.Height);
Expand Down Expand Up @@ -201,6 +202,24 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
}
}

private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)
{
//I don't really know much about this, but i'll give it a shot
float[] userColorHsl = new float[3];
float[] backgroundColorHsl = new float[3];
userColor.ToHsl(out userColorHsl[0], out userColorHsl[1], out userColorHsl[2]);
background_color.ToHsl(out backgroundColorHsl[0], out backgroundColorHsl[1], out backgroundColorHsl[2]);

if (Math.Abs(userColorHsl[2] - backgroundColorHsl[2]) < 10)
{
userColorHsl[2] += 50;
SKColor newColor = SKColor.FromHsl(userColorHsl[0], userColorHsl[1], userColorHsl[2]);
return newColor;
}
else
return userColor;
}

private void RenderVideo(RenderOptions renderOptions, List<TwitchComment> finalComments, List<Comment> comments, object sender)
{
System.Drawing.Bitmap canvas = new System.Drawing.Bitmap(renderOptions.chat_width, renderOptions.chat_height);
Expand Down

0 comments on commit 111dfb6

Please sign in to comment.