读控制台调色板的RGB值 [英] Reading the RGB values of the console color palette

查看:622
本文介绍了读控制台调色板的RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C或C ++是有任何方式直接读取调色板RGB值?特别有趣的是xterm的(和其他人)使用的扩展色彩空间定义多达256个终端的颜色。

In C or C++ is there any way to read the color palette RGB values directly? Especially interesting is the extended color space used by xterm (and others) to define up to 256 terminal colors.

在点上的情况是,我想使用ANSI转义序列,如 \\ E] 4定义自己的颜色(3; RGB:CC /33分之78\\ E \\\\ ,或者直接在C),但我需要保存用户的颜色之前,我重新定义它们(万一,他们已经重新定义他们的颜色),使我的程序完成时,我可以恢复它们。重挫用户设置不是很好。

The case in point is that I want to define my own colors (using ANSI escape sequences, like \e]4;3;rgb:cc/78/33\e\\, or directly in c) but I need to save the users colors before I redefine them (in the unlikely event that they have already redefined their colors) so that I can restore them when my program finishes. Clobbering user setting is not nice.

现在我的目标使用ANSI转义序列做这个客户端的方式。但是,因为我找不到你怎么弄的颜色了,我开始寻找到C或C ++而不是做这个。

Right now I'm aiming to use ANSI escape sequences to do this the client way. But since I cant find how you get the colors out I'm starting to look into doing this in c or c++ instead.

该解决方案将被写入与原生扩展(基本上是嵌入式C或C ++ code)红宝石的宝石,我会的目标是获得一个跨平台的解决方案,尽管主要对象是OS X和其次的Linux环境...

The solution will be written as a ruby gem with a native extension (basically embedded c or c++ code) and I'll aim to get a cross platform solution, even though the main target is OS X and secondly Linux environments...

从我最初的实验中我得到的地方,我可以定义我想在调色板中的code点什么颜色的点。我也可以轻松地恢复系统默认的颜色(因为它们是ANSI标准)。我看过高和低的方式在ANSI转义codeS要做到这一点,但没有发现。我想,这是保存在内存中的某个地方,如果有任何的方式来找到在哪里,读的颜色应该是很容易...

From my initial experiments I have gotten to the point where I can define whatever colors I want for a code point in the color palette. I can also easily restore the default system colors (since they are ANSI standard). I have looked high and low for a way to do this in ANSI escape codes, but found none. I figure that this is kept in memory somewhere and if there is any way to find where, reading the colors should be easy...

要到目前为止总结注释中的信息:

To sum up the information in the comments so far:

看起来始终如一做到这一点的唯一方法是要打印的字符█的屏幕在不同的颜色和抢夺的颜色了这一点。由于这个项目被认为是跨平台在三大操作系统和因为Linux目前在用户3显示管理器上,他们的方式使用和窗口有两个(7,8),我只能想象小时的乐趣小时的是:)

It looks like the only way to do this consistently is to print a screen of █ characters in the different colors and grabbing the colors off of that. Since this project is supposed to be cross platform over the three major OS's and since Linux currently have 3 display managers in user on on they way into use and windows has two (7 and 8) I can only imagine the hours and hours of fun that would be :)

所以,我的解决方案™是刚刚揍用户颜色(如果他们不是系统默认其他什么...这,让我们面对它是pretty少见)。我将提供一个设置文件,用户可以知道,如果他们不快乐与系统默认颜色应该恢复插件。务实和乏味,但它再次得到的我会在这:)

So my "solution"™ is to just clobber the users colors (if they had anything other than the system defaults ... which, let's face it is pretty uncommon). I will provide a settings file where the user can tell the plugin what colors should be restored if they are not happy with the system defaults. Pragmatic and boring, but it get's me going on this again :)

推荐答案

抱歉,这不是导致解决方案,但对于其他人,我增加DAC面板IO访问

sorry this not leads to solution but for others i added DAC palette IO access

看旧的遗留EGA / VGA引用...

look the old legacy EGA/VGA references ...


  • 您可以通过I / O
  • 访问调色板
  • 我认为这是端口0x03C8,0x03C9十六进制。

  • 当然在现代操作系统你有没有打开

  • 所以尝试在DOS-BOX或什么都并保存原始调色板值,它们应该是相同的。

直接访问试试这个:

BYTE r,g,b,c=5; // R,G,B values are 6 bit only !!!
out 0x3C8,c;    // set color index to work with <0,255>
in  r,0x3C9;    // read color pallete for color c
in  g,0x3C9;    // not sure if it should be r,g,b 
in  b,0x3C9;    // or b,g,r ... i did not use it for too many years
out 0x3C8,c;    // set color index to work with <0,255>
out 0x3C9,r;    // write color pallete for color c
out 0x3C9,g;
out 0x3C9,b;

C / C ++不具备的,出操作这样使用:

C/C++ do not have in,out operations so use this:

BYTE i,o;       // this must be local !!!
WORD port;      // this must be local !!!
asm {
    mov dx,port // in i,port
    in al,dx
    mov o,al

    mov dx,port // out port,o
    mov al,o
    out dx,al
    }

这篇关于读控制台调色板的RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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