#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; #undef __FUNCT__ #define __FUNCT__ "PetscDrawUtilitySetGamma" PetscErrorCode PetscDrawUtilitySetGamma(PetscReal g) { PetscFunctionBegin; Gamma = g; PetscFunctionReturn(0); } /* * This algorithm is from Foley and van Dam, page 616 * given * (0:359, 0:100, 0:100). * h l s * set * (0:255, 0:255, 0:255) * r g b */ PETSC_STATIC_INLINE int PetscHlsHelper(int h,int m1,int m2) { while (h > 360) h = h - 360; while (h < 0) h = h + 360; if (h < 60) return m1 + (m2-m1)*h/60; if (h < 180) return m2; if (h < 240) return m1 + (m2-m1)*(240-h)/60; return m1; } PETSC_STATIC_INLINE void PetscHlsToRgb(int h,int l,int s,unsigned char *r,unsigned char *g,unsigned char *b) { int m1,m2; /* in 0 to 100 */ if (l <= 50) m2 = l * (100 + s) / 100 ; /* not sure of "/100" */ else m2 = l + s - l*s/100; m1 = 2*l - m2; if (!s) { /* ignore h */ *r = 255 * l / 100; *g = 255 * l / 100; *b = 255 * l / 100; } else { *r = (255 * PetscHlsHelper(h+120,m1,m2)) / 100; *g = (255 * PetscHlsHelper(h,m1,m2)) / 100; *b = (255 * PetscHlsHelper(h-120,m1,m2)) / 100; } } #undef __FUNCT__ #define __FUNCT__ "PetscDrawCmap_Hue" static PetscErrorCode PetscDrawCmap_Hue(int mapsize, unsigned char R[],unsigned char G[],unsigned char B[]) { int i,hue,lightness,saturation; PetscReal igamma = 1.0 / Gamma; PetscFunctionBegin; hue = 0; /* in 0:359 */ lightness = 50; /* in 0:100 */ saturation = 100; /* in 0:100 */ 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); } #undef __FUNCT__ #define __FUNCT__ "PetscDrawCmap_Hot" 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); } #undef __FUNCT__ #define __FUNCT__ "PetscDrawCmap_Bone" 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