"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "layer1/Color.cpp" between
pymol-open-source-2.2.0.tar.gz and pymol-open-source-2.3.0.tar.gz

About: PyMOL is a Python-enhanced molecular graphics tool. It excels at 3D visualization of proteins, small molecules, density, surfaces, and trajectories. It also includes molecular editing, ray tracing, and movies. Open Source version.

Color.cpp  (pymol-open-source-2.2.0):Color.cpp  (pymol-open-source-2.3.0)
skipping to change at line 34 skipping to change at line 34
#include"Ortho.h" #include"Ortho.h"
#include"Word.h" #include"Word.h"
#include"Color.h" #include"Color.h"
#include"PConv.h" #include"PConv.h"
#include"ObjectGadgetRamp.h" #include"ObjectGadgetRamp.h"
#include"Util.h" #include"Util.h"
#include"Executive.h" #include"Executive.h"
#include"MyPNG.h" #include"MyPNG.h"
#include"Scene.h" #include"Scene.h"
#include"LangUtil.h"
#include"OVContext.h" #include"OVContext.h"
#include"OVreturns.h" #include"OVreturns.h"
static int AutoColor[] = { static int AutoColor[] = {
26, /* carbon */ 26, /* carbon */
5, /* cyan */ 5, /* cyan */
154, /* lightmagenta */ 154, /* lightmagenta */
6, /* yellow */ 6, /* yellow */
9, /* salmon */ 9, /* salmon */
29, /* hydrogen */ 29, /* hydrogen */
skipping to change at line 422 skipping to change at line 422
} }
} }
return index; /* failsafe */ return index; /* failsafe */
} }
int ColorExtFromPyList(PyMOLGlobals * G, PyObject * list, int partial_restore) int ColorExtFromPyList(PyMOLGlobals * G, PyObject * list, int partial_restore)
{ {
int n_ext = 0; int n_ext = 0;
int a; int a;
int ok = true; int ok = true;
int ll;
CColor *I = G->Color; CColor *I = G->Color;
PyObject *rec; PyObject *rec;
ExtRec *ext; ExtRec *ext;
if(partial_restore) { if(partial_restore) {
ext = I->Ext; ext = I->Ext;
for(a = 0; a < I->NExt; a++) { for(a = 0; a < I->NExt; a++) {
ext->old_session_index = 0; ext->old_session_index = 0;
ext++; ext++;
} }
I->HaveOldSessionExtColors = true; I->HaveOldSessionExtColors = true;
} else { } else {
I->HaveOldSessionExtColors = false; I->HaveOldSessionExtColors = false;
} }
if(ok) if(ok)
ok = (list != NULL); ok = (list != NULL);
if(ok) if(ok)
ok = PyList_Check(list); ok = PyList_Check(list);
if(ok)
ll = PyList_Size(list);
/* TO SUPPORT BACKWARDS COMPATIBILITY... /* TO SUPPORT BACKWARDS COMPATIBILITY...
Always check ll when adding new PyList_GetItem's */ Always check ll when adding new PyList_GetItem's */
if(ok) { if(ok) {
n_ext = PyList_Size(list); n_ext = PyList_Size(list);
if(partial_restore) { if(partial_restore) {
VLACheck(I->Ext, ExtRec, n_ext + I->NExt); VLACheck(I->Ext, ExtRec, n_ext + I->NExt);
ext = I->Ext + I->NExt; ext = I->Ext + I->NExt;
} else { } else {
VLACheck(I->Ext, ExtRec, n_ext); VLACheck(I->Ext, ExtRec, n_ext);
skipping to change at line 821 skipping to change at line 818
int ColorGetNColor(PyMOLGlobals * G) int ColorGetNColor(PyMOLGlobals * G)
{ {
CColor *I = G->Color; CColor *I = G->Color;
return (I->NColor); return (I->NColor);
} }
/*========================================================================*/ /*========================================================================*/
void ColorFree(PyMOLGlobals * G) void ColorFree(PyMOLGlobals * G)
{ {
CColor *I = G->Color; CColor *I = G->Color;
if(I->ColorTable) {
FreeP(I->ColorTable);
}
VLAFreeP(I->Color); VLAFreeP(I->Color);
VLAFreeP(I->Ext); VLAFreeP(I->Ext);
if(I->Lex) if(I->Lex)
OVLexicon_Del(I->Lex); OVLexicon_Del(I->Lex);
if(I->Idx) if(I->Idx)
OVOneToOne_Del(I->Idx); OVOneToOne_Del(I->Idx);
FreeP(I); DeleteP(I);
} }
/*========================================================================*/ /*========================================================================*/
static int reg_name(OVLexicon * lex, OVOneToOne * o2o, int index, const char *na me) static int reg_name(OVLexicon * lex, OVOneToOne * o2o, int index, const char *na me)
{ {
OVreturn_word result; OVreturn_word result;
if(OVreturn_IS_OK(result = OVLexicon_GetFromCString(lex, name))) { if(OVreturn_IS_OK(result = OVLexicon_GetFromCString(lex, name))) {
OVOneToOne_Set(o2o, result.word, index); OVOneToOne_Set(o2o, result.word, index);
return result.word; return result.word;
skipping to change at line 2502 skipping to change at line 2496
int ColorTableLoad(PyMOLGlobals * G, const 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;
if(!strcmp(fname, "rgb")) { if(!strcmp(fname, "rgb")) {
if(I->ColorTable) { if(!I->ColorTable.empty()) {
FreeP(I->ColorTable); I->ColorTable.clear();
I->ColorTable = NULL;
PRINTFB(G, FB_Color, FB_Actions) PRINTFB(G, FB_Color, FB_Actions)
" Color: purged table; restoring RGB colors.\n" ENDFB(G); " Color: purged table; restoring RGB colors.\n" ENDFB(G);
} }
ColorUpdateFromLut(G, -1); ColorUpdateFromLut(G, -1);
} else if(!strcmp(fname, "greyscale")) { } else if(!strcmp(fname, "greyscale")) {
int x, y; int x, y;
unsigned int r = 0, g = 0, b = 0; unsigned int r = 0, g = 0, b = 0;
unsigned int *pixel, mask, *p; unsigned int *pixel, mask, *p;
unsigned int rc; unsigned int rc;
FreeP(I->ColorTable);
if(I->BigEndian) if(I->BigEndian)
mask = 0x000000FF; mask = 0x000000FF;
else else
mask = 0xFF000000; mask = 0xFF000000;
table = Alloc(unsigned int, 512 * 512); I->ColorTable.resize(512 * 512);
p = (unsigned int *) table; p = I->ColorTable.data();
for(x = 0; x < width; x++) for(x = 0; x < width; x++)
for(y = 0; y < height; y++) for(y = 0; y < height; y++)
*(p++) = mask; *(p++) = mask;
for(y = 0; y < height; y++) for(y = 0; y < height; y++)
for(x = 0; x < width; x++) { for(x = 0; x < width; x++) {
rc = (r + g + b)/3; rc = (r + g + b)/3;
pixel = table + ((width) * y) + x; pixel = I->ColorTable.data() + ((width) * y) + x;
if(I->BigEndian) { if(I->BigEndian) {
*(pixel) = mask | (rc << 24) | (rc << 16) | (rc << 8); *(pixel) = mask | (rc << 24) | (rc << 16) | (rc << 8);
} else { } else {
*(pixel) = mask | (rc << 16) | (rc << 8) | rc; *(pixel) = mask | (rc << 16) | (rc << 8) | rc;
} }
b = b + 4; b = b + 4;
if(!(0xFF & b)) { if(!(0xFF & b)) {
b = 0; b = 0;
g = g + 4; g = g + 4;
if(!(0xFF & g)) { if(!(0xFF & g)) {
g = 0; g = 0;
r = r + 4; r = r + 4;
} }
} }
} }
I->ColorTable = table;
if(!quiet) { if(!quiet) {
PRINTFB(G, FB_Color, FB_Actions) PRINTFB(G, FB_Color, FB_Actions)
" Color: defined table '%s'.\n", fname ENDFB(G); " Color: defined table '%s'.\n", fname ENDFB(G);
} }
ColorUpdateFromLut(G, -1); ColorUpdateFromLut(G, -1);
ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor); ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor);
SceneChanged(G); SceneChanged(G);
} else if(!strcmp(fname, "pymol")) { } else if(!strcmp(fname, "pymol")) {
skipping to change at line 2582 skipping to change at line 2571
float red_max = 0.95F; float red_max = 0.95F;
float blue_max = 0.97F; float blue_max = 0.97F;
float min_factor = 0.15F; float min_factor = 0.15F;
red_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_red); red_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_red);
green_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_green); green_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_green);
blue_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_blue); blue_max = SettingGetGlobal_f(G, cSetting_pymol_space_max_blue);
min_factor = SettingGetGlobal_f(G, cSetting_pymol_space_min_factor); min_factor = SettingGetGlobal_f(G, cSetting_pymol_space_min_factor);
FreeP(I->ColorTable);
if(I->BigEndian) if(I->BigEndian)
mask = 0x000000FF; mask = 0x000000FF;
else else
mask = 0xFF000000; mask = 0xFF000000;
table = Alloc(unsigned int, 512 * 512); I->ColorTable.resize(512 * 512);
p = (unsigned int *) table; p = I->ColorTable.data();
for(x = 0; x < width; x++) for(x = 0; x < width; x++)
for(y = 0; y < height; y++) for(y = 0; y < height; y++)
*(p++) = mask; *(p++) = mask;
for(y = 0; y < height; y++) for(y = 0; y < height; y++)
for(x = 0; x < width; x++) { for(x = 0; x < width; x++) {
rc = r; rc = r;
gc = g; gc = g;
bc = b; bc = b;
skipping to change at line 2647 skipping to change at line 2635
if(bc < rf) if(bc < rf)
bc = (int) rf; bc = (int) rf;
if(rc > 255) if(rc > 255)
rc = 255; rc = 255;
if(bc > 255) if(bc > 255)
bc = 255; bc = 255;
if(gc > 255) if(gc > 255)
gc = 255; gc = 255;
pixel = table + ((width) * y) + x; pixel = I->ColorTable.data() + ((width) * y) + x;
if(I->BigEndian) { if(I->BigEndian) {
*(pixel) = mask | (rc << 24) | (gc << 16) | (bc << 8); *(pixel) = mask | (rc << 24) | (gc << 16) | (bc << 8);
} else { } else {
*(pixel) = mask | (bc << 16) | (gc << 8) | rc; *(pixel) = mask | (bc << 16) | (gc << 8) | rc;
} }
b = b + 4; b = b + 4;
if(!(0xFF & b)) { if(!(0xFF & b)) {
b = 0; b = 0;
g = g + 4; g = g + 4;
if(!(0xFF & g)) { if(!(0xFF & g)) {
g = 0; g = 0;
r = r + 4; r = r + 4;
} }
} }
} }
I->ColorTable = table;
if(!quiet) { if(!quiet) {
PRINTFB(G, FB_Color, FB_Actions) PRINTFB(G, FB_Color, FB_Actions)
" Color: defined table '%s'.\n", fname ENDFB(G); " Color: defined table '%s'.\n", fname ENDFB(G);
} }
ColorUpdateFromLut(G, -1); ColorUpdateFromLut(G, -1);
ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor); ExecutiveInvalidateRep(G, cKeywordAll, cRepAll, cRepInvColor);
SceneChanged(G); SceneChanged(G);
} else { } else {
if(strlen(fname)) { if(strlen(fname)) {
unsigned int u_width = (unsigned int) width, u_height = (unsigned int) h auto image = MyPNGRead(fname);
eight; if(image) {
unsigned char *u_table = (unsigned char *) table; std::tie(width, height) = image->getSize();
if(MyPNGRead(fname, &u_table, &u_width, &u_height)) {
table = (unsigned int *) u_table;
width = (signed int) u_width;
height = (signed int) u_height;
if((width == 512) && (height == 512)) { if((width == 512) && (height == 512)) {
FreeP(I->ColorTable); auto imageSize = width * height;
I->ColorTable = table; I->ColorTable.resize(imageSize);
std::copy(image->pixels(), image->pixels() + imageSize, I->ColorTabl
e.data());
if(!quiet) { if(!quiet) {
PRINTFB(G, FB_Color, FB_Actions) PRINTFB(G, FB_Color, FB_Actions)
" Color: loaded table '%s'.\n", fname ENDFB(G); " Color: loaded table '%s'.\n", fname ENDFB(G);
} }
ColorUpdateFromLut(G, -1); ColorUpdateFromLut(G, -1);
} else { } else {
PRINTFB(G, FB_Color, FB_Errors) PRINTFB(G, FB_Color, FB_Errors)
" ColorTableLoad-Error: invalid dimensions w x h = %d x %d; shoul d be 512 x 512.\n", " ColorTableLoad-Error: invalid dimensions w x h = %d x %d; shoul d be 512 x 512.\n",
skipping to change at line 2708 skipping to change at line 2694
ok = false; ok = false;
} }
} else { } else {
PRINTFB(G, FB_Color, FB_Errors) PRINTFB(G, FB_Color, FB_Errors)
" ColorTableLoad-Error: unable to load '%s'.\n", fname ENDFB(G); " ColorTableLoad-Error: unable to load '%s'.\n", fname ENDFB(G);
ok = false; ok = false;
} }
} else { } else {
PRINTFB(G, FB_Color, FB_Actions) PRINTFB(G, FB_Color, FB_Actions)
" Color: purged table; colors unchanged.\n" ENDFB(G); " Color: purged table; colors unchanged.\n" ENDFB(G);
FreeP(I->ColorTable); I->ColorTable.clear();
} }
} }
if(!ok) {
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, const 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.data();
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;
const float _2 = 2.0F, _0 = 0.0F, _05 = 0.5F, _04999 = 0.4999F; const float _2 = 2.0F, _0 = 0.0F, _05 = 0.5F, _04999 = 0.4999F;
const float inv255 = 1.0F / 255.0F; const float inv255 = 1.0F / 255.0F;
skipping to change at line 2864 skipping to change at line 2847
} }
/*========================================================================*/ /*========================================================================*/
void ColorUpdateFromLut(PyMOLGlobals * G, int index) void ColorUpdateFromLut(PyMOLGlobals * G, int index)
{ {
int i; int i;
int once = false; int once = false;
CColor *I = G->Color; CColor *I = G->Color;
float *color, *new_color; float *color, *new_color;
I->LUTActive = (I->ColorTable || (I->Gamma != 1.0F)); I->LUTActive = (!I->ColorTable.empty() || (I->Gamma != 1.0F));
i = index; i = index;
if(index >= 0) { if(index >= 0) {
once = true; once = true;
} }
for(i = 0; i < I->NColor; i++) { for(i = 0; i < I->NColor; i++) {
if(!once) if(!once)
index = i; index = i;
if(index < I->NColor) { if(index < I->NColor) {
skipping to change at line 2913 skipping to change at line 2896
} else { } else {
return false; return false;
} }
} }
/*========================================================================*/ /*========================================================================*/
int ColorInit(PyMOLGlobals * G) int ColorInit(PyMOLGlobals * G)
{ {
CColor *I = NULL; CColor *I = NULL;
if((I = (G->Color = Calloc(CColor, 1)))) { if ((G->Color = new CColor())) {
I = G->Color;
unsigned int test; unsigned int test;
unsigned char *testPtr; unsigned char *testPtr;
test = 0xFF000000; test = 0xFF000000;
testPtr = (unsigned char *) &test; testPtr = (unsigned char *) &test;
I->BigEndian = (*testPtr) & 0x01; I->BigEndian = (*testPtr) & 0x01;
I->Color = VLACalloc(ColorRec, 5500); I->Color = VLACalloc(ColorRec, 5500);
I->Ext = VLACalloc(ExtRec, 2); I->Ext = VLACalloc(ExtRec, 2);
I->Gamma = 1.0F;
ColorReset(G); /* will alloc I->Idx and I->Lex */ ColorReset(G); /* will alloc I->Idx and I->Lex */
I->Front[0] = 1.0F;
I->Front[1] = 1.0F;
I->Front[2] = 1.0F;
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
void ColorUpdateFront(PyMOLGlobals * G, const float *back) void ColorUpdateFront(PyMOLGlobals * G, const float *back)
{ {
CColor *I = G->Color; CColor *I = G->Color;
copy3f(back, I->Back); copy3f(back, I->Back);
skipping to change at line 2952 skipping to change at line 2932
if(diff3f(I->Front, back) < 0.5F) if(diff3f(I->Front, back) < 0.5F)
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->Ortho)){
const float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_r gb)); 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]; float vv[3];
const float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb _bottom)); const float *v = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rgb _bottom));
const float *vb = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rg b_top)); const float *vb = ColorGet(G, SettingGet_color(G, NULL, NULL, cSetting_bg_rg b_top));
 End of changes. 27 change blocks. 
44 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)