Hi, I have a sheep. Or an elephant. Etcephant
Jaymz Julian
jaymz at artificial-stupidity.net
Thu Apr 1 19:39:41 PST 2004
so i stopped being lazy and made convolutions work via XRenderSetPictureFilter.
It still uses cache, because it was unusably slow on my hardware without it.
It atakes it's optional parameters as the first 5 elepments of the array, and then
the convolution follows.
[xsize, ysize, offset, divisor, wraptypeis this closer to what people were thinking of?
-- jj
--
--
Jaymz Julian - Coder, Visionary, Fat Ass.
"Hannibal is a serial killer. He only likes to kill and eat people.
Very few people have `I want to be killed and eaten' on their cards,
so Hannibal is out of a job." - http://cards.sf.net
-------------- next part --------------
Index: fb/Makefile.am
===================================================================
RCS file: /cvs/xserver/xserver/fb/Makefile.am,v
retrieving revision 1.5
diff -u -3 -p -r1.5 Makefile.am
--- a/fb/Makefile.am 11 Nov 2003 05:46:07 -0000 1.5
+++ b/fb/Makefile.am 2 Apr 2004 03:34:33 -0000
@@ -44,4 +44,9 @@ libfb_a_SOURCES = \
fbtile.c \
fbtrap.c \
fbutil.c \
- fbwindow.c
+ fbwindow.c \
+ convolution/fbConvolutionGeneral.c \
+ convolution/fbSimpleConvolution.c \
+ convolution/fbFastBlur.c \
+ convolution/fbSimpleBlurSquare.c \
+ convolution/fbSimpleBlurRound.c
Index: fb/fb.h
===================================================================
RCS file: /cvs/xserver/xserver/fb/fb.h,v
retrieving revision 1.42
diff -u -3 -p -r1.42 fb.h
--- a/fb/fb.h 5 Jan 2004 21:08:46 -0000 1.42
+++ b/fb/fb.h 2 Apr 2004 03:34:38 -0000
@@ -709,6 +709,53 @@ typedef struct {
*/
#define FbEvenStip(w,bpp) ((w) * (bpp) <= FB_UNIT && FbPowerOfTwo(w) && FbPowerOfTwo(bpp))
+
+
+#define fbComposeGetSolid(pict, bits) { \
+ FbBits *__bits__; \
+ FbStride __stride__; \
+ int __bpp__; \
+ int __xoff__,__yoff__; \
+\
+ fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
+ switch (__bpp__) { \
+ case 32: \
+ (bits) = *(CARD32 *) __bits__; \
+ break; \
+ case 24: \
+ (bits) = Fetch24 ((CARD8 *) __bits__); \
+ break; \
+ case 16: \
+ (bits) = *(CARD16 *) __bits__; \
+ (bits) = cvt0565to0888(bits); \
+ break; \
+ case 8: \
+ (bits) = *(CARD8 *) __bits__; \
+ (bits) = (bits) << 24; \
+ break; \
+ case 1: \
+ (bits) = *(CARD32 *) __bits__; \
+ (bits) = FbLeftStipBits((bits),1) ? 0xff000000 : 0x00000000;\
+ break; \
+ default: \
+ return; \
+ } \
+ /* manage missing src alpha */ \
+ if ((pict)->pFormat->direct.alphaMask == 0) \
+ (bits) |= 0xff000000; \
+}
+
+#define fbComposeGetStart(pict,x,y,type,stride,line,mul) {\
+ FbBits *__bits__; \
+ FbStride __stride__; \
+ int __bpp__; \
+ int __xoff__,__yoff__; \
+\
+ fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
+ (stride) = __stride__ * sizeof (FbBits) / sizeof (type); \
+ (line) = ((type *) __bits__) + (stride) * ((y) + __yoff__) + (mul) * ((x) + __xoff__); \
+}
+
/*
* fb24_32.c
*/
Index: fb/fbpict.c
===================================================================
RCS file: /cvs/xserver/xserver/fb/fbpict.c,v
retrieving revision 1.29
diff -u -3 -p -r1.29 fbpict.c
--- a/fb/fbpict.c 15 Jan 2004 09:09:29 -0000 1.29
+++ b/fb/fbpict.c 2 Apr 2004 03:34:41 -0000
@@ -27,6 +27,7 @@
#include <config.h>
#endif
#include "fb.h"
+#include "fbConvolution.h"
#ifdef RENDER
@@ -116,50 +117,6 @@ fbIn24 (CARD32 x, CARD8 y)
return m|n|o|p;
}
-#define fbComposeGetSolid(pict, bits) { \
- FbBits *__bits__; \
- FbStride __stride__; \
- int __bpp__; \
- int __xoff__,__yoff__; \
-\
- fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
- switch (__bpp__) { \
- case 32: \
- (bits) = *(CARD32 *) __bits__; \
- break; \
- case 24: \
- (bits) = Fetch24 ((CARD8 *) __bits__); \
- break; \
- case 16: \
- (bits) = *(CARD16 *) __bits__; \
- (bits) = cvt0565to0888(bits); \
- break; \
- case 8: \
- (bits) = *(CARD8 *) __bits__; \
- (bits) = (bits) << 24; \
- break; \
- case 1: \
- (bits) = *(CARD32 *) __bits__; \
- (bits) = FbLeftStipBits((bits),1) ? 0xff000000 : 0x00000000;\
- break; \
- default: \
- return; \
- } \
- /* manage missing src alpha */ \
- if ((pict)->pFormat->direct.alphaMask == 0) \
- (bits) |= 0xff000000; \
-}
-
-#define fbComposeGetStart(pict,x,y,type,stride,line,mul) {\
- FbBits *__bits__; \
- FbStride __stride__; \
- int __bpp__; \
- int __xoff__,__yoff__; \
-\
- fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
- (stride) = __stride__ * sizeof (FbBits) / sizeof (type); \
- (line) = ((type *) __bits__) + (stride) * ((y) + __yoff__) + (mul) * ((x) + __xoff__); \
-}
#define genericCombine24(a,b,c,d) (((a)*(c)+(b)*(d)))
@@ -1427,7 +1384,16 @@ fbComposite (CARD8 op,
Bool dstAlphaMap = pDst->alphaMap != 0;
int x_msk, y_msk, x_src, y_src, x_dst, y_dst;
int w, h, w_this, h_this;
-
+
+ static PicturePtr srcConvCache=NULL;
+ static PicturePtr maskConvCache=NULL;
+
+ if(srcConvCache==NULL)
+ srcConvCache=(PicturePtr)xalloc(sizeof(PictureRec));
+
+ if(maskConvCache==NULL)
+ maskConvCache=(PicturePtr)xalloc(sizeof(PictureRec));
+
xDst += pDst->pDrawable->x;
yDst += pDst->pDrawable->y;
xSrc += pSrc->pDrawable->x;
@@ -1655,11 +1621,12 @@ fbComposite (CARD8 op,
pbox = REGION_RECTS (®ion);
while (n--)
{
+ PicturePtr wSrc, wMask;
h = pbox->y2 - pbox->y1;
y_src = pbox->y1 - yDst + ySrc;
y_msk = pbox->y1 - yDst + yMask;
y_dst = pbox->y1;
- while (h)
+ while (h>0)
{
h_this = h;
w = pbox->x2 - pbox->x1;
@@ -1671,14 +1638,14 @@ fbComposite (CARD8 op,
y_msk = mod (y_msk, pMask->pDrawable->height);
if (h_this > pMask->pDrawable->height - y_msk)
h_this = pMask->pDrawable->height - y_msk;
- }
+ }
if (srcRepeat)
{
y_src = mod (y_src, pSrc->pDrawable->height);
if (h_this > pSrc->pDrawable->height - y_src)
h_this = pSrc->pDrawable->height - y_src;
}
- while (w)
+ while (w>0)
{
w_this = w;
if (maskRepeat)
@@ -1693,7 +1660,24 @@ fbComposite (CARD8 op,
if (w_this > pSrc->pDrawable->width - x_src)
w_this = pSrc->pDrawable->width - x_src;
}
- (*func) (op, pSrc, pMask, pDst,
+ /* check if we have a convolution to apply to src.
+ * if yes, memcpy() pSrc to srcConvCache, with a new
+ * drawable, and then convole into it from pSrc, and then
+ * replace pSrc with it
+ */
+ wSrc=pSrc;
+ wMask=pMask;
+ if(isConvolutionFilter(pSrc->filter))
+ {
+ handleConvolution(pSrc, srcConvCache, x_src, y_src, x_src+w_this, y_src+h_this);
+ wSrc=srcConvCache;
+ }
+ if(isConvolutionFilter(pMask->filter))
+ {
+ handleConvolution(pMask, maskConvCache, x_src, y_src, x_src+w_this, y_src+h_this);
+ wMask=maskConvCache;
+ }
+ (*func) (op, wSrc, wMask, pDst,
x_src, y_src, x_msk, y_msk, x_dst, y_dst,
w_this, h_this);
w -= w_this;
Index: include/picturestr.h
===================================================================
RCS file: /cvs/xserver/xserver/include/picturestr.h,v
retrieving revision 1.26
diff -u -3 -p -r1.26 picturestr.h
--- a/include/picturestr.h 15 Jan 2004 09:03:47 -0000 1.26
+++ b/include/picturestr.h 2 Apr 2004 03:34:48 -0000
@@ -64,6 +64,7 @@ typedef struct _PictTransform {
typedef struct _Picture {
DrawablePtr pDrawable;
+ DrawablePtr convCache; /* cache for various filter ops */
PictFormatPtr pFormat;
CARD32 format; /* PICT_FORMAT */
int refcnt;
@@ -110,6 +111,16 @@ typedef struct {
PictFilterValidateParamsProcPtr ValidateParams;
} PictFilterRec, *PictFilterPtr;
+typedef struct
+{
+ xFixed xSize;
+ xFixed ySize;
+ xFixed divisor;
+ xFixed offset;
+ xFixed wrapType;
+ xFixed convolution[1]; /* [0] only works on gnu */
+} Convolution;
+
#define PictFilterNearest 0
#define PictFilterBilinear 1
@@ -117,6 +128,12 @@ typedef struct {
#define PictFilterGood 3
#define PictFilterBest 4
+#define PictFilterSimpleConvolution 5
+#define PictFilterFastBlur 6
+#define PictFilterSquareBlur 7
+#define PictFilterRoundBlur 8
+#define PictFilterGaussianBlur 9
+
typedef struct {
char *alias;
int alias_id;
Index: render/filter.c
===================================================================
RCS file: /cvs/xserver/xserver/render/filter.c,v
retrieving revision 1.3
diff -u -3 -p -r1.3 filter.c
--- a/render/filter.c 15 Jan 2004 09:03:47 -0000 1.3
+++ b/render/filter.c 2 Apr 2004 03:34:50 -0000
@@ -40,6 +40,9 @@
#include "servermd.h"
#include "picturestr.h"
+Bool validateSimpleConvolutionParams(PicturePtr pPicture, int id, xFixed *params, int nparams);
+Bool validateBlur(PicturePtr pPicture, int id, xFixed *params, int nparams);
+
static char **filterNames;
static int nfilterNames;
@@ -99,6 +102,16 @@ PictureSetDefaultIds (void)
return FALSE;
if (PictureGetFilterId (FilterBest, -1, TRUE) != PictFilterBest)
return FALSE;
+ if (PictureGetFilterId (FilterSimpleConvolution, -1, TRUE) != PictFilterSimpleConvolution)
+ return FALSE;
+ if (PictureGetFilterId (FilterFastBlur, -1, TRUE) != PictFilterFastBlur)
+ return FALSE;
+ if (PictureGetFilterId (FilterSquareBlur, -1, TRUE) != PictFilterSquareBlur)
+ return FALSE;
+ if (PictureGetFilterId (FilterRoundBlur, -1, TRUE) != PictFilterRoundBlur)
+ return FALSE;
+ if (PictureGetFilterId (FilterGaussianBlur, -1, TRUE) != PictFilterGaussianBlur)
+ return FALSE;
return TRUE;
}
@@ -223,13 +236,25 @@ PictureSetDefaultFilters (ScreenPtr pScr
return FALSE;
if (PictureAddFilter (pScreen, FilterBilinear, 0) < 0)
return FALSE;
-
+
if (!PictureSetFilterAlias (pScreen, FilterNearest, FilterFast))
return FALSE;
if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterGood))
return FALSE;
if (!PictureSetFilterAlias (pScreen, FilterBilinear, FilterBest))
return FALSE;
+
+ if (PictureAddFilter (pScreen, FilterSimpleConvolution, validateSimpleConvolutionParams) < 0)
+ return FALSE;
+ if (PictureAddFilter (pScreen, FilterFastBlur, validateBlur) < 0)
+ return FALSE;
+ if (PictureAddFilter (pScreen, FilterSquareBlur, validateBlur) < 0)
+ return FALSE;
+ if (PictureAddFilter (pScreen, FilterRoundBlur, validateBlur) < 0)
+ return FALSE;
+ if (PictureAddFilter (pScreen, FilterGaussianBlur, validateBlur) < 0)
+ return FALSE;
+
return TRUE;
}
@@ -275,3 +300,21 @@ SetPictureFilter (PicturePtr pPicture, c
pPicture->filter = pFilter->id;
return Success;
}
+
+Bool validateBlur(PicturePtr pPicture, int id, xFixed *params, int nparams)
+{
+ if(nparams!=5)
+ return FALSE;
+ return TRUE;
+}
+Bool validateSimpleConvolutionParams(PicturePtr pPicture, int id, xFixed *params, int nparams)
+{
+ Convolution *c=params;
+ int x,y;
+ if(nparams<5)
+ return FALSE;
+ if(nparams!=((c->xSize*c->ySize)+5))
+ return FALSE;
+ return TRUE;
+}
+
Index: render/picture.c
===================================================================
RCS file: /cvs/xserver/xserver/render/picture.c,v
retrieving revision 1.35
diff -u -3 -p -r1.35 picture.c
--- a/render/picture.c 18 Nov 2003 07:10:14 -0000 1.35
+++ b/render/picture.c 2 Apr 2004 03:34:52 -0000
@@ -709,6 +709,8 @@ SetPictureToDefaults (PicturePtr pPic
pPicture->serialNumber = GC_CHANGE_SERIAL_BIT;
pPicture->stateChanges = (1 << (CPLastBit+1)) - 1;
+
+ pPicture->convCache = NULL;
}
PicturePtr
-------------- next part --------------
Index: render.h
===================================================================
RCS file: /cvs/xlibs/Render/render.h,v
retrieving revision 1.12
diff -u -3 -p -r1.12 render.h
--- render.h 21 Apr 2003 17:19:22 -0000 1.12
+++ render.h 2 Apr 2004 03:35:06 -0000
@@ -160,8 +160,18 @@ typedef unsigned long PictFormat;
#define FilterGood "good"
#define FilterBest "best"
+/* Filters included in 0.9 */
+#define FilterSimpleConvolution "SimpleConvolution"
+#define FilterFastBlur "FastBlur"
+#define FilterSquareBlur "SquareBlur"
+#define FilterRoundBlur "RoundBlur"
+#define FilterGaussianBlur "GaussianBlur"
+
#define FilterAliasNone -1
+#define WrapNone 0
+#define WrapClamp 0
+
/* Subpixel orders included in 0.6 */
#define SubPixelUnknown 0
#define SubPixelHorizontalRGB 1
More information about the xserver
mailing list