在Linux / Xorg上设置颜色亮度 [英] Setting color brightness on Linux/Xorg

查看:382
本文介绍了在Linux / Xorg上设置颜色亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有任何命令(或API)设置X.Org/Linux颜色亮度?

Is there any command (or API) to set X.Org/Linux color brightness?

换句话说,我需要一些方便的 xgamma 命令,但用于实时更改RGB亮度

In other words, I need something as handy as the xgamma command but for changing RGB brightness real-time.

这是可能吗?

推荐答案

使用 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, screen, &gamma)) break;
        printf("gamma: %f %f %f", gamma.red, gamma.green, gamma.blue);
        if (!XF86VidModeGetGamma(display, screen, &gamma)) break;
        printf(" -> %f %f %f\n", gamma.red, gamma.green, gamma.blue);
        sleep(1);
    }
    XF86VidModeSetGamma(display, screen, &orig);
    XF86VidModeGetGamma(display, screen, &orig);

    XCloseDisplay(display);
    return 0;
}

这会使gamma从0.25到4.0并返回,然后恢复原始gamma。

This brings the gamma from 0.25 to 4.0 and back, and then restores the original gamma.

或者你可以反复调用 system(xgamma -gamma%f)同样的结果。

Or you could just repeatedly call system("xgamma -gamma %f"), with pretty much the same results.

这篇关于在Linux / Xorg上设置颜色亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆