From: <hba...@us...> - 2009-07-06 01:22:12
|
Revision: 10118 http://plplot.svn.sourceforge.net/plplot/?rev=10118&view=rev Author: hbabcock Date: 2009-07-06 00:29:07 +0000 (Mon, 06 Jul 2009) Log Message: ----------- Added functions plspal0 and plspal1 (set cmap0 palette and set cmap1 palette) to the API. plspal0 takes the name of a cmap0.pal format file and sets the colors in color map 0 based on the data in the file. plspal1 takes the name name of a cmap1.pal format file and sets the colors in color map 1 based on the data in the file. Modified Paths: -------------- trunk/include/plplot.h trunk/src/plctrl.c Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-07-05 16:12:27 UTC (rev 10117) +++ trunk/include/plplot.h 2009-07-06 00:29:07 UTC (rev 10118) @@ -672,6 +672,8 @@ #define plsmin c_plsmin #define plsori c_plsori #define plspage c_plspage +#define plspal0 c_plspal0 +#define plspal1 c_plspal1 #define plspause c_plspause #define plsstrm c_plsstrm #define plssub c_plssub @@ -1497,6 +1499,16 @@ c_plspage(PLFLT xp, PLFLT yp, PLINT xleng, PLINT yleng, PLINT xoff, PLINT yoff); +/* Set the colors for color table 0 from a cmap0 file */ + +PLDLLIMPEXP void +c_plspal0(const char *filename); + +/* Set the colors for color table 1 from a cmap1 file */ + +PLDLLIMPEXP void +c_plspal1(const char *filename); + /* Set the pause (on end-of-page) status */ PLDLLIMPEXP void Modified: trunk/src/plctrl.c =================================================================== --- trunk/src/plctrl.c 2009-07-05 16:12:27 UTC (rev 10117) +++ trunk/src/plctrl.c 2009-07-06 00:29:07 UTC (rev 10118) @@ -1210,6 +1210,112 @@ } /*--------------------------------------------------------------------------*\ + * void c_plspal0(filename) + * + * Set the palette for color map 0 using a cmap0*.pal format file. + * filename: the name of the cmap0*.pal file to use. +\*--------------------------------------------------------------------------*/ + +void +c_plspal0(const char *filename) +{ + int i, r, g, b, a; + int number_colors; + char color_info[30]; + FILE *fp; + + fp = fopen(filename, "r"); + fscanf(fp, "%d\n", &number_colors); + for(i=0;i<number_colors;i++){ + fgets(color_info, 30, fp); + color_info[strlen(color_info)-1] = '\0'; /* remove return character */ + if(strlen(color_info) == 7){ + sscanf(color_info, "#%2x%2x%2x", &r, &g, &b); + c_plscol0(i, r, g, b); + } + else if(strlen(color_info) == 9){ + sscanf(color_info, "#%2x%2x%2x%2x", &r, &g, &b, &a); + c_plscol0a(i, r, g, b, a); + } + else{ + printf("Unrecognized cmap0 format %s\n", color_info); + } + + } + fclose(fp); +} + +/*--------------------------------------------------------------------------*\ + * void c_plspal1(filename) + * + * Set the palette for color map 1 using a cmap1*.pal format file. + * filename: the name of the cmap1*.pal file to use. +\*--------------------------------------------------------------------------*/ + +void +c_plspal1(const char *filename) +{ + int i; + int number_colors; + int have_alpha; + char color_info[30]; + int r_i, g_i, b_i, a_i, pos_i; + PLFLT *r, *g, *b, *a, *pos; + FILE *fp; + + have_alpha = 1; + fp = fopen(filename, "r"); + fscanf(fp, "%d\n", &number_colors); + r = (PLFLT *)malloc(number_colors * sizeof(PLFLT)); + g = (PLFLT *)malloc(number_colors * sizeof(PLFLT)); + b = (PLFLT *)malloc(number_colors * sizeof(PLFLT)); + a = (PLFLT *)malloc(number_colors * sizeof(PLFLT)); + pos = (PLFLT *)malloc(number_colors * sizeof(PLFLT)); + + for(i=0;i<number_colors;i++){ + fgets(color_info, 30, fp); + color_info[strlen(color_info)-1] = '\0'; + if(color_info[7] == ' '){ + have_alpha = 0; + sscanf(color_info, "#%2x%2x%2x %d", &r_i, &g_i, &b_i, &pos_i); + r[i] = (PLFLT)r_i; + g[i] = (PLFLT)g_i; + b[i] = (PLFLT)b_i; + pos[i] = 0.01 * (PLFLT)pos_i; + } + else if(color_info[9] == ' '){ + sscanf(color_info, "#%2x%2x%2x%2x %d", &r_i, &g_i, &b_i, &a_i, &pos_i); + r[i] = (PLFLT)r_i; + g[i] = (PLFLT)g_i; + b[i] = (PLFLT)b_i; + a[i] = (PLFLT)a_i; + pos[i] = 0.01 * (PLFLT)pos_i; + } + else{ + printf("Unrecognized cmap1 format %s\n", color_info); + } + } + fclose(fp); + + /* Set the first control point position to 0.0 and the last */ + /* to 1.0 to deal with any possible round off errors. */ + pos[0] = 0.0; + pos[number_colors-1] = 1.0; + + if (have_alpha == 1){ + c_plscmap1la(1, number_colors, pos, r, g, b, a, NULL); + } else { + c_plscmap1l(1, number_colors, pos, r, g, b, NULL); + } + + free(r); + free(g); + free(b); + free(a); + free(pos); +} + +/*--------------------------------------------------------------------------*\ * A grab-bag of various control routines. \*--------------------------------------------------------------------------*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |