[xserver-commit] xserver/render filter.c,1.2,1.3

Keith Packard xserver-commit@pdx.freedesktop.org
Thu, 15 Jan 2004 01:03:49 -0800


Committed by: keithp

Update of /cvs/xserver/xserver/render
In directory pdx:/tmp/cvs-serv17870/render

Modified Files:
	filter.c 
Log Message:
2004-01-15  Keith Packard  <keithp@keithp.com>
	* dix/dixutils.c: (ISOLatin1ToLower), (CompareISOLatin1Lowered):
	* include/dix.h:
	Add CompareISOLatin1Lowered.
	* include/picturestr.h:
	* render/filter.c: (PictureGetFilterId), (PictureAddFilter),
	(PictureSetDefaultFilters), (SetPictureFilter):
	Change filter management to permit varargs filters.
	Use CompareISOLatin1Lowered to make filter name tests
	case-insensitive (as required by spec).


Index: filter.c
===================================================================
RCS file: /cvs/xserver/xserver/render/filter.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- filter.c	11 Sep 2003 05:12:51 -0000	1.2
+++ filter.c	15 Jan 2004 09:03:47 -0000	1.3
@@ -43,6 +43,12 @@
 static char **filterNames;
 static int  nfilterNames;
 
+/*
+ * standard but not required filters don't have constant indices
+ */
+
+int pictFilterConvolution;
+
 int
 PictureGetFilterId (char *filter, int len, Bool makeit)
 {
@@ -53,15 +59,14 @@
     if (len < 0)
 	len = strlen (filter);
     for (i = 0; i < nfilterNames; i++)
-	if (len == strlen (filterNames[i]) && 
-	    !strncmp (filterNames[i], filter, len))
+	if (!CompareISOLatin1Lowered (filterNames[i], -1, filter, len))
 	    return i;
     if (!makeit)
 	return -1;
-    name = xalloc (strlen (filter) + 1);
+    name = xalloc (len + 1);
     if (!name)
 	return -1;
-    strncpy (name, filter, len);
+    memcpy (name, filter, len);
     name[len] = '\0';
     if (filterNames)
 	names = xrealloc (filterNames, (nfilterNames + 1) * sizeof (char *));
@@ -119,7 +124,9 @@
 }
 
 int
-PictureAddFilter (ScreenPtr pScreen, char *filter, xFixed *params, int nparams)
+PictureAddFilter (ScreenPtr			    pScreen,
+		  char				    *filter,
+		  PictFilterValidateParamsProcPtr   ValidateParams)
 {
     PictureScreenPtr    ps = GetPictureScreen(pScreen);
     int			id = PictureGetFilterId (filter, -1,  TRUE);
@@ -143,9 +150,8 @@
     ps->filters = filters;
     i = ps->nfilters++;
     ps->filters[i].name = PictureGetFilterName (id);
-    ps->filters[i].params = params;
-    ps->filters[i].nparams = nparams;
     ps->filters[i].id = id;
+    ps->filters[i].ValidateParams = ValidateParams;
     return id;
 }
 
@@ -212,11 +218,12 @@
     if (!filterNames)
 	if (!PictureSetDefaultIds ())
 	    return FALSE;
-    if (PictureAddFilter (pScreen, FilterNearest, 0, 0) < 0)
+
+    if (PictureAddFilter (pScreen, FilterNearest, 0) < 0)
 	return FALSE;
-    if (PictureAddFilter (pScreen, FilterBilinear, 0, 0) < 0)
+    if (PictureAddFilter (pScreen, FilterBilinear, 0) < 0)
 	return FALSE;
-
+    
     if (!PictureSetFilterAlias (pScreen, FilterNearest, FilterFast))
 	return FALSE;
     if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterGood))
@@ -246,21 +253,25 @@
 
     if (!pFilter)
 	return BadName;
-    if (nparams > pFilter->nparams)
+    if (pFilter->ValidateParams)
+    {
+	if (!(*pFilter->ValidateParams) (pPicture, pFilter->id, params, nparams))
+	    return BadMatch;
+    }
+    else if (nparams)
 	return BadMatch;
-    if (pFilter->nparams != pPicture->filter_nparams)
+
+    if (nparams != pPicture->filter_nparams)
     {
-	new_params = xalloc (pFilter->nparams * sizeof (xFixed));
+	new_params = xalloc (nparams * sizeof (xFixed));
 	if (!new_params)
 	    return BadAlloc;
 	xfree (pPicture->filter_params);
 	pPicture->filter_params = new_params;
-	pPicture->filter_nparams = pFilter->nparams;
+	pPicture->filter_nparams = nparams;
     }
     for (i = 0; i < nparams; i++)
 	pPicture->filter_params[i] = params[i];
-    for (; i < pFilter->nparams; i++)
-	pPicture->filter_params[i] = pFilter->params[i];
     pPicture->filter = pFilter->id;
     return Success;
 }