+static void fill_line_gradient(RGBA*line, U32*z, int y, int x1, int x2, fillinfo_t*info)
+{
+ int x = x1;
+
+ gfxmatrix_t*m = info->matrix;
+ RGBA*g= info->gradient;
+
+ double det = m->m00*m->m11 - m->m01*m->m10;
+ if(fabs(det) < 0.0005) {
+ /* x direction equals y direction */
+ return;
+ }
+
+ det = 1.0/det;
+ double xx1 = ( (-m->tx) * m->m11 - (y - m->ty) * m->m10) * det;
+ double yy1 = (- (-m->tx) * m->m01 + (y - m->ty) * m->m00) * det;
+ double xinc1 = m->m11 * det;
+ double yinc1 = m->m01 * det;
+
+ U32 bit = 1<<(x1&31);
+ int bitpos = (x1/32);
+
+ do {
+ if(z[bitpos]&bit) {
+ RGBA col;
+ int ainv;
+
+ int pos = 0;
+ if(info->linear_or_radial) {
+ double xx = xx1 + x * xinc1;
+ double yy = yy1 + y * yinc1;
+ double r = sqrt(xx*xx + yy*yy);
+ if(r>1) r = 1;
+ pos = (int)(r*255.999);
+ } else {
+ double r = xx1 + x * xinc1;
+ if(r>1) r = 1;
+ if(r<-1) r = -1;
+ pos = (int)((r+1)*127.999);
+ }
+ col = g[pos];
+ ainv = 255-col.a;
+
+ /* needs bitmap with premultiplied alpha */
+ line[x].r = ((line[x].r*ainv)/255)+col.r;
+ line[x].g = ((line[x].g*ainv)/255)+col.g;
+ line[x].b = ((line[x].b*ainv)/255)+col.b;
+ line[x].a = 255;
+ }
+ bit <<= 1;
+ if(!bit) {
+ bit = 1;bitpos++;
+ }
+ } while(++x<x2);
+}
+