⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit.c

📁 LINUX lilo-22.7 源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
    color("   Normal:  ", mn.fg, mn.bg, mn.sh);    color("Highlight:  ", mn.h_fg, mn.h_bg, mn.h_sh);    if (timopt && timer)	color("    Timer:  ", mn.t_fg, mn.t_bg, mn.t_sh);}static void show_layout(void){    printf("\nTable dimensions:\n");    printf("  Number of columns:  %hd\n",  mn.ncol);    printf("  Entries per column (number of rows):  %hd\n", mn.maxcol);    if (mn.ncol > 1) {	printf(	"  Column pitch (X-spacing from character 1 of one column to character 1\n"		"      of the next column):  %d%s (chars)  %hdp (pixels)\n", mn.xpitch/8,    		mn.xpitch%8 ? "+" : "", mn.xpitch);    	printf( "  Spill threshold (number of entries filled-in in the first column\n"    		"      before entries are made in the second column):  %hd\n", mn.mincol);    }    location("Table upper left corner:\n  ", mn.col, mn.row);}static void edit_timer(void){    char *cmd;    int editing = 1;        do {    	if (timer) printf("\nTimer colors:\n");    	show_timer();    	printf("\nTimer setup:  ");    		if (timer) printf("C)olors, P)osition, D)isable");	else printf("E)nable");		printf(", B)ack:  ");		cmd = getLine();		if (timer) switch(toupper(*cmd)) {	    case 'C':		get3colors("Timer", &mn.t_fg);		break;	    case 'D':		while (timer) {		    mn.t_row -= 480;		}		break;	    case 'P':		getXY("\nTimer col", &mn.t_col, 8, 1);		getXY("Timer row", &mn.t_row, 16, 1);		break;	    case 'B':		editing = 0;		break;	    default:	    	printf("???");	}	else switch(toupper(*cmd)) {	    case 'E':		while (!timer) {		    mn.t_row += 480;		}		break;	    case 'B':		editing = 0;		break;	    default:	    	printf("???");	}	free(cmd);	printf("\n");    } while (editing);}static void edit_layout(void){    char *cmd;    int editing = 1;        do {	show_layout();    		printf("\nLayout options:  D)imensions, P)osition, B)ack:  ");	cmd = getLine();	switch(toupper(*cmd)) {	    case 'D':		number("\nNumber of columns", &mn.ncol, 1, 80/MAX_IMAGE_NAME);		number("Entries per column", &mn.maxcol, 1, 30);		if (mn.ncol > 1) {		    getXY("Column pitch", &mn.xpitch, 8, 0);		    number("Spill threshold", &mn.mincol, 1, mn.maxcol);		}		break;	    case 'P':		getXY("\nTable UL column", &mn.col, 8, 1);		getXY("Table UL row", &mn.row, 16, 1);		break;	    case 'B':	    	editing = 0;	    	break;	    default:	    	printf("???");	}	free(cmd);	printf("\n");    } while (editing);}static void edit_colors(void){    char *cmd;    int editing = 1;        do {	printf("\n");	show_colors(1);    		printf("\nText color options:  N)ormal, H)ighlight, ");	if (timer) printf("T)imer, ");	printf("B)ack:  ");	cmd = getLine();	switch(toupper(*cmd)) {	    case 'N':		get3colors("Normal text", &mn.fg);		break;	    case 'H':		get3colors("Highlight text", &mn.h_fg);		break;	    case 'T':		if (timer) get3colors("Timer text", &mn.t_fg);		else goto bad;		break;	    case 'B':	    	editing = 0;	    	break;	    default:	    bad:	    	printf("???");	}	free(cmd);	printf("\n");    } while (editing);}static void edit_bitmap(char *bitmap_file){    char *cmd;    int editing = 1;        printf("Editing contents of bitmap file:  %s\n", bitmap_file);        bmp_file_open(bitmap_file);    do {	show_layout();	printf("\nText colors:\n");	show_colors(0);	show_timer();		printf("\nCommands are:  L)ayout, C)olors, T)imer, Q)uit, W)rite:  ");	cmd = getLine();	switch(toupper(*cmd)) {	    case 'C':		edit_colors();		break;	    case 'L':		edit_layout();		break;	    case 'T':		edit_timer();		break;	    case 'W':	        if (yesno("Save companion configuration file?", 0))						dat_file_creat(bitmap_file);	    	editing = !yesno("Save changes to bitmap file?", 0);	    	if (!editing) {	    	    printf("Writing output file:  %s\n", bitmap_file);	    	    bmp_file_close(!test);  /* update */	    	    if (test) printf("***The bitmap file has not been changed***\n");		}	    	break;	    case 'Q':	    	editing = !yesno("Abandon changes?", 0);	    	if (!editing) bmp_file_close(0);  /* no update */	    	break;	    default:	    	printf("???");	}	free(cmd);	printf("\n");    } while (editing);    exit(0);}static void transfer_params(char *config_file){    int n;    char *bitmap_file, *opt;    char *cp;    int cfd;    cfg_bitmap_only();		/* disable everything but cf_bitmap */        cfd = cfg_open(config_file);    if (verbose >= 3) printf("cfg_open returns: %d\n", cfd);    n = cfg_parse(cf_bitmap);    if (verbose >= 3) printf("cfg_parse returns: %d\n", n);    if (n != 0) {	die("Illegal token in '%s'", config_file);    }    if ((bitmap_file = cfg_get_strg(cf_bitmap, "bitmap")) != NULL) {	opt = "Using";	cp = strrchr(config_file, '/');	if (cp && bitmap_file[0] != '/') {	    *++cp = 0;	    bitmap_file = strcat(strcpy(alloc(strlen(config_file) + strlen(bitmap_file) + 1),					config_file),				 bitmap_file);	    *cp = '/';	}    } else {	opt = "Assuming";	cp = strrchr(config_file, '.');	if (cp) *cp = 0;	bitmap_file = alloc(strlen(config_file) + strlen(BMP_BMP) + 1);	strcpy(bitmap_file, config_file);	strcat(bitmap_file, BMP_BMP);	if (cp) *cp = '.';    }    printf("Transfer parameters from '%s' to '%s'", config_file, bitmap_file);    if (yesno("?", 0)==0) exit(0);    if (verbose > 0) printf("%s bitmap file:  %s\n", opt, bitmap_file);        bmp_file_open(bitmap_file);        bmp_do_table(cfg_get_strg(cf_bitmap, "bmp-table"), menu);    bmp_do_colors(cfg_get_strg(cf_bitmap, "bmp-colors"), menu);    bmp_do_timer(cfg_get_strg(cf_bitmap, "bmp-timer"), menu);        bmp_file_close(1);  /* update */        exit(0);}void do_bitmap_edit(char *filename){    char *bmp = BMP_BMP;    char *fn = strrchr(filename, *bmp);    if (!fn)	die ("'%s'/'%s' filename extension required:  %s", BMP_BMP, BMP_CONF, filename);    if (strcmp(fn, BMP_CONF)==0) transfer_params(filename);    if (strcmp(fn, BMP_BMP)==0) edit_bitmap(filename);        die("Unknown filename extension:  %s", filename);}#undef mn#else	/* STANDALONE */static RGB vga_palette[16] = {/*		 B	 G	 R		*/	{	000,	000,	000,	0 },	/*  k -- black	*/	{	170,	000,	000,	0 },	/*  b -- blue	*/	{	000,	170,	000,	0 },	/*  g -- green	*/	{	170,	170,	000,	0 },	/*  c -- cyan	*//*		 B	 G	 R		*/	{	000,	000,	170,	0 },	/*  r -- red	*/	{	170,	000,	170,	0 },	/*  m -- magenta */	{	000,	 85,	170,	0 },	/*  y -- yellow (amber) */	{	170,	170,	170,	0 },	/*  w -- white	*//*		 B	 G	 R		*/	{	 85,	 85,	 85,	0 },	/*  K -- BLACK (dark grey) */	{	255,	000,	000,	0 },	/*  B -- BLUE	*/	{	000,	255,	000,	0 },	/*  G -- GREEN	*/	{	255,	255,	000,	0 },	/*  C -- CYAN	*//*		 B	 G	 R		*/	{	000,	000,	255,	0 },	/*  R -- RED	*/	{	255,	000,	255,	0 },	/*  M -- MAGENTA */	{	000,	255,	255,	0 },	/*  Y -- YELLOW	*/	{	255,	255,	255,	0 }	/*  W -- WHITE	*/			};FILE* errstd;static BITMAPLILOHEADER lh;static int idx[16];static float hue[NPALETTE], y_yiq[NPALETTE], s_hsv[NPALETTE], 			s_hls[NPALETTE], v_hsv[NPALETTE], l_hls[NPALETTE];void gsort(float array[]){    int i, j;    int n=16;        for (j=n-1; j>0; j--) {	for (i=0; i<j; i++) {	    if (array[idx[i]] > array[idx[i+1]]) {		int t = idx[i];		idx[i] = idx[i+1];		idx[i+1] = t;	    }	}    }}#define MAX(a,b) (a>b?a:b)#define MIN(a,b) (a<b?a:b)static void compute_arrays(RGB pal[], int n){    int i;    float r, g, b, max, min, delta;    float l, h, mm, hsv, hls;        for (i=0; i<n; i++) {	idx[i] = i;	r = NORM(pal[i].red);	g = NORM(pal[i].green);	b = NORM(pal[i].blue);		max = MAX(r,g);	max = MAX(max,b);	min = MIN(r,g);	min = MIN(min,b);	mm = max+min;	l = mm * 0.5;	delta = max-min;	hsv = (max!=0.0 ? delta/max : 0.0);	if (delta==0.0) {	    hls = 0.0;	    h = -1.0;	} else {	    hls = delta / ( (mm <= 1.0) ? mm: (2.0 - mm) );	    h = r==max ? (g - b)/delta :		g==max ? (b - r)/delta + 2 :			 (r - g)/delta + 4;	    h *= 60;	    if (h < 0) h += 360;	}/* compute the YIQ luminance [0..1] */	y_yiq[i] = r*0.3 + g*0.59 + b*0.11;		l_hls[i] = l;	s_hls[i] = hls;	s_hsv[i] = hsv;	v_hsv[i] = max;	hue[i] = h;	    }  /* for ... */}char *Hue(int idx){    static char val[8];    static const char name[] = "RYGCBM";    int i;    float h;        h = hue[idx];    if (h<0) return "";    h += 30;    i = h/60.0;    h -= i*60.0;    i %= 6;    h -= 30;    if (fabs(h)<0.1) { val[0]=name[i]; val[1]=0; }    else sprintf(val,"%c%+3.1f", name[i], h);        return val;}void printline(RGB pal[], int i){/*	      R   G   B   i     Y      V    S(hsv)   S(hls)   L      H	     */    printf("(%3d,%3d,%3d)%3d  %6.3f  %6.3f  %6.3f    %6.3f  %6.3f  %+6.1f  %s\n",    	pal[i].red, pal[i].green, pal[i].blue, i,    	y_yiq[i], v_hsv[i], s_hsv[i], s_hls[i], l_hls[i], hue[i], Hue(i) );}void printpalette(RGB pal[], int n){    int i;/* 	      R   G   B   i     Y      V    S(hsv)   S(hls)   L      H	     */printf("   R   G   B   i     Y       V     S-hsv     S-hls     L       H\n");    for (i=0; i<n; i++)  printline(pal, idx[i]);    printf("\n");}int main(int argc, char *argv[]){    int ifd;    char *outname;    int i;/*    char *cc = "kbgcrmywKBGCRMYW";  */        errstd = stderr;    if (argc < 2) {        printf("Input file not specified\n");    	exit(1);    }    ifd = open(argv[1], O_RDONLY);    if (ifd<0) pdie("opening input file");    if (argc > 2) die("Too many arguments");    if (argc < 3) outname = "out.bmp";    else outname = argv[2];    compute_arrays(vga_palette, 16);    printf("\nVGA palette:\n\n\n");    printpalette(vga_palette, 16);    gsort(y_yiq);    printf("\n\nVGA pallette by luminance\n\n\n");    printpalette(vga_palette, 16);        i = get_std_headers(ifd, &fh, &bmh, &lh);    if (i) {    	printf("Error exit on GET:  %d\n", i);    	exit(i);    }    printf("\n\n\nContained palette:\n\n");    compute_arrays(palette, 16);        gsort(y_yiq);    printpalette(palette, 16);        close(ifd);    return 0;}#endif	/* STANDALONE */

⌨️ 快捷键说明

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