changeset 247:cfde1deedd62

Add radial blur function.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 09 Oct 2012 17:47:19 +0300
parents 3bf8ebf09a6a
children e6303e0c62cb
files vptest.c
diffstat 1 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/vptest.c	Tue Oct 09 17:46:54 2012 +0300
+++ b/vptest.c	Tue Oct 09 17:47:19 2012 +0300
@@ -124,6 +124,76 @@
 }
 
 
+#define DM_RADIAL_BLUR(YC, XC) \
+        DMVector p1 = { xc, yc, 0, 0 }, p2 = { cx, cy, 0, 0 }, v; \
+        dm_vector_sub_r(&v, &p2, &p1); \
+        dm_vector_scale(&v, scale); \
+        dm_vector_add(&v, &p1); \
+        if (v.y YC || v.x XC) continue; \
+        DMRGBA32 *dp = pix + xc, \
+                 *q = ((DMRGBA32 *)img->pixels) + ((int)(v.y) * pitch) + (int)v.x; \
+        dp->r = (q->r + dp->r) / 2; \
+        dp->g = (q->g + dp->g) / 2; \
+        dp->b = (q->b + dp->b) / 2;
+
+/*
+    asm("movq        %2,     %%xmm1\n"		\
+        "movq        %1,     %%xmm2\n"		\
+        "paddusb     %%xmm2, %%xmm1\n"		\
+        "movq        %%xmm1, %0\n"		\
+        : "=m" (*c)				\
+        : "m" (*c), "m" (*px)	\
+        : "memory", "%xmm1", "%xmm2");
+*/
+
+const Uint64 qpmask[2] = { 0xffffffff, 0 };
+const Uint64 *qmask = qpmask;
+
+
+void dmRadialBlur(SDL_Surface *img, int cx, int cy, DMFloat scale)
+{
+    int pitch = img->pitch / sizeof(DMRGBA32);
+    int xc, yc;
+
+    for (yc = cy; yc >= 0; yc--)
+    {
+        DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
+        for (xc = cx + 1; xc < img->w; xc++)
+        {
+            DM_RADIAL_BLUR(< 0, >= img->w)
+        }
+    }
+
+    for (yc = cy; yc >= 0; yc--)
+    {
+        DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
+        for (xc = cx; xc > 0; xc--)
+        {
+            DM_RADIAL_BLUR(< 0, < 0)
+        }    
+    }
+
+    for (yc = cy + 1; yc < img->h; yc++)
+    {
+        DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
+        for (xc = cx; xc > 0; xc--)
+        {
+            DM_RADIAL_BLUR(>= img->h, < 0)
+        }    
+    }
+
+    for (yc = cy + 1; yc < img->h; yc++)
+    {
+        DMRGBA32 *pix = ((DMRGBA32 *)img->pixels) + yc * pitch;
+        for (xc = cx + 1; xc < img->w; xc++)
+        {
+            DM_RADIAL_BLUR(>= img->h, >= img->w)
+        }    
+    }
+}
+
+
+
 int main(int argc, char *argv[])
 {
     SDL_Surface *screen = NULL, *bmap = NULL, *fbmap = NULL;