| 144 | // ------------------------------------------------------------------------------- |
| 145 | |
| 146 | void inxbuild() |
| 147 | { |
| 148 | ILint i,j,smallpos,smallval; |
| 149 | ILint *p,*q; |
| 150 | ILint previouscol,startpos; |
| 151 | |
| 152 | previouscol = 0; |
| 153 | startpos = 0; |
| 154 | for (i=0; i<netsizethink; i++) { |
| 155 | p = network[i]; |
| 156 | smallpos = i; |
| 157 | smallval = p[1]; // index on g |
| 158 | // find smallest in i..netsize-1 |
| 159 | for (j=i+1; j<netsizethink; j++) { |
| 160 | q = network[j]; |
| 161 | if (q[1] < smallval) { // index on g |
| 162 | smallpos = j; |
| 163 | smallval = q[1]; // index on g |
| 164 | } |
| 165 | } |
| 166 | q = network[smallpos]; |
| 167 | // swap p (i) and q (smallpos) entries |
| 168 | if (i != smallpos) { |
| 169 | j = q[0]; q[0] = p[0]; p[0] = j; |
| 170 | j = q[1]; q[1] = p[1]; p[1] = j; |
| 171 | j = q[2]; q[2] = p[2]; p[2] = j; |
| 172 | j = q[3]; q[3] = p[3]; p[3] = j; |
| 173 | } |
| 174 | // smallval entry is now in position i |
| 175 | if (smallval != previouscol) { |
| 176 | netindex[previouscol] = (startpos+i)>>1; |
| 177 | for (j=previouscol+1; j<smallval; j++) netindex[j] = i; |
| 178 | previouscol = smallval; |
| 179 | startpos = i; |
| 180 | } |
| 181 | } |
| 182 | netindex[previouscol] = (startpos+maxnetpos)>>1; |
| 183 | for (j=previouscol+1; j<256; j++) netindex[j] = maxnetpos; // really 256 |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | // Search for BGR values 0..255 (after net is unbiased) and return colour index |