简体   繁体   English

读取控制台调色板的RGB值

[英]Reading the RGB values of the console color palette

Meat

In C or C++ is there any way to read the color palette RGB values directly? 在C或C ++中有没有办法直接读取调色板RGB值? Especially interesting is the extended color space used by xterm (and others) to define up to 256 terminal colors. 特别有趣的是xterm(和其他人)使用的扩展颜色空间来定义多达256种终端颜色。

Potatoes 土豆

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. 这个例子就是我要定义自己的颜色(使用ANSI转义序列,如\\e]4;3;rgb:cc/78/33\\e\\\\ ,或直接在c)但我需要保存我重新定义它们之前的用户颜色(在不太可能的情况下,他们已经重新定义了它们的颜色),以便我可以在程序完成时恢复它们。 Clobbering user setting is not nice. Clobbering用户设置不是很好。

Right now I'm aiming to use ANSI escape sequences to do this the client way. 现在我的目标是使用ANSI转义序列以客户端方式执行此操作。 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 ++来做这件事。

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... 该解决方案将被编写为具有原生扩展(基本上是嵌入式c或c ++代码)的ruby gem,我的目标是获得跨平台解决方案,即使主要目标是OS X,其次是Linux环境......

Sause 的调味汁

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). 我也可以轻松恢复默认的系统颜色(因为它们是ANSI标准)。 I have looked high and low for a way to do this in ANSI escape codes, but found none. 我在ANSI转义码中有一种方法可以做到这一点,但是没有找到。 I figure that this is kept in memory somewhere and if there is any way to find where, reading the colors should be easy... 我认为这是保存在某个地方的内存中,如果有任何方法可以找到哪里,阅读颜色应该很容易......

Dessert 甜点

To sum up the information in the comments so far: 总结到目前为止评论中的信息:

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 :) 由于这个项目应该是三个主要操作系统的跨平台,并且因为Linux目前在用户上有3个显示管理器,他们使用和windows有两个(7和8)我只能想象有趣的小时和小时将会 :)

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 :) 务实和无聊,但它让我再次继续:)

[Edit 1] sorry this not leads to solution but for others i added DAC palette IO access [编辑1]抱歉这不会导致解决方案,但对于其他人我添加了DAC调色板IO访问

look the old legacy EGA/VGA references ... 看看旧的传统EGA / VGA参考......

  • you can access palette via I/O 您可以通过I / O访问调色板
  • i think it was ports 0x03C8, 0x03C9 hex. 我认为这是端口0x03C8,0x03C9十六进制。
  • of course in modern OS you have no access to it 当然,在现代操作系统中,您无法访问它
  • so try it in DOS-BOX or what ever and save the original palette values, they should be the same. 所以在DOS-BOX中尝试它或者保存原始调色板值,它们应该是相同的。

for direct access try this: 直接访问试试这个:

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++ do not have in,out operations so use this: C / C ++没有in,out操作所以使用这个:

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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM