Patch from Andrew Johnson to speed up vertical gradients. Fixes #169982.

2005-07-12  Elijah Newren  <newren@gmail.com>

	Patch from Andrew Johnson to speed up vertical gradients.  Fixes
	#169982.

	* src/gradient.c:
	(meta_gradient_create_interwoven):
	(meta_gradient_create_vertical):
	(meta_gradient_create_multi_vertical):

	use memcpy instead of really long loops to set values in memory to
	a given pattern.
This commit is contained in:
Elijah Newren 2005-07-12 22:34:25 +00:00 committed by Elijah Newren
parent 0e956c674f
commit 7bda73a415
2 changed files with 48 additions and 92 deletions

View File

@ -1,3 +1,16 @@
2005-07-12 Elijah Newren <newren@gmail.com>
Patch from Andrew Johnson to speed up vertical gradients. Fixes
#169982.
* src/gradient.c:
(meta_gradient_create_interwoven):
(meta_gradient_create_vertical):
(meta_gradient_create_multi_vertical):
use memcpy instead of really long loops to set values in memory to
a given pattern.
2005-07-12 Elijah Newren <newren@gmail.com> 2005-07-12 Elijah Newren <newren@gmail.com>
Patch from Björn Lindqvist to split up main() into more manageable Patch from Björn Lindqvist to split up main() into more manageable

View File

@ -166,7 +166,6 @@ meta_gradient_create_interwoven (int width,
long r2, g2, b2, dr2, dg2, db2; long r2, g2, b2, dr2, dg2, db2;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
unsigned char *ptr; unsigned char *ptr;
unsigned char rr, gg, bb;
unsigned char *pixels; unsigned char *pixels;
int rowstride; int rowstride;
@ -199,37 +198,21 @@ meta_gradient_create_interwoven (int width,
if (k == 0) if (k == 0)
{ {
rr = r1>>16; ptr[0] = (unsigned char) r1>>16;
gg = g1>>16; ptr[1] = (unsigned char) g1>>16;
bb = b1>>16; ptr[2] = (unsigned char) b1>>16;
} }
else else
{ {
rr = r2>>16; ptr[0] = (unsigned char) r2>>16;
gg = g2>>16; ptr[1] = (unsigned char) g2>>16;
bb = b2>>16; ptr[2] = (unsigned char) b2>>16;
}
for (j=0; j<width/8; j++)
{
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8)
{
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
} }
for (j=1; j <= width/2; j *= 2)
memcpy (&(ptr[j*3]), ptr, j*3);
memcpy (&(ptr[j*3]), ptr, (width - j)*3);
if (++l == ll) if (++l == ll)
{ {
if (k == 0) if (k == 0)
@ -346,7 +329,6 @@ meta_gradient_create_vertical (int width, int height,
long r, g, b, dr, dg, db; long r, g, b, dr, dg, db;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
unsigned char *ptr; unsigned char *ptr;
unsigned char rr, gg, bb;
int r0, g0, b0; int r0, g0, b0;
int rf, gf, bf; int rf, gf, bf;
int rowstride; int rowstride;
@ -378,30 +360,14 @@ meta_gradient_create_vertical (int width, int height,
{ {
ptr = pixels + i * rowstride; ptr = pixels + i * rowstride;
rr = r>>16; ptr[0] = (unsigned char)(r>>16);
gg = g>>16; ptr[1] = (unsigned char)(g>>16);
bb = b>>16; ptr[2] = (unsigned char)(b>>16);
for (j=0; j<width/8; j++)
{ for (j=1; j <= width/2; j *= 2)
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb; memcpy (&(ptr[j*3]), ptr, j*3);
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb; memcpy (&(ptr[j*3]), ptr, (width - j)*3);
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8)
{
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
r+=dr; r+=dr;
g+=dg; g+=dg;
b+=db; b+=db;
@ -565,9 +531,7 @@ meta_gradient_create_multi_vertical (int width, int height,
unsigned char *ptr, *tmp, *pixels; unsigned char *ptr, *tmp, *pixels;
int height2; int height2;
int x; int x;
unsigned char rr, gg, bb;
int rowstride; int rowstride;
int pad;
g_return_val_if_fail (count > 2, NULL); g_return_val_if_fail (count > 2, NULL);
@ -577,7 +541,6 @@ meta_gradient_create_multi_vertical (int width, int height,
pixels = gdk_pixbuf_get_pixels (pixbuf); pixels = gdk_pixbuf_get_pixels (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf);
pad = rowstride - (width * 3);
ptr = pixels; ptr = pixels;
if (count > height) if (count > height)
@ -602,25 +565,15 @@ meta_gradient_create_multi_vertical (int width, int height,
for (j=0; j<height2; j++) for (j=0; j<height2; j++)
{ {
rr = r>>16; ptr[0] = (unsigned char)(r>>16);
gg = g>>16; ptr[1] = (unsigned char)(g>>16);
bb = b>>16; ptr[2] = (unsigned char)(b>>16);
for (x=0; x<width/4; x++) for (x=1; x <= width/2; x *= 2)
{ memcpy (&(ptr[x*3]), ptr, x*3);
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb; memcpy (&(ptr[x*3]), ptr, (width - x)*3);
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
switch (width%4)
{
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
ptr += pad; ptr += rowstride;
r += dr; r += dr;
g += dg; g += dg;
@ -632,29 +585,19 @@ meta_gradient_create_multi_vertical (int width, int height,
b = colors[i].blue << 8; b = colors[i].blue << 8;
} }
rr = r>>16;
gg = g>>16;
bb = b>>16;
if (k<height) if (k<height)
{ {
tmp = ptr; tmp = ptr;
for (x=0; x<width/4; x++)
{
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
switch (width%4)
{
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
default: break;
}
ptr += pad; ptr[0] = (unsigned char) r>>16;
ptr[1] = (unsigned char) g>>16;
ptr[2] = (unsigned char) b>>16;
for (x=1; x <= width/2; x *= 2)
memcpy (&(ptr[x*3]), ptr, x*3);
memcpy (&(ptr[x*3]), ptr, (width - x)*3);
ptr += rowstride;
for (j=k+1; j<height; j++) for (j=k+1; j<height; j++)
{ {