From: <hba...@us...> - 2008-01-16 03:56:06
|
Revision: 8136 http://plplot.svn.sourceforge.net/plplot/?rev=8136&view=rev Author: hbabcock Date: 2008-01-15 19:56:11 -0800 (Tue, 15 Jan 2008) Log Message: ----------- Added color table 1 alpha value support. Modified Paths: -------------- trunk/examples/c/x30c.c trunk/include/plplot.h trunk/src/plctrl.c Modified: trunk/examples/c/x30c.c =================================================================== --- trunk/examples/c/x30c.c 2008-01-15 19:56:27 UTC (rev 8135) +++ trunk/examples/c/x30c.c 2008-01-16 03:56:11 UTC (rev 8136) @@ -34,25 +34,34 @@ static PLFLT px[] = {0.1, 0.5, 0.5, 0.1}; static PLFLT py[] = {0.1, 0.1, 0.5, 0.5}; +static PLFLT pos[] = {0.0, 1.0}; +static PLFLT rcoord[] = {1.0, 1.0}; +static PLFLT gcoord[] = {0.0, 0.0}; +static PLFLT bcoord[] = {0.0, 0.0}; +static PLFLT acoord[] = {0.0, 1.0}; +static PLBOOL rev[] = {0, 0}; + int main(int argc, const char *argv[]) { int i, j, icol, r, g, b; - double a; + PLFLT a; + PLFLT clevel[101]; + PLFLT **z; plparseopts (&argc, argv, PL_PARSE_FULL); plinit (); + plscmap0n (4); + plscmap0a (red, green, blue, alpha, 4); + /* page 1 */ pladv (0); plvpor (0.0, 1.0, 0.0, 1.0); plwind (0.0, 1.0, 0.0, 1.0); plcol0 (0); plbox ("", 1.0, 0, "", 1.0, 0); - plscmap0n (4); - plscmap0a (red, green, blue, alpha, 4); - for (i = 0; i < 9; i++) { icol = i%3 + 1; plgcol0a (icol, &r, &g, &b, &a); @@ -65,6 +74,43 @@ } } + /* page 2 */ + plAlloc2dGrid(&z, 2, 2); + z[0][0] = 0.0; + z[1][0] = 0.0; + z[0][1] = 1.0; + z[1][1] = 1.0; + + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(0.0, 1.0, 0.0, 1.0); + + for(i = 0; i < 5; i++){ + px[0] = 0.05 + 0.2 * i; + px[1] = px[0] + 0.1; + px[2] = px[1]; + px[3] = px[0]; + icol = i%3 + 1; + plgcol0a (icol, &r, &g, &b, &a); + plscol0a (icol, r, g, b, 1.0); + plcol0 (icol); + for(j = 0; j < 5; j++){ + py[0] = 0.05 + 0.2 * j; + py[1] = py[0]; + py[2] = py[0] + 0.1; + py[3] = py[2]; + plfill(4, px, py); + } + } + + plscmap1n(128); + plscmap1la(1, 2, pos, rcoord, gcoord, bcoord, acoord, rev); + + for(i=0;i<101;i++){ + clevel[i] = 0.01 * (PLFLT)i; + } + plshades(z, 2, 2, NULL, 0.0, 1.0, 0.0, 1.0, clevel, 101, 10, -1, 2, plfill, 1, NULL, NULL); + plend(); exit(0); } Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2008-01-15 19:56:27 UTC (rev 8135) +++ trunk/include/plplot.h 2008-01-16 03:56:11 UTC (rev 8136) @@ -392,6 +392,7 @@ PLFLT l; /* lightness */ PLFLT s; /* saturation */ PLFLT p; /* position */ + PLFLT a; /* alpha (or transparency) */ int rev; /* if set, interpolate through h=0 */ } PLControlPt; @@ -556,7 +557,9 @@ #define plscmap0a c_plscmap0a #define plscmap0n c_plscmap0n #define plscmap1 c_plscmap1 +#define plscmap1a c_plscmap1a #define plscmap1l c_plscmap1l +#define plscmap1la c_plscmap1la #define plscmap1n c_plscmap1n #define plscol0 c_plscol0 #define plscol0a c_plscol0a @@ -1211,6 +1214,11 @@ PLDLLIMPEXP void c_plscmap1(PLINT *r, PLINT *g, PLINT *b, PLINT ncol1); +/* Set color map 1 colors by 8 bit RGB and alpha values */ + +PLDLLIMPEXP void +c_plscmap1a(PLINT *r, PLINT *g, PLINT *b, PLFLT *a, PLINT ncol1); + /* Set color map 1 colors using a piece-wise linear relationship between */ /* intensity [0,1] (cmap 1 index) and position in HLS or RGB color space. */ @@ -1218,6 +1226,14 @@ c_plscmap1l(PLBOOL itype, PLINT npts, PLFLT *intensity, PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLBOOL *rev); +/* Set color map 1 colors using a piece-wise linear relationship between */ +/* intensity [0,1] (cmap 1 index) and position in HLS or RGB color space. */ +/* Will also linear interpolate alpha values. */ + +PLDLLIMPEXP void +c_plscmap1la(PLBOOL itype, PLINT npts, PLFLT *intensity, + PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLFLT *a, PLBOOL *rev); + /* Set number of colors in cmap 1 */ PLDLLIMPEXP void Modified: trunk/src/plctrl.c =================================================================== --- trunk/src/plctrl.c 2008-01-15 19:56:27 UTC (rev 8135) +++ trunk/src/plctrl.c 2008-01-16 03:56:11 UTC (rev 8136) @@ -226,6 +226,22 @@ void c_plscol0(PLINT icol0, PLINT r, PLINT g, PLINT b) { + if (plsc->cmap0 == NULL) + plscmap0n(0); + if (icol0 < 0 || icol0 >= plsc->ncol0) { + char buffer[256]; + sprintf(buffer, "plscol0: Illegal color table value: %d", (int) icol0); + plabort(buffer); + return; + } + if ((r < 0 || r > 255) || (g < 0 || g > 255) || (b < 0 || b > 255)) { + char buffer[256]; + sprintf(buffer, "plscol0: Invalid RGB color: %d, %d, %d", + (int) r, (int) g, (int) b); + plabort(buffer); + return; + } + plscol0a(icol0, r, g, b, 1.0); } @@ -241,7 +257,6 @@ { if (plsc->cmap0 == NULL) plscmap0n(0); - if (icol0 < 0 || icol0 >= plsc->ncol0) { char buffer[256]; sprintf(buffer, "plscol0a: Illegal color table value: %d", (int) icol0); @@ -367,8 +382,8 @@ /*--------------------------------------------------------------------------*\ * plscmap0a() * - * Set color map 0 colors by 8 bit RGB values. This sets the entire color - * map -- only as many colors as specified will be allocated. + * Set color map 0 colors by 8 bit RGB and alpha value. This sets the + * entire color map -- only as many colors as specified will be allocated. \*--------------------------------------------------------------------------*/ void @@ -437,6 +452,42 @@ } /*--------------------------------------------------------------------------*\ + * plscmap1a() + * + * Set color map 1 colors by 8 bit RGB and alpha values + * This also sets the number of colors. +\*--------------------------------------------------------------------------*/ + +void +c_plscmap1a(PLINT *r, PLINT *g, PLINT *b, PLFLT *a, PLINT ncol1) +{ + int i; + + plscmap1n(ncol1); + + for (i = 0; i < plsc->ncol1; i++) { + if ((r[i] < 0 || r[i] > 255) || + (g[i] < 0 || g[i] > 255) || + (b[i] < 0 || b[i] > 255) || + (a[i] < 0.0 || a[i] > 1.0)) { + + char buffer[256]; + sprintf(buffer, "plscmap1a: Invalid RGB color: %d, %d, %d, %f", + (int) r[i], (int) g[i], (int) b[i], (double) a[i]); + plabort(buffer); + return; + } + plsc->cmap1[i].r = r[i]; + plsc->cmap1[i].g = g[i]; + plsc->cmap1[i].b = b[i]; + plsc->cmap1[i].a = a[i]; + } + + if (plsc->level > 0) + plP_state(PLSTATE_CMAP1); +} + +/*--------------------------------------------------------------------------*\ * plscmap1l() * * Set color map 1 colors using a piece-wise linear relationship between @@ -536,6 +587,7 @@ plsc->cmap1cp[n].l = l; plsc->cmap1cp[n].s = s; plsc->cmap1cp[n].p = pos[n]; + plsc->cmap1cp[n].a = 1.0; if (rev == NULL) plsc->cmap1cp[n].rev = 0; @@ -549,6 +601,75 @@ } /*--------------------------------------------------------------------------*\ + * plscmap1la() + * + * This is the same as plscmap1l, but also allows alpha value interpolation. + * + \*-------------------------------------------------------------------------*/ + +void +c_plscmap1la(PLINT itype, PLINT npts, PLFLT *pos, + PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLFLT *a, PLINT *rev) +{ + int n; + PLFLT h, l, s, r, g, b; + + if (npts < 2) { + plabort("plscmap1la: Must specify at least two control points"); + return; + } + + if ( (pos[0] != 0) || (pos[npts-1] != 1)) { + plabort("plscmap1la: First, last control points must lie on boundary"); + return; + } + + if ( npts > PL_MAX_CMAP1CP ) { + plabort("plscmap1la: exceeded maximum number of control points"); + return; + } + +/* Allocate if not done yet */ + + if (plsc->cmap1 == NULL) + plscmap1n(0); + +/* Save control points */ + + plsc->ncp1 = npts; + + for (n = 0; n < npts; n++) { + + if (itype == 0) { + h = coord1[n]; + l = coord2[n]; + s = coord3[n]; + } + else { + r = coord1[n]; + g = coord2[n]; + b = coord3[n]; + c_plrgbhls(r, g, b, &h, &l, &s); + } + + plsc->cmap1cp[n].h = h; + plsc->cmap1cp[n].l = l; + plsc->cmap1cp[n].s = s; + plsc->cmap1cp[n].p = pos[n]; + plsc->cmap1cp[n].a = a[n]; + + if (rev == NULL) + plsc->cmap1cp[n].rev = 0; + else + plsc->cmap1cp[n].rev = rev[n]; + } + +/* Calculate and set color map */ + + plcmap1_calc(); +} + +/*--------------------------------------------------------------------------*\ * plcmap1_calc() * * Bin up cmap 1 space and assign colors to make inverse mapping easy. @@ -559,8 +680,8 @@ plcmap1_calc(void) { int i, n; - PLFLT delta, dp, dh, dl, ds; - PLFLT h, l, s, p, r, g, b; + PLFLT delta, dp, dh, dl, ds, da; + PLFLT h, l, s, p, r, g, b, a; /* Loop over all control point pairs */ @@ -575,6 +696,7 @@ dh = plsc->cmap1cp[n+1].h - plsc->cmap1cp[n].h; dl = plsc->cmap1cp[n+1].l - plsc->cmap1cp[n].l; ds = plsc->cmap1cp[n+1].s - plsc->cmap1cp[n].s; + da = plsc->cmap1cp[n+1].a - plsc->cmap1cp[n].a; /* Adjust dh if we are to go around "the back side" */ @@ -599,6 +721,7 @@ h = plsc->cmap1cp[n].h + dh * delta; l = plsc->cmap1cp[n].l + dl * delta; s = plsc->cmap1cp[n].s + ds * delta; + a = plsc->cmap1cp[n].a + da * delta; while (h >= 360.) h -= 360.; @@ -611,7 +734,7 @@ plsc->cmap1[i].r = MAX(0, MIN(255, (int) (256. * r))); plsc->cmap1[i].g = MAX(0, MIN(255, (int) (256. * g))); plsc->cmap1[i].b = MAX(0, MIN(255, (int) (256. * b))); - plsc->cmap1[i].a = 1.0; + plsc->cmap1[i].a = a; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |