加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

在Linux / Xorg上设置颜色亮度

发布时间:2020-12-14 02:10:34 所属栏目:Linux 来源:网络整理
导读:是否有任何命令(或API)来设置X.Org/ Linux颜色亮度? 换句话说,我需要像xgamma命令一样方便的东西,但实时改变RGB亮度. 这可能吗? 解决方法 使用 XF86VidMode*系列功能. #include X11/Xlib.h#include X11/extensions/xf86vmode.h#include math.h#include std
是否有任何命令(或API)来设置X.Org/ Linux颜色亮度?

换句话说,我需要像xgamma命令一样方便的东西,但实时改变RGB亮度.

这可能吗?

解决方法

使用 XF86VidMode*系列功能.

#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    Display *display;
    int screen;
    int major,minor;
    int i;
    XF86VidModeGamma orig;

    display = XOpenDisplay(NULL);
    if (!display) return -1;
    screen = DefaultScreen(display);
    if (!XF86VidModeQueryVersion(display,&major,&minor)
            || major < 2 || major == 2 && minor < 0
            || !XF86VidModeGetGamma(display,screen,&orig)) {
        XCloseDisplay(display);
        return -1;
    }

    for (i = 0; i <= 32; i++) {
        XF86VidModeGamma gamma;
        gamma.red = exp2f(2 - fabs(i - 16) / 4);
        gamma.green = gamma.red;
        gamma.blue = gamma.red;
        if (!XF86VidModeSetGamma(display,&gamma)) break;
        printf("gamma: %f %f %f",gamma.red,gamma.green,gamma.blue);
        if (!XF86VidModeGetGamma(display,&gamma)) break;
        printf(" -> %f %f %fn",gamma.blue);
        sleep(1);
    }
    XF86VidModeSetGamma(display,&orig);
    XF86VidModeGetGamma(display,&orig);

    XCloseDisplay(display);
    return 0;
}

这将伽马从0.25增加到4.0并返回,然后恢复原始伽玛.

或者你可以反复调用system(“xgamma -gamma%f”),结果几乎相同.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读