VGA下的palette技术

os^代码当前使用的vga下分辨率

0x13: 320x200x8位彩色模式,可以显示256种颜色

其它模式:

  1. 0x03:80x25,也就是master分支使用的文本模式
  2. 0x12:640x480x4位彩色模式,

调色板技术^调色板

存在的意义是:为了节省空间采用的索引压缩的算法,并且只有颜色<=256色有用

  1. 压缩空间的例子:

    颜色数为16个的彩色图用原生rgb表示需要3byte大小,*但是因为图片只用到了16种颜色,所以不需要用原生的rgb来表示,因为其它的色彩用不到,**将16种颜色的rgb存在表中,表的大小为163=48byte,那么用索引4bits大小就能表示这16个颜色,则原来颜色需要3*8=24bits,现在只需要4bits大小空间,占用比为(4/24=1/6),空间大小只是原来的1/6.

  2. vga显卡上有16个寄存器用来存储基本颜色,设置后向vram不在写入rgb表示像素颜色,而是用索引(index)来对应像素颜色

向DAC寄存器写入16个基础颜色后,直接通过index索引来定位需要显示的颜色就行了


以下英文资料都来自^osdevga

planes(位平面)

The video memory consists of four ‘planes’ (individual units) of memory, each with a size of 64KB, giving the VGA 256k of video memory. Connected to it is the Sequencer, which interprets this memory to generate colors which are fed to the subsequent stages. The way colors are organized in this memory mainly depends on the color depth.

vga的ram大小是256k,由4个64k的plane组成.(?不确定)在320x200下只用到了plane 0

Memory Layout in 256-color graphics modes

In this mode, each byte of video memory describes exactly one pixel. Pixels are generated by increasing address in linear mode, with all colors taken from plane 0. In planar mode (Also known as Mode X) each address describes 4 consecutive pixels, one from each plane. Plane 0 describing the first pixel, plane 1 the next, and so on. Technically speaking this is what always happens, but the standard 320x200x256 mode “chains” the planes such that 2 lowest order bits select the plane and the memory thus appears linear.

In linear mode, each byte in host memory corresponds to one pixel on the display, making this mode very easy to use. Mode X requires the use of Plane Write Enable register to select the plane to be written

此模式下,每一个字节用来描述一个像素,线性模式下地址增加产生像素.(Mode X下一个地址的byte产生4个像素,来自plane0-4)

初始化调色板(palette)时为什么要将rgb[]/4,数值右移2位

作者的解释_30天day4^作者的解释

Port 0x3C8

Port 0x3C8, 0x3C9 and 0x3C7 control the DAC. Each register in the DAC consists of 18 bits(DAC中的每个寄存器由18bits组成), 6 bits for each color component(每一个颜色像素占6bits). To write a color, write the color index to port 0x3C8, then write 3 bytes to 0x3C9 in the order red, green, blue. If you want to write multiple consecutive DAC entries, you only need to write the first entry’s index to 0x3C8 then write all values to 0x3C9 in the order red, green, blue, red, green, blue, and so on. The accessed DAC entry will automatically increment after every three bytes written. To read the DAC entries, write the index to be read to 0x3C7, then read the bytes from port 0x3C9 in a similar fashion (as with writing, the index will increment after every three bytes read)

如上知:

  1. rgb的r/g/b由6bits表示,
  2. 写颜色前,先向0x03c8端口写入color index,然后向0x03c8端口连续写入(调色板颜色)的rgb值,并且DAC访问入口会自动增加3bytes.

算是对调色板palette有部分认知了(总结

资料1