浏览代码

* median.c: use the libc's qsort to find the median value. Not really the

best method anyway (see the research notes on the wiki), but now X = 8
    is faster than the previous implementation's X = 6.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2807 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 年前
父节点
当前提交
82bb59111c
共有 1 个文件被更改,包括 20 次插入35 次删除
  1. +20
    -35
      pipi/filter/median.c

+ 20
- 35
pipi/filter/median.c 查看文件

@@ -27,6 +27,11 @@
#include "pipi.h"
#include "pipi_internals.h"

static int cmpint(void const *i1, void const *i2)
{
return *(int const *)i1 > *(int const *)i2;
}

pipi_image_t *pipi_median(pipi_image_t *src, int radius)
{
return pipi_median_ext(src, radius, radius);
@@ -45,7 +50,7 @@ pipi_image_t *pipi_median_ext(pipi_image_t *src, int rx, int ry)
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
double *list;
int x, y, w, h, i, j, k, size, gray;
int x, y, w, h, i, j, size, gray;

w = src->w;
h = src->h;
@@ -68,7 +73,6 @@ pipi_image_t *pipi_median_ext(pipi_image_t *src, int rx, int ry)
{
for(x = 0; x < w; x++)
{
double tmp;
double *parser = list;

/* Make a list of neighbours */
@@ -90,41 +94,22 @@ pipi_image_t *pipi_median_ext(pipi_image_t *src, int rx, int ry)
}
else
{
*parser++ = srcdata[4 * (y2 * w + x2)];
*parser++ = srcdata[4 * (y2 * w + x2) + 1];
*parser++ = srcdata[4 * (y2 * w + x2) + 2];
*parser++ = srcdata[4 * (y2 * w + x2) + 3];
parser[0] = srcdata[4 * (y2 * w + x2)];
parser[size * 1] = srcdata[4 * (y2 * w + x2) + 1];
parser[size * 2] = srcdata[4 * (y2 * w + x2) + 2];
parser[size * 3] = srcdata[4 * (y2 * w + x2) + 3];
parser++;
}
}
}

/* Sort the list */
for(i = 0; i < size; i++)
qsort(list, size, sizeof(int), cmpint);
if(!gray)
{
for(j = 0; j < i; j++)
{
if(gray)
{
if(list[i] < list[j])
{
tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
else
{
for(k = 0; k < 4; k++)
{
if(list[4 * i + k] < list[4 * j + k])
{
tmp = list[4 * i + k];
list[4 * i + k] = list[4 * j + k];
list[4 * j + k] = tmp;
}
}
}
}
qsort(list + size, size, sizeof(int), cmpint);
qsort(list + 2 * size, size, sizeof(int), cmpint);
qsort(list + 3 * size, size, sizeof(int), cmpint);
}

/* Store the median value */
@@ -134,10 +119,10 @@ pipi_image_t *pipi_median_ext(pipi_image_t *src, int rx, int ry)
}
else
{
dstdata[4 * (y * w + x)] = list[size / 2 * 4];
dstdata[4 * (y * w + x) + 1] = list[size / 2 * 4 + 1];
dstdata[4 * (y * w + x) + 2] = list[size / 2 * 4 + 2];
dstdata[4 * (y * w + x) + 3] = list[size / 2 * 4 + 3];
dstdata[4 * (y * w + x)] = list[size / 2];
dstdata[4 * (y * w + x) + 1] = list[size / 2 + size * 1];
dstdata[4 * (y * w + x) + 2] = list[size / 2 + size * 2];
dstdata[4 * (y * w + x) + 3] = list[size / 2 + size * 3];
}
}
}


正在加载...
取消
保存