| 531 | typedef struct BUCKET { ILubyte Colours[4]; struct BUCKET *Next; } BUCKET; |
| 532 | |
| 533 | ILuint ILAPIENTRY iluColoursUsed() |
| 534 | { |
| 535 | ILuint i, c, Bpp, ColVal, SizeData, BucketPos = 0, NumCols = 0; |
| 536 | BUCKET Buckets[8192], *Temp; |
| 537 | ILubyte ColTemp[4]; |
| 538 | ILboolean Matched; |
| 539 | BUCKET *Heap[9]; |
| 540 | ILuint HeapPos = 0, HeapPtr = 0, HeapSize; |
| 541 | |
| 542 | imemclear(Buckets, sizeof(BUCKET) * 8192); |
| 543 | for (c = 0; c < 9; c++) { |
| 544 | Heap[c] = 0; |
| 545 | } |
| 546 | |
| 547 | iluCurImage = ilGetCurImage(); |
| 548 | if (iluCurImage == NULL) { |
| 549 | ilSetError(ILU_ILLEGAL_OPERATION); |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | Bpp = iluCurImage->Bpp; |
| 554 | SizeData = iluCurImage->SizeOfData; |
| 555 | |
| 556 | // Create our miniature memory heap. |
| 557 | // I have determined that the average number of colours versus |
| 558 | // the number of pixels is about a 1:8 ratio, so divide by 8. |
| 559 | HeapSize = IL_MAX(1, iluCurImage->SizeOfData / iluCurImage->Bpp / 8); |
| 560 | Heap[0] = (BUCKET*)ialloc(HeapSize * sizeof(BUCKET)); |
| 561 | if (Heap[0] == NULL) |
| 562 | return IL_FALSE; |
| 563 | |
| 564 | for (i = 0; i < SizeData; i += Bpp) { |
| 565 | *(ILuint*)ColTemp = 0; |
| 566 | /*for (c = 0; c < Bpp; c++) { |
| 567 | ColTemp[c] = iluCurImage->Data[i + c]; |
| 568 | }*/ |
| 569 | ColTemp[0] = iluCurImage->Data[i]; |
| 570 | if (Bpp > 1) { |
| 571 | ColTemp[1] = iluCurImage->Data[i + 1]; |
| 572 | ColTemp[2] = iluCurImage->Data[i + 2]; |
| 573 | } |
| 574 | if (Bpp > 3) |
| 575 | ColTemp[3] = iluCurImage->Data[i + 3]; |
| 576 | |
| 577 | BucketPos = *(ILuint*)ColTemp % 8192; |
| 578 | |
| 579 | // Add to hash table |
| 580 | if (Buckets[BucketPos].Next == NULL) { |
| 581 | NumCols++; |
| 582 | //Buckets[BucketPos].Next = (BUCKET*)ialloc(sizeof(BUCKET)); |
| 583 | Buckets[BucketPos].Next = Heap[HeapPos] + HeapPtr++; |
| 584 | if (HeapPtr >= HeapSize) { |
| 585 | Heap[++HeapPos] = (BUCKET*)ialloc(HeapSize * sizeof(BUCKET)); |
| 586 | if (Heap[HeapPos] == NULL) |
| 587 | goto alloc_error; |
| 588 | HeapPtr = 0; |
| 589 | } |
| 590 | *(ILuint*)Buckets[BucketPos].Next->Colours = *(ILuint*)ColTemp; |
nothing calls this directly
no test coverage detected