How can I split an 8-bit color value into two 4-bit color values?

So, I wrote a program that reads in a bitmap and prints to the console using windows.h.

Windows (in the console) allows me to have two colors for each character space - foreground color and background color.

I will limit the 4-bit palette for these colors:

http://www.infotart.com/blog/wp-content/uploads/2008/06/windows_4bit_color_swatches.png

My program works fine for 16 colors, but I had problems getting 256 calculations. (or find out if this is possible)

I need to get an indexed RGB color value (from 256 8-bit colors, something like 224, 64, 0) and display it as two of the 16 available colors, one of which fades out.

The foreground symbol will be one of the ASCII anti-aliasing symbols (I think 176, 177, 178).

So, I believe that each background should have the values ​​R, G, B 0, 128, 255, etc. and the foreground can be 0, 32, 64, 96, 128, 160, 192, 224 or 255

So, if I had the number RGB = 192.0.0, I could set the background RGB = 128.0.0 and in the foreground RGB = 255.0.0 with the ASCII character 176 (with 25% smoothing)

It seems that it would be quite simple if I had a separate anti-aliasing symbol, available for red green and blue separately, but, unfortunately, I do not.

I know that the console is a terrible choice, but I have to try and do it without the help of gdi windows.

I am completely obsessed with trying to understand the algorithm for this, and even have a problem, even if my logic makes sense.

- ? , .

+3
4

RGB ASCII, 8088 Corruption , , CGA.

8088 Corruption IBM ( Google Video).

, ( archive.org), , "ASCII dither", "".

, , ASCII. , , ASCII X .

(, , x86), , , -, .

+1

, , "" RGB .

, , , . 3- ( R, G, B) [0..255] . ( 2 ): , , .

: , , , RGB , . RGB .

, , 256 * 16 * 16 256 ^ 3 , - .

, .

- 256x16x16 RGB-, , , RGB.

0

ImageMagick (Apache 2.0 license) ( ) . , , octrees.

RGB, , , (Src: Wikipedia).

dithering, , , , , .

0

4- RGB, , RGB RGB. , RGB , + :

[255,0,0] + [0,128, 0] = [(255 + 0)/2, (0 + 128)/2, (0 + 0)/2] = [127, 64, 0] ( )

.

, , ! , 16 / , , . 256 , RGB, , , , , 256 , .

Of course, this fixed approach to the lookup table will only work in 256 color palettes as well (and this is not necessary). If this is not the case, you may need to determine a more efficient method for finding the best match color. I am sure that one can be more intelligent than just an exhaustive search.

0
source

Source: https://habr.com/ru/post/1782715/


All Articles