| 739 | } |
| 740 | |
| 741 | static int TestColorConvert( |
| 742 | const Triple& rgb, const Triple& hsv, const Triple& xyz, const Triple& lab, const Triple& prolab) |
| 743 | { |
| 744 | std::cout << "Ensuring the following colors are consistent: " << std::endl; |
| 745 | std::cout << " RGB: " << rgb << std::endl; |
| 746 | std::cout << " HSV: " << hsv << std::endl; |
| 747 | std::cout << " CIE XYZ: " << xyz << std::endl; |
| 748 | std::cout << " CIE-L*ab: " << lab << std::endl; |
| 749 | std::cout << " ProLAB: " << prolab << std::endl; |
| 750 | |
| 751 | Triple result1; |
| 752 | |
| 753 | #define COMPARE(testname, target, dest) \ |
| 754 | do \ |
| 755 | { \ |
| 756 | if ((target) != (dest)) \ |
| 757 | { \ |
| 758 | vtkGenericWarningMacro(<< "Incorrect " #testname " conversion. Got " << (dest) \ |
| 759 | << " expected " << (target)); \ |
| 760 | return 0; \ |
| 761 | } \ |
| 762 | } while (false) |
| 763 | |
| 764 | // Test conversion between RGB and HSV. |
| 765 | vtkMath::RGBToHSV(rgb(), result1()); |
| 766 | COMPARE(RGBToHSV, hsv, result1); |
| 767 | vtkMath::HSVToRGB(hsv(), result1()); |
| 768 | COMPARE(HSVToRGB, rgb, result1); |
| 769 | |
| 770 | vtkMath::RGBToHSV(rgb[0], rgb[1], rgb[2], &result1[0], &result1[1], &result1[2]); |
| 771 | COMPARE(RGBToHSV, hsv, result1); |
| 772 | vtkMath::HSVToRGB(hsv[0], hsv[1], hsv[2], &result1[0], &result1[1], &result1[2]); |
| 773 | COMPARE(HSVToRGB, rgb, result1); |
| 774 | |
| 775 | // Test conversion between RGB and XYZ. |
| 776 | vtkMath::RGBToXYZ(rgb(), result1()); |
| 777 | COMPARE(RGBToXYZ, xyz, result1); |
| 778 | vtkMath::XYZToRGB(xyz(), result1()); |
| 779 | COMPARE(XYZToRGB, rgb, result1); |
| 780 | |
| 781 | vtkMath::RGBToXYZ(rgb[0], rgb[1], rgb[2], &result1[0], &result1[1], &result1[2]); |
| 782 | COMPARE(RGBToXYZ, xyz, result1); |
| 783 | vtkMath::XYZToRGB(xyz[0], xyz[1], xyz[2], &result1[0], &result1[1], &result1[2]); |
| 784 | COMPARE(XYZToRGB, rgb, result1); |
| 785 | |
| 786 | // Test conversion between Lab and XYZ. |
| 787 | vtkMath::LabToXYZ(lab(), result1()); |
| 788 | COMPARE(LabToXYZ, xyz, result1); |
| 789 | vtkMath::XYZToLab(xyz(), result1()); |
| 790 | COMPARE(XYZToLab, lab, result1); |
| 791 | |
| 792 | vtkMath::LabToXYZ(lab[0], lab[1], lab[2], &result1[0], &result1[1], &result1[2]); |
| 793 | COMPARE(LabToXYZ, xyz, result1); |
| 794 | vtkMath::XYZToLab(xyz[0], xyz[1], xyz[2], &result1[0], &result1[1], &result1[2]); |
| 795 | COMPARE(XYZToLab, lab, result1); |
| 796 | |
| 797 | // Test conversion between Lab and RGB. |
| 798 | vtkMath::LabToRGB(lab(), result1()); |
no test coverage detected