import Foundation let data = try! Data(contentsOf: URL(fileURLWithPath: "shot.bmp")) let pixOff = data.withUnsafeBytes { $0.load(fromByteOffset: 10, as: UInt32.self) } let w = Int(data.withUnsafeBytes { $0.load(fromByteOffset: 18, as: Int32.self) }) let hRaw = Int(data.withUnsafeBytes { $0.load(fromByteOffset: 22, as: Int32.self) }); let h = abs(hRaw) let B = Int(data.withUnsafeBytes { $0.load(fromByteOffset: 28, as: UInt16.self) })/8 let rowBytes = (B * w + 3) & ~3 var cols: [Int] = Array(repeating: 0, count: w) for y in 365...400 { let rowStart = Int(pixOff) + (hRaw > 0 ? (h-1-y) : y) * rowBytes for x in 0.. 120 && b > r + 30 && b > g + 15 && r < 160 { cols[x] += 1 } } } var runs: [(Int,Int)] = [] var s = -1 for x in 0.. 3 && s < 0 { s = x } if (cols[x] <= 3 || x == w-1) && s >= 0 { runs.append((s,x)); s = -1 } } for r in runs { print("blue run x=\(r.0)-\(r.1) width=\(r.1-r.0) center=\((r.0+r.1)/2)") }