| 454 | } |
| 455 | |
| 456 | void pack_dxt(unsigned long *px, unsigned char *dest) |
| 457 | { |
| 458 | int i1, i2, best_ninter, err, best_err, ncolors; |
| 459 | unsigned long uniq[16]; |
| 460 | unsigned long col1, col2, best_col1, best_col2, pack; |
| 461 | unsigned char *c1, *c2; |
| 462 | unsigned short *sptr, tmpshort; |
| 463 | /* int minc1, minc2, maxc1, maxc2, cc1, cc2, step, channel; */ |
| 464 | |
| 465 | /* mark duplicate colors */ |
| 466 | ncolors=0; |
| 467 | for (i1=0;i1<16;i1++) { |
| 468 | col1 = px[i1]&0xf8fcf8; |
| 469 | for (i2=0;i2<ncolors;i2++) if (uniq[i2]==col1) break; |
| 470 | if (i2==ncolors) uniq[ncolors++] = col1; |
| 471 | } |
| 472 | |
| 473 | /* optimize over pairs of colors */ |
| 474 | if (ncolors == 1) { |
| 475 | best_col1 = uniq[0]; best_col2 = uniq[0]; best_err = 1000; best_ninter = 3; |
| 476 | } else { |
| 477 | best_err = (1<<30); |
| 478 | for (i1=0; i1<ncolors-1; i1++) |
| 479 | for (i2=i1+1; i2<ncolors; i2++) { |
| 480 | err = score_dxt(px, 2, uniq[i1], uniq[i2], &pack); |
| 481 | if (err < best_err) |
| 482 | { best_col1 = uniq[i1]; best_col2 = uniq[i2]; best_ninter = 2; best_err = err; } |
| 483 | err = score_dxt(px, 3, uniq[i1], uniq[i2], &pack); |
| 484 | if (err < best_err) |
| 485 | { best_col1 = uniq[i1]; best_col2 = uniq[i2]; best_ninter = 3; best_err = err; } |
| 486 | } |
| 487 | } |
| 488 | c1 = (unsigned char *)&col1; c2 = (unsigned char *)&col2; |
| 489 | |
| 490 | /* fudge the pair of colors */ |
| 491 | /* |
| 492 | if (best_err > 0) |
| 493 | for (channel = 0; channel<3 ; channel++) { |
| 494 | col1 = best_col1; col2 = best_col2; |
| 495 | step = (channel == 1) ? 4 : 8; |
| 496 | minc1 = maxc1 = c1[channel]; |
| 497 | minc2 = maxc2 = c2[channel]; |
| 498 | if (minc1 >= 8) minc1-=8; else minc1=0; |
| 499 | if (minc2 >= 8) minc2-=8; else minc2=0; |
| 500 | if (maxc1 <= 244) maxc1+=8; else maxc1=252; |
| 501 | if (maxc2 <= 244) maxc2+=8; else maxc2=252; |
| 502 | for (c1[channel] = cc1 = minc1; |
| 503 | cc1 <= maxc1; c1[channel]+=step, cc1+=step) |
| 504 | for (c2[channel] = cc2 = minc2; |
| 505 | cc2 <= maxc2; c2[channel]+=step, cc2+=step) { |
| 506 | err = score_dxt(px, best_ninter, col1, col2, &pack); |
| 507 | if (err < best_err) |
| 508 | { best_col1 = col1; best_col2 = col2; best_err = err; } |
| 509 | } |
| 510 | } |
| 511 | */ |
| 512 | col1 = best_col1; col2 = best_col2; |
| 513 |
no test coverage detected