From 5d219697bfc8aef860cdc13fa71377aef11ae749 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 22 Jul 2009 13:39:07 +0000 Subject: [PATCH] That optimisation sucked. Reverted median filter to something that works both on Linux and Windows. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3564 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/filter/median.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/pipi/filter/median.c b/pipi/filter/median.c index 14f4c5f..c63462d 100644 --- a/pipi/filter/median.c +++ b/pipi/filter/median.c @@ -26,15 +26,12 @@ #include "pipi.h" #include "pipi_internals.h" -static int cmpint(void const *i1, void const *i2) +static int cmpdouble(void const *i1, void const *i2) { - /* On Linux amd64, this is 20 to 30 % faster than using a real - * comparison (which wouldn't work on Windows since it expects both - * negative and positive values), a ternary operator, or floats instead - * of doubles. */ - union { int32_t i; double d; } u; - u.d = *(double const *)i1 - *(double const *)i2; - return u.i; + double a = *(double const *)i1; + double b = *(double const *)i2; + + return (a > b) - (a < b); } pipi_image_t *pipi_median(pipi_image_t *src, int radius) @@ -109,12 +106,12 @@ pipi_image_t *pipi_median_ext(pipi_image_t *src, int rx, int ry) } /* Sort the list */ - qsort(list, size, sizeof(double), cmpint); + qsort(list, size, sizeof(double), cmpdouble); if(!gray) { - qsort(list + size, size, sizeof(double), cmpint); - qsort(list + 2 * size, size, sizeof(double), cmpint); - qsort(list + 3 * size, size, sizeof(double), cmpint); + qsort(list + size, size, sizeof(double), cmpdouble); + qsort(list + 2 * size, size, sizeof(double), cmpdouble); + qsort(list + 3 * size, size, sizeof(double), cmpdouble); } /* Store the median value */