( achv, colors, sum, maxval, newcolors )
| 271 | */ |
| 272 | |
| 273 | static acolorhist_vector |
| 274 | mediancut( achv, colors, sum, maxval, newcolors ) |
| 275 | acolorhist_vector achv; |
| 276 | int colors, sum, newcolors; |
| 277 | unsigned char maxval; |
| 278 | { |
| 279 | acolorhist_vector acolormap; |
| 280 | box_vector bv; |
| 281 | register int bi, i; |
| 282 | int boxes; |
| 283 | |
| 284 | bv = (box_vector) malloc( sizeof(struct box) * newcolors ); |
| 285 | acolormap = |
| 286 | (acolorhist_vector) malloc( sizeof(struct acolorhist_item) * newcolors); |
| 287 | if ( bv == (box_vector) 0 || acolormap == (acolorhist_vector) 0 ) { |
| 288 | fprintf( stderr, " out of memory allocating box vector\n" ); |
| 289 | fflush(stderr); |
| 290 | exit(6); |
| 291 | } |
| 292 | for ( i = 0; i < newcolors; ++i ) |
| 293 | PAM_ASSIGN( acolormap[i].acolor, 0, 0, 0, 0 ); |
| 294 | |
| 295 | /* |
| 296 | ** Set up the initial box. |
| 297 | */ |
| 298 | bv[0].ind = 0; |
| 299 | bv[0].colors = colors; |
| 300 | bv[0].sum = sum; |
| 301 | boxes = 1; |
| 302 | |
| 303 | /* |
| 304 | ** Main loop: split boxes until we have enough. |
| 305 | */ |
| 306 | while ( boxes < newcolors ) { |
| 307 | register int indx, clrs; |
| 308 | int sm; |
| 309 | register int minr, maxr, ming, mina, maxg, minb, maxb, maxa, v; |
| 310 | int halfsum, lowersum; |
| 311 | |
| 312 | /* |
| 313 | ** Find the first splittable box. |
| 314 | */ |
| 315 | for ( bi = 0; bi < boxes; ++bi ) |
| 316 | if ( bv[bi].colors >= 2 ) |
| 317 | break; |
| 318 | if ( bi == boxes ) |
| 319 | break; /* ran out of colors! */ |
| 320 | indx = bv[bi].ind; |
| 321 | clrs = bv[bi].colors; |
| 322 | sm = bv[bi].sum; |
| 323 | |
| 324 | /* |
| 325 | ** Go through the box finding the minimum and maximum of each |
| 326 | ** component - the boundaries of the box. |
| 327 | */ |
| 328 | minr = maxr = PAM_GETR( achv[indx].acolor ); |
| 329 | ming = maxg = PAM_GETG( achv[indx].acolor ); |
| 330 | minb = maxb = PAM_GETB( achv[indx].acolor ); |
no outgoing calls
no test coverage detected