( apixels, cols, rows, maxacolors, acolorsP )
| 612 | |
| 613 | |
| 614 | static acolorhash_table |
| 615 | pam_computeacolorhash( apixels, cols, rows, maxacolors, acolorsP ) |
| 616 | rgbaPixel** apixels; |
| 617 | int cols, rows, maxacolors; |
| 618 | int* acolorsP; |
| 619 | { |
| 620 | acolorhash_table acht; |
| 621 | register rgbaPixel* pP; |
| 622 | acolorhist_list achl; |
| 623 | int col, row, hash; |
| 624 | |
| 625 | acht = pam_allocacolorhash( ); |
| 626 | *acolorsP = 0; |
| 627 | |
| 628 | /* Go through the entire image, building a hash table of colors. */ |
| 629 | for ( row = 0; row < rows; ++row ) |
| 630 | for ( col = 0, pP = apixels[row]; col < cols; ++col, ++pP ) |
| 631 | { |
| 632 | hash = pam_hashapixel( *pP ); |
| 633 | for ( achl = acht[hash]; achl != (acolorhist_list) 0; achl = achl->next ) |
| 634 | if ( PAM_EQUAL( achl->ch.acolor, *pP ) ) |
| 635 | break; |
| 636 | if ( achl != (acolorhist_list) 0 ) |
| 637 | ++(achl->ch.value); |
| 638 | else |
| 639 | { |
| 640 | if ( ++(*acolorsP) > maxacolors ) |
| 641 | { |
| 642 | pam_freeacolorhash( acht ); |
| 643 | return (acolorhash_table) 0; |
| 644 | } |
| 645 | achl = (acolorhist_list) malloc( sizeof(struct acolorhist_list_item) ); |
| 646 | if ( achl == 0 ) { |
| 647 | fprintf( stderr, " out of memory computing hash table\n" ); |
| 648 | exit(7); |
| 649 | } |
| 650 | achl->ch.acolor = *pP; |
| 651 | achl->ch.value = 1; |
| 652 | achl->next = acht[hash]; |
| 653 | acht[hash] = achl; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return acht; |
| 658 | } |
| 659 | |
| 660 | |
| 661 |
no test coverage detected