summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@ppc64.localdomain>2006-03-16 16:50:29 -0500
committerZack Rusin <zack@ppc64.localdomain>2006-03-16 16:50:29 -0500
commit8304ea4eaa75de4d1de3a3e399930c56ceff78d4 (patch)
tree4b67712ddb5822952f6bf0ca5e0c8c1034fab66c
parent4a808117dc21de9c94418912666405f8cfb3754e (diff)
better blending
-rw-r--r--main.cpp6
-rw-r--r--surface.cpp38
-rw-r--r--surface.h15
-rw-r--r--utils.h1
4 files changed, 35 insertions, 25 deletions
diff --git a/main.cpp b/main.cpp
index f692233..7d415ad 100644
--- a/main.cpp
+++ b/main.cpp
@@ -88,8 +88,8 @@ test_oper(void)
x = rand() % (surf_win->w - (surf_img->w/2));
y = rand() % (surf_win->h - (surf_img->h/2));
- xrender_surf_simple_blend(disp, current_op.op,
- surf_img, surf_win, x, y, surf_img->w, surf_img->h, transformations);
+ xrender_surf_blend(disp, current_op.op,
+ surf_img, surf_win, x, y, surf_img->w, surf_img->h);
}
void
@@ -156,6 +156,8 @@ main_loop(void)
{
char buf[256];
snprintf(buf, 255, "'%s (transformation)' ", current_op.name);
+ xrender_surf_prepare(disp, surf_img, surf_img->w, surf_img->h, transformations,
+ SurfaceBilinear);
time_test(buf, test_oper);
current_op = all_render_ops[i++];
XSync(disp, False);
diff --git a/surface.cpp b/surface.cpp
index 8390d6a..51cdac9 100644
--- a/surface.cpp
+++ b/surface.cpp
@@ -100,24 +100,8 @@ xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, const QImage
}
void
-xrender_surf_blend(Display *disp, XRenderSurf *src, XRenderSurf *dst, int x, int y, int w, int h, int smooth)
-{
- //XFilters *flt;
- XTransform xf;
-
- xf.matrix[0][0] = (65536 * src->w) / (w*2); xf.matrix[0][1] = 0; xf.matrix[0][2] = 0;
- xf.matrix[1][0] = 0; xf.matrix[1][1] = (65536 * src->h) / h; xf.matrix[1][2] = 0;
- xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 65536;
- if (smooth) XRenderSetPictureFilter(disp, src->pic, "bilinear", NULL, 0);
- else XRenderSetPictureFilter(disp, src->pic, "nearest", NULL, 0);
- XRenderSetPictureTransform(disp, src->pic, &xf);
- XRenderComposite(disp, PictOpOver, src->pic, None, dst->pic, 0, 0, 0, 0, x, y, w, h);
-}
-
-
-void
-xrender_surf_simple_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *dst,
- int x, int y, int w, int h, int transformations)
+xrender_surf_prepare(Display *disp, XRenderSurf *src, int w, int h,
+ int transformations, SurfaceFilter filter)
{
if (transformations) {
XTransform xf;
@@ -125,8 +109,24 @@ xrender_surf_simple_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *
xf.matrix[0][0] = (65536 * src->w) / (w*2); xf.matrix[0][1] = 0; xf.matrix[0][2] = 0;
xf.matrix[1][0] = 0; xf.matrix[1][1] = (65536 * src->h) / h; xf.matrix[1][2] = 0;
xf.matrix[2][0] = 0; xf.matrix[2][1] = 0; xf.matrix[2][2] = 65536;
- XRenderSetPictureFilter(disp, src->pic, "nearest", NULL, 0);
XRenderSetPictureTransform(disp, src->pic, &xf);
}
+
+ switch(filter) {
+ case SurfaceBilinear:
+ XRenderSetPictureFilter(disp, src->pic, "bilinear", NULL, 0);
+ break;
+ case SurfaceNearest:
+ XRenderSetPictureFilter(disp, src->pic, "nearest", NULL, 0);
+ break;
+ default:
+ break;
+ }
+}
+
+void
+xrender_surf_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *dst,
+ int x, int y, int w, int h)
+{
XRenderComposite(disp, op, src->pic, None, dst->pic, 0, 0, 0, 0, x, y, w, h);
}
diff --git a/surface.h b/surface.h
index 0c1a191..02d8e1f 100644
--- a/surface.h
+++ b/surface.h
@@ -6,6 +6,13 @@
class QImage;
+typedef enum _SurfaceFilter {
+ SurfaceNone,
+ SurfaceNearest,
+ SurfaceBilinear,
+ SurfaceConvolution
+} SurfaceFilter;
+
typedef struct _XRenderSurf {
int w, h;
int depth;
@@ -21,9 +28,9 @@ XRenderSurf *xrender_surf_adopt(Display *disp, Drawable draw, Visual *vis, int w
void xrender_surf_free(Display *disp, XRenderSurf *rs);
void xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h,
const QImage &img_data);
-void xrender_surf_blend(Display *disp, XRenderSurf *src, XRenderSurf *dst,
- int x, int y, int w, int h, int smooth);
-void xrender_surf_simple_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *dst,
- int x, int y, int w, int h, int transformations);
+void xrender_surf_prepare(Display *disp, XRenderSurf *src, int w, int h,
+ int transformations, SurfaceFilter filter);
+void xrender_surf_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *dst,
+ int x, int y, int w, int h);
#endif
diff --git a/utils.h b/utils.h
index 0688655..fe9bd7e 100644
--- a/utils.h
+++ b/utils.h
@@ -7,6 +7,7 @@
/* number of repetitions */
#define REPS 1024
+//#define REPS 256
double get_time(void);
void time_test(char *description, void (*func) (void));