1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
   |  
void PixelUpSort (int width, int height, int** im, int *SortPixels)
		{
			int i, j, current, s, *idx[MAXGREYVAL], hist[MAXGREYVAL];
			int *tmp;
			/* first, we build a histogram */
			for (i=0; i<MAXGREYVAL; i++)
				hist[i] = 0;
			for (j=0; j<height; j++)
				for (i=0, tmp= im[j]; i< width; i++, tmp++)
					hist[*tmp]++;
			/* Now we compute offsets for the sorted array */
			s=0;
			for (i=0;i<MAXGREYVAL; i++)
			{ 
				idx[i] = SortPixels+s; 
				s+=hist[i];
			}
			/* Now we do the actual sorting */
			for (j=0; j<height; j++)
				for (i=0, current=j*width,tmp=im[j]; 
					i<width; i++, tmp++, current++)
					*(idx[*tmp]++) = current;
			return;
		} |