//Adjust black bars to horizontal bottom static unsafe void AdjustBlackbarBottom(byte *bitmapData, ref int targetMargin) { try { for (int captureStep = vMarginMinimumOffset; captureStep < vBlackBarStepVertical; captureStep += vMarginBlackAccuracy) { int CaptureZoneVer = captureStep; for (int captureRange = vMarginMinimumOffset; captureRange < vBlackBarRangeVertical; captureRange += vMarginBlackAccuracy) { int CaptureZoneHor = captureRange; ColorRGBA ColorPixel = ColorProcessing.GetPixelColor(bitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor, CaptureZoneVer); if (ColorPixel != null) { if (setDebugMode && setDebugBlackBar) { ColorProcessing.SetPixelColor(bitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor, CaptureZoneVer, ColorRGBA.Orange); } if (ColorPixel.R > setAdjustBlackBarBrightness || ColorPixel.G > setAdjustBlackBarBrightness || ColorPixel.B > setAdjustBlackBarBrightness) { targetMargin = captureStep; //Debug.WriteLine("Adjusting black bar margin to: " + captureStep); return; } } } } targetMargin = vBlackBarStepVertical; } catch { } }
//Capture the color pixels private static unsafe void CaptureColorAlgorithm(byte *BitmapData, ref int CapturedColors, ref int AverageRed, ref int AverageGreen, ref int AverageBlue, int CaptureZoneHor, int CaptureZoneVer, int CaptureZoneSize, LedSideTypes SideType) { try { int CaptureEvenStep = 1; int CaptureZoneHorRange = 0; int CaptureZoneVerRange = 0; for (int captureStep = 0; captureStep < CaptureZoneSize; captureStep++) { if (CaptureEvenStep == 1) { CaptureEvenStep = 0; } else { CaptureEvenStep = 1; } for (int captureRange = 0; captureRange < vCaptureRange; captureRange += 2) { if (SideType == LedSideTypes.TopLeftToRight) { CaptureZoneHorRange = captureStep; CaptureZoneVerRange = -captureRange - CaptureEvenStep; } else if (SideType == LedSideTypes.TopRightToLeft) { CaptureZoneHorRange = -captureStep; CaptureZoneVerRange = -captureRange - CaptureEvenStep; } else if (SideType == LedSideTypes.BottomLeftToRight) { CaptureZoneHorRange = captureStep; CaptureZoneVerRange = captureRange + CaptureEvenStep; } else if (SideType == LedSideTypes.BottomRightToLeft) { CaptureZoneHorRange = -captureStep; CaptureZoneVerRange = captureRange + CaptureEvenStep; } else if (SideType == LedSideTypes.LeftBottomToTop) { CaptureZoneHorRange = captureRange + CaptureEvenStep; CaptureZoneVerRange = captureStep; } else if (SideType == LedSideTypes.LeftTopToBottom) { CaptureZoneHorRange = captureRange + CaptureEvenStep; CaptureZoneVerRange = -captureStep; } else if (SideType == LedSideTypes.RightBottomToTop) { CaptureZoneHorRange = -captureRange - CaptureEvenStep; CaptureZoneVerRange = captureStep; } else if (SideType == LedSideTypes.RightTopToBottom) { CaptureZoneHorRange = -captureRange - CaptureEvenStep; CaptureZoneVerRange = -captureStep; } ColorRGBA ColorPixel = ColorProcessing.GetPixelColor(BitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor + CaptureZoneHorRange, CaptureZoneVer + CaptureZoneVerRange); if (ColorPixel != null) { if (setDebugMode && setDebugColor) { ColorProcessing.SetPixelColor(BitmapData, vScreenOutputWidth, vScreenOutputHeight, CaptureZoneHor + CaptureZoneHorRange, CaptureZoneVer + CaptureZoneVerRange, ColorRGBA.Purple); } AverageRed += ColorPixel.R; AverageGreen += ColorPixel.G; AverageBlue += ColorPixel.B; CapturedColors++; } } } } catch { } }