|
From: Daniel J S. <dan...@ie...> - 2004-09-28 09:24:48
|
OK, I think I have a solid version of the new colormap list scheme. It
needs a good cleaning yet, but give it a try. (The patch is against CVS
from a day or two ago.) There are still some comments printed out when
colormaps are created, deleted, etc. Watch them to see if they make
sense, e.g., a color map is removed when it is not unique, or when it is
no longer needed, etc.
The major change is the PaletteMake() routine. The "recursion" variable
is gone, the colormap is built first and then compared (because
sm_palette is not stored as part of cmap_t), and the comparison is
against the whole of the colormap list. So, where there used to be
palettes_differ() there is now cmaps_differ(), which looks like [if
someone can find a better way of computing the size of the memory block
to compare, let me know]:
/*-----------------------------------------------------------------------------
* cmaps_differ - Compare two colormaps, return 1 if differ.
*---------------------------------------------------------------------------*/
static int
cmaps_differ(cmap_t *cmap1, cmap_t *cmap2)
{
/* First compare non-pointer elements. */
if ( memcmp(&(cmap1->colors[0]), &(cmap2->colors[0]),
(long)&(cmap1->pixels)-(long)&(cmap1->colors[0])) )
return 1;
/* Now compare pointer elements. */
if (cmap1->allocated) {
if (cmap1->pixels && cmap2->pixels) {
if ( memcmp(cmap1->pixels, cmap2->pixels,
cmap1->allocated*sizeof(cmap1->pixels[0])) )
return 1;
} else
return 1;
}
return 0; /* They are the same. */
}
I like the use of memcmp [potentially a fast assembly routine if done
right] versus the individual comparisons inside palettes_differ().
Dan
|