------------------------------------------------------------------------------
| 711 | |
| 712 | //------------------------------------------------------------------------------ |
| 713 | void vtkTIFFReader::GetColor( |
| 714 | int index, unsigned short* red, unsigned short* green, unsigned short* blue) |
| 715 | { |
| 716 | *red = 0; |
| 717 | *green = 0; |
| 718 | *blue = 0; |
| 719 | if (index < 0) |
| 720 | { |
| 721 | vtkErrorMacro("Color index has to be greater than 0"); |
| 722 | return; |
| 723 | } |
| 724 | if (this->TotalColors > 0 && this->ColorRed && this->ColorGreen && this->ColorBlue) |
| 725 | { |
| 726 | if (index >= this->TotalColors) |
| 727 | { |
| 728 | vtkErrorMacro( |
| 729 | "Color index has to be less than number of colors (" << this->TotalColors << ")"); |
| 730 | return; |
| 731 | } |
| 732 | *red = *(this->ColorRed + index); |
| 733 | *green = *(this->ColorGreen + index); |
| 734 | *blue = *(this->ColorBlue + index); |
| 735 | return; |
| 736 | } |
| 737 | |
| 738 | unsigned short photometric; |
| 739 | |
| 740 | if (!TIFFGetField(this->InternalImage->Image, TIFFTAG_PHOTOMETRIC, &photometric)) |
| 741 | { |
| 742 | if (this->InternalImage->Photometrics != PHOTOMETRIC_PALETTE) |
| 743 | { |
| 744 | vtkErrorMacro("You can only access colors for palette images"); |
| 745 | return; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | unsigned short *red_orig, *green_orig, *blue_orig; |
| 750 | |
| 751 | switch (this->InternalImage->BitsPerSample) |
| 752 | { |
| 753 | case 1: |
| 754 | case 2: |
| 755 | case 4: |
| 756 | case 8: |
| 757 | case 16: |
| 758 | break; |
| 759 | default: |
| 760 | vtkErrorMacro( |
| 761 | "Sorry, can not image with " << this->InternalImage->BitsPerSample << "-bit samples"); |
| 762 | return; |
| 763 | } |
| 764 | if (!TIFFGetField( |
| 765 | this->InternalImage->Image, TIFFTAG_COLORMAP, &red_orig, &green_orig, &blue_orig)) |
| 766 | { |
| 767 | vtkErrorMacro("Missing required \"Colormap\" tag"); |
| 768 | return; |
| 769 | } |
| 770 | this->TotalColors = (1L << this->InternalImage->BitsPerSample); |