rust 怎么通过 GetDeviceGammaRamp 伽马值判断是否有软件开启护眼

因为一些原因需要用两个护眼软件,需要判断另一个护眼软件是否开启,开启后当前护眼软件就不定时设置护眼模式。如果未开启,就定时开启护眼模式。

rust 复制代码
#[derive(Debug)]
struct GammaRamp {
    red: [u16; 256],
    green: [u16; 256],
    blue: [u16; 256],
}

fn is_eye_protection_off(ramp: &GammaRamp) -> bool {
    // 标准伽马 ramp 应该是线性的(近似)
    // 检查 R、G、B 通道是否大致一致且呈线性增长
    let mut is_linear = true;
    
    // 检查关键点的线性度
    for i in (0..256).step_by(32) {
        let expected = (i * 65535 / 255) as u16;
        let tolerance = 1000; // 允许的误差范围
        
        if (ramp.red[i] as i32 - expected as i32).abs() > tolerance ||
           (ramp.green[i] as i32 - expected as i32).abs() > tolerance ||
           (ramp.blue[i] as i32 - expected as i32).abs() > tolerance {
            is_linear = false;
            break;
        }
    }
    
    // 检查 RGB 通道是否平衡(护眼模式通常会降低蓝色通道)
    let mid = 128;
    let red_mid = ramp.red[mid];
    let green_mid = ramp.green[mid];
    let blue_mid = ramp.blue[mid];
    
    let rgb_balance = (red_mid as i32 - green_mid as i32).abs() < 500 &&
                      (green_mid as i32 - blue_mid as i32).abs() < 500;
    
    is_linear && rgb_balance
}