From 111dfb6abf23cefc625172be0b3cdee2ca218fc4 Mon Sep 17 00:00:00 2001 From: lay295 Date: Sun, 27 Oct 2019 01:34:12 -0400 Subject: [PATCH] Try and compensate for low contrast message colors --- TwitchDownloaderWPF/PageChatRender.xaml.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/TwitchDownloaderWPF/PageChatRender.xaml.cs b/TwitchDownloaderWPF/PageChatRender.xaml.cs index 3bef042f..1dfd6c87 100644 --- a/TwitchDownloaderWPF/PageChatRender.xaml.cs +++ b/TwitchDownloaderWPF/PageChatRender.xaml.cs @@ -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 imageList = new List(); SKBitmap sectionImage = new SKBitmap((int)canvasSize.Width, (int)canvasSize.Height); @@ -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 finalComments, List comments, object sender) { System.Drawing.Bitmap canvas = new System.Drawing.Bitmap(renderOptions.chat_width, renderOptions.chat_height);