//desired: h in [0,360), s and v in [0,1] except if s = 0 then h = undefined void ShiftPalette( unsigned char Palette[769], double DH, double DS, double DV, double DsH, double DsS, double DsV ) { double r, g, b, h, s, v; int i; for (i = 192; i < 224; i++) { r = ( (double) .003921568627 )*Palette[i*3]; g = ( (double) .003921568627 )*Palette[i*3+1]; b = ( (double) .003921568627 )*Palette[i*3+2]; RGB_To_HSV( r, g, b, &h, &s, &v ); h += DH; s += DS; v += DV; if (h >= 360) h -= 360; if (h < 0) h += 360; if (s > 1) s -= 1; if (s < 0) s += 1; if (s == 0) s += .01; if (v > 1) v -= 1; if (v < 0) v += 1; HSV_To_RGB( &r, &g, &b, h, s, v ); Palette[i*3] = (unsigned char) (r*255); Palette[i*3+1] = (unsigned char) (g*255); Palette[i*3+2] = (unsigned char) (b*255); } for (i = 224; i < 256; i++) { r = ( (double) .003921568627 )*Palette[i*3]; g = ( (double) .003921568627 )*Palette[i*3+1]; b = ( (double) .003921568627 )*Palette[i*3+2]; RGB_To_HSV( r, g, b, &h, &s, &v ); h += DsH; s += DsS; v += DsV; if (h >= 360) h -= 360; if (h < 0) h += 360; if (s > 1) s -= 1; if (s < 0) s += 1; if (s == 0) s += .01; if (v > 1) v -= 1; if (v < 0) v += 1; HSV_To_RGB( &r, &g, &b, h, s, v ); Palette[i*3] = (unsigned char) (r*255); Palette[i*3+1] = (unsigned char) (g*255); Palette[i*3+2] = (unsigned char) (b*255); } }
//## begin module%40E266F20126.epilog preserve=yes void COpenGL::DrawColorBar() { //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); //gluOrtho2D(-1, 1, -1, 1); glLoadIdentity(); glPushMatrix(); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); //glNormal3f(0,0,1); int index = 0; float sum = 120; float fInterval = (float)(1.6) / sum; for (int h=0; h<240; h+=2) { //glColor3f(1, 0, 0); float r = 0; float g = 0; float b = 0; HSV_To_RGB(r, g, b, (float)(h), (float)(1.0), (float)(1.0)); glColor3f(r, g, b); glBegin(GL_POLYGON); glVertex3f((float)(-1.2), (float)(0.9) - index*fInterval, (float)(-0.5)); glVertex3f((float)(-1.1), (float)(0.9) - index*fInterval, (float)(-0.5)); glVertex3f((float)(-1.1), (float)(0.9) - (index+1)*fInterval, (float)-0.5); glVertex3f((float)(-1.2), (float)(0.9) - (index+1)*fInterval, (float)-0.5); glEnd(); index++; } glPopMatrix(); switch(m_nDispType ) { case 0: glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; case 1: glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; case 2: glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); break; default: break; } }