|
From: Ethan M. <merritt@u.washington.edu> - 2007-06-04 23:01:11
|
On Monday 04 June 2007 13:14, Ethan Merritt wrote:
> On Sunday 03 June 2007 19:48, m sutton wrote:
> > I would like a couple of my patches to be considered for inclusion into CVS:
> >
> > 1659135 dashed grid for GD term to accept linewidths
>
> OK, that's better than the earlier version.
On closer inspection, I'm not entirely happy.
This line:
static int png_linetype_dotted[MAXLINEWIDTH*MAXLINEWIDTH*5];
ties up 0.2 MByte permanently, on the off-chance that we want
to change the grid width. Yeah I know, virtual memory is cheap these days.
But it's ugly. Doesn't 200,000,000 bytes of storage to specify
a 2+3 dot pattern seem a little outrageous?
My reading of the libgd docs is that there is no need for static arrays.
I quote:
As of version 1.1.1, the style array is copied when you set
the style, so you need not be concerned with keeping the
array around indefinitely.
Can't you do something like:
if (lw != last_lw) {
int i;
int psize = lw*lw*2;
int ssize = lw*lw*5;
int *png_linetype_dotted = gp_alloc( 5*lw*lw*sizeof(int), "dots");
/* Fill style with with color then transparent.
* The style is 2 on / 3 off and scales with linewidth.
*/
for(i = 0;i < psize; i++)
png_linetype_dotted[i] = png_state.color;
for (;i < ssize; i++)
png_linetype_dotted[i] = gdTransparent;
gdImageSetStyle(png_state.image, png_linetype_dotted, ssize);
free(png_linetype_dotted);
last_lw = lw;
}
This seems to work, but I haven't tested extensively
--
Ethan A Merritt
|