rem: matrix = wheelCreateMatrix(colorWheelSize+4, colorWheelSize+4); if (!matrix) return NULL;  RRGBtoHSV(&panel->color, &cur_hsv);  for (i = 0; i < 256; i++) matrix->values[i] = (unsigned char)(rint(i*cur_hsv.value/255));  cur_hsv.value = 255;  ofs[0] = -1; ofs[1] = -(colorWheelSize + 4);  for (y = 0; y < (colorWheelSize+4)/2; y++) { for (x = y; x < (colorWheelSize+4-y); x++) { xcor = ((float)(2.0*x - 4.0) / colorWheelSize) - 1; ycor = ((float)(2.0*y - 4.0) / colorWheelSize) - 1;  sat = rint(255.0 * sqrt((xcor*xcor) + (ycor*ycor)));     if (y < (colorWheelSize+4)/2) ofs[0]++;  ofs[1] += colorWheelSize + 4;			   ofs[2] = (colorWheelSize + 4) * (colorWheelSize + 4) - 1 - ofs[0];	 ofs[3] = (colorWheelSize + 4) * (colorWheelSize + 4) - 1 - ofs[1];							  if (sat < 256) { cur_hsv.saturation = (unsigned char)sat;  if (xcor != 0) hue = atan(ycor/xcor); else { if (ycor > 0) hue = W_PI * 0.5; else hue = W_PI * 1.5; }  if (xcor < 0) hue += W_PI; if ((xcor > 0) && (ycor < 0)) hue += W_PI * 2.0;  hue = -hue;		  if (hue < 0) hue += W_PI * 2.0;  dhue[0] = (hue*360) / (W_PI * 2.0);  for (i = 0; i < 4; i++) {  if (i > 0) dhue[i] = (dhue[i-1] + 90) % 360;  if ((i == 1) || (i == 3)) dhue[i] = 360 - dhue[i];  if (i == 2) dhue[i] = 360 - dhue[i] + 180;  rp = matrix->data[0] + (ofs[i] * sizeof(unsigned char)); gp = matrix->data[1] + (ofs[i] * sizeof(unsigned char)); bp = matrix->data[2] + (ofs[i] * sizeof(unsigned char));  cur_hsv.hue = dhue[i]; RHSVtoRGB(&cur_hsv, &cur_rgb);  *rp = (unsigned char)(cur_rgb.red); *gp = (unsigned char)(cur_rgb.green); *bp = (unsigned char)(cur_rgb.blue); } } else { for (i = 0; i < 4; i++) { rp = matrix->data[0] + (ofs[i] * sizeof(unsigned char)); gp = matrix->data[1] + (ofs[i] * sizeof(unsigned char)); bp = matrix->data[2] + (ofs[i] * sizeof(unsigned char));  *rp = (unsigned char)(0); *gp = (unsigned char)(0); *bp = (unsigned char)(0); } } } if (y < (colorWheelSize+4)/2) ofs[0] += 2*y+1;  ofs[1] += 1 - (colorWheelSize + 4) * (colorWheelSize + 4 - 1 - 2*y); }  return matrix;
add: ofs[1] += 1 - (colorWheelSize + 4) * (colorWheelSize + 4 - 1 - 2*y); }  return matrix;
context: wheelInitMatrix(W_ColorPanel *panel){	int				i;	int				x,y;	wheelMatrix		*matrix;	unsigned char	*rp, *gp, *bp;	RHSVColor		cur_hsv;	RColor			cur_rgb;	long	ofs[4];	float			hue;	int			sat;	float			xcor, ycor;	float			W_PI = 4 *atan(1);	int				dhue[4];		matrix = wheelCreateMatrix(colorWheelSize+4, colorWheelSize+4);	if (!matrix)		return NULL;		RRGBtoHSV(&panel->color, &cur_hsv);		for (i = 0; i < 256; i++)		matrix->values[i] = (unsigned char)(rint(i*cur_hsv.value/255));		cur_hsv.value = 255;		ofs[0] = -1;	ofs[1] = -(colorWheelSize + 4);/*	ofs[2] = 0;		superfluous	ofs[3] = 0;*/	for (y = 0; y < (colorWheelSize+4)/2; y++) {		for (x = y; x < (colorWheelSize+4-y); x++) {			xcor = ((float)(2.0*x - 4.0) / colorWheelSize) - 1;			ycor = ((float)(2.0*y - 4.0) / colorWheelSize) - 1;			sat = rint(255.0 * sqrt((xcor*xcor) + (ycor*ycor)));			/* offsets are counterclockwise (in triangles) */			if (y < (colorWheelSize+4)/2)				ofs[0]++;									/* top quarter */			ofs[1] += colorWheelSize + 4;			/* left quarter */			ofs[2] = (colorWheelSize + 4) * (colorWheelSize + 4) - 1 - ofs[0];	/* bottom quarter */			ofs[3] = (colorWheelSize + 4) * (colorWheelSize + 4) - 1 - ofs[1];							/* right quarter */			if (sat < 256) {				cur_hsv.saturation = (unsigned char)sat;								if (xcor != 0)					hue = atan(ycor/xcor);				else {					if (ycor > 0)						hue = W_PI * 0.5;					else						hue = W_PI * 1.5;				}								if (xcor < 0)					hue += W_PI;				if ((xcor > 0) && (ycor < 0))					hue += W_PI * 2.0;								hue = -hue;		/* Reverse direction of ColorWheel */								if (hue < 0)					hue += W_PI * 2.0;								dhue[0] = (hue*360) / (W_PI * 2.0);								for (i = 0; i < 4; i++) {					if (i > 0)						dhue[i] = (dhue[i-1] + 90) % 360;									if ((i == 1) || (i == 3))						dhue[i] = 360 - dhue[i];					if (i == 2)						dhue[i] = 360 - dhue[i] + 180;						rp = matrix->data[0] + (ofs[i] * sizeof(unsigned char));					gp = matrix->data[1] + (ofs[i] * sizeof(unsigned char));					bp = matrix->data[2] + (ofs[i] * sizeof(unsigned char));										cur_hsv.hue = dhue[i];					RHSVtoRGB(&cur_hsv, &cur_rgb);					*rp = (unsigned char)(cur_rgb.red);					*gp = (unsigned char)(cur_rgb.green);					*bp = (unsigned char)(cur_rgb.blue);				}			}			else {				for (i = 0; i < 4; i++) {					rp = matrix->data[0] + (ofs[i] * sizeof(unsigned char));					gp = matrix->data[1] + (ofs[i] * sizeof(unsigned char));					bp = matrix->data[2] + (ofs[i] * sizeof(unsigned char));										*rp = (unsigned char)(0);					*gp = (unsigned char)(0);					*bp = (unsigned char)(0);				}			}		}		if (y < (colorWheelSize+4)/2)			ofs[0] += 2*y+1;		ofs[1] += 1 - (colorWheelSize + 4) * (colorWheelSize + 4 - 1 - 2*y);	}		return matrix;}