📄 color.c
字号:
/*--------------------------------------------------------------------*\ color table object\*--------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "par.h"#include "ui_menu.h"#include "ui_window.h"#include "main.h"#include "color.h"#include "draw.h"static ColorTable ctable = 0;/* some color tables in terms of pivot values */static string ct_names[] = { "gray", "straw", "flag", "tiger", "blue", "rainbow", "avo", "velocity",};static Color_ gray[] = { 0., 1., 1., 1., .5, .5, .5, .5, 1., 0., 0., 0., 1., 1., 0., 0., -1.};static Color_ flag[] = { 0., 0., 0., 1., .5, 1., 1., 1., 1., 1., 0., 0., 1., 0., 1., 0., -1.,};static Color_ tiger[] = { 0., 0., 0., 0., .5, 1., 1., 1., 1., 1., 0., 0., 1., 0., 1., 0., -1.,};static Color_ velocity[] = { 0., 1., 0., 1., .15, 0., .0, 1., .3, 0., 1., .0, .5, 1., 1., 0., .8, 1., .0, 0., 1., 1., 1., 1., -1.,};static Color_ rainbow[] = { 0., 0., 0., 0., .1, 0., .3, 1., .3, 0., 1., .3, .5, 1., 1., 0., .7, 1., .5, 0., .9, 1., 0., 0., 1., 1., 1., 1., 1., 0., 1., 1., -1.,};static Color_ blue[] = { 0., 0., 0., 0., .5, 0., 0., 1., 1., 1., 1., 1., 1., 1., 0., 0., -1.,};static Color_ straw[] = { 0., 0., .3, 1., .5, .7, .7, 0., 1., 1., 1., 0., 1., 1., 0., 0., -1.,};static Color_ avo[] = { 0., 0., 0., 1., .399, 0., 0., 1., .4, .5, .5, 1., .599, .5, .5, 1., .6, 1., .7, 0., .749, 1., .7, 0., .75, 1., 1., 0., .89, 1., 1., 0., .9, 1., 0., 0., 1., 1., 0., 0., -1.,};/* overlay colors */static string over_names[] = { "red", "green", "white", "black",};static Color_ overlay[] = { 0., 1., 0., 0., /* 1 red */ 0., 0., 1., 0., /* 0 green */ 0., 1., 1., 1., /* 3 white */ 0., 0., 0., 0., /* 2 black */};static string mark_names[] = { "red", "green", "white", "black"};static string background_names[] = { "red", "green", "white", "black"};extern Data data;/* initialize color */void ColorInit(void){ int i; cwp_String name; extern ColorTable ctable; /*---------------------*/ /* NEW macro expansion */ /*---------------------*/ { extern int _alloc; ctable = (ColorTable) malloc(sizeof(ctable[0])); _alloc += sizeof(ctable); if( ctable == 0 ){ err("cant allocate %d bytes for ctable; %d already allocated", sizeof(ctable), _alloc); } if( memwatch ){ (void) printf("malloc %s=%d\n", " ctable", sizeof(ctable[0])); } } ctable->base = DrawColorBase(); ctable->size = DrawColorSize() - 4; ctable->contrast = CONTRAST; ctable->contrast0 = CONTRAST0; getparint("contrast", &ctable->contrast); getparint("contrast0", &ctable->contrast0); /*--------------------------*/ /* load default color table */ /*--------------------------*/ if( irint( data->gh.gtype /data->gh.scale )== 5 ){ ctable->color = COLOR_VELOCITY; } if( getparstring("color", (char**)&name) ){ if( !strcmp(name, "gray") ){ ctable->color = COLOR_GRAY; }else if( !strcmp(name, "straw") ){ ctable->color = COLOR_STRAW; }else if( !strcmp(name, "flag") ){ ctable->color = COLOR_FLAG; }else if( !strcmp(name, "tiger") ){ ctable->color = COLOR_TIGER; }else if( !strcmp(name, "rainbow") ){ ctable->color = COLOR_RAINBOW; }else if( !strcmp(name, "blue") ){ ctable->color = COLOR_BLUE; }else if( !strcmp(name, "avo") ){ ctable->color = COLOR_AVO; }else if( !strcmp(name, "velocity") ){ ctable->color = COLOR_VELOCITY; }else{ (void)fprintf( stderr ,"Unrecognized color map: %s" ,name ); } } ctable->overlay = COLOR_OVERLAY; if( getparstring("overlay", (char**)&name) ){ for( i = 0; i < sizeof(overlay) / sizeof(overlay[0]) - 1; i++ ){ if( !strcmp(over_names[i], name) ){ ctable->overlay = i; break; } } } for( i = 0; i < NCOLOR; i++ ){ ctable->red0[i] = 0; ctable->green0[i] = 0; ctable->blue0[i] = 0; ctable->red[i] = 0; ctable->green[i] = 0; ctable->blue[i] = 0; } DrawColor1(ctable->base, BACKGROUND_RED); ColorSwitch();}/* interpret color menu positions */void ColorSwitch(void){ extern ColorTable ctable; if( !ctable ){ return; } switch (ctable->color ){ case COLOR_GRAY: ColorLoad(gray); break; case COLOR_STRAW: ColorLoad(straw); break; case COLOR_FLAG: ColorLoad(flag); break; case COLOR_TIGER: ColorLoad(tiger); break; case COLOR_RAINBOW: ColorLoad(rainbow); break; case COLOR_BLUE: ColorLoad(blue); break; case COLOR_AVO: ColorLoad(avo); break; case COLOR_VELOCITY: ColorLoad(velocity); break; default: err( "Invalid ctable->color value" ); }}/* set contrast-gpow value 0 - 100 */void ColorSetContrast(int contrast){ extern ColorTable ctable; if( !ctable ){ return; } ctable->contrast = contrast;}/* set contrast-middle value 0-100 */void ColorSetContrast0(int contrast0){ extern ColorTable ctable; if( !ctable ){ return; } ctable->contrast0 = contrast0;}/* set color option */void ColorSetChoice(int color){ extern ColorTable ctable; if( !ctable ){ return; } ctable->color = color;}/* set overlay color (see above constants) */void ColorSetOverlay(int index){ extern ColorTable ctable; if( !ctable ){ return; } ctable->overlay = index;}/* set color background */void ColorSetBackground(int index){ extern ColorTable ctable; if( !ctable ){ return; } ctable->background = index; switch (index ){ case COLOR_RED: DrawColor1(ctable->base, BACKGROUND_RED); break; case COLOR_GREEN: DrawColor1(ctable->base, BACKGROUND_GREEN); break; case COLOR_WHITE: DrawColor1(ctable->base, BACKGROUND_WHITE); break; case COLOR_BLACK: DrawColor1(ctable->base, BACKGROUND_BLACK); break; default: err( "Invalid background color index" ); }}/* set mark color */void ColorSetMark(int index){ extern ColorTable ctable; if( !ctable ){ return; } ctable->mark = index; switch (index ){ case COLOR_RED: DrawColor1(ctable->base + ctable->size + 2, MARK_RED); break; case COLOR_GREEN: DrawColor1(ctable->base + ctable->size + 2, MARK_GREEN); break; case COLOR_WHITE: DrawColor1(ctable->base + ctable->size + 2, MARK_WHITE); break; case COLOR_BLACK: DrawColor1(ctable->base + ctable->size + 2, MARK_BLACK); break; default: err( "Invalid background color index" ); }}/* return color table size */int ColorSize(void){ extern ColorTable ctable; if( !ctable ){ return (NCOLOR); } return (ctable->size);}/* print color table information */void ColorInfo(void){ Message message; extern ColorTable ctable; if( !ctable ){ return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -