Private Sub FindLargestGapAtTheCenter (bc As BitmapCreator) As B4XRect
Dim y As Int = bc.mHeight / 2
Dim MaxGapStart As Int
Dim MaxGapEnd As Int
Dim GapStart As Int
Dim white As ARGBColor
white = bc.ColorToARGB(xui.Color_White, white)
Dim argb As ARGBColor
Dim InsideAGap As Boolean
For x = 0 To bc.mWidth - 1 Step 2 'step is an optimization factor
bc.GetARGB(x, y, argb)
If argb.r = white.r And argb.b = white.b And argb.g = white.g Then
If InsideAGap = False Then
GapStart = x
InsideAGap = True
End If
Else
If InsideAGap Then
If x-1 - GapStart > MaxGapEnd - MaxGapStart Then
MaxGapEnd = x - 1
MaxGapStart = GapStart
End If
InsideAGap = False
End If
End If
Next
Dim r As B4XRect
r.Initialize(MaxGapStart, y, MaxGapEnd, y)
Return r
End Sub