Color.cpp (pymol-v2.1.0.tar.bz2) | : | Color.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 82 | skipping to change at line 82 | |||
5266, /* lightteal */ | 5266, /* lightteal */ | |||
5280, /* darksalmon */ | 5280, /* darksalmon */ | |||
5267, /* splitpea */ | 5267, /* splitpea */ | |||
5268, /* raspberry */ | 5268, /* raspberry */ | |||
104, /* grey50 */ | 104, /* grey50 */ | |||
23, /* deepblue */ | 23, /* deepblue */ | |||
51, /* brown */ | 51, /* brown */ | |||
}; | }; | |||
static int nAutoColor = 40; | static int nAutoColor = 40; | |||
static void lookup_color(CColor * I, float *in, float *out, int big_endian); | static void lookup_color(CColor * I, const float *in, float *out, int big_endian ); | |||
void ColorGetBkrdContColor(PyMOLGlobals * G, float *rgb, int invert_flag) | void ColorGetBkrdContColor(PyMOLGlobals * G, float *rgb, int invert_flag) | |||
{ | { | |||
float *bkrd = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb)); | const float *bkrd = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rg b)); | |||
if(!invert_flag) { | if(!invert_flag) { | |||
if((bkrd[0] + bkrd[1] + bkrd[2]) > 0.5F) { | if((bkrd[0] + bkrd[1] + bkrd[2]) > 0.5F) { | |||
rgb[0] = 1.0F; | rgb[0] = 1.0F; | |||
rgb[1] = 1.0F; | rgb[1] = 1.0F; | |||
rgb[2] = 1.0F; | rgb[2] = 1.0F; | |||
} else { | } else { | |||
rgb[0] = 0.0F; | rgb[0] = 0.0F; | |||
rgb[1] = 0.0F; | rgb[1] = 0.0F; | |||
rgb[2] = 0.0F; | rgb[2] = 0.0F; | |||
skipping to change at line 115 | skipping to change at line 115 | |||
if(fabs(bkrd[a] - rgb[a]) < 0.5F) { | if(fabs(bkrd[a] - rgb[a]) < 0.5F) { | |||
if(bkrd[a] > 0.5F) | if(bkrd[a] > 0.5F) | |||
rgb[a] = 0.0F; | rgb[a] = 0.0F; | |||
else | else | |||
rgb[a] = 1.0F; | rgb[a] = 1.0F; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
unsigned int ColorGet32BitWord(PyMOLGlobals * G, float *rgba) | unsigned int ColorGet32BitWord(PyMOLGlobals * G, const float *rgba) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
unsigned int rc, gc, bc, ac; | unsigned int rc, gc, bc, ac; | |||
unsigned int result; | unsigned int result; | |||
rc = (int) (255 * rgba[0] + 0.49999F); | rc = (int) (255 * rgba[0] + 0.49999F); | |||
gc = (int) (255 * rgba[1] + 0.49999F); | gc = (int) (255 * rgba[1] + 0.49999F); | |||
bc = (int) (255 * rgba[2] + 0.49999F); | bc = (int) (255 * rgba[2] + 0.49999F); | |||
ac = (int) (255 * rgba[3] + 0.49999F); | ac = (int) (255 * rgba[3] + 0.49999F); | |||
skipping to change at line 225 | skipping to change at line 225 | |||
if(!ok) { | if(!ok) { | |||
color[0] = 1.0; | color[0] = 1.0; | |||
color[1] = 1.0; | color[1] = 1.0; | |||
color[2] = 1.0; | color[2] = 1.0; | |||
} else if(I->LUTActive) { | } else if(I->LUTActive) { | |||
lookup_color(I, color, color, I->BigEndian); | lookup_color(I, color, color, I->BigEndian); | |||
} | } | |||
return (ok); | return (ok); | |||
} | } | |||
/* Color::ColorGetCheckRamped -- This function gets a color as 3 floats from an | ||||
index and writes it into | ||||
* the color argument. If the index is a ramp, then it uses the vertex and stat | ||||
e arguments to lookup the | ||||
* color value in the ramp. | ||||
* NOTES: does not support index values cColorObject(-5) or cColorAtomic(-4) col | ||||
or since the object | ||||
* or atom color is not passed in. | ||||
* | ||||
* PARAMS | ||||
* | ||||
* index - color index value | ||||
* vertex - x/y/z used for ramp lookup (if color index is a ramp) | ||||
* color - output color array of 3 floats | ||||
* state - state lookup if ramp | ||||
* | ||||
* RETURN VALUE: returns whether the color index is dependent on a ramp. | ||||
* | ||||
*/ | ||||
bool ColorGetCheckRamped(PyMOLGlobals * G, int index, const float *vertex, float | ||||
*color, int state) | ||||
{ | ||||
bool isRamped = false; | ||||
if(ColorCheckRamped(G, index)) { | ||||
ColorGetRamped(G, index, vertex, color, state); | ||||
isRamped = true; | ||||
} else { | ||||
copy3f(ColorGet(G, index), color); | ||||
} | ||||
return isRamped; | ||||
} | ||||
static int ColorFindExtByName(PyMOLGlobals * G, const char *name, int null_okay, int *best) | static int ColorFindExtByName(PyMOLGlobals * G, const char *name, int null_okay, int *best) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
int result = -1; | int result = -1; | |||
int wm; | int wm; | |||
int a; | int a; | |||
int mybest; | int mybest; | |||
if(!best) | if(!best) | |||
best = &mybest; | best = &mybest; | |||
*best = 0; | *best = 0; | |||
skipping to change at line 729 | skipping to change at line 757 | |||
ext_color = cColorExtCutoff - ext_color; /* indicates external */ | ext_color = cColorExtCutoff - ext_color; /* indicates external */ | |||
if((!ext_best) || (ext_best > best)) /* perfect or better match? */ | if((!ext_best) || (ext_best > best)) /* perfect or better match? */ | |||
color = ext_color; | color = ext_color; | |||
} | } | |||
} | } | |||
} | } | |||
return (color); | return (color); | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
float *ColorGetNamed(PyMOLGlobals * G, const char *name) | const float *ColorGetNamed(PyMOLGlobals * G, const char *name) | |||
{ | { | |||
return (ColorGet(G, ColorGetIndex(G, name))); | return (ColorGet(G, ColorGetIndex(G, name))); | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
char *ColorGetName(PyMOLGlobals * G, int index) | const char *ColorGetName(PyMOLGlobals * G, int index) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
if((index >= 0) && (index < I->NColor)) { | if((index >= 0) && (index < I->NColor)) { | |||
return OVLexicon_FetchCString(I->Lex, I->Color[index].Name); | return OVLexicon_FetchCString(I->Lex, I->Color[index].Name); | |||
} else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { | } else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { | |||
index = (((index & 0xFFFFFF) | ((index << 2) & 0xFC000000) | /* conve rt 6 bits of trans into 8 */ | index = (((index & 0xFFFFFF) | ((index << 2) & 0xFC000000) | /* conve rt 6 bits of trans into 8 */ | |||
((index >> 4) & 0x03000000))); | ((index >> 4) & 0x03000000))); | |||
if(index & 0xFF000000) /* if transparent */ | if(index & 0xFF000000) /* if transparent */ | |||
sprintf(I->RGBName, "0x%08x", index); | sprintf(I->RGBName, "0x%08x", index); | |||
else /* else */ | else /* else */ | |||
skipping to change at line 2464 | skipping to change at line 2492 | |||
color = I->Color; | color = I->Color; | |||
for(a = 0; a < n_color; a++) { | for(a = 0; a < n_color; a++) { | |||
/* mark all current colors non-custom so that they don't get saved in sessio n files */ | /* mark all current colors non-custom so that they don't get saved in sessio n files */ | |||
color[a].Custom = false; | color[a].Custom = false; | |||
} | } | |||
I->NColor = n_color; | I->NColor = n_color; | |||
I->NExt = 0; | I->NExt = 0; | |||
} | } | |||
int ColorTableLoad(PyMOLGlobals * G, char *fname, float gamma, int quiet) | int ColorTableLoad(PyMOLGlobals * G, const char *fname, float gamma, int quiet) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
int ok = true; | int ok = true; | |||
I->Gamma = gamma; | I->Gamma = gamma; | |||
if(!fname[0]) { | if(!fname[0]) { | |||
ColorUpdateFromLut(G, -1); | ColorUpdateFromLut(G, -1); | |||
} else { | } else { | |||
int width = 512, height = 512; | int width = 512, height = 512; | |||
unsigned int *table = NULL; | unsigned int *table = NULL; | |||
skipping to change at line 2694 | skipping to change at line 2722 | |||
FreeP(table); | FreeP(table); | |||
} | } | |||
} | } | |||
if(ok) { | if(ok) { | |||
ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor); | ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor); | |||
SceneChanged(G); | SceneChanged(G); | |||
} | } | |||
return (ok); | return (ok); | |||
} | } | |||
static void lookup_color(CColor * I, float *in, float *out, int big_endian) | static void lookup_color(CColor * I, const float *in, float *out, int big_endian ) | |||
{ | { | |||
const float _1 = 1.0F; | const float _1 = 1.0F; | |||
unsigned int *table = I->ColorTable; | unsigned int *table = I->ColorTable; | |||
if(table) { | if(table) { | |||
unsigned int r, g, b, rr, gr, br; | unsigned int r, g, b, rr, gr, br; | |||
unsigned int ra, ga, ba; | unsigned int ra, ga, ba; | |||
unsigned int rc[2][2][2], gc[2][2][2], bc[2][2][2]; | unsigned int rc[2][2][2], gc[2][2][2], bc[2][2][2]; | |||
unsigned int *entry; | unsigned int *entry; | |||
int x, y, z; | int x, y, z; | |||
float fr, fg, fb, frm1x, fgm1, fbm1, rct, gct, bct; | float fr, fg, fb, frm1x, fgm1, fbm1, rct, gct, bct; | |||
skipping to change at line 2925 | skipping to change at line 2953 | |||
zero3f(I->Front); | zero3f(I->Front); | |||
} | } | |||
void ColorUpdateFrontFromSettings(PyMOLGlobals * G){ | void ColorUpdateFrontFromSettings(PyMOLGlobals * G){ | |||
int bg_gradient = SettingGet_b(G, NULL, NULL, cSetting_bg_gradient); | int bg_gradient = SettingGet_b(G, NULL, NULL, cSetting_bg_gradient); | |||
const char * bg_image_filename = SettingGet_s(G, NULL, NULL, cSetting_bg_image _filename); | const char * bg_image_filename = SettingGet_s(G, NULL, NULL, cSetting_bg_image _filename); | |||
short bg_image = bg_image_filename && bg_image_filename[0]; | short bg_image = bg_image_filename && bg_image_filename[0]; | |||
if (!bg_gradient){ | if (!bg_gradient){ | |||
if (!bg_image && !OrthoBackgroundDataIsSet(G)){ | if (!bg_image && !OrthoBackgroundDataIsSet(G)){ | |||
float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb)); | const float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_r gb)); | |||
ColorUpdateFront(G, v); | ColorUpdateFront(G, v); | |||
} else { | } else { | |||
float v[] = { 0.f, 0.f, 0.f }; | float v[] = { 0.f, 0.f, 0.f }; | |||
ColorUpdateFront(G, v); | ColorUpdateFront(G, v); | |||
} | } | |||
} else { | } else { | |||
float vv[3], *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rg | float vv[3]; | |||
b_bottom)); | const float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb | |||
float *vb = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb_top) | _bottom)); | |||
); | const float *vb = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rg | |||
b_top)); | ||||
average3f(v, vb, vv); | average3f(v, vb, vv); | |||
ColorUpdateFront(G, vv); | ColorUpdateFront(G, vv); | |||
} | } | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
float *ColorGetSpecial(PyMOLGlobals * G, int index) | const float *ColorGetSpecial(PyMOLGlobals * G, int index) | |||
{ | { | |||
if(index >= 0) | if(index >= 0) | |||
return ColorGet(G, index); | return ColorGet(G, index); | |||
else { | else { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
I->RGBColor[0] = (float) index; | I->RGBColor[0] = (float) index; | |||
I->RGBColor[1] = -1.0F; | I->RGBColor[1] = -1.0F; | |||
I->RGBColor[2] = -1.0F; | I->RGBColor[2] = -1.0F; | |||
return I->RGBColor; | return I->RGBColor; | |||
} | } | |||
} | } | |||
float *ColorGet(PyMOLGlobals * G, int index) | const float *ColorGet(PyMOLGlobals * G, int index) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
float *ptr; | const float *ptr; | |||
if((index >= 0) && (index < I->NColor)) { | if((index >= 0) && (index < I->NColor)) { | |||
if(I->Color[index].LutColorFlag && SettingGetGlobal_b(G, cSetting_clamp_colo rs)) | if(I->Color[index].LutColorFlag && SettingGetGlobal_b(G, cSetting_clamp_colo rs)) | |||
ptr = I->Color[index].LutColor; | ptr = I->Color[index].LutColor; | |||
else | else | |||
ptr = I->Color[index].Color; | ptr = I->Color[index].Color; | |||
return (ptr); | return (ptr); | |||
} else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { /* a 24-bit RGB color */ | } else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { /* a 24-bit RGB color */ | |||
I->RGBColor[0] = ((index & 0x00FF0000) >> 16) / 255.0F; | I->RGBColor[0] = ((index & 0x00FF0000) >> 16) / 255.0F; | |||
I->RGBColor[1] = ((index & 0x0000FF00) >> 8) / 255.0F; | I->RGBColor[1] = ((index & 0x0000FF00) >> 8) / 255.0F; | |||
I->RGBColor[2] = ((index & 0x000000FF)) / 255.0F; | I->RGBColor[2] = ((index & 0x000000FF)) / 255.0F; | |||
skipping to change at line 2980 | skipping to change at line 3009 | |||
} else if(index == cColorFront) { | } else if(index == cColorFront) { | |||
return I->Front; | return I->Front; | |||
} else if(index == cColorBack) { | } else if(index == cColorBack) { | |||
return I->Back; | return I->Back; | |||
} else { | } else { | |||
/* invalid color id, then simply return white */ | /* invalid color id, then simply return white */ | |||
return (I->Color[0].Color); | return (I->Color[0].Color); | |||
} | } | |||
} | } | |||
float *ColorGetRaw(PyMOLGlobals * G, int index) | const float *ColorGetRaw(PyMOLGlobals * G, int index) | |||
{ | { | |||
CColor *I = G->Color; | CColor *I = G->Color; | |||
float *ptr; | const float *ptr; | |||
if((index >= 0) && (index < I->NColor)) { | if((index >= 0) && (index < I->NColor)) { | |||
ptr = I->Color[index].Color; | ptr = I->Color[index].Color; | |||
return (ptr); | return (ptr); | |||
} else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { /* a 24-bit RGB color */ | } else if((index & cColor_TRGB_Mask) == cColor_TRGB_Bits) { /* a 24-bit RGB color */ | |||
I->RGBColor[0] = ((index & 0x00FF0000) >> 16) / 255.0F; | I->RGBColor[0] = ((index & 0x00FF0000) >> 16) / 255.0F; | |||
I->RGBColor[1] = ((index & 0x0000FF00) >> 8) / 255.0F; | I->RGBColor[1] = ((index & 0x0000FF00) >> 8) / 255.0F; | |||
I->RGBColor[2] = ((index & 0x000000FF)) / 255.0F; | I->RGBColor[2] = ((index & 0x000000FF)) / 255.0F; | |||
return I->RGBColor; | return I->RGBColor; | |||
} else { | } else { | |||
/* invalid color id, then simply return white */ | /* invalid color id, then simply return white */ | |||
skipping to change at line 3034 | skipping to change at line 3063 | |||
} else { | } else { | |||
color[0] = 1.0F; | color[0] = 1.0F; | |||
color[1] = 1.0F; | color[1] = 1.0F; | |||
color[2] = 1.0F; | color[2] = 1.0F; | |||
/* invalid color id, then simply return white */ | /* invalid color id, then simply return white */ | |||
return 0; | return 0; | |||
} | } | |||
return 1; | return 1; | |||
} | } | |||
int Color3fToInt(PyMOLGlobals * G, float *rgb){ | int Color3fToInt(PyMOLGlobals * G, const float *rgb){ | |||
unsigned int rc, gc, bc; | unsigned int rc, gc, bc; | |||
rc = pymol_roundf(rgb[0] * 255.); | rc = pymol_roundf(rgb[0] * 255.); | |||
gc = pymol_roundf(rgb[1] * 255.); | gc = pymol_roundf(rgb[1] * 255.); | |||
bc = pymol_roundf(rgb[2] * 255.); | bc = pymol_roundf(rgb[2] * 255.); | |||
return ( ( cColor_TRGB_Bits & 0xFF000000) | | return ( ( cColor_TRGB_Bits & 0xFF000000) | | |||
( ( rc << 16 ) & 0x00FF0000) | | ( ( rc << 16 ) & 0x00FF0000) | | |||
( ( gc << 8 ) & 0x0000FF00) | | ( ( gc << 8 ) & 0x0000FF00) | | |||
( ( bc & 0x000000FF ) ) ); | ( ( bc & 0x000000FF ) ) ); | |||
} | } | |||
End of changes. 16 change blocks. | ||||
18 lines changed or deleted | 51 lines changed or added |