+void gradient_pyramid(Surface *sf, int inw, int inh)
+{
+ pixel32 *data = sf->data.planar.pixel_data;
+ pixel32 *end = data + inw*inh - 1;
+ pixel32 current;
+ float drx, dgx, dbx, dry, dgy, dby;
+ unsigned int r,g,b;
+ int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
+ for (y = 0; y < h; ++y) {
+ drx = (float)(sf->data.planar.secondary->r -
+ sf->data.planar.primary->r);
+ dry = drx/(float)h;
+ drx/= (float)w;
+
+ dgx = (float)(sf->data.planar.secondary->g -
+ sf->data.planar.primary->g);
+ dgy = dgx/(float)h;
+ dgx/= (float)w;
+
+ dbx = (float)(sf->data.planar.secondary->b -
+ sf->data.planar.primary->b);
+ dby = dbx/(float)h;
+ dbx/= (float)w;
+ for (x = 0; x < w; ++x, data) {
+ r = sf->data.planar.primary->r +
+ ((int)(drx * x) + (int)(dry * y))/2;
+ g = sf->data.planar.primary->g +
+ ((int)(dgx * x) + (int)(dgy * y))/2;
+ b = sf->data.planar.primary->b +
+ ((int)(dbx * x) + (int)(dby * y))/2;
+ current = (r << default_red_offset)
+ + (g << default_green_offset)
+ + (b << default_blue_offset);
+ *(data+x) = current;
+ *(data+inw-x) = current;
+ *(end-x) = current;
+ *(end-(inw-x)) = current;
+ }
+ data+=inw;
+ end-=inw;
+ }
+}
+
+void gradient_rectangle(Surface *sf, int inw, int inh)
+{
+ pixel32 *data = sf->data.planar.pixel_data;
+ pixel32 *end = data + inw*inh - 1;
+ pixel32 current;
+ float drx, dgx, dbx, dry, dgy, dby;
+ unsigned int r,g,b;
+ int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
+ int val;
+
+ for (y = 0; y < h; ++y) {
+ drx = (float)(sf->data.planar.primary->r -
+ sf->data.planar.secondary->r);
+ dry = drx/(float)h;
+ drx/= (float)w;
+
+ dgx = (float)(sf->data.planar.primary->g -
+ sf->data.planar.secondary->g);
+ dgy = dgx/(float)h;
+ dgx/= (float)w;
+
+ dbx = (float)(sf->data.planar.primary->b -
+ sf->data.planar.secondary->b);
+ dby = dbx/(float)h;
+ dbx/= (float)w;
+ for (x = 0; x < w; ++x, data) {
+ if ((float)x/(float)w < (float)y/(float)h) val = (int)(drx * x);
+ else val = (int)(dry * y);
+
+ r = sf->data.planar.secondary->r + val;
+ g = sf->data.planar.secondary->g + val;
+ b = sf->data.planar.secondary->b + val;
+ current = (r << default_red_offset)
+ + (g << default_green_offset)
+ + (b << default_blue_offset);
+ *(data+x) = current;
+ *(data+inw-x) = current;
+ *(end-x) = current;
+ *(end-(inw-x)) = current;
+ }
+ data+=inw;
+ end-=inw;
+ }
+}
+
+void gradient_pipecross(Surface *sf, int inw, int inh)
+{
+ pixel32 *data = sf->data.planar.pixel_data;
+ pixel32 *end = data + inw*inh - 1;
+ pixel32 current;
+ float drx, dgx, dbx, dry, dgy, dby;
+ unsigned int r,g,b;
+ int x, y, h=(inh/2) + 1, w=(inw/2) + 1;
+ int val;
+
+ for (y = 0; y < h; ++y) {
+ drx = (float)(sf->data.planar.secondary->r -
+ sf->data.planar.primary->r);
+ dry = drx/(float)h;
+ drx/= (float)w;
+
+ dgx = (float)(sf->data.planar.secondary->g -
+ sf->data.planar.primary->g);
+ dgy = dgx/(float)h;
+ dgx/= (float)w;
+
+ dbx = (float)(sf->data.planar.secondary->b -
+ sf->data.planar.primary->b);
+ dby = dbx/(float)h;
+ dbx/= (float)w;
+ for (x = 0; x < w; ++x, data) {
+ if ((float)x/(float)w > (float)y/(float)h) val = (int)(drx * x);
+ else val = (int)(dry * y);
+
+ r = sf->data.planar.primary->r + val;
+ g = sf->data.planar.primary->g + val;
+ b = sf->data.planar.primary->b + val;
+ current = (r << default_red_offset)
+ + (g << default_green_offset)
+ + (b << default_blue_offset);
+ *(data+x) = current;
+ *(data+inw-x) = current;
+ *(end-x) = current;
+ *(end-(inw-x)) = current;
+ }
+ data+=inw;
+ end-=inw;
+ }
+}
+#ifdef USE_GL
+void render_gl_gradient(Surface *sf, int x, int y, int w, int h)
+{
+ float pr,pg,pb;
+ float sr, sg, sb;
+ float ar, ag, ab;
+
+ pr = (float)sf->data.planar.primary->r/255.0;
+ pg = (float)sf->data.planar.primary->g/255.0;
+ pb = (float)sf->data.planar.primary->b/255.0;
+ if (sf->data.planar.secondary) {
+ sr = (float)sf->data.planar.secondary->r/255.0;
+ sg = (float)sf->data.planar.secondary->g/255.0;
+ sb = (float)sf->data.planar.secondary->b/255.0;
+ }
+ switch (sf->data.planar.grad) {
+ case Background_Solid: /* already handled */
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glVertex2i(x+w, y);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glVertex2i(x, y+h);
+ glVertex2i(x, y);
+ glEnd();
+ return;
+ case Background_Horizontal:
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w, y);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y+h);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_Vertical:
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glVertex2i(x+w, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glVertex2i(x, y+h);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_Diagonal:
+ ar = (pr + sr) / 2.0;
+ ag = (pg + sg) / 2.0;
+ ab = (pb + sb) / 2.0;
+ glBegin(GL_TRIANGLES);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x, y);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w, y+h);
+
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x, y+h);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_CrossDiagonal:
+ ar = (pr + sr) / 2.0;
+ ag = (pg + sg) / 2.0;
+ ab = (pb + sb) / 2.0;
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w, y+h);
+
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w, y+h);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x, y+h);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_Pyramid:
+ ar = (pr + sr) / 2.0;
+ ag = (pg + sg) / 2.0;
+ ab = (pb + sb) / 2.0;
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x, y+h/2);
+
+ glVertex2i(x, y+h/2);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y+h);
+
+ glVertex2i(x, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w/2, y+h);
+
+ glVertex2i(x+w/2, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w, y+h/2);
+
+ glVertex2i(x+w, y+h/2);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y);
+
+ glVertex2i(x+w, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(ar, ag, ab);
+ glVertex2i(x+w/2, y);
+
+ glVertex2i(x+w/2, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_PipeCross:
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glVertex2i(x, y+h/2);
+
+ glVertex2i(x, y+h/2);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y+h);
+
+ glVertex2i(x, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glVertex2i(x+w/2, y+h);
+
+ glVertex2i(x+w/2, y+h);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glVertex2i(x+w, y+h/2);
+
+ glVertex2i(x+w, y+h/2);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y);
+
+ glVertex2i(x+w, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glVertex2i(x+w/2, y);
+
+ glVertex2i(x+w/2, y);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glEnd();
+ break;
+ case Background_Rectangle:
+ glBegin(GL_TRIANGLES);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y+h);
+
+ glVertex2i(x, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y+h);
+
+ glVertex2i(x+w, y+h);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x+w, y);
+
+ glVertex2i(x+w, y);
+ glColor3f(sr, sg, sb);
+ glVertex2i(x+w/2, y+h/2);
+ glColor3f(pr, pg, pb);
+ glVertex2i(x, y);
+
+ glEnd();
+ break;