Browse Source

Isolate blur implementation to a function.

This will allow easier switching between naive/SSE2/AVX implementations.
master
Sebastian Frysztak 8 years ago
parent
commit
ade9a20788
  1. 39
      blur.c
  2. 4
      blur.h

39
blur.c

@ -22,9 +22,7 @@
*/ */
#include <math.h> #include <math.h>
#include <stdint.h> #include "blur.h"
#include <stdio.h>
#include <cairo.h>
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
@ -35,13 +33,7 @@ blur_image_surface (cairo_surface_t *surface, int radius)
cairo_surface_t *tmp; cairo_surface_t *tmp;
int width, height; int width, height;
int src_stride, dst_stride; int src_stride, dst_stride;
int x, y, z, w; uint32_t *src, *dst;
uint8_t *src, *dst;
uint32_t *s, *d, a, p;
int i, j, k;
uint8_t kernel[17];
const int size = ARRAY_LENGTH (kernel);
const int half = size / 2;
if (cairo_surface_status (surface)) if (cairo_surface_status (surface))
return; return;
@ -71,12 +63,31 @@ blur_image_surface (cairo_surface_t *surface, int radius)
if (cairo_surface_status (tmp)) if (cairo_surface_status (tmp))
return; return;
src = cairo_image_surface_get_data (surface); src = (uint32_t*)cairo_image_surface_get_data (surface);
src_stride = cairo_image_surface_get_stride (surface); src_stride = cairo_image_surface_get_stride (surface);
dst = cairo_image_surface_get_data (tmp); dst = (uint32_t*)cairo_image_surface_get_data (tmp);
dst_stride = cairo_image_surface_get_stride (tmp); dst_stride = cairo_image_surface_get_stride (tmp);
blur_impl_naive(src, dst, width, height, src_stride, dst_stride, 10000);
cairo_surface_destroy (tmp);
cairo_surface_flush (surface);
cairo_surface_mark_dirty (surface);
}
void blur_impl_naive(uint32_t* _src, uint32_t* _dst, int width, int height, int src_stride, int dst_stride, int radius)
{
int x, y, z, w;
uint32_t *s, *d, a, p;
int i, j, k;
uint8_t kernel[17];
const int size = ARRAY_LENGTH (kernel);
const int half = size / 2;
uint8_t *src = (uint8_t*)_src;
uint8_t *dst = (uint8_t*)_dst;
a = 0; a = 0;
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
double f = i - half; double f = i - half;
@ -135,9 +146,5 @@ blur_image_surface (cairo_surface_t *surface, int radius)
d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a; d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
} }
} }
cairo_surface_destroy (tmp);
cairo_surface_flush (surface);
cairo_surface_mark_dirty (surface);
} }

4
blur.h

@ -1,7 +1,11 @@
#ifndef _BLUR_H #ifndef _BLUR_H
#define _BLUR_H #define _BLUR_H
#include <stdint.h>
#include <cairo.h>
void blur_image_surface (cairo_surface_t *surface, int radius); void blur_image_surface (cairo_surface_t *surface, int radius);
void blur_impl_naive(uint32_t* src, uint32_t* dst, int width, int height, int src_stride, int dst_stride, int radius);
#endif #endif

Loading…
Cancel
Save