📄 color.c
字号:
} (void)sprintf(message, "Color: base=%d size=%d color=%s overlay=%s mark=%s back=%s contrast=%d contrast0=%d gpow=%g", ctable->base, ctable->size, ct_names[ctable->color], over_names[ctable->overlay], mark_names[ctable->mark], background_names[ctable->background], ctable->contrast, ctable->contrast0, ctable->gpow); UIMessage(message);}/* return background color */int ColorBackground(void){ extern ColorTable ctable; if( !ctable ){ return (NO_INDEX); } return (ctable->base);}/* return base color */int ColorBase(void){ extern ColorTable ctable; if( !ctable ){ return (NO_INDEX); } return (ctable->base + 2);}/* return mark color */int ColorMark(void){ extern ColorTable ctable; if( !ctable ){ return (NO_INDEX); } return (ctable->base + ctable->size + 2);}/* create color table given pivot colors; apply contrast */void ColorLoad(Color cdata){ if( data->overlay_mode ){ ColorOverlay( cdata ); }else{ ColorLoad0( cdata ); }}void ColorLoad0(Color cdata){ float frac = 0; float stretch[NCOLOR + 1]; float value; int i; int icolor; int midpoint; extern ColorTable ctable; if( !ctable ){ return; } /*--------------------------------------------*/ /* convert contrast (0-100) into gpow (.2-5.) */ /*--------------------------------------------*/ ctable->gpow = ctable->contrast > 50 ? (ctable->contrast - 40.) / 10. : 10. / (60. - ctable->contrast);/*--------------------------------------------------------------------*\ Compute a non-linear contrast stretch factor table for the color scale which is symmetric about the midpoint..\*--------------------------------------------------------------------*/ for( i = 0; i < ctable->size / 2; i++ ){ frac = (float) (i - 1) / (float) (ctable->size / 2 - 2); frac = frac > 0. ? frac : 0.; frac = frac < 1. ? frac : 1.; frac = pow(frac, ctable->gpow); stretch[ctable->size / 2 - 1 + i] = .5 * (1. + frac); stretch[ctable->size / 2 - 1 - i] = .5 * (1. - frac); } stretch[ctable->size - 1] = .5 * (1. + frac);/*--------------------------------------------------------------------*\ Loop over all the entries in the Color_ array. Whenever we reach an Color_.index point, change color proportions. Then loop through all the colors in that portion of the range assigning all the even entries in the map.\*--------------------------------------------------------------------*/ for( icolor = 1, i = 0; cdata[icolor].index >= 0.; icolor++ ){ /*----------------------------------------*/ /* cdata must be monotonically increasing */ /*----------------------------------------*/ if( cdata[icolor].index > cdata[icolor - 1].index ){ while (i < ctable->size && stretch[i] <= cdata[icolor].index ){ /*-------------*/ /* data colors */ /*-------------*/ if( (i % 2) == 0 ){ frac = (stretch[i] - cdata[icolor - 1].index) / (cdata[icolor].index - cdata[icolor - 1].index); value = ((1. - frac) * cdata[icolor - 1].red + frac * cdata[icolor].red) * COLOR_SCALE; ctable->red0[i + 2] = value < COLOR_SCALE ? value : COLOR_SCALE; value = ((1. - frac) * cdata[icolor - 1].green + frac * cdata[icolor].green) * COLOR_SCALE; ctable->green0[i + 2] = value < COLOR_SCALE ? value : COLOR_SCALE; value = ((1. - frac) * cdata[icolor - 1].blue + frac * cdata[icolor].blue) * COLOR_SCALE; ctable->blue0[i + 2] = value < COLOR_SCALE ? value : COLOR_SCALE; } i++; } } }/*--------------------------------------------------------------------*\ Write the overlay color into all the odd numbered entries in the colormap. This lets the program flip the lower order bit to draw and erase overlay information.\*--------------------------------------------------------------------*/ for( i = 1; i < ctable->size + 4; i += 2 ){ ctable->red[i] = overlay[ctable->overlay].red * COLOR_SCALE; ctable->green[i] = overlay[ctable->overlay].green * COLOR_SCALE; ctable->blue[i] = overlay[ctable->overlay].blue * COLOR_SCALE; } /*---------------------*/ /* zero point contrast */ /*---------------------*/ midpoint = (ctable->contrast0 * ctable->size) / 100; for( i = 0; i < ctable->size; i += 2 ){ if( i < midpoint ){ icolor = (i * 50) / ctable->contrast0; }else{ icolor = ctable->size / 2 + ((i - midpoint) * ctable->contrast0) / 50; } icolor = icolor > 0 ? icolor : 0; icolor = icolor < ctable->size - 1 ? icolor : ctable->size - 1; icolor = (icolor / 2) * 2; ctable->red[i + 2] = ctable->red0[icolor + 2]; ctable->green[i + 2] = ctable->green0[icolor + 2]; ctable->blue[i + 2] = ctable->blue0[icolor + 2]; }/*--------------------------------------------------------------------*\ Set mark color using last entry in Color_ array by searching for a negative value in Color_.index\*--------------------------------------------------------------------*/ for( icolor = 0; cdata[icolor].index >= 0.; ){ icolor++; } icolor--; ctable->red[ctable->size + 2] = cdata[icolor].red * COLOR_SCALE; ctable->green[ctable->size + 2] = cdata[icolor].green * COLOR_SCALE; ctable->blue[ctable->size + 2] = cdata[icolor].blue * COLOR_SCALE; DrawColors(ctable->red, ctable->green, ctable->blue, ctable->size + 4);}/* save color parameters */void ColorSavePar(void){ Message message; extern ColorTable ctable; if( !ctable ){ return; } (void)sprintf(message, "Color: color=%s overlay=%s contrast=%d contrast0=%d", ct_names[ctable->color], over_names[ctable->overlay], ctable->contrast, ctable->contrast0); UISaveMessage(message);}/* write color table contents to a file */void ColorTableDump(void){ extern ColorTable ctable; string filename; FILE *fd; int i; (void)sprintf(filename, "color.table.%d.txt", ctable->size); fd = fopen(filename, "w"); for( i = 0; i < ctable->size; i++ ){ (void)fprintf(fd, "%3d : %5d %5d %5d : %5d %5d %5d\n", i, ctable->red0[i], ctable->green0[i], ctable->blue0[i], ctable->red[i], ctable->green[i], ctable->blue[i]); } (void)fclose(fd); UIMessage("color table dumped to file");}/*--------------------------------------------------------------------*\ Setup an overlay color scale for merged seismic & velocity information.\*--------------------------------------------------------------------*/void ColorOverlay( Color cdata ){ float frac = 0; float stretch[NCOLOR + 1]; float value; float red; float green; float blue; int i; int j; int k; int m; int n; float sfac; int color_scale; int cbase; int icolor; int midpoint; int sbin; int vbin; int sindex; int vindex; int shift=3; extern ColorTable ctable; if( !ctable || !data || !data->gh.n1 ){ return; } sbin = irint(data->gh.d4 / data->gh.scale); vbin = irint(data->gh.d5 / data->gh.scale); if( data->overlay_mode && sbin * vbin > 126 ){ fprintf( stderr, "Aborting unable to handle more than 126 colors!\n" ); exit(1); } cbase = ctable->base;/*--------------------------------------------------------------------*\ Compute a linear contrast stretch factor table for the velocity color scale which is symmetric about the midpoint.\*--------------------------------------------------------------------*/ for( i = 0; i < vbin; i++ ){ frac = (float) (i) / (float) ( vbin ); stretch[i] = frac; }/*--------------------------------------------------------------------*\ Loop over all the entries in the Color_ array. Whenever we reach an Color_.index point, change color proportions. Then loop through all the colors in that portion of the range assigning all the even entries in the map. For each color, allocate sbin intensity levels.\*--------------------------------------------------------------------*/ color_scale = COLOR_SCALE; for( icolor = 1, k = cbase; cdata[icolor].index >= 0.; icolor++ ){ /*----------------------------------------*/ /* cdata must be monotonically increasing */ /*----------------------------------------*/ if( cdata[icolor].index > cdata[icolor - 1].index ){#if 0 printf( "%d " ,icolor-1 ); printf( "%f " ,cdata[icolor-1].index ); printf( "%f " ,cdata[icolor-1].red ); printf( "%f " ,cdata[icolor-1].green ); printf( "%f " ,cdata[icolor-1].blue ); printf( "\n" );#endif j = 0; n = vbin*(cdata[icolor].index-cdata[icolor - 1].index); while (k < vbin && stretch[k] <= cdata[icolor].index ){ frac =(float)j/n; red = (1.0-frac)*cdata[icolor-1].red + cdata[icolor].red*frac; green = (1.0-frac)*cdata[icolor-1].green + cdata[icolor].green*frac; blue = (1.0-frac)*cdata[icolor-1].blue + cdata[icolor].blue*frac; red += (1.0 - red)* .65; green += (1.0 - green)* .65; blue += (1.0 - blue)* .65;#if 0 printf( " %d" ,j ); printf( " %d" ,k ); printf( " %f" ,stretch[k] ); printf( " %f" ,frac ); printf( " %f" ,red ); printf( " %f" ,green ); printf( " %f" ,blue ); printf( "\n" );#endif for( i=0; i<sbin; i++ ){ m = 6+2*(k*sbin+i); sfac = (float)(i+shift)/(sbin+shift); sfac *= color_scale;#if 0 printf( " %d" ,k ); printf( " %d" ,i ); printf( " %d" ,m ); printf( " %f" ,sfac ); printf( " %f" ,red * sfac ); printf( " %f" ,green * sfac ); printf( " %f" ,blue * sfac ); printf( "\n" );#endif ctable->red[m+1] = red * sfac ; ctable->green[m+1] = green * sfac ; ctable->blue[m+1] = blue * sfac ; ctable->red[m] = red * sfac ; ctable->green[m] = green * sfac ; ctable->blue[m] = blue * sfac ; } j++; k++; } } }/*--------------------------------------------------------------------*\ Write the overlay color into all the odd numbered entries in the colormap. This lets the program flip the lower order bit to draw and erase overlay information.\*--------------------------------------------------------------------*/ for( i = 1; i < ctable->size + 4; i += 2 ){ ctable->red[i] = overlay[ctable->overlay].red * COLOR_SCALE; ctable->green[i] = overlay[ctable->overlay].green * COLOR_SCALE; ctable->blue[i] = overlay[ctable->overlay].blue * COLOR_SCALE; }#if 0 /*---------------------*/ /* zero point contrast */ /*---------------------*/ midpoint = (ctable->contrast0 * ctable->size) / 100; for( i = 0; i < ctable->size; i += 2 ){ if( i < midpoint ){ icolor = (i * 50) / ctable->contrast0; }else{ icolor = ctable->size / 2 + ((i - midpoint) * ctable->contrast0) / 50; } icolor = icolor > 0 ? icolor : 0; icolor = icolor < ctable->size - 1 ? icolor : ctable->size - 1; icolor = (icolor / 2) * 2; ctable->red[i + 2] = ctable->red0[icolor + 2]; ctable->green[i + 2] = ctable->green0[icolor + 2]; ctable->blue[i + 2] = ctable->blue0[icolor + 2]; }#endif/*--------------------------------------------------------------------*\ Set mark color using last entry in Color_ array by searching for a negative value in Color_.index\*--------------------------------------------------------------------*/ for( icolor = 0; cdata[icolor].index >= 0.; ){ icolor++; } icolor--; ctable->red[ctable->size + 2] = cdata[icolor].red * COLOR_SCALE; ctable->green[ctable->size + 2] = cdata[icolor].green * COLOR_SCALE; ctable->blue[ctable->size + 2] = cdata[icolor].blue * COLOR_SCALE; DrawColors(ctable->red, ctable->green, ctable->blue, ctable->size + 4);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -