#include /*I "petscsys.h" I*/ #include /* Set up a color map, using uniform separation in hue space. Map entries are Red, Green, Blue. Values are "gamma" corrected. */ /* Gamma is a monitor dependent value. The value here is an approximate that gives somewhat better results than Gamma = 1. */ static PetscReal Gamma = 2.0; PetscErrorCode PetscDrawUtilitySetGamma(PetscReal g) { PetscFunctionBegin; Gamma = g; PetscFunctionReturn(0); } PETSC_STATIC_INLINE double PetscHlsHelper(double m1,double m2,double h) { while (h > 1.0) h -= 1.0; while (h < 0.0) h += 1.0; if (h < 1/6.0) return m1 + (m2-m1)*h*6; if (h < 1/2.0) return m2; if (h < 2/3.0) return m1 + (m2-m1)*(2/3.0-h)*6; return m1; } PETSC_STATIC_INLINE void PetscHlsToRgb(double h,double l,double s,double *r,double *g,double *b) { if (s > 0.0) { double m2 = l <= 0.5 ? l * (1.0+s) : l+s-(l*s); double m1 = 2*l - m2; *r = PetscHlsHelper(m1,m2,h+1/3.); *g = PetscHlsHelper(m1,m2,h); *b = PetscHlsHelper(m1,m2,h-1/3.); } else { /* ignore hue */ *r = *g = *b = l; } } PETSC_STATIC_INLINE void PetscGammaCorrect(double *r,double *g,double *b) { PetscReal igamma = 1/Gamma; *r = (double)PetscPowReal((PetscReal)*r,igamma); *g = (double)PetscPowReal((PetscReal)*g,igamma); *b = (double)PetscPowReal((PetscReal)*b,igamma); } static PetscErrorCode PetscDrawCmap_Hue(int mapsize, unsigned char R[],unsigned char G[],unsigned char B[]) { int i; double maxhue = 212.0/360,lightness = 0.5,saturation = 1.0; PetscFunctionBegin; for (i=0; i knots[k+1]) k++; m = (u-knots[k])/(knots[k+1]-knots[k]); switch(k) { case 0: r = 0; g = 0; b = (m+1)/2; break; case 1: r = 0; g = m; b = 1; break; case 2: r = m; g = 1; b = 1-m; break; case 3: r = 1; g = 1-m; b = 0; break; case 4: r = 1-m/2; g = 0; b = 0; break; } R[i] = (unsigned char)(255*PetscMin(r,1.0)); G[i] = (unsigned char)(255*PetscMin(g,1.0)); B[i] = (unsigned char)(255*PetscMin(b,1.0)); } PetscFunctionReturn(0); } static PetscErrorCode PetscDrawCmap_Hot(int mapsize,unsigned char R[],unsigned char G[],unsigned char B[]) { int i; const double knots[] = {0, 3/8., 3/4., 1}; PetscFunctionBegin; for (i=0; i knots[k+1]) k++; m = (u-knots[k])/(knots[k+1]-knots[k]); switch(k) { case 0: r = m; g = 0; b = 0; break; case 1: r = 1; g = m; b = 0; break; case 2: r = 1; g = 1; b = m; break; } R[i] = (unsigned char)(255*PetscMin(r,1.0)); G[i] = (unsigned char)(255*PetscMin(g,1.0)); B[i] = (unsigned char)(255*PetscMin(b,1.0)); } PetscFunctionReturn(0); } static PetscErrorCode PetscDrawCmap_Bone(int mapsize,unsigned char R[],unsigned char G[],unsigned char B[]) { int i; PetscFunctionBegin; (void)PetscDrawCmap_Hot(mapsize,R,G,B); for (i=0; i= (PetscReal)+1)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"brighten parameter %g must be in the range (-1,1)",(double)beta); if (PetscDrawCmapTable[id].cmap) { ierr = PetscDrawCmapTable[id].cmap(mapsize,R,G,B);CHKERRQ(ierr); } else { const unsigned char (*rgb)[3] = PetscDrawCmapTable[id].data; if (mapsize != 256-PETSC_DRAW_BASIC_COLORS) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Colormap '%s' with size %d not supported",cmap_name_list[id],mapsize); for (i=0; i 0.0) ? (1 - beta) : (1 / (1 + beta)); for (i=0; i