41 #include "medians_1D.h"
52 void swap(pixelvalue *a, pixelvalue *b) {
54 register pixelvalue t;
68 __attribute__((__no_instrument_function__))
75 low = 0 ; high = n-1 ; median = (low + high) / 2;
80 if (high == low + 1) {
82 swap(&a[low], &a[high]) ;
87 middle = (low + high) / 2;
88 if (a[middle] > a[high])
swap(&a[middle], &a[high]) ;
89 if (a[low] > a[high])
swap(&a[low], &a[high]) ;
90 if (a[middle] > a[low])
swap(&a[middle], &a[low]) ;
93 swap(&a[middle], &a[low+1]) ;
99 do ll++;
while (a[low] > a[ll]) ;
100 do hh--;
while (a[hh] > a[low]) ;
105 swap(&a[ll], &a[hh]) ;
109 swap(&a[low], &a[hh]) ;
128 __attribute__((__no_instrument_function__))
131 register int i,j,l,m ;
132 register pixelvalue x ;
161 __attribute__((__no_instrument_function__))
176 __attribute__((__no_instrument_function__))
179 int i, less, greater, equal, half;
180 pixelvalue min, max, guess, maxltguess, mingtguess;
184 for (i=1 ; i<n ; i++) {
185 if (m[i]<min) min=m[i];
186 if (m[i]>max) max=m[i];
191 less = 0; greater = 0; equal = 0;
194 for (i=0; i<n; i++) {
197 if (m[i]>maxltguess) maxltguess = m[i] ;
198 }
else if (m[i]>guess) {
200 if (m[i]<mingtguess) mingtguess = m[i] ;
203 if (less <= half && greater <= half) break ;
204 else if (less>greater) max = maxltguess ;
205 else min = mingtguess;
207 if (less >= half)
return maxltguess;
208 else if (less+equal >= half)
return guess;
209 else return mingtguess;