wzcolor.cxx
来自「有限元学习研究用源代码(老外的),供科研人员参考」· CXX 代码 · 共 86 行
CXX
86 行
#include "wzcolor.hxx"
static char hexa[]=
{'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
void wzColor::get(wzString s) const
{s[0]='#';
s[1]=hexa[R>>4];
s[2]=hexa[R&0xf];
s[3]=hexa[R&0xf];
s[4]=hexa[G>>4];
s[5]=hexa[G&0xf];
s[6]=hexa[G&0xf];
s[7]=hexa[B>>4];
s[8]=hexa[B&0xf];
s[9]=hexa[B&0xf];
s[10]='\0';
}
void wzColor::set(wzString s)
{
if(s[0]!='#') {R=G=B=0; return;}
unsigned int p[13], i=1;
while(s[i]){
if ((s[i]>='0') && (s[i] <='9')){ p[i] = (s[i]-'0');}
else if((s[i]>='a') && (s[i] <='f')){
p[i] = ((unsigned)s[i]-(unsigned)'a')+10;
}
else {break;}
i++;
}
if(i<=3){
R=G=B=0; return;
}else if(i<=6){
R = (p[1])<<4;
G = (p[2])<<4;
B = (p[3])<<4;
}else if(i<=9){
R = ((p[1])<<4)+(p[2]);
G = ((p[3])<<4)+(p[4]);
B = ((p[5])<<4)+(p[6]);
}else if(i<=12){
R = ((p[1])<<4)+(p[2]);
G = ((p[4])<<4)+(p[5]);
B = ((p[7])<<4)+(p[8]);
}else{
R = ((p[1])<<4)+(p[2]);
G = ((p[5])<<4)+(p[6]);
B = ((p[9])<<4)+(p[10]);
}
}
static const int zeroIsWater = 1;
void wzColor::getElevation(wzShort &i) const
{
i = ((int)(*(signed char *)&B + (R/0x10)))*0x100 + G + zeroIsWater;
}
void wzColor::setElevation(wzShort m)
{int mm, up;
mm = m - zeroIsWater;
up = mm / 0x100;
if(mm<0) {up = -up;}
G = mm % 0x100;
R = (up%0x10)*0x10;
B = (up/0x10)*0x10;
if(mm<0) {B = 0xff-B;}
/* up = mm / 0x100;
G = mm % 0x100;
R = (up%0x10)*0x10;
*(signed char *)&B = (up/0x10)*0x10;
*/
}
/*
#include <iostream.h>
ostream& operator<<(ostream& o, wzColor c)
{char b[20];
c.get(b); o<<b;
return o;
}
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?