Skip to content

Commit f5ab956

Browse files
committed
- Use square root color merge for screen capture.
1 parent b3494ed commit f5ab956

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

Client/AmbiPro/AppVariables.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ partial class AppVariables
5656
public static int vCaptureRangeVertical = 0;
5757
public static CaptureDetails vCaptureDetails;
5858
public static CaptureSettings vCaptureSettings;
59-
public static ColorRGBA[][] vCaptureHistoryArray = new ColorRGBA[20][];
59+
public static ColorRGBA[] vCaptureColorHistoryOpacity = null;
60+
public static ColorRGBA[][] vCaptureColorHistoryMerge = new ColorRGBA[20][];
6061

6162
//Debug Variables
6263
public static bool vDebugCaptureAllowed = false;
@@ -87,7 +88,8 @@ public static void ResetVariables()
8788
vCaptureRangeVertical = 0;
8889
vCaptureDetails = new CaptureDetails();
8990
vCaptureSettings = new CaptureSettings();
90-
vCaptureHistoryArray = new ColorRGBA[20][];
91+
vCaptureColorHistoryOpacity = null;
92+
vCaptureColorHistoryMerge = new ColorRGBA[20][];
9193
}
9294
catch { }
9395
}

Client/AmbiPro/ScreenColors.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using ArnoldVinkCode;
22
using System;
3+
using System.Collections.Generic;
34
using System.Diagnostics;
5+
using System.Linq;
46
using static AmbiPro.AppClasses;
57
using static AmbiPro.AppEnums;
68
using static AmbiPro.AppVariables;
@@ -180,10 +182,7 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
180182
colorFirstRange = 0;
181183
try
182184
{
183-
int colorCount = 0;
184-
int colorAverageR = 0;
185-
int colorAverageG = 0;
186-
int colorAverageB = 0;
185+
List<ColorRGBA> captureColors = [];
187186
int captureSizeStep = 0;
188187
int captureEvenStep = 1;
189188
int captureRangeStep = 0;
@@ -250,19 +249,16 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
250249
//Draw debug pixel colors
251250
DebugDrawPixelColors(bitmapByteArray, captureZoneHor, captureZoneVer, ledSideType, captureZoneHorRange, captureZoneVerRange, captureInBlackbarRange);
252251

252+
//Check blackbar range and add captured pixel color
253+
if (!captureInBlackbarRange)
254+
{
255+
captureColors.Add(colorPixel);
256+
}
257+
253258
//Calculate color luminance
254259
int colorLuminance = colorPixel.CalculateLuminance();
255260
bool colorIsNotBlack = colorLuminance > setAdjustBlackBarBrightness;
256261

257-
//Check blackbar range and add pixel color to average color
258-
if (!captureInBlackbarRange || colorIsNotBlack)
259-
{
260-
colorAverageR += colorPixel.R;
261-
colorAverageG += colorPixel.G;
262-
colorAverageB += colorPixel.B;
263-
colorCount++;
264-
}
265-
266262
//Check if color found and set first found range
267263
if (!colorFound && colorIsNotBlack)
268264
{
@@ -274,15 +270,10 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
274270
}
275271
}
276272

277-
//Calculate average color
278-
if (colorCount > 0)
273+
//Merge captured pixel colors
274+
if (captureColors.Any())
279275
{
280-
colorCapture = new ColorRGBA()
281-
{
282-
R = (byte)(colorAverageR / colorCount),
283-
G = (byte)(colorAverageG / colorCount),
284-
B = (byte)(colorAverageB / colorCount)
285-
};
276+
colorCapture = AdjustColorMerge.ColorMergeSqrt(captureColors);
286277
}
287278
}
288279
catch (Exception ex)

0 commit comments

Comments
 (0)