1
1
using ArnoldVinkCode ;
2
2
using System ;
3
+ using System . Collections . Generic ;
3
4
using System . Diagnostics ;
5
+ using System . Linq ;
4
6
using static AmbiPro . AppClasses ;
5
7
using static AmbiPro . AppEnums ;
6
8
using static AmbiPro . AppVariables ;
@@ -180,10 +182,7 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
180
182
colorFirstRange = 0 ;
181
183
try
182
184
{
183
- int colorCount = 0 ;
184
- int colorAverageR = 0 ;
185
- int colorAverageG = 0 ;
186
- int colorAverageB = 0 ;
185
+ List < ColorRGBA > captureColors = [ ] ;
187
186
int captureSizeStep = 0 ;
188
187
int captureEvenStep = 1 ;
189
188
int captureRangeStep = 0 ;
@@ -250,19 +249,16 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
250
249
//Draw debug pixel colors
251
250
DebugDrawPixelColors ( bitmapByteArray , captureZoneHor , captureZoneVer , ledSideType , captureZoneHorRange , captureZoneVerRange , captureInBlackbarRange ) ;
252
251
252
+ //Check blackbar range and add captured pixel color
253
+ if ( ! captureInBlackbarRange )
254
+ {
255
+ captureColors . Add ( colorPixel ) ;
256
+ }
257
+
253
258
//Calculate color luminance
254
259
int colorLuminance = colorPixel . CalculateLuminance ( ) ;
255
260
bool colorIsNotBlack = colorLuminance > setAdjustBlackBarBrightness ;
256
261
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
-
266
262
//Check if color found and set first found range
267
263
if ( ! colorFound && colorIsNotBlack )
268
264
{
@@ -274,15 +270,10 @@ private static void CaptureScreenColorAlgorithm(byte[] bitmapByteArray, out Colo
274
270
}
275
271
}
276
272
277
- //Calculate average color
278
- if ( colorCount > 0 )
273
+ //Merge captured pixel colors
274
+ if ( captureColors . Any ( ) )
279
275
{
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 ) ;
286
277
}
287
278
}
288
279
catch ( Exception ex )
0 commit comments