Changeset 2807 for libpipi/trunk
 Timestamp:
 Aug 29, 2008, 11:55:21 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libpipi/trunk/pipi/filter/median.c
r2748 r2807 28 28 #include "pipi_internals.h" 29 29 30 static int cmpint(void const *i1, void const *i2) 31 { 32 return *(int const *)i1 > *(int const *)i2; 33 } 34 30 35 pipi_image_t *pipi_median(pipi_image_t *src, int radius) 31 36 { … … 46 51 float *srcdata, *dstdata; 47 52 double *list; 48 int x, y, w, h, i, j, k,size, gray;53 int x, y, w, h, i, j, size, gray; 49 54 50 55 w = src>w; … … 69 74 for(x = 0; x < w; x++) 70 75 { 71 double tmp;72 76 double *parser = list; 73 77 … … 91 95 else 92 96 { 93 *parser++ = srcdata[4 * (y2 * w + x2)]; 94 *parser++ = srcdata[4 * (y2 * w + x2) + 1]; 95 *parser++ = srcdata[4 * (y2 * w + x2) + 2]; 96 *parser++ = srcdata[4 * (y2 * w + x2) + 3]; 97 parser[0] = srcdata[4 * (y2 * w + x2)]; 98 parser[size * 1] = srcdata[4 * (y2 * w + x2) + 1]; 99 parser[size * 2] = srcdata[4 * (y2 * w + x2) + 2]; 100 parser[size * 3] = srcdata[4 * (y2 * w + x2) + 3]; 101 parser++; 97 102 } 98 103 } … … 100 105 101 106 /* Sort the list */ 102 for(i = 0; i < size; i++) 107 qsort(list, size, sizeof(int), cmpint); 108 if(!gray) 103 109 { 104 for(j = 0; j < i; j++) 105 { 106 if(gray) 107 { 108 if(list[i] < list[j]) 109 { 110 tmp = list[i]; 111 list[i] = list[j]; 112 list[j] = tmp; 113 } 114 } 115 else 116 { 117 for(k = 0; k < 4; k++) 118 { 119 if(list[4 * i + k] < list[4 * j + k]) 120 { 121 tmp = list[4 * i + k]; 122 list[4 * i + k] = list[4 * j + k]; 123 list[4 * j + k] = tmp; 124 } 125 } 126 } 127 } 110 qsort(list + size, size, sizeof(int), cmpint); 111 qsort(list + 2 * size, size, sizeof(int), cmpint); 112 qsort(list + 3 * size, size, sizeof(int), cmpint); 128 113 } 129 114 … … 135 120 else 136 121 { 137 dstdata[4 * (y * w + x)] = list[size / 2 * 4];138 dstdata[4 * (y * w + x) + 1] = list[size / 2 * 4 +1];139 dstdata[4 * (y * w + x) + 2] = list[size / 2 * 4 +2];140 dstdata[4 * (y * w + x) + 3] = list[size / 2 * 4 +3];122 dstdata[4 * (y * w + x)] = list[size / 2]; 123 dstdata[4 * (y * w + x) + 1] = list[size / 2 + size * 1]; 124 dstdata[4 * (y * w + x) + 2] = list[size / 2 + size * 2]; 125 dstdata[4 * (y * w + x) + 3] = list[size / 2 + size * 3]; 141 126 } 142 127 }
Note: See TracChangeset
for help on using the changeset viewer.