zhuyuan-ice-gl-zy001/.tmp_axprobe/cmp.swift

18 lines
1,015 B
Swift
Raw Normal View History

2026-08-20 00:01:53 +08:00
import Foundation
func btnColor(_ path: String) -> String {
let data = try! Data(contentsOf: URL(fileURLWithPath: path))
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
// button center in this capture: window-rel (500,548); capture is nominalResolution(1x?) -> check size
let sx = 500.0 * Double(w) / 1161.0
let sy = 548.0 * Double(h) / 1102.0
let x = Int(sx), y = Int(sy)
let rowStart = Int(pixOff) + (hRaw > 0 ? (h-1-y) : y) * rowBytes
let i = rowStart + x * B
return "size=\(w)x\(h) px(\(x),\(y)) BGR=(\(data[i]),\(data[i+1]),\(data[i+2]))"
}
print("AWAY: " + btnColor("away.bmp"))
print("OVER: " + btnColor("over.bmp"))