writecolmap.c

来自「这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易」· C语言 代码 · 共 36 行

C
36
字号
#include <u.h>#include <libc.h>#include <draw.h>/* * This code (and the devdraw interface) will have to change * if we ever get bitmaps with ldepth > 3, because the * colormap will have to be written in chunks */voidwritecolmap(Display *d, RGB *m){	int i, n, fd;	char buf[64], *t;	ulong r, g, b;	sprint(buf, "/dev/draw/%d/colormap", d->dirno);	fd = open(buf, OWRITE);	if(fd < 0)		drawerror(d, "wrcolmap: open colormap failed");	t = malloc(8192);	n = 0;	for(i = 0; i < 256; i++) {		r = m[i].red>>24;		g = m[i].green>>24;		b = m[i].blue>>24;		n += sprint(t+n, "%d %lud %lud %lud\n", 255-i, r, g, b);	}	i = write(fd, t, n);	free(t);	close(fd);	if(i != n)		drawerror(d, "wrcolmap: bad write");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?