Reading Console RGB Color Values

Meat

In C or C ++, is there a way to directly read the values ​​of the RGB color palette? Of particular interest is the expanded color space used by xterm (and others) to define up to 256 terminal colors.

Potatoes

The thing is, I want to define my own colors (using ANSI escape sequences, for example, \e]4;3;rgb:cc/78/33\e\\or directly in c), but I need to save the colors of users before overriding them (in the unlikely event they have already redefined their colors) to restore them when my program ends. Unable to hide user settings.

Now I'm going to use ANSI escape sequences to do this in a client-side way. But since I cannot find how you get the colors, I start doing this with c or C ++.

The solution will be written as a ruby ​​stone with a native extension (mostly built-in c or C ++ code), and I will try to get a cross-platform solution, although the main goal is OS X and, secondly, Linux environments ..

Cause

, , . ( ANSI). , escape- ANSI, . , - , - , ...

:

, - █ ​​ . , Linux 3 , (7 8), , :)

, "" ™ - ( - , ), , ). , , , . , :)

+4
1

[ 1] , , DAC IO

EGA/VGA...

  • /
  • , 0x03C8, 0x03C9 hex.
  • , .
  • 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/++ , :

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
    }
0

All Articles